Skip to content

gh-1159: Add CosmologyWithOmegaM protocol#1162

Open
paddyroddy wants to merge 6 commits into
mainfrom
paddy/issue-1159
Open

gh-1159: Add CosmologyWithOmegaM protocol#1162
paddyroddy wants to merge 6 commits into
mainfrom
paddy/issue-1159

Conversation

@paddyroddy

@paddyroddy paddyroddy commented Jul 7, 2026

Copy link
Copy Markdown
Member

Description

Adds a CosmologyWithOmegaM protocol as OmegaM isn't used that often.

Closes: #1159

Changelog entry

Added: A CosmologyWithOmegaM protocol

Checks

  • Is your code passing linting?
  • Is your code passing tests?
  • Have you added additional tests (if required)?
  • Have you modified/extended the documentation (if required)?
  • Have you added a one-liner changelog entry above (if required)?

@paddyroddy paddyroddy requested a review from Copilot July 7, 2026 16:05
@paddyroddy paddyroddy self-assigned this Jul 7, 2026
@paddyroddy paddyroddy added enhancement New feature or request science Science improvement or question labels Jul 7, 2026
@paddyroddy paddyroddy marked this pull request as ready for review July 7, 2026 16:05

Copilot AI 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.

Pull request overview

Adds a more specific typing protocol (CosmologyWithOmegaM) to represent cosmology objects that provide Omega_m(z), and uses it where Omega_m is actually required (e.g., density-based shell weights). This refines type contracts in GLASS without changing runtime behavior.

Changes:

  • Introduce CosmologyWithOmegaM protocol in glass.cosmology.
  • Update DensityWeight to require CosmologyWithOmegaM instead of the broader Cosmology.
  • Adjust the corresponding unit test type annotation for DensityWeight.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
glass/cosmology.py Adds the new CosmologyWithOmegaM protocol and removes HasOmegaM from the base Cosmology protocol.
glass/shells.py Narrows DensityWeight.cosmo to CosmologyWithOmegaM and updates the attribute docstring accordingly.
tests/core/test_shells.py Updates test_density_weight to require a cosmology object that supports Omega_m.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread glass/cosmology.py
Comment thread glass/shells.py
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@paddyroddy paddyroddy requested review from connoraird and ntessore July 7, 2026 16:18
@paddyroddy paddyroddy added the needs-2-reviewers Could be considered "controversial" so worth a second pair of eyes label Jul 7, 2026

Copilot AI 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.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

glass/shells.py:153

  • Renaming the dataclass field from cosmo to cosmo_omega_m changes the public constructor/attribute API (e.g., existing DensityWeight(cosmo=...) calls would break) and is inconsistent with the other weight classes in this module which all use cosmo. It should remain cosmo and only the type should be narrowed to CosmologyWithOmegaM. Also, the __call__ docstring currently says “comoving distance” even though this class is a density weight.
    cosmo_omega_m: CosmologyWithOmegaM

    def __call__(self, z: FloatArray) -> FloatArray:
        """
        Uniform weight in comoving distance.

Comment thread tests/core/test_shells.py Outdated
Comment thread glass/shells.py Outdated
Comment thread glass/cosmology.py
@paddyroddy paddyroddy added the typing Static typing label Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request needs-2-reviewers Could be considered "controversial" so worth a second pair of eyes science Science improvement or question typing Static typing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove HasOmegaM from Cosmology protocol

2 participants