Skip to content

Headless script: save everything at the end of a run, masks in the extension frame - #102

Merged
seb5g merged 12 commits into
5.3.xfrom
feature/headless-save-final
Nov 9, 2026
Merged

seb5g merged 12 commits into
5.3.xfrom
feature/headless-save-final

Conversation

@seb5g

@seb5g seb5g commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

What

Changes to the algorithm playground (utilities/headless_algorithms.py, scripts/algorithm_playground.py) and to the layout of the saved files.

1. Masks use the frame of the extension (the bug behind the wrong saved output).
The headless set_mask took the slices as centered on the field and shifted them by half the field. Slices pasted from the extension (origin at the corner of the field) landed in a corner, the target region was driven to zero and the algorithm did not converge (noise output, infinite fitness). Masks are now in the frame of the extension, the same slices work in both. The plots stay centered on the field and the mask outline is shifted accordingly. default_mask returns the extension frame too.
The saving itself was checked: the saved arrays equal the live ones at each step.

2. save_final (SAVE_FINAL in the script): saves all the fields and the metrics of the last iteration once at the end of the run, as the Save action of the extension. It can be used alone or with save_fields and save_metrics.

3. Layout of a run in the file. The group ShapingXXX of a run (with the settings of the run) holds one sub group per kind of data:

  • Fields: the fields saved at each iteration, enlarged along their own step navigation axis (own ModuleSaver child of ShapingSaver)
  • Metrics: the metrics, same
  • Final: the fields saved once at the end, no navigation axis
  • Input and Target: the fields as used by the algorithm, with the settings of their loaders, readable with load_field_from_h5

Only the sub groups of the requested data are created. This also applies to the continuous saving of the AlgoApp (same saver).

4. Save of the extension and of the AlgoApp use the same layout. The main group is Shaping (no index) with the settings, Final (algorithm results), SLM, Input and Target. load reads this layout and still reads the old one (/RawData/Algorithm, Input, Target, SLM under /RawData). AlgoApp.save takes an add_to_group callback used by the extension to add the SLM, Input and Target groups.

5. Shared code. ContinuousSaver is renamed RunSaver (it saves a whole run). add_field_group and add_algorithm_group are used by both the extension Save and the runs.

6. scripts/plot_convergence.py: matplotlib plot of the saved metrics against the iteration.

Docs: user guide updated (saved file layout, convergence script).

Tests

tests/test_algorithm_playground.py, tests/test_custom_apps.py: tests of save_final, of the sub groups, of the Input and Target groups, of the mask frame and of the Shaping layout of the AlgoApp save; the existing ones adapted. The full test suite passes locally (178 tests). The extension's own save/load are not instantiated by any test.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RKuN84WCxVCr25SiruMKcX

…ub group of the run group

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RKuN84WCxVCr25SiruMKcX
…orner of the field)

The slices pasted from the extension were taken as centered and shifted by half the field, so the mask landed in a
corner and the algorithms did not converge. The plots stay centered, their mask outline is shifted accordingly.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RKuN84WCxVCr25SiruMKcX
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RKuN84WCxVCr25SiruMKcX

seb5g commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

CI failure was test_the_input_beam_is_compensated_for_the_amplitude_modulators (and a second test with a centered mask): they gave the intermediate mask around the center, which is now interpreted in the frame of the extension (origin at the corner). Pushed a fix to the tests (shift by half the field) and to the docs snapshot script, which had the same assumption. The playground tests and test_algo_helpers.py pass locally.


Generated by Claude Code

seb5g commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

The tests / tests job on the push run (Python 3.11, PySide6, Xvfb) died with a segmentation fault inside QApplication.processEvents() (field/utils.py progressbar, called by load_field in test_intermediate_field_saved, an existing test that does not touch the new code). It looks like a Qt crash under Xvfb, not a test failure; the same tests pass in the other jobs on this head (e.g. Python 3.10 / PyQt5). I re-ran the failed job once. If it fails the same way I will dig into it.


Generated by Claude Code

…n sub group of the run, with their own savers

The groups Fields000 and Metrics000 are enlarged along their own step axis, Final000 holds the fields saved once. They are
saved by ModuleSaver children of the ShapingSaver, as the control modules are in the group of an extension.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RKuN84WCxVCr25SiruMKcX
…ave of the extension

ContinuousSaver is renamed RunSaver (it saves a whole run). The Input and Target fields of a run are saved with the settings
of their loaders by the code of the field files (add_field_group), and the Final group by the one of AlgoApp.save
(add_algorithm_group).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RKuN84WCxVCr25SiruMKcX

seb5g commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

The tests jobs on the previous commit failed in the flake8 step: F821 undefined name 'Field' in the string annotations of utilities/h5saving.py. Fixed by importing Field under TYPE_CHECKING; the same flake8 selection (E9,F63,F7,F82) now reports 0 locally, and the new saving tests pass.


Generated by Claude Code

…p of the extension saves them

All the settings of the loader app (from FieldLoaderApp.params) with the values the script used, plus the settings of the
loader.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RKuN84WCxVCr25SiruMKcX
…index); convergence plot script

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RKuN84WCxVCr25SiruMKcX
@seb5g
seb5g merged commit 105cba8 into 5.3.x Nov 9, 2026
7 checks passed
@seb5g
seb5g deleted the feature/headless-save-final branch November 9, 2026 13:34
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.

2 participants