Skip to content

Remove cyclic dependency#656

Open
marcpaterno wants to merge 18 commits into
masterfrom
remove-cyclic-dependency
Open

Remove cyclic dependency#656
marcpaterno wants to merge 18 commits into
masterfrom
remove-cyclic-dependency

Conversation

@marcpaterno

@marcpaterno marcpaterno commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR restructures the likelihood package architecture to break a circular dependency between modules. The key changes are:

  • New file: firecrown/likelihood_base.py - Core likelihood base classes (Likelihood, Statistic, TrivialStatistic, ConstGaussian, ConstGaussianPM, StudentT, TwoPoint) have been moved from _base.py to the package root. This decouples the base classes from the likelihood subpackage.

  • Updated imports: All modules across the codebase now import base classes from firecrown.likelihood_base instead of firecrown.likelihood._base.

  • Private module re-exports: The firecrown.likelihood._base module now re-exports from firecrown.likelihood_base with deprecation notices to maintain backward compatibility.

  • SACC utility refactoring: SACC-related helper functions (load_sacc_data, ensure_path) were moved from firecrown.likelihood.factories._sacc_utils to firecrown.utils._sacc_ops, with the old module kept as a backward-compatible shim.

  • Import path updates: All internal imports were updated to reference the new module locations. Test files were updated to use the new import paths.

Type of change

  • Refactoring

Dependencies

  • sacc >= 2.4 - Required for sacc.utils.detect_sacc_file_type used in SACC file format detection.

Testing

  • All existing tests pass with the new import structure.
  • The deprecation shims ensure legacy imports continue to work.
  • Import order has been standardized across all files following ruff's isort rules.

Checklist

The following checklist will make sure that you are following the code style and
guidelines of the project as described in the
contributing page.

  • I have run make pre-commit and fixed any issues
  • I have added tests that prove my fix is effective or that my feature works
  • I have made corresponding changes to the documentation
  • I have 100% test coverage for my changes (please check this after the CI system has verified the coverage)

Regenerate conda-lock files for Python 3.12, 3.13, and 3.14 with updated dependency versions.
…data

Expand exception handling in SACC file loading operations to catch both
OSError and ValueError. The sacc library can raise ValueError for invalid
file formats or corrupted data, so this ensures those errors are properly
handled during format detection and file loading attempts.

This is needed to support sacc v2.2
…ng SACC data"

This reverts commit e33299e.
SACC 2.2 can no longer read compressed files, and that needs to be fixed
before we can start supporting the new version.
This is needed because SACC 2.2 no longer transparently handles
compressed files. I have filed an issue in SACC and will follow up with
a PR there to implement the needed support.
Regenerate conda-lock files for Python 3.12, 3.13, and 3.14 with updated dependency versions.
Move load_sacc_data and ensure_path from the private module
firecrown.likelihood.factories._sacc_utils into firecrown.utils
(via _sacc_ops). The old module is kept as a backward-compatible
re-export shim with a deprecation notice.

Replace the manual try-HDF5/try-FITS fallback in load_sacc_data and
Transform.detect_format with a call to sacc.utils.detect_sacc_file_type,
delegating format detection to SACC itself.
Remove a duplicate sacc.utils.detect_sacc_file_type import in
_transform.py. In _sacc_utils.py, import ensure_path and
load_sacc_data directly from firecrown.utils._sacc_ops instead of
the firecrown.utils package, and declare them explicitly in
__all__ for re-export.
Update conda-lock.yml files to synchronize dependency versions
and reformat YAML indentation for consistency.

- py3.12: updated package hashes and dependencies
- py3.13: updated package hashes and dependencies
- py3.14: updated package hashes and dependencies
Move core likelihood base classes from _base.py to
a new likelihood_base.py at the package root. This breaks a
cyclic dependency by decoupling the base classes from the likelihood
subpackage, allowing cleaner imports throughout the codebase.

All imports across the package have been updated to reference the new
module location.
This organization follows the rules applied by ruff, i.e.

1. standard library imports
2. third-parth imports
3. project imports
4. relative imports

Within each group, imports are in alphabetical order.

        modified:   firecrown/fctools/link_checker.py
Change imports of ConstGaussian and TwoPointFactory to use private
modules directly, which avoids circular dependency issues while
maintaining the same functionality.
Merge branch 'master' into remove-cyclic-dependency
@marcpaterno
marcpaterno requested a review from vitenti July 7, 2026 18:47
@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.0%. Comparing base (3a37fb6) to head (08f2c03).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #656   +/-   ##
=======================================
  Coverage   100.0%   100.0%           
=======================================
  Files         146      147    +1     
  Lines        8715     8697   -18     
  Branches     1038     1038           
=======================================
- Hits         8715     8697   -18     
Files with missing lines Coverage Δ
firecrown/app/__init__.py 100.0% <100.0%> (ø)
firecrown/app/analysis/__init__.py 100.0% <100.0%> (ø)
firecrown/app/analysis/_analysis_builder.py 100.0% <100.0%> (ø)
firecrown/app/analysis/_cobaya.py 100.0% <100.0%> (ø)
firecrown/app/analysis/_config_generator.py 100.0% <100.0%> (ø)
firecrown/app/analysis/_cosmosis.py 100.0% <100.0%> (ø)
firecrown/app/analysis/_download.py 100.0% <100.0%> (ø)
firecrown/app/analysis/_numcosmo.py 100.0% <100.0%> (ø)
firecrown/app/analysis/_types.py 100.0% <100.0%> (ø)
firecrown/app/cosmology.py 100.0% <100.0%> (ø)
... and 77 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant