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

Tunable CCL global settings at the Python-level #918

Merged
merged 52 commits into from
Aug 2, 2022

Conversation

nikfilippas
Copy link
Contributor

@nikfilippas nikfilippas commented Feb 7, 2022

This PR decouples the (otherwise connected at the C level) CCL accuracy parameters from Cosmology objects, at the Python level.

In a new module parameters.py I have implemented the class CCLParameters which wraps the SWIG-generated classes for the spline parameters, the GSL parameters, and the physical constants.

In the spirit of making Cosmology objects truly immutable (which they ought to be) I have deprecated the option to mutate the accuracy parameters of any instantiated Cosmology: all new instances are populated with the global parameters at the time they are created.

Users can access (and set) the global parameters using ccl.gsl_params, ccl.spline_params, and ccl.physical_constants.

To do this I removed the const type definition of the C-level spline and GSL parameters, so they are added in ccllib.cvar by SWIG. Physical constants were already mutable (because T_CMB is temporarily mutated in Cosmology).

This feature comes with the advantage that we can remove all dummy cosmologies from the codebase. Every time we need one just to look up the accuracy parameters, we can just peek at the parameters at the time of instantiation, if a Cosmology is not provided.

Maybe it's also worth considering having something like ccl.spline_params.set_accuracy("high" | "medium" | "low") with pre-made parameter sets. High accuracy would be what is expected from LSST-like analyses with slower computation, while low accuracy will give a considerable increase in speed. This is one of the things mentioned in #588.

@nikfilippas nikfilippas linked an issue Feb 7, 2022 that may be closed by this pull request
@coveralls
Copy link

coveralls commented Feb 8, 2022

Pull Request Test Coverage Report for Build 2781756053

  • 131 of 131 (100.0%) changed or added relevant lines in 13 files are covered.
  • 3 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.06%) to 97.307%

Files with Coverage Reduction New Missed Lines %
pyccl/halos/profiles.py 3 99.11%
Totals Coverage Status
Change from base Build 2781374318: 0.06%
Covered Lines: 4770
Relevant Lines: 4902

💛 - Coveralls

@tilmantroester
Copy link
Contributor

@nikfilippas Do you want to rebase/merge master and I then rewrite the warning to match the new gsl_params setup?

Copy link
Collaborator

@damonge damonge left a comment

Choose a reason for hiding this comment

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

OK, thanks a lot @nikfilippas . First review. Main thing is you need to explain to me this object business you're using in parameters.py

benchmarks/test_tracers.py Show resolved Hide resolved
pyccl/__init__.py Outdated Show resolved Hide resolved
pyccl/boltzmann.py Show resolved Hide resolved
pyccl/errors.py Show resolved Hide resolved
pyccl/pk2d.py Show resolved Hide resolved
pyccl/parameters.py Show resolved Hide resolved
pyccl/parameters.py Show resolved Hide resolved
pyccl/parameters.py Show resolved Hide resolved
pyccl/parameters.py Show resolved Hide resolved
pyccl/parameters.py Show resolved Hide resolved
Copy link
Collaborator

@damonge damonge left a comment

Choose a reason for hiding this comment

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

Ok, a couple of new comments and a couple old ones remaining.

One overall comment: in an ideal world I'd have preferred to start by cleaning up the C layer so actually none of this need to live there. This would simplify a lot of the code you've had to add here, but c'est la vie. I think this is what we'll do in the future.

pyccl/parameters.py Show resolved Hide resolved
src/ccl_core.c Show resolved Hide resolved
@nikfilippas
Copy link
Contributor Author

nikfilippas commented Jul 6, 2022

@damonge back to you. I agree with your overall comment. CCL has to be re-written in C++ like @tilmantroester has suggested, but changing the entire internal structure will require a lot of work. And at that point, why not simply write the whole thing in a language like Julia and just use the Python layer as a lightweight wrapper. This PR does the job in what I believe is an elegant way, but at some point how CCL handles the parameters needs to change.

pyccl/ccl_core.i Outdated Show resolved Hide resolved
pyccl/parameters.py Show resolved Hide resolved
@damonge
Copy link
Collaborator

damonge commented Aug 1, 2022

@tilmantroester @nikfilippas are we happy to leave C-level modifications for a future PR and merge this one? If so, I can approve.

@nikfilippas
Copy link
Contributor Author

@damonge I think there is consensus now.

@damonge
Copy link
Collaborator

damonge commented Aug 2, 2022

@nikfilippas can you resolve the conflicts? I'll approve then when the tests pass.

@nikfilippas
Copy link
Contributor Author

@damonge Done.

Copy link
Collaborator

@damonge damonge left a comment

Choose a reason for hiding this comment

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

LGTM!

@nikfilippas nikfilippas merged commit 71f8d34 into master Aug 2, 2022
@nikfilippas nikfilippas deleted the global_ccl_params branch August 2, 2022 11:44
@nikfilippas nikfilippas mentioned this pull request Mar 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should global settings live outside of the cosmo object?
4 participants