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

camb.model.*Params attributes default to zero #50

Open
tilmantroester opened this issue Jul 22, 2019 · 3 comments
Open

camb.model.*Params attributes default to zero #50

tilmantroester opened this issue Jul 22, 2019 · 3 comments

Comments

@tilmantroester
Copy link
Contributor

When creating a new instance of one of the camb.model.*Params classes, the attributes are set to zero by default instead of the sensible defaults in model.f90. For example, in case of camb.model.AccuracyParams:

>>> import camb
>>> acc = camb.model.AccuracyParams()
>>> print(acc)
class: <AccuracyParams>
 AccuracyBoost = 0.0
 lSampleBoost = 0.0
 lAccuracyBoost = 0.0
 AccuratePolarization = False
 AccurateBB = False
 AccurateReionization = False
 TimeStepBoost = 0.0
 BackgroundTimeStepBoost = 0.0
 IntTolBoost = 0.0
 SourcekAccuracyBoost = 0.0
 IntkAccuracyBoost = 0.0
 TransferkBoost = 0.0
 NonFlatIntAccuracyBoost = 0.0
 BessIntBoost = 0.0
 LensingBoost = 0.0
 NonlinSourceBoost = 0.0
 BesselBoost = 0.0
 LimberBoost = 0.0
 SourceLimberBoost = 0.0
 KmaxBoost = 0.0
 neutrino_q_boost = 0.0```

This then leads to obscure errors when computing anything. It would be nice if the python class gets populated with the Fortran defaults or at least that an error is thrown if not all attributes are specified.
@cmbant
Copy link
Owner

cmbant commented Jul 22, 2019

I agree it is odd. But currently only objects descended from F2003Class can be expected to initialize as the Fortran in python generated instances. It wasn't really intended that people make separate instances of CAMBstructure types as these are basically just standard ctypes memory and only used as elements of containing F2003Class instances. I think the only obvious solution is to convert all CAMBstructure types to F2003Class or add custom init methods for each subclass declared. For me this is not a priority, but happy to consider pull requests if you think it would be useful.

@tilmantroester
Copy link
Contributor Author

For now I've just avoided the use of the CAMBstructure derived classes. At some point it would be nice to be able to create instances to pass to camb.model.CAMBparams without having to maintain a list of default values (which might diverge from the CAMB ones over time).

Would replacing CAMBstructure with F2003Class and adding the @fortran_class decorator and a _fortran_class_name_ class attribute be all that needs to be done?

@cmbant
Copy link
Owner

cmbant commented Jul 25, 2019

You’d have to modify the corresponding fortran class as well adding required defining methods, and make the component allocatable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants