Skip to content

Preserve sampling chains in saved results - #988

Open
Fstarnb wants to merge 4 commits into
pybop-team:developfrom
Fstarnb:fix/898-sampling-result-chains
Open

Fstarnb wants to merge 4 commits into
pybop-team:developfrom
Fstarnb:fix/898-sampling-result-chains

Conversation

@Fstarnb

@Fstarnb Fstarnb commented Oct 14, 2026

Copy link
Copy Markdown

Description

Saved SamplingResult data now includes the retained sampling chains. Result.save_data writes them for JSON, MATLAB, and pickle formats. Result.load_data restores them as a SamplingResult, with chains and all_samples populated. Before this change the chains were not saved, so a loaded sampling result had no chain data.

This supersedes #987, which was closed earlier.

Fixes #898

Design notes

  • The issue suggested rebuilding the chains from x_model. This PR stores the chains and their shape explicitly. Evaluation logs do not record accepted chain states or discarded warm-up iterations, so rebuilding them would not be exact.
  • Result.load_data keeps its public behaviour and return type. The loading code is split into the internal helpers _load_data_dict and _from_data_dict.
  • Loading a file that has no chains (for example, a file written before this change) raises a ValueError rather than guessing the chains.
  • The problem metadata of a loaded result holds parameter names only. This is noted in the docstring, because rebuilding a full problem needs the original definition.

Type of change

  • Bug fix

Testing

  • tests/unit/test_sampling.py and tests/unit/test_save_data.py: 93 passed.
  • tests/unit/test_optimisation.py -k "save or load or Result": 5 passed.
  • Full unit suite (tests/unit): 311 passed, 6 skipped, 0 failed.
  • ruff check and ruff format --check on the changed files: clean.
  • Not run: nox -s pre-commit (ran ruff directly) and nox -s doctest.

Changelog entry added under Features.

🤖 Generated with Claude Code

@codecov

codecov Bot commented Oct 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.94%. Comparing base (3171a07) to head (086844c).
⚠️ Report is 19 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #988      +/-   ##
===========================================
+ Coverage    92.13%   92.94%   +0.80%     
===========================================
  Files           74       84      +10     
  Lines         5799     6818    +1019     
===========================================
+ Hits          5343     6337     +994     
- Misses         456      481      +25     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

Reconstruct chains for SamplingResult

1 participant