Skip to content

Add IAEA-benchmark example notebooks and API tests for 23 unfold methods - #128

Open
Radiationsafety wants to merge 4 commits into
mainfrom
feature/examples-and-tests-for-missing-methods
Open

Radiationsafety wants to merge 4 commits into
mainfrom
feature/examples-and-tests-for-missing-methods

Conversation

@Radiationsafety

Copy link
Copy Markdown
Owner

Previously, 23 public unfold_* methods on the Detector class had no dedicated example notebook. This commit adds:

  1. 23 new example notebooks (examples/56-… through examples/78-…) that exercise each of the following methods on the IAEA Compendium benchmark CSV (tests/MonteCarlo_Calculated_spectra_from_IAEA_Comp_for_comparison.csv):

    • unfold_gnowee, unfold_maeo, unfold_nnqp, unfold_qpmad, unfold_zfit
    • unfold_iterative_refinement, unfold_odl_pdhg, unfold_amaxed_regularization
    • unfold_crystal_ball, unfold_directed_divergence, unfold_express
    • unfold_ferdor, unfold_imaxed, unfold_mystic_hybrid, unfold_nsduaz
    • unfold_odl_douglas_rachford, unfold_qubo, unfold_rebunki
    • unfold_rfsp_jul, unfold_scipy_direct_method, unfold_staysl
    • unfold_tikhonov_legendre, unfold_ensemble

    Each notebook follows the same 8-section template:
    (1) setup & detector construction from RF_GSF, (2) load IAEA CSV
    and fold a chosen spectrum into readings, (3) call the method with
    documented kwargs, (4) compute compare_spectra quality metrics,
    (5) plot unfolded vs ground truth + per-sphere residuals,
    (6) dose rates via ICRP-116, (7) sweep across 5 IAEA spectra,
    (8) take-aways.

  2. A comprehensive test module tests/test_all_unfold_methods_api.py with 5 test classes (~200 parametrized tests):

    • TestAllUnfoldMethodsImported: every method exists on Detector and is exported in bssunfold.core.all
    • TestMethodSignatureContract: every method accepts the canonical (readings, initial_spectrum=None, ...) signature with the shared Monte-Carlo / housekeeping kwargs
    • TestMethodSmoke: end-to-end smoke test validating required output keys, spectrum shape, non-negativity, residual_norm, etc.
    • TestParameterAssignment: every method-specific kwarg is accepted with non-default values
    • TestIAEACompendiumEndToEnd: full IAEA benchmark execution with compare_spectra sanity ranges
    • TestNotebooksExecute: headless nbconvert execution of each new notebook (skipped if jupyter/optional backends are missing)
  3. docs/examples.rst: new IAEA Compendium Benchmark Notebooks section with a table mapping every new notebook to its method.

All 177 non-notebook-execution tests pass in this environment. The 23 notebooks were verified to execute end-to-end via jupyter nbconvert before commit.

Previously, 23 public unfold_* methods on the Detector class had no
dedicated example notebook. This commit adds:

1. 23 new example notebooks (examples/56-… through examples/78-…)
   that exercise each of the following methods on the IAEA Compendium
   benchmark CSV (tests/MonteCarlo_Calculated_spectra_from_IAEA_Comp_for_comparison.csv):
   - unfold_gnowee, unfold_maeo, unfold_nnqp, unfold_qpmad, unfold_zfit
   - unfold_iterative_refinement, unfold_odl_pdhg, unfold_amaxed_regularization
   - unfold_crystal_ball, unfold_directed_divergence, unfold_express
   - unfold_ferdor, unfold_imaxed, unfold_mystic_hybrid, unfold_nsduaz
   - unfold_odl_douglas_rachford, unfold_qubo, unfold_rebunki
   - unfold_rfsp_jul, unfold_scipy_direct_method, unfold_staysl
   - unfold_tikhonov_legendre, unfold_ensemble

   Each notebook follows the same 8-section template:
   (1) setup & detector construction from RF_GSF, (2) load IAEA CSV
   and fold a chosen spectrum into readings, (3) call the method with
   documented kwargs, (4) compute compare_spectra quality metrics,
   (5) plot unfolded vs ground truth + per-sphere residuals,
   (6) dose rates via ICRP-116, (7) sweep across 5 IAEA spectra,
   (8) take-aways.

2. A comprehensive test module tests/test_all_unfold_methods_api.py
   with 5 test classes (~200 parametrized tests):
   - TestAllUnfoldMethodsImported: every method exists on Detector
     and is exported in bssunfold.core.__all__
   - TestMethodSignatureContract: every method accepts the canonical
     (readings, initial_spectrum=None, ...) signature with the shared
     Monte-Carlo / housekeeping kwargs
   - TestMethodSmoke: end-to-end smoke test validating required output
     keys, spectrum shape, non-negativity, residual_norm, etc.
   - TestParameterAssignment: every method-specific kwarg is accepted
     with non-default values
   - TestIAEACompendiumEndToEnd: full IAEA benchmark execution with
     compare_spectra sanity ranges
   - TestNotebooksExecute: headless nbconvert execution of each new
     notebook (skipped if jupyter/optional backends are missing)

3. docs/examples.rst: new IAEA Compendium Benchmark Notebooks
   section with a table mapping every new notebook to its method.

All 177 non-notebook-execution tests pass in this environment.
The 23 notebooks were verified to execute end-to-end via jupyter
nbconvert before commit.
@netlify

netlify Bot commented Sep 18, 2026

Copy link
Copy Markdown

Deploy Preview for bssunfold ready!

Name Link
🔨 Latest commit 59a0227
🔍 Latest deploy log https://app.netlify.com/projects/bssunfold/deploys/6aad1066cfe2e80008531d8f
😎 Deploy Preview https://deploy-preview-128--bssunfold.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@codacy-production

codacy-production Bot commented Sep 18, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

BSSunfold Agent added 3 commits September 18, 2026 10:11
…, register pytest marks

Three issues were breaking test collection on the macOS CI runner:

1. **src/bssunfold/core/__init__.py** was missing the import line for
   unfold_extragradient. The names solve_extragradient and
   unfold_extragradient were listed in __all__ (line 566-567)
   but never actually imported from .unfold_extragradient. This
   caused tests/test_optimization_methods.py to fail collection
   with ImportError: cannot import name 'solve_extragradient'.

2. **tests/test_smt.py** had the import z3 statement *before*
   the pytest.importorskip('z3') call, so the ImportError fired
   at collection time before pytest could skip the module. Reordered
   so pytest.importorskip('z3') runs first; import z3 now
   executes only when the backend is actually installed.

3. **pyproject.toml** registered only the slow pytest marker.
   The custom markers @pytest.mark.qubo and @pytest.mark.zfit
   used in tests/test_new_unfold_methods.py were unregistered,
   producing noisy PytestUnknownMarkWarning on every CI run.
   Added both markers to [tool.pytest.ini_options].markers.

After these fixes the full test suite (2969 tests) collects cleanly
with no warnings.
Address ruff findings reported by CI:

- I001 (import sorting): reorder the bssunfold import to match
  ruff's isort rules and drop the redundant blank line.
- UP035 + F401 (typing.Callable): the symbol was imported from
  typing but never used; remove it entirely.
- E501 (line too long, lines 106/112/215): reflow the iaea_csv
  fixture and the assert message so every line stays under 88
  characters.

After these fixes, ruff check --output-format=github src/ tests/
reports zero findings on the entire repository.
Two dict literals in the test file were aligned with extra whitespace
after the colon for visual column alignment:

    "unfold_gnowee":              dict(...),
    "unfold_iterative_refinement":dict(...),

That violates pycodestyle E241, which is enabled in the project's
strict ruff gate. Reformat both blocks:

- SMOKE_KWARGS (lines 248-275) — each entry now uses a single space
  after the colon; multi-line dict() calls wrap with continuation
  indentation.
- TestNotebooksExecute.NOTEBOOKS (lines 611-635) — same treatment.

After this fix, `ruff check --preview src/ tests/` reports zero
findings (preview mode is stricter than the CI gate, so this is a
superset of what CI will check).
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