Skip to content

fix(optimization): update linked configurations that own no variable - #1129

Merged
HarrisonKramer merged 1 commit into
optiland:masterfrom
lyn1dev:fix/1120-update-linked-configurations
Nov 10, 2026
Merged

HarrisonKramer merged 1 commit into
optiland:masterfrom
lyn1dev:fix/1120-update-linked-configurations

Conversation

@lyn1dev

@lyn1dev lyn1dev commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Summary

OptimizationProblem.update_optics() updated only the optics that own a variable. A
configuration that contributes operands but no variable was therefore never refreshed:
its pickups to its source configuration were never applied, so its operand was constant
and the optimizer silently ignored it.

update_optics() now updates the variable-owning optics first and then every other optic
referenced by operand.input_data["optic"], each optic once per call. Updating the source
first means a derived configuration's pickups read the current variable values. No public
signature changes; a problem whose operands only use the optics that own variables does
exactly the same work as before.

Related issue

Fixes #1120

How I verified this

  • The reproduction in the issue now prints 30.0 30.0 after update_optics(); before the
    change it printed 30.0 22.01359.
  • New test in tests/test_multiconfig.py: a radius variable on a base CookeTriplet and an
    f2 operand on a configuration derived from it (no variable of its own, pickups to the
    base). The optimizer moves the base radius from 22.0136 to 19.9184, the derived
    configuration's radius equals the base radius afterwards (its pickups were applied), and
    the operand reaches its 45.0 target. I checked the numbers by comparing the two radii and
    the operand value against the target rather than only trusting the optimizer's status.
  • The same test fails on both backends when the change to update_optics() is reverted, and
    passes with it, so it guards the fix rather than the optimizer.
  • MPLBACKEND=Agg .venv/Scripts/python.exe -m pytest -v tests/test_multiconfig.py:
    8 passed (NumPy and PyTorch).
  • MPLBACKEND=Agg .venv/Scripts/python.exe -m pytest -q tests/optimization/:
    736 passed, 10 skipped.
  • MPLBACKEND=Agg .venv/Scripts/python.exe -m pytest -q tests/test_ml.py: 18 passed;
    MPLBACKEND=Agg .venv/Scripts/python.exe -m pytest -q tests/diagnostics: 116 passed.
  • ruff check optiland/: all checks passed. ruff format --check on the changed files:
    already formatted.
  • mypy optiland/: success, no issues in 612 source files.
  • Environment: python -m venv .venv, then pip install -e "." --group dev and
    pip install torch for the PyTorch backend, because uv was not available here.

Checklist

  • If this PR addresses an issue, I claimed it there first and nobody else had.
  • I have read the entire diff and can explain every change.
  • This PR is one logical change and is as small as it reasonably can be.
  • Tests are added or updated, and the relevant ones pass locally (NumPy and PyTorch where applicable).
  • Public API is unchanged, or the change was discussed in the linked issue.
  • Docs and docstrings are updated where needed.

AI assistance

  • No AI tools were used.
  • AI tools helped (tool: DeepSeek V4.1 Flash). I reviewed, ran, and understand all of the output.

update_optics() only refreshed the optics that own a variable, so a
configuration that contributes operands but no variable kept its stale
values: its pickups were never applied and its operands did not respond
to the variables.

Update the variable-owning optics first, then every other optic
referenced by an operand, each optic once per call, so that a derived
configuration reads an already-updated source.
@codecov

codecov Bot commented Nov 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@HarrisonKramer

Copy link
Copy Markdown
Collaborator

Hi @lyn1dev, thanks for the fix and the test. It follows the approach in the issue exactly. Merging now.

Best,
Kramer

@HarrisonKramer
HarrisonKramer merged commit 2ec5f0b into optiland:master Nov 10, 2026
17 checks passed
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.

Optimization does not update linked configurations that own no variable

2 participants