-
Notifications
You must be signed in to change notification settings - Fork 22
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
Make signature for SupernovaModel.get_*_spectra
uniform for all models/subclasses
#223
Comments
For Regarding the “optional” section: |
Thanks for pointing to these issues, I somehow missed them. Having
I would leave that question to the models authors/implementers. If they provide such an option, SNEWPY interface should be capable of using it. |
There are other means of improving the performance, in particular using the vectorized calculations instead of python loops (for example #221). As I showed in my previous take on this in #152 , this will speed up our calculation at least ~5 times, so this 40% benefit might not be that dramatic now? |
Those speedups are certainly useful, but could easily be canceled out if we go from 4 to 6 flavours in a future version, add a model with finer time binning, etc.
No. But even if they do, I’m not sure how adding |
It makes our base class interface (methods signature) consistent with the children classes. If in the base class you define some interface it is a convention, a protocol all the children classes must follow. Having it otherwise makes a lot of confusion and removes any sense of deriving from the base class - and that's what we have now.
Exactly as you say: class SupernovaModel:
...
def get_initial_spectra(self, t, E, **kwargs):
...
def get_transformed_spectra(self, t, E, flavor_xform, **kwargs):
spectra = self.get_initial_spectra(t, E, **kwargs) #passing all the extra arguments here
class ComplicatedModel:
...
def get_initial_spectra(self, t, E, *, important_parameter, other_parameter):
... Then calling I don't see why would that not work any arguments, other then |
Python not being strict about this is, in my eyes, a feature; not a bug. I agree that this flexibility can, in principle, be abused to write confusing code; but in this case, I see very little risk of any developer being confused by that additional However, I have a slightly more serious issue with this as well: Adding
For example, it wouldn’t work for the |
What we have now
The signature signatures for these functions in the base
SupernovaModel
class are:snewpy/python/snewpy/models/base.py
Line 99 in b353799
snewpy/python/snewpy/models/base.py
Line 126 in b353799
Currently most of the models conform to the base signatures, but some models require additional parameters, like
Fornax*
:snewpy/python/snewpy/models/ccsn.py
Line 664 in b353799
Why is it bad
Having different signatures in base and children classes might lead to confusion and errors. In the Fornax2019 case, for example, there is no way to pass the additional parameters to the
get_transformed_spectra
, so running the following code:results in
What I suggest
Add the
**kwargs
argument to the signatures:Optional (subjective opinion)
Method
get_initial_spectra
hasflavors
argument, which is not present inget_transformed_spectra
. This also adds some confusion - as a user I would expect that these methods have the same arguments, apart from theflavor_xform
.I see no need to pass flavors to
get_initial_spectra
- if a user needs only specific flavors, he can just filter what he needs from the output.So I would even go for
The text was updated successfully, but these errors were encountered: