Skip to content

feat: uni-modal cosmology wrt Ob0 - #16847

Merged
nstarman merged 1 commit into
astropy:mainfrom
nstarman:cosmo-Ob0-default
Oct 10, 2024
Merged

nstarman merged 1 commit into
astropy:mainfrom
nstarman:cosmo-Ob0-default

Conversation

@nstarman

@nstarman nstarman commented Aug 19, 2024 •

Copy link
Copy Markdown
Member

Deprecates Ob0=None, changing it to Ob0=0.
Currently FLRW is multi-modal in that it supports both a cosmology with no baryon component and also one with a baryon component. Except that the no-baryon cosmology is implemented as an attribute that always raises an exception. This is not an ideal code pattern. From a code perspective the best is to have two different classes, each representing one of these modalities. Pragmatically, at least for now, just having Ob0 = 0 fulfills the same requirements without adding a new class nor all the child classes for the dark energy EoS. Longer term, one of the
goals of the cosmology API project and its application to Astropy is to make defining new cosmology classes significantly easier through more modular components. Then we can have true no-baryon cosmologies, not just baryons=0.

This is a breaking change since Ob0 = None is now Ob0 = 0 and no longer ever errors.

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

@nstarman nstarman added this to the v7.0.0 milestone Aug 19, 2024
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Astropy! 🌌 This checklist is meant to remind the package maintainers who will review this pull request of some common things to look for.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see instructions for rebase and squash.
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the "Extra CI" label. Codestyle issues can be fixed by the bot.
  • Is a change log needed? If yes, did the change log check pass? If no, add the "no-changelog-entry-needed" label. If this is a manual backport, use the "skip-changelog-checks" label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate "backport-X.Y.x" label(s) before merge.

@nstarman
nstarman force-pushed the cosmo-Ob0-default branch 2 times, most recently from 6c8c678 to 9b48ed7 Compare August 19, 2024 14:47
@nstarman
nstarman marked this pull request as ready for review August 19, 2024 14:48
@nstarman
nstarman requested a review from a team as a code owner August 19, 2024 14:48
@nstarman
nstarman requested review from mhvk and removed request for a team August 19, 2024 14:48
@nstarman
nstarman force-pushed the cosmo-Ob0-default branch 2 times, most recently from b61406f to 8111cfb Compare August 19, 2024 15:11
@astropy astropy deleted a comment from github-actions Bot Aug 19, 2024

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't feel completely competent to judge the impact, but it certainly seems to make more sense to keep the class consistent like this, rather than sometimes getting errors. My comments are mostly about making clearer what is changed.

Comment thread astropy/cosmology/flrw/base.py Outdated
if value is None:
return value
warnings.warn(
"Ob0=None is deprecated, use Ob0=0 instead.",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also mention that there will no failures!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

✅

tba.arguments.pop("Ob0", None)
cosmo = cosmo_cls(*tba.args, **tba.kwargs)
with pytest.raises(ValueError):
cosmo.Ob(1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Proabbly makes sense to check that cosmo.Ob(1) == 0

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

SGTM.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

✅

Comment thread docs/cosmology/index.rst
In this case the dark matter-only density at redshift 0 is available as class
attribute ``Odm0`` and the redshift evolution of dark and baryonic matter
densities can be computed using the methods ``Odm`` and ``Ob``, respectively.
If ``Ob0`` is not specified at class instantiation, it defaults to ``None`` and

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should state that if Ob0 is not specified, it will be set to 0 and thus ignored in further calculations. Only then does the next example make sense (though I'd add cosmo.Ob(1) as well, to show it stays zero).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

✅

Comment thread docs/changes/cosmology/16847.api.rst Outdated
Setting ``Ob0 = None`` in FLRW cosmologies has been deprecated in favor of ``Ob0 =
0.0``. Conceptually this is a change in that baryons are now always a component of the
cosmology. Practically, the only change (besides that ``Ob0`` is never ``None``) is that
methods relying on ``Ob0`` always work, rather than sometimes raising an exception.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Add ", instead by default taking the contribution of the baryons to be negligible."

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

✅

@nstarman
nstarman force-pushed the cosmo-Ob0-default branch 2 times, most recently from e09f90f to 2e1320e Compare September 10, 2024 17:19
@nstarman
nstarman requested a review from mhvk October 9, 2024 20:10
@nstarman nstarman modified the milestone: v7.0.0 Oct 9, 2024
@nstarman nstarman mentioned this pull request Oct 10, 2024
12 of 22 tasks

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The other PRs brought this up again. Still seems reasonable, and I now have only a most minimal comment left. Approving, since either I'm right and this is a trivial change, or I'm not, and then what you have is OK.

# validation
assert Ob0.validate(cosmo, None) is None
with pytest.warns(
DeprecationWarning, match=re.escape("Ob0=None is deprecated")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why the re.escape - this string should work fine directly, no?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good Q. Not sure if I added this because of a test failure or as a matter of habit.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hopefully habits will be auto-fixed astral-sh/ruff#13705

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Removed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Indeed, this seems auto-detectable (it already detects f-strings without actual {...}).

cosmo.Ob(1)
tba.arguments["Ob0"] = None
with pytest.warns(
DeprecationWarning, match=re.escape("Ob0=None is deprecated")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I now quickly checked, and it does just work without re.escape.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Removed.

Deprecate Ob0=None, changing to Ob0=0

Signed-off-by: nstarman <[email protected]>
@nstarman
nstarman enabled auto-merge October 10, 2024 15:02
@nstarman
nstarman merged commit ecb98df into astropy:main Oct 10, 2024
@nstarman nstarman mentioned this pull request Dec 4, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants