Skip to content

fix: define and apply the fitted background in exp07's GenX script - #11

Merged
NaNIsaac merged 2 commits into
mainfrom
fix/exp07-genx-background
Oct 23, 2026
Merged

NaNIsaac merged 2 commits into
mainfrom
fix/exp07-genx-background

Conversation

@NaNIsaac

Copy link
Copy Markdown
Owner

Tier: physics

  • exp07's GenX script (runs/exp07_fourier_hires/engine/script_builder.py) now defines the background:
    • ibkg with getter and setter in Sim_Vars, starting from init_params["ibkg"];
    • the instrument starts from it instead of a fixed Ibkg=1e-10;
    • Sim() copies it into the instrument.
  • Results change. engine/fitting.py registers "v.set_ibkg" as a fit parameter, and with the script on main GenX raises AttributeError: 'Sim_Vars' object has no attribute 'get_ibkg' when that parameter is registered (genx 3.7.13 as locked, and 3.8.0). The exp07 GenX fit therefore stopped in _setup_parameters. Now it can run, the background is fitted and applied, and the starting background is the 1e-7 the fitter passes rather than 1e-10.
  • No exp07 run was redone (out of scope).

Fixes item 1 of #9. Item 2 (layer order) is a decision and is not touched.

Stacked on #6 (chore/conventions), which adds the tests directory and the pytest setup. Merge #6 first; GitHub then retargets this PR to main.

Correction to #9 item 1

The issue says the background "is fitted but not applied". That is the Reflecto case (Reflecto#2, fixed in Reflecto#5). In exp07 it is worse: the script never defined ibkg (git log -S ibkg on the file is empty), so the fit could not register the parameter at all.

Evidence

Test first (18f80c9), then the fix (0071c07). tests/test_exp07_genx_script.py:

test main this PR
test_background_can_be_registered_as_a_fit_parameter (what fitting.py does) AttributeError pass
test_background_reaches_the_simulation (ibkg 1e-7 → 1e-5 moves the q = 0.5 tail by 9.9e-6) fails pass
test_intensity_scale_reaches_the_simulation (control: i0 was already applied) pass pass

The tests simulate with compile=False. The default compile=True reruns the script and resets v, so it would hide any parameter change.

Tests

Local, Windows, uv sync --frozen (genx 3.7.13):

  • uv run pytest: 27 passed (26 s);
  • uvx ruff@0.17.1 check: clean.

@NaNIsaac
NaNIsaac changed the base branch from chore/conventions to main October 23, 2026 06:34
@NaNIsaac
NaNIsaac merged commit 752a601 into main Oct 23, 2026
5 checks passed
@NaNIsaac
NaNIsaac deleted the fix/exp07-genx-background branch October 23, 2026 15:51
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