Skip to content

Fix unit tests for PR #41: adapt to Correlations refactor, fix numpy 2.0 compatibility#42

Closed
Copilot wants to merge 16 commits intomainfrom
copilot/fix-unit-tests-zooc21
Closed

Fix unit tests for PR #41: adapt to Correlations refactor, fix numpy 2.0 compatibility#42
Copilot wants to merge 16 commits intomainfrom
copilot/fix-unit-tests-zooc21

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 1, 2026

PR #41 (zeus21_hack) removed the standalone Correlations class and folded correlation computation into Cosmo_Parameters.run_correlations() (called automatically in __post_init__), and changed Power_Spectra to pull arrays from CosmoParams directly. Tests were still using the old API, causing collection failures.

Test API updates

  • test_correlations.py: Replace zeus21.Correlations(UserParams, CosmoParams) with assertions on correlation arrays now living on CosmoParams (_klistCF, _PklinCF, xi_RR_CF, xiEta_RR_CF, rlist_CF). Window function tests moved to z21_utilities._WinTH/G/TH1D.
  • test_astrophysics.py: Remove CorrFClass; update Power_Spectra call and rlist_CF/_klistCF refs.
  • test_maps.py: Same, across all three test functions.
  • test_sfrd.py: Remove stale _ = zeus21.Correlations(...).
# Before
CorrFClass = zeus21.Correlations(UserParams, CosmoParams)
PS21 = zeus21.Power_Spectra(UserParams, CosmoParams, AstroParams, CorrFClass, Coeffs)

# After
PS21 = zeus21.Power_Spectra(UserParams, CosmoParams, AstroParams, Coeffs)
# correlation arrays now on CosmoParams: CosmoParams._klistCF, .xi_RR_CF, etc.

Pre-existing bugs exposed by collection succeeding

  • zeus21/inputs.py: np.trapznp.trapezoid (removed in NumPy 2.0; requirements.txt pins numpy>=2.0). Affects the USE_RELATIVE_VELOCITIES code path in runclass().
  • test_inputs.py, test_cosmology.py, test_UVLFs.py: kmax_CLASS=10. is now too small — run_correlations() runs at Cosmo_Parameters init time and the computed _klistCF values exceed the CLASS k-grid at that setting. Raised to 100..
  • test_inputs.py: AstroParams._clumpingAstroParams.clumping (attribute was renamed in the refactor).
Original prompt

Fix unit tests in ZeusCosmo/Zeus21 for PR #41 after refactor that removed standalone Correlations class and moved correlation computation/storage into Cosmo_Parameters.

Context:

  • PR v2.0 of zeus21! #41 refactors correlations so they are no longer a standalone object/file-path dependency. Correlation computation now happens inside Cosmo_Parameters.run_correlations() (in zeus21/inputs.py), and arrays are stored on the Cosmo_Parameters instance.
  • Power_Spectra no longer takes a CorrFClass argument; it pulls needed correlation arrays from Cosmo_Parameters.
  • Some tests still import/instantiate the old zeus21.Correlations and call Power_Spectra with the old signature.

Tasks:

  1. Update failing tests to match the new API:
    • Remove any from zeus21.correlations import * or direct Correlations(...) usage.
    • Stop constructing CorrFClass in tests.
    • Update Power_Spectra instantiation to new signature (expected: Power_Spectra(UserParams, CosmoParams, AstroParams, Coeffs); verify in code).
  2. Refactor tests/test_correlations.py to validate correlations via Cosmo_Parameters instead of a removed class:
    • Ensure CosmoParams has correlation-related attributes after initialization (e.g. _klistCF, _PklinCF, xi_RR_CF, and any other correlation arrays in use).
    • Add reasonable assertions: arrays exist, are finite, non-empty, and shapes are consistent.
  3. Ensure all tests pass in CI for PR v2.0 of zeus21! #41.
  4. Keep changes minimal and test-focused; do not reintroduce removed classes.

Acceptance criteria:

  • pytest suite passes.
  • Tests reflect the new public API and expected behavior.

PR target:

  • Apply fixes on the branch associated with PR v2.0 of zeus21! #41 in ZeusCosmo/Zeus21 (do not create a separate unrelated PR).

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Please find a solution for failing job 73948760349. Use the logs, job definition, and any referenced files where the failure occurred. Keep your response focused on the solution and include code suggestions when appropriate.

User: we need to update tests so they follow the latest file changes (eg correlations doesnt exist separately anymore, its in cosmo parameters)

Assistant: To align the tests with the latest code changes in PR #41 (where correlations are no longer a standalone object/file-path dependency and are now carried via Cosmo_Parameters), you should update any tests that still:

  1. import zeus21.correlations directly, or
  2. instantiate Correlations(UserParams, CosmoParams, ClassyCosmo), or
  3. construct Power_Spectra(..., ClassyCosmo, CorrFClass, Coeffs) (old signature), or
  4. assume ClassyCosmo.pars[...] for correlation-related data.

What changed (relevant to the tests)

From the PR diffs:

  • The old Correlations class was removed from zeus21/correlations.py; now the correlations machinery lives inside Cosmo_Parameters.run_correlations() (in zeus21/inputs.py), and the resulting arrays are stored on the Cosmo_Parameters instance (e.g. _klistCF, _PklinCF, xi_RR_CF, etc.).
  • Power_Spectra moved to zeus21/correlations.py but now expects no external Correlations instance; it pulls correlation arrays from Cosmo_Parameters.

Concrete test updates you should make

1) tests/test_astrophysics.py — remove stale import + stop creating Correlations the old way

Right now this file still has:

  • from zeus21.correlations import * (stale)
  • CorrFClass = zeus21.Correlations(UserParams, CosmoParams) (this will fail, because Correlations isn’t a thing anymore)
  • PS21 = zeus21.Power_Spectra(UserParams, CosmoParams, AstroParams, CorrFClass, Coeffs) (wrong signature per PR diff)

Fix:

  • Delete from zeus21.correlations import *
  • Delete CorrFClass = ...
  • Instantiate Power_Spectra using the new signature shown in the PR diff of zeus21/correlations.py:
    • PS21 = zeus21.Power_Spectra(UserParams, CosmoParams, AstroParams, Coeffs)

Also: anywhere the test used correlation-derived fields via the old PS21.Deltasq_dxa etc may need to be adjusted (you already replaced the “correlation coefficient inequality” assertions with a simpler positive-definite check, which is consistent with the “correlations not separate anymore” change).

2) tests/test_correlations.py — this test’s purpose needs redefining

This file currently does:

  • CorrFClass = zeus21.Correlations(UserParams, CosmoParams) then tests correlation functions.

But there is no zeus21.Correlations anymore. The replacement is: correlations are computed as a side effect of constructing Cosmo_Parameters (it calls run_correlations() in __post_init__).

Fix direction:

  • Replace “class instantiation” with assertions that the correlation-related arrays exist on CosmoParams, e.g.:
    • hasattr(CosmoParams, "xi_RR_CF")
    • shapes of CosmoParams.xi_RR_CF, CosmoParams._klistCF, etc are sensible / non-empty
    • if relative velociti...

This pull request was created from Copilot chat.

Copilot AI and others added 3 commits May 1, 2026 15:28
…it-tests-zooc21

Co-authored-by: JulianBMunoz <22434409+JulianBMunoz@users.noreply.github.com>
…lumping issues

Agent-Logs-Url: https://github.com/ZeusCosmo/Zeus21/sessions/398e6899-c0e5-43b6-a9b1-5d57b57f83d5

Co-authored-by: JulianBMunoz <22434409+JulianBMunoz@users.noreply.github.com>
By @slibanore and Alessandra Venditti, now LFs for UVLF and HaLF separately and in a LF.py file
Copilot AI changed the title [WIP] Fix unit tests after Correlations class refactor Fix unit tests for PR #41: adapt to Correlations refactor, fix numpy 2.0 compatibility May 1, 2026
Copilot AI requested a review from JulianBMunoz May 1, 2026 15:40
@JulianBMunoz JulianBMunoz deleted the copilot/fix-unit-tests-zooc21 branch May 1, 2026 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants