Skip to content

Towards Pedagogical Cosmological Models #17150

Open

Description

@nstarman

Currently Astropy provides the very broad FLRW subclasses which have the full gamut of density components. With these classes we can achieve any of the standard pedagogical classes, e.g. matter-only, M+Lambda, etc.
However, this generality ends up obscuring in the code the beautiful and simple analytic expressions to which many computed quantities reduce.
I want to provide pedagogical models like a MatterOnly, MatterAndDarkEnergy (names not final).
Doing this will take 3 steps:

  1. Splitting out of FLRW private ABCs for the components, e.g. a DarkMatterComponent class. FLRW will subclass these orthogonal ABCs, implement the necessary concrete methods.
  2. Move these component classes into a new module and make them public (preferably private, but importing them to the top-level namespace)
  3. Make new pedagogically-focused cosmology classes. Interested users (e.g. students) can see the analytic expressions in the code and explained in the docstrings.

For details of what this will look like, see https://cosmology.readthedocs.io/projects/api/en/latest/

Component PRs:

Pedagogical Classes:

Activity

  1. pllim commented on Oct 9, 2024

    @pllim
    Member

    pedagogically-focused cosmology classes

    Will these classes actually be useful outside of teaching? If not, maybe better as example over at Learn Astropy?

  2. nstarman commented on Oct 9, 2024

    @nstarman
    MemberAuthor

    They are good approximations during periods of 1 or 2 component domination, so are still useful in research contexts. The simplified analytic expressions should also be faster.

  3. moved this from Triage to Todo in Cosmology, the Expansionon Oct 9, 2024
  4. nstarman commented on Oct 10, 2024

    @nstarman
    MemberAuthor
  5. moved this from Todo to In Progress in Cosmology, the Expansionon Oct 10, 2024
  6. mhvk commented on Oct 10, 2024

    @mhvk
    Contributor

    This is starting to look like cosmology could be a set of Model instances! That might actually be interesting - would enable fitting a cosmology to a set of data points...

    Like @pllim, I'm not quite clear whether astropy itself should contain the pedagogical implementations, but I think it will become clearer whether that makes sense or not once some of the modular pieces are in place. It will also be good to see to what extent these make the code simpler - the temperature and scale factor seem good cases, but a bit less obvious to me that others will be.

  7. nstarman commented on Dec 13, 2024

    @nstarman
    MemberAuthor

    a set of Model instances!

    Preferably not! But better I/O between them would be nice. The current interface is limited.
    https://github.com/astropy/astropy/blob/main/astropy/cosmology/_io/model.py

  8. spranav1205 commented on Dec 17, 2024

    @spranav1205

    Hi @nstarman ,

    I’m a beginner looking to contribute to this project. If I understand correctly, you're restructuring the FLRW class by creating new classes for various methods, as mentioned in the list.

    While going through the codebase, I found it challenging to fully understand the testing code. There are a few nested test classes, and I couldn't locate the instance for cosmo_cls.

    Could you please help me understand the test code, particularly where cosmo_cls is instantiated? With your guidance, I hope to separate a few classes as part of the restructuring.

    Thanks!

  9. nstarman commented on Dec 18, 2024

    @nstarman
    MemberAuthor

    Thanks @spranav1205 for the interest! I'd be happy to look at PRs that separate the cosmology class into its component classes, according to the schema outlined in https://cosmology.readthedocs.io/projects/api/en/latest/.
    This task is currently waiting on #17543 before it can be worked on again.
    In the meantime, Astropy uses pytest as its testing framework. up-to-date pytest tests use fixtures as inputs to the test functions. Here's a refined search for the cosmo_cls fixture — https://github.com/search?q=repo%3Aastropy%2Fastropy+%22def+cosmo_cls%22&type=code — the use of which depends on a per-test basis. Hope that helps!

  10. spranav1205 commented on Dec 20, 2024

    @spranav1205

    Thanks for your guidance! I'll look into it.

  11. preshanth commented on Jun 4, 2025

    @preshanth
    Contributor

    @nstarman you planning to keep pushing this list forward. I would like to try and help if thats the case.

  12. 6 remaining items

  13. nstarman commented on Oct 20, 2025

    @nstarman
    MemberAuthor

    Thanks @preshanth. That sounds great. Do you want to take a look at DarkMatterComponent ?

  14. preshanth commented on Oct 22, 2025

    @preshanth
    Contributor

    @nstarman Any other trait you want me to take a stab at ?

  15. nstarman commented on Oct 23, 2025

    @nstarman
    MemberAuthor

    TotalComponent should be a simple one. It has to abstract since it can't know what are the set of implemented components.
    Then DistanceMeasures, which should just be the public API methods, not the private implementations. I'm interested in discussing what are the minimum set of abstract methods required to get the distance measures working!

  16. added this to the v8.0.0 milestone on Oct 23, 2025
  17. added theissue type on Oct 23, 2025
  18. preshanth commented on Oct 23, 2025

    @preshanth
    Contributor

    I will start with TotalComponent maybe the PhotonComponent after that ? Let me ponder the DistanceMeasures too in the meantime.

  19. preshanth commented on Oct 30, 2025

    @preshanth
    Contributor

    Can I present an issue with my fix for neutrino component and distance measure in a separate ticket? We can hash it out and then I can submit a PR for them one at a time. I also want to make another ticket for unit tests for the traits themselves.

  20. nstarman commented on Oct 30, 2025

    @nstarman
    MemberAuthor

    That'd be great. I pushed a couple PR drafts, one of which will impact a distance measures PR significantly. There's a couple other related issues with setting up the distance measures (two-argument forms, default implementations, etc), so maybe I'll take that one.

  21. preshanth commented on Nov 18, 2025

    @preshanth
    Contributor

    Do you want to leave the doc tests in place ? They also make good unit tests. I was going to do some check for known failures and put in a trait unit test PR that sound alright ? Don't want to increase your reviewing workload so let me know if that's okay

  22. nstarman commented on Nov 18, 2025

    @nstarman
    MemberAuthor

    Do you want to leave the doc tests in place ? They also make good unit tests.

    Yes, agreed.

    I was going to do some check for known failures and put in a trait unit test PR that sound alright ?

    Great!

  23. pllim commented on May 1, 2026

    @pllim
    Member

    This is not a release blocker, so I am removing milestone for this issue. FYI.

  24. removed this from the v8.0.0 milestone on May 1, 2026
  25. preshanth commented on May 4, 2026

    @preshanth
    Contributor

    @nstarman Would you like me to look at anything remaining here. There are two open Drafts I am not sure what else to touch. Happy to help if you point me towards something useful.

  26. nstarman commented on May 14, 2026

    @nstarman
    MemberAuthor

    @preshanth Oh, sorry for the delayed response.
    The DistanceMeasures PR is slowly going, but it's going.
    A PhotonComponent PR would be amazing!

  27. preshanth commented on May 15, 2026

    @preshanth
    Contributor

    I will take a stab at that and put in a PR over the weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions