Add IAEA-benchmark example notebooks and API tests for 23 unfold methods - #128
Open
Radiationsafety wants to merge 4 commits into
Open
Radiationsafety wants to merge 4 commits into
Radiationsafety wants to merge 4 commits into
Conversation
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.
✅ Deploy Preview for bssunfold ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 0 |
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.
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, 23 public unfold_* methods on the Detector class had no dedicated example notebook. This commit adds:
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):
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.
A comprehensive test module tests/test_all_unfold_methods_api.py with 5 test classes (~200 parametrized tests):
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.