Skip to content

Refactor and fix MAD-NG interface - #834

Open
jgray-19 wants to merge 1 commit into
xsuite:mainfrom
jgray-19:madng_interface_fix
Open

Refactor and fix MAD-NG interface#834
jgray-19 wants to merge 1 commit into
xsuite:mainfrom
jgray-19:madng_interface_fix

Conversation

@jgray-19

@jgray-19 jgray-19 commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Description

Refactors xtrack/madng_interface.py around readable MAD-NG program string blocks and explicit data exchange through pymadng. Updates the interface for pymadng==0.9.6, meaning that phix and phiy needs to be renamed to wxp and wyp.

In the current conversion - the RBends have the wrong length, therefore MADX.option.rbarc is configured before loading the generated MAD-NG sequence, rather than after, which has no effect.

Fixed the mapdef usage and docstring.

Fixes Line.match(..., use_tpsa=True) with TargetRmatrixTerm by retrieving results through unique internal range-term keys. Adds coverage for TPSA R-matrix matching.

Checklist

Mandatory:

  • I have added tests to cover my changes
  • All the tests are passing, including my new ones
  • I described my changes in this PR description

Optional:

  • The code I wrote follows good style practices (see PEP 8 and PEP 20).
  • I have updated the docs in relation to my changes, if applicable
  • I have tested also GPU contexts

  Refactors xtrack/madng_interface.py around readable Lua programs and explicit data exchange through pymadng. The refactor centralizes MAD-NG model setup, Twiss
  ranges, target construction, tracking, R-matrix evaluation, Jacobian extraction, and cleanup while preserving TPSA variables correctly.

  Updates the interface for pymadng==0.9.6, meaning that phix and phiy needs to be rename dto wxp and wyp.

MADX.option.rbarc is configured before loading the generated MAD-NG sequence (rbends had the wrong length - additional test)

Fixed the mapdef usage and docstring.

  Fixes Line.match(..., use_tpsa=True) with TargetRmatrixTerm by retrieving results through unique internal range-term keys. Adds coverage for TPSA R-matrix matching.
@jgray-19
jgray-19 marked this pull request as ready for review August 2, 2026 01:03
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