Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TEP006] Aggregate TARDIS restructure and configuration system cleanup #652

Merged
merged 127 commits into from
Dec 20, 2016

Conversation

ftsamis
Copy link
Member

@ftsamis ftsamis commented Aug 18, 2016

This is an aggregate of:

@@ -14,11 +14,11 @@
class BasePlasma(object):

outputs_dict = {}
def __init__(self, plasma_properties, **kwargs):
def __init__(self, plasma_properties, property_args=None, **kwargs):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ftsamis that looks awesome! I'm wondering if we should call this property_kwargs? But if you think args is better let's go with this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, property_kwargs is a better name. Done

@wkerzendorf
Copy link
Member

@tardis-sn/tardis-core I would like to have as many collaboration members as possible look over this. This is a major change, but seemingly has passed all the tests for now.

logger = logging.getLogger(__name__)


class Radial1DModel(object):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing documentation. This needs to be fixed here or as an issue
it's not clear what the different attributes are and how the class works.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

from tardis.util import quantity_linspace


class HomologousDensity(object):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here - documentation missing and explanation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

self.density_0 = density_0
self.time_0 = time_0

def after_time(self, time_explosion):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not clear if this function name is clear - @tardis-sn/tardis-core ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @wkerzendorf

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Propose an alternative.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

calculate_density_evolution? @chvogl If no other alternative in the next hour just use that and we are done!!

Copy link
Contributor

@chvogl chvogl Dec 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think something like calculate_density_at_time_of_simulation would be more comprehensible.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't like long names, but done.

time_explosion).cgs

@classmethod
def from_config(cls, config):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

documentation missing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Also for all other from_config classmethods.

@@ -110,29 +120,30 @@ def legacy_update_spectrum(self, no_of_virtual_packets):
self.spectrum_virtual.update_luminosity(
self.montecarlo_virtual_luminosity)

def run(self, model, no_of_packets, no_of_virtual_packets=0, nthreads=1,last_run=False):
def run(self, model, plasma, no_of_packets, no_of_virtual_packets=0, nthreads=1,last_run=False):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should fix the documentation here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

exptau = 1 - np.exp(-
runner.line_lists_tau_sobolevs.reshape(-1,
runner.j_estimator.shape[0]) )
model.Edotlu = Edotlu_norm_factor*exptau*runner.Edotlu_estimator
runner.Edotlu = Edotlu_norm_factor*exptau*runner.Edotlu_estimator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP 8 violation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope for this PR. Introduced in #595.

@wkerzendorf wkerzendorf requested review from chvogl and removed request for yeganer December 16, 2016 09:41

mean_densities = mean_densities[inner_boundary_index:outer_boundary_index]

time_of_model,velocity, unscaled_mean_densities = file_parsers[filetype](filename)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8 Violation

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!

self.density_0 = density_0
self.time_0 = time_0

def after_time(self, time_explosion):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @wkerzendorf

if d_conf.type == 'branch85_w7':
density_0 = calculate_power_law_density(v_middle, d_conf.w7_v_0,
d_conf.w7_rho_0, -7)
return cls(density_0, d_conf.w7_time_0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nicer to have the returns outside the if statements. Just set time_0 equal to d_conf.w7_time_0 for this case and move the return to the end.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. Fixed.

def calculate_power_law_density(velocities, velocity_0, rho_0, exponent):
"""

This function computes a descret exponential density profile.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope for this PR, introduced in #26.

self.packet_source = packet_source.BlackBodySimpleSource(seed)
self.spectrum_frequency = spectrum_frequency
self.virtual_spectrum_range = virtual_spectrum_range # TODO: linspace handling
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is still relevant it would be nice to make an issue out of this. Otherwise just remove the TODO.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is closely related to #644. I removed the TODO comment for now. Fixed.

def from_config(cls, config):
if config.plasma.disable_electron_scattering:
logger.warn('Disabling electron scattering - this is not physical')
sigma_thomson = 1e-200 / (u.cm ** 2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cross sections have units of (length)**2.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic was actually copied as-is from current master:

validated_config_dict['montecarlo']['sigma_thomson'] = 6.652486e-25 / (u.cm ** 2)
.

Since I don't really know what sigma_thomson or cross sections are in this context, I'd like a confirmation on if we should change that. @wkerzendorf?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After some digging in the code, it seems that the unit of sigma_thomson is completely ignored afterwards, since cmontecarlo uses just its value. So, neither the wrong unit, neither correcting it would affect the computations in any way, which means it is probably safe to fix this by directly using, as @chvogl proposed, the astropy.constants.sigma_T.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed as proposed.

sigma_thomson = 1e-200 / (u.cm ** 2)
else:
logger.debug("Electron scattering switched on")
sigma_thomson = 6.652486e-25 / (u.cm ** 2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should use the Thomson scattering cross-section from astropy (astropy.constants.sigma_T) instead of hardcoding the value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same answer as above. @wkerzendorf. On your second comment, if there is a constant for that it seems perfectly reasonable to use it as far as I am concerned.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed as proposed.


return cls(seed=config.montecarlo.seed,
spectrum_frequency=spectrum_frequency,
# TODO: Linspace handling for virtual_spectrum_range
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make an issue out of this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the TODO comment. Fixed.

Copy link
Contributor

@unoebauer unoebauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had a very quick look at it - looks very impressive to me, good job @ftsamis! Apart from the legacy support thing (the violation of which I am ok with), nothing stuck out. I am all for merging and closing this chapter.


return radial1d_mdl
return simulation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break existing scripts which expect that radial1d_mdl is returned by run_tardis.

I am tempted to swallow this and will update e.g. tardisanalysis.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is true, although having the entire simulation object returned is much more useful and takes the need to duplicate information, which we heavily did until now, i.e. copying various stuff to model.

So, swallowing this would be a fair trade-off, I believe. ☺

@wkerzendorf
Copy link
Member

@ftsamis undo the last change. this breaks the tests - we shouldn't do this in this PR.

@ftsamis
Copy link
Member Author

ftsamis commented Dec 20, 2016

@wkerzendorf That's because I forgot to convert sigma_T to cgs. I agree though that this could be best done in a different PR, so I reverted the change.

Edit: I had converted sigma_T to cgs. No idea what caused the tests to fail.

@wkerzendorf
Copy link
Member

@ftsamis congratulations - I'm merging this now.

@wkerzendorf wkerzendorf merged commit b77b9e1 into tardis-sn:master Dec 20, 2016
@ftsamis ftsamis deleted the restructure-aggregate branch December 20, 2016 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants