Skip to content

refactor(cosmo): refactor separate baryon component - #17522

Merged
eerovaher merged 1 commit into
astropy:mainfrom
nstarman:cosmo/api/sep-omegab
Dec 12, 2024
Merged

eerovaher merged 1 commit into
astropy:mainfrom
nstarman:cosmo/api/sep-omegab

Conversation

@nstarman

@nstarman nstarman commented Dec 9, 2024

Copy link
Copy Markdown
Member

Part of #17150
With this separation (and others like it) we will be able to define a cosmology w/out baryons, not just setting it to 0.

  • 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.1.0 milestone Dec 9, 2024
@github-actions

github-actions Bot commented Dec 9, 2024

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.

@github-actions

github-actions Bot commented Dec 9, 2024

Copy link
Copy Markdown
Contributor

👋 Thank you for your draft pull request! Do you know that you can use [ci skip] or [skip ci] in your commit messages to skip running continuous integration tests until you are ready?

@nstarman
nstarman force-pushed the cosmo/api/sep-omegab branch from 4da417e to 90fd25a Compare December 11, 2024 00:53
@nstarman
nstarman marked this pull request as ready for review December 11, 2024 15:21
@nstarman
nstarman requested a review from a team as a code owner December 11, 2024 15:21
@nstarman
nstarman requested a review from eerovaher December 11, 2024 15:22
class _BaryonComponent:
"""The cosmology has attributes and methods for the baryon density."""

Ob0: float

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is Ob0 not moved to the new mixin?

@nstarman nstarman Dec 11, 2024 •

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.

in _BaryonComponent we're not mandating that Ob0 is a parameter of the cosmology, just an attribute.

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.

This will allow, e.g. models without Ob0 as a cosmological parameter.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

My thinking is that if Ob(z) is well defined then Ob0=Ob(0) must also be well defined, so why can't this mixin handle both?

@nstarman nstarman Dec 11, 2024 •

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.

Ob0=Ob(0) is well defined as Ob0 (assuming inv_efunc(0) = 1). In (nearly?) all model formulations Ob0 is either

  1. Not a part of the cosmology, e.g. a Lambda-only universe or a radiation-only universe.
  2. A settable parameter of the cosmology
  3. A derived parameter of the cosmology.

So I don't want to make Ob0 "defined" in the sense of a "Parameter" as it is on the FLRW objects.

Any class that subclasses _BaryonComponent is in category 2 or 3, but if it's a derived parameter then it is vastly preferable to make Ob0 a @property, not a "astropy.cosmology.Parameter"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think I know enough about cosmology to judge how good this reasoning is, but at least the reasoning is now written down.

Ob0: float
"""Omega baryons: density of baryonic matter in units of the critical density at z=0."""

inv_efunc: Callable[[NDArray[Any]], NDArray[Any]]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should this be an abstract method?

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.

I don't think so. The best would probably be to have a HasInvEFunc protocol, but I think this suffices. It allows subclasses to implement inv_efunc however they want (method, callable attribute) so long as it's present for Ob() to call.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

An abstract method in the mixin would indeed force the subclasses to implement inv_efunc() as a method and prevent them from implementing it as a callable attribute. It is not obvious to me why both options should be supported, but apparently you've thought about this.

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.

It is not obvious to me why both options should be supported

Nor to me, but the plan is factor out all these building blocks of a cosmology, organize them into a user-facing sub-module, build some of the classic pedagogical models, and make it easy for users to put these building blocks together to easily make custom cosmologies. So I'm keeping these mixin classes very general.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should keep in mind that expanding the public API is much simpler than restricting it, so it might be better to avoid making the API too flexible right now.

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 astropy/cosmology/flrw/base.py Resolved
@eerovaher
eerovaher merged commit 60d4f08 into astropy:main Dec 12, 2024
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