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

Additional halos features #1068

Merged
merged 6 commits into from
Apr 17, 2023
Merged

Additional halos features #1068

merged 6 commits into from
Apr 17, 2023

Conversation

nikfilippas
Copy link
Contributor

This is a rebased copy of 1065.

I brought the extra stuff from 1064 to here, so that we keep the other PR as clean as possible, and this PR also defines a library-level control to turn on/off the custom __eq__ methods, just as we had with the __repr__ methods.

Old Description

The main change this PR introduces, is to make mass_def an optional argument in HMCalculator because if mass_function and halo_bias are passed as instances (rather than str) we can just use their own mass_def. We can do that because some lines below we enforce that all mass_defs are equal.
So an HMCalculator can be instantiated in one of the following ways:

## From strings
# hmc way 1
hmc = ccl.halos.HMCalculator(mass_function="Tinker10", halo_bias="Tinker10", mass_def="200c")


## From instances
# Initialize instances
# instances way 1
mdef = ccl.halos.MassDef200c()
hmf = ccl.halos.MassFunctionTinker10(mass_def=mdef)  # mass_def can also be a string
hbf = ccl.halos.HaloBiasTinker10(mass_def=mdef)      # mass_def can also be a string

# instances way 2
hmf = ccl.halos.MassFunc.from_name("Tinker10")(mass_def="200c")  # mass_def can also be an instance
hbf = ccl.halos.HaloBias.from_name("Tinker10")(mass_def="200c")  # mass_def can also be an instance

# instances way 3
hmf = ccl.halos.MassFunc.create_instance("Tinker10", mass_def="200c")  # mass_def can also be an instance
hbf = ccl.halos.HaloBias.create_instance("Tinker10", mass_def="200c")  # mass_def can also be an instance

# hmc way 2
hmc = ccl.halos.HMCalculator(mass_function=hmf, halo_bias=hbf, mass_def=mdef)

# hmc way 3
hmc = ccl.halos.HMCalculator(mass_function=hmf, halo_bias=hbf)

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.

Small things

raise ValueError(f"Unknown Delta type {Delta}.")
if isinstance(Delta, str):
if Delta.isdigit():
Delta = int(Delta)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are you allowing for people to pass numbers as strings?

Copy link
Contributor Author

@nikfilippas nikfilippas Apr 17, 2023

Choose a reason for hiding this comment

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

It's mainly for our convenience, so that a mass definition can be insantiated using MassDef.from_name("300c").
It takes less lines of code to convert a string to digit than splitting up the string, checking if it can be converted to digit, and then converting it to one.
Internally "300c" becomes 2 strings: "300" and "c". So doesn't hurt to make this feature public.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately there is no string method that checks for floats, only for integers.
So MassDef.from_name("350.4c") won't work. I can make it work but it will be a couple more lines for very little benefit I reckon.

if isinstance(mass_function, str) or isinstance(halo_bias, str):
raise ValueError("Need to provide mass_def if mass_function "
"or halo_bias are str.")
self.mass_def = mass_function.mass_def
Copy link
Collaborator

Choose a reason for hiding this comment

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

I haven't seen a test for this, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added tests

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.

merge if tests pass

@nikfilippas nikfilippas merged commit 3fad2e1 into halos_v3 Apr 17, 2023
@nikfilippas nikfilippas deleted the additional_halos_features branch April 17, 2023 17:46
nikfilippas added a commit that referenced this pull request Apr 17, 2023
* ported changes in halos/profiles

* changes from star in halos/ (no tests)

* refactor concentration, mass_function, halo_bias; improvements in HMCalculator

* HaloProfile subclasses & HaloProfile.normprof attribute

* simplify imports

* remove HaloProfile.name

* cleaned up pk_Npt

* add extrap_pk argument

* FFTLogParams class instead of dictionary in HaloProfile

* simplified code

* removed mass_def from HMIngredients; comprehensive code review 1

* re-implementation, bugfixes, tests

* c_m_relation >> concentration; code improvements; A_SPLINE_MAX in Python

* HMIngredients initializers - no repeated code

* rogue file

* patch for new changes

* updated Build Status badge website

* fix websites

* added a DOI badge & links

* added nonbreaking space

* removed extra space

* FancyRepr out of CCLObject to simplify

* update tests to match changes

* coverage

* simple test for tkkssc

* more tests for tkkssc

* addressed comments 1

* addressed comments 2: mass_def defaults are name strings etc.

* deprecate Gaussian & PowerLaw profiles

* bugfix in master: sometimes mass_def_strict=False fails unexpectedly

* typo

* addressed comments

* New feature: Arbitrary function for profile normalization

* gain efficiency

* comments + deprecate k_min from HMCalculator

* renamed initialize_from_input --> create_instance

* brought in CCLNamedClass from docs_v3

* brought in from docs_v3: directly callable HMIngredients

* prep for Davids input

* renamed HMCalculator --> HaloModel

* fix typo

* brought in from docs_v3: initialize mass_def from any string (e.g. 400c)

* Revert "renamed HMCalculator --> HaloModel"

This reverts commit 43591ce.

* counterterms func inside of 4pt func

* replace deprecated abstractproperty

* abstract linked methods for HaloProfile, MassFunc, HaloBias, Concentration

* fully working implementation

* renamed lM --> log10M etc.

* minor cosmetic fix

* alternative way to include linked abstract methods and declare the template methods

* reorder

* even simpler

* bring back eq_attrs

* r -> r_t

* Additional halos features (#1068)

* first commit

* enclose classmethods in the class

* brought in minor improvements to halos

* coverage
@nikfilippas nikfilippas mentioned this pull request Apr 20, 2023
34 tasks
nikfilippas added a commit that referenced this pull request Apr 21, 2023
* ported changes in halos/profiles

* changes from star in halos/ (no tests)

* refactor concentration, mass_function, halo_bias; improvements in HMCalculator

* HaloProfile subclasses & HaloProfile.normprof attribute

* simplify imports

* remove HaloProfile.name

* cleaned up pk_Npt

* add extrap_pk argument

* FFTLogParams class instead of dictionary in HaloProfile

* simplified code

* removed mass_def from HMIngredients; comprehensive code review 1

* re-implementation, bugfixes, tests

* c_m_relation >> concentration; code improvements; A_SPLINE_MAX in Python

* HMIngredients initializers - no repeated code

* rogue file

* patch for new changes

* updated Build Status badge website

* fix websites

* added a DOI badge & links

* added nonbreaking space

* removed extra space

* FancyRepr out of CCLObject to simplify

* update tests to match changes

* coverage

* simple test for tkkssc

* more tests for tkkssc

* addressed comments 1

* addressed comments 2: mass_def defaults are name strings etc.

* deprecate Gaussian & PowerLaw profiles

* bugfix in master: sometimes mass_def_strict=False fails unexpectedly

* typo

* addressed comments

* New feature: Arbitrary function for profile normalization

* gain efficiency

* comments + deprecate k_min from HMCalculator

* renamed initialize_from_input --> create_instance

* brought in CCLNamedClass from docs_v3

* brought in from docs_v3: directly callable HMIngredients

* prep for Davids input

* renamed HMCalculator --> HaloModel

* fix typo

* brought in from docs_v3: initialize mass_def from any string (e.g. 400c)

* Revert "renamed HMCalculator --> HaloModel"

This reverts commit 43591ce.

* counterterms func inside of 4pt func

* replace deprecated abstractproperty

* abstract linked methods for HaloProfile, MassFunc, HaloBias, Concentration

* fully working implementation

* renamed lM --> log10M etc.

* minor cosmetic fix

* first commit

* alternative way to include linked abstract methods and declare the template methods

* reorder

* even simpler

* enclose classmethods in the class

* brought in minor improvements to halos

* clone of 1064

* bring back eq_attrs

* r -> r_t

* Additional halos features (#1068)

* first commit

* enclose classmethods in the class

* brought in minor improvements to halos

* coverage

* removed MassConcentration

* full implementation (v3 only)

* comments

* single-liner

* coverage
damonge added a commit that referenced this pull request May 3, 2023
* halo profiles in their own directory

* concentrations in their own directory

* mass functions & halo biases in their own directory

* moved CIB stuff to profiles & 2pts

* split halo model into 1/2/4-pt

* fix imports

* remove empty module

* fix typo

* Baryons in v3 (#1039)

* Added new baryons module that will deprecate old BCM

* Tracers v3 (#1040)

* Tracers in V3

* Background, boltzmann, and cls in v3 (#1041)

* Background, boltzmann and cls in v3

* Covariances in v3 (#1046)

* Covariances in V3

* Correlations v3 (#1042)

* Correlations in v3

* split base.py and restructured into its own dir to simplify

* Neutrinos, parameters, power in v3 (#1047)

* done

* Make `T_ncdm` a cosmological parameter + (v3) (#1049)

* first commit

* rename TNCDM to T_ncdm but preserve API

* T_CMB directly into cosmo struct

* Omega_g in ccl_parameters_create; no split between C/Python

* physical_constants.T_CMB doesn't mutate anymore!

* force mutate T_CMB in benchmarks

* define defaults on instantiation just in case constants mutate

* A_s & sigma8: don't play with numbers

* simplify

* remove leftover mallocs

* temporarily preserve API for CCLv3

* Unfreeze option for `physical_constants` (#1050)

* first commit

* update rtd

* addressed comments 1

* Remove `T_CMB` and `T_ncdm` as constants (reloaded) (#1058)

* first commit

* OmNuh2 fix

* addressed comments

* keep only massive

* first step

* temp commit

* debug neutrinos & deprecate Omnuh2

* ccl_omega_x & ccl_Omeganuh2 consistency

---------

Co-authored-by: David Alonso <[email protected]>

* RTD: Removed The Docs

---------

Co-authored-by: David Alonso <[email protected]>

* flaked

---------

Co-authored-by: Nick Koukoufilippas <[email protected]>

* Pk2D and Tk3D in v3 (#1048)

* tk3d and pk2d in v3

---------

Co-authored-by: Nick Koukoufilippas <[email protected]>

* PT biases in v3 (#1056)

* New PT bias framework

* Halos v3 (#1043)

* ported changes in halos/profiles

* changes from star in halos/ (no tests)

* refactor concentration, mass_function, halo_bias; improvements in HMCalculator

* HaloProfile subclasses & HaloProfile.normprof attribute

* simplify imports

* remove HaloProfile.name

* cleaned up pk_Npt

* add extrap_pk argument

* FFTLogParams class instead of dictionary in HaloProfile

* simplified code

* removed mass_def from HMIngredients; comprehensive code review 1

* re-implementation, bugfixes, tests

* c_m_relation >> concentration; code improvements; A_SPLINE_MAX in Python

* HMIngredients initializers - no repeated code

* rogue file

* patch for new changes

* updated Build Status badge website

* fix websites

* added a DOI badge & links

* added nonbreaking space

* removed extra space

* FancyRepr out of CCLObject to simplify

* update tests to match changes

* coverage

* simple test for tkkssc

* more tests for tkkssc

* addressed comments 1

* addressed comments 2: mass_def defaults are name strings etc.

* deprecate Gaussian & PowerLaw profiles

* bugfix in master: sometimes mass_def_strict=False fails unexpectedly

* typo

* addressed comments

* New feature: Arbitrary function for profile normalization

* gain efficiency

* comments + deprecate k_min from HMCalculator

* renamed initialize_from_input --> create_instance

* brought in CCLNamedClass from docs_v3

* brought in from docs_v3: directly callable HMIngredients

* prep for Davids input

* renamed HMCalculator --> HaloModel

* fix typo

* brought in from docs_v3: initialize mass_def from any string (e.g. 400c)

* Revert "renamed HMCalculator --> HaloModel"

This reverts commit 43591ce.

* counterterms func inside of 4pt func

* replace deprecated abstractproperty

* abstract linked methods for HaloProfile, MassFunc, HaloBias, Concentration

* fully working implementation

* renamed lM --> log10M etc.

* minor cosmetic fix

* alternative way to include linked abstract methods and declare the template methods

* reorder

* even simpler

* bring back eq_attrs

* r -> r_t

* Additional halos features (#1068)

* first commit

* enclose classmethods in the class

* brought in minor improvements to halos

* coverage

* Tests v3 (#1059)

* ported changes in halos/profiles

* changes from star in halos/ (no tests)

* refactor concentration, mass_function, halo_bias; improvements in HMCalculator

* HaloProfile subclasses & HaloProfile.normprof attribute

* simplify imports

* remove HaloProfile.name

* cleaned up pk_Npt

* add extrap_pk argument

* FFTLogParams class instead of dictionary in HaloProfile

* simplified code

* removed mass_def from HMIngredients; comprehensive code review 1

* re-implementation, bugfixes, tests

* c_m_relation >> concentration; code improvements; A_SPLINE_MAX in Python

* HMIngredients initializers - no repeated code

* rogue file

* patch for new changes

* updated Build Status badge website

* fix websites

* added a DOI badge & links

* added nonbreaking space

* removed extra space

* FancyRepr out of CCLObject to simplify

* update tests to match changes

* coverage

* simple test for tkkssc

* more tests for tkkssc

* addressed comments 1

* addressed comments 2: mass_def defaults are name strings etc.

* deprecate Gaussian & PowerLaw profiles

* remove all warnings in testing

* use pytest as per docs instead of numpy.testing and pyutils.assert_warns

* bugfix in master: sometimes mass_def_strict=False fails unexpectedly

* typo

* addressed comments

* New feature: Arbitrary function for profile normalization

* gain efficiency

* comments + deprecate k_min from HMCalculator

* renamed initialize_from_input --> create_instance

* brought in CCLNamedClass from docs_v3

* brought in from docs_v3: directly callable HMIngredients

* prep for Davids input

* renamed HMCalculator --> HaloModel

* fix typo

* brought in from docs_v3: initialize mass_def from any string (e.g. 400c)

* Revert "renamed HMCalculator --> HaloModel"

This reverts commit 43591ce.

* comments

* comments

* shortcut for __eq__ methods

* Eq. for EulerianPT calculator (#1073)

* __eq_attrs__ for nl_pt

* No normprof (#1072)

* extricated normprof

* Cosmology v3 (#1071)

* rename core --> Cosmology

* renamed core --> cosmology in docs/imports except docstrings

* cosmology v2

* first pass

* neutrinosneutrinosneutrinos

* simplified

* yamlyamlyaml

* fully fix neutrino mayhem

* new arg names in tests

* comments

* comments on comments on comments

* removed tests

* no warn

---------

Co-authored-by: David Alonso <[email protected]>

* avoid warning due to zeros (#1076)

* Fix halo inconsistencies v3 (#1069)

* ported changes in halos/profiles

* changes from star in halos/ (no tests)

* refactor concentration, mass_function, halo_bias; improvements in HMCalculator

* HaloProfile subclasses & HaloProfile.normprof attribute

* simplify imports

* remove HaloProfile.name

* cleaned up pk_Npt

* add extrap_pk argument

* FFTLogParams class instead of dictionary in HaloProfile

* simplified code

* removed mass_def from HMIngredients; comprehensive code review 1

* re-implementation, bugfixes, tests

* c_m_relation >> concentration; code improvements; A_SPLINE_MAX in Python

* HMIngredients initializers - no repeated code

* rogue file

* patch for new changes

* updated Build Status badge website

* fix websites

* added a DOI badge & links

* added nonbreaking space

* removed extra space

* FancyRepr out of CCLObject to simplify

* update tests to match changes

* coverage

* simple test for tkkssc

* more tests for tkkssc

* addressed comments 1

* addressed comments 2: mass_def defaults are name strings etc.

* deprecate Gaussian & PowerLaw profiles

* bugfix in master: sometimes mass_def_strict=False fails unexpectedly

* typo

* addressed comments

* New feature: Arbitrary function for profile normalization

* gain efficiency

* comments + deprecate k_min from HMCalculator

* renamed initialize_from_input --> create_instance

* brought in CCLNamedClass from docs_v3

* brought in from docs_v3: directly callable HMIngredients

* prep for Davids input

* renamed HMCalculator --> HaloModel

* fix typo

* brought in from docs_v3: initialize mass_def from any string (e.g. 400c)

* Revert "renamed HMCalculator --> HaloModel"

This reverts commit 43591ce.

* counterterms func inside of 4pt func

* replace deprecated abstractproperty

* abstract linked methods for HaloProfile, MassFunc, HaloBias, Concentration

* fully working implementation

* renamed lM --> log10M etc.

* minor cosmetic fix

* first commit

* alternative way to include linked abstract methods and declare the template methods

* reorder

* even simpler

* enclose classmethods in the class

* brought in minor improvements to halos

* clone of 1064

* bring back eq_attrs

* r -> r_t

* Additional halos features (#1068)

* first commit

* enclose classmethods in the class

* brought in minor improvements to halos

* coverage

* removed MassConcentration

* full implementation (v3 only)

* comments

* single-liner

* coverage

* Final checklist v3 (#1075)

* imports

* homogenize all imports as per PEP8 and the Python Import System

* homogenize all imports as per PEP8 and the Python Import System

* instance checks

* all exceptions raised correctly

* comments

* add aliases

* reverted changes and introduced proper enums

* Preserve API in v2.final (#1077)

* first commit

* Einasto mass translator + MassDef concentration API

* universal api no-break

* comments

* MassDef vars

* Coverage v3 (#1078)

* coverage

* comments

---------

Co-authored-by: David Alonso <[email protected]>
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.

2 participants