Skip to content

Default a branch's inherit to its own name; report empty branches#76

Merged
DavidSagan merged 1 commit into
mainfrom
branch-default-inherit
Jul 24, 2026
Merged

Default a branch's inherit to its own name; report empty branches#76
DavidSagan merged 1 commit into
mainfrom
branch-default-inherit

Conversation

@DavidSagan

Copy link
Copy Markdown
Member

The bug

A branch's inherit is optional and "Default is the name of the Branch" (lattice-construction.md, s:lattice.construct). So

branches:
  - ln:
      periodic: false

is the branch ln built from the BeamLine ln, overriding its periodic. Expansion reached a definition only through a bare - ln or an explicit inherit:, and never consulted the entry's own key — so this form expanded to nothing at all, silently.

The missing elements then surfaced somewhere unrelated. On a real file the only sign was:

controller 'oo': target 'q>MagneticMultipoleP.Kn1' matches nothing in the expanded lattice

which is true but says nothing useful, and it also masked a genuine error in the file (a line referring to an element that did not exist).

The fix

  • default_branch_inherit runs before expand() and writes a keyed branch entry's own key back out as an inherit, when the branch has neither an explicit inherit nor a line of its own and the name is defined. Appending it leaves the branch's own keys ahead of the inherited ones, which is what keeps periodic an override. Fork-built branches copy their to_line outright and never pass through here.

  • check_branches_expanded runs after expansion — so root and forked branches alike have had their chance to fill in — and reports any branch holding no elements:

    • branch 'ln': no root BeamLine 'ln' is defined when the name was defaulted from the key and resolves to nothing;
    • branch 'ln': expanded to no elements otherwise. An explicit inherit naming nothing is left to expand()'s existing inherit: 'x' is not defined.

Without this, an empty branch is diagnosed only wherever some later check first trips over it.

Also

where() in pals_check.cpp now joins an element with its parameter group using the same > the parameter paths use:

element 'beginning_b1>ReferenceP': unknown parameter 'species_ref:'; did you mean 'species_ref'?

rather than element 'beginning_b1' ReferenceP: .... A group with no owning element still renders bare.

Tests

Four new cases (suite: 221 cases / 1162 assertions, all passing):

  • test_expansion.cpp — a branch with no inherit picks up its named root line and keeps its periodic override; an explicit inherit still wins over the branch key; an empty branch is reported, both the undefined-root and empty-line variants.
  • test_controllers.cpp — the reported shape end to end: q>MagneticMultipoleP.Kn1 resolves and drives the parameter.

Verified as real regressions by stubbing out both new calls: 3 of the 4 fail without the fix. The explicit-inherit case is a guard against the default overreaching, so it passes either way.

🤖 Generated with Claude Code

A branch's `inherit` is optional and defaults to the branch's own name
(lattice-construction.md, s:lattice.construct), so

    branches:
      - ln:
          periodic: false

is the branch `ln` built from the BeamLine `ln`. Expansion reached a
definition only through a bare `- ln` or an explicit `inherit`, so this
form expanded to nothing at all -- silently. The missing elements then
surfaced somewhere unrelated and far downstream, as a controller target
that "matches nothing in the expanded lattice".

Supply the default in `default_branch_inherit`, before expand() runs, by
writing the entry's key back out as an `inherit`. Appending it leaves the
branch's own keys ahead of the inherited ones, which is what keeps
`periodic` an override.

`check_branches_expanded` then reports any branch that comes out of
expansion holding no elements, so this class of mistake is diagnosed
where it happens rather than wherever a later check first trips over it.

Also: `where()` in pals_check joins an element and its parameter group
with the `>` the parameter paths use -- `element 'beginning_b1>ReferenceP'`
rather than `element 'beginning_b1' ReferenceP`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@DavidSagan
DavidSagan merged commit d8c1c59 into main Jul 24, 2026
3 checks passed
@DavidSagan
DavidSagan deleted the branch-default-inherit branch July 24, 2026 20:09
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