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

Cosmology property is_flat #12606

Merged
merged 2 commits into from Dec 20, 2021
Merged

Cosmology property is_flat #12606

merged 2 commits into from Dec 20, 2021

Conversation

nstarman
Copy link
Member

@nstarman nstarman commented Dec 18, 2021

Signed-off-by: Nathaniel Starkman (@nstarman) nstarkman@protonmail.com

Description

Add property is_flat to cosmologies to verify the curvature of the Universe.

It's abstract on Cosmology, making it abstract (finally).
On FLRW it checks Ok0 and Otot0.
On subclassess of FlatCosmologyMixin it's just True.

Flatness is a subtle thing. On FLRW cosmologies it's simple, but not in general. So it's abstract on Cosmology.

Checklist for package maintainer(s)

This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.

  • 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 "When to rebase and squash commits".
  • 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.
  • 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 a milestone set? Milestone must be set but astropy-bot check might be missing; do not let the green checkmark fool you.
  • 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 added this to the v5.1 milestone Dec 18, 2021
@nstarman nstarman added this to In progress (PR) in Cosmology, the Expansion via automation Dec 18, 2021
@github-actions
Copy link

👋 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
Copy link
Member Author

I still need to add a what's-new and update some doc, but the code is ready to review.

@nstarman nstarman marked this pull request as ready for review December 18, 2021 01:45
@nstarman nstarman requested a review from mhvk December 18, 2021 02:55
Copy link
Contributor

@mhvk mhvk left a comment

Choose a reason for hiding this comment

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

Looks good except I would perhaps suggest not to make it an abstract property; it just seems to add quite a bit of boilerplate, especially calling super just to get NotImplementedError back again. It also makes for a real API break - user-defined classes now have to change. (I've more generally found the concept of these abstract methods a bit less useful than I thought initially; I've not see a clear win with it.)

But really only a suggestion - if you think this is not a real problem, that's fine too.

@@ -77,6 +77,10 @@ def __init__(self, H0, Tcmb0=0*u.K, m_nu=0*u.eV, name=None, meta=None):
self.Tcmb0 = Tcmb0
self.m_nu = m_nu

@property
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes me wonder a little whether the abstractproperty really is all that useful.

Cosmology, the Expansion automation moved this from In progress (PR) to Reviewer approved Dec 18, 2021
@nstarman
Copy link
Member Author

nstarman commented Dec 19, 2021

it just seems to add quite a bit of boilerplate, especially calling super just to get NotImplementedError back again. It also makes for a real API break - user-defined classes now have to change.

It does add a bit of boilerplate, but crucially all that boilerplate is in the test code. I cannot find on GH any example of someone directly subclassing Cosmology, the base class, which would cause an API break and add boilerplate to user code. Our test code requires the boilerplate since it is testing directly subclassing Cosmology.
FLRW is actually the effective base class since all built-in cosmologies are its subclasses; and FLRW is necessarily abstract because of w(z). So we are in this awkward situation where the true base class is useless and not abstract and the useful 'base' class is abstract.
I modeled is_flat on w(z), including its slightly odd "double" abstraction: erroring if the method isn't overwritten and raising NotImplementedError if called. I actually kind of like this construction. The abstractmethod indicates subclasses must define the method, the NotImplementedError means one cannot just super their way around that. The latter is how the tests are checking that Cosmology is correctly abstract.

But really only a suggestion - if you think this is not a real problem, that's fine too.

I think I'll keep it as is. Thanks again for the detailed and quick review!

@nstarman
Copy link
Member Author

nstarman commented Dec 19, 2021

Don't merge yet, I'm still working on the docs.

Done. Added a what's-new.

@nstarman nstarman added 💤 merge-when-ci-passes Do not use: We have auto-merge option now. whatsnew-needed and removed whatsnew-needed 💤 merge-when-ci-passes Do not use: We have auto-merge option now. labels Dec 19, 2021
Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
Signed-off-by: Nathaniel Starkman (@nstarman) <nstarkman@protonmail.com>
@nstarman nstarman merged commit 9ef8d4f into astropy:main Dec 20, 2021
Cosmology, the Expansion automation moved this from Reviewer approved to Done Dec 20, 2021
@nstarman nstarman deleted the cosmo_flat_flag branch December 20, 2021 13:35
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.

None yet

2 participants