accelmo.backend.madng.scripts

Helpers for loading or generating MAD-NG tracking scripts.

accelmo.backend.madng.scripts.SET_KNOBS_PLAIN = 'local v = python:recv()\nfor i, name in ipairs(set_names) do loaded_sequence[name] = v[i] end'

Set knobs from set_names and one received vector; plain assigns numbers, not TPSA constants.

accelmo.backend.madng.scripts.dump_debug_script(script_name, text, *, debug, mad_logfile=None, worker_id=None)[source]

Write a generated MAD script to disk when debug mode is enabled.

Return type:

Path | None

Parameters:
  • script_name (str)

  • text (str)

  • debug (bool)

  • mad_logfile (Path | None)

  • worker_id (int | None)

accelmo.backend.madng.scripts.build_zero_field_removal_script()[source]

Lua that removes thick zero-field magnets; the gaps are tracked as implicit drifts.

Run after machine state and TPSA knobs are installed. An element carrying a knob is never removed (its strength is TPSA), nor is one whose strength is a deferred expression, which a machine-state variable can still change.

Return type:

str

accelmo.backend.madng.scripts.build_track_speedup_script(track_methods)[source]

Remove zero-field magnets and set per-kind track methods.

Return type:

str

Parameters:

track_methods (dict[str, int])

accelmo.backend.madng.scripts.build_tracking_init_script(observables, *, start_on_first_turn=False)[source]

Build the tracking initialisation script for the requested observables.

Return type:

str

Parameters:
  • observables (tuple[str, ...])

  • start_on_first_turn (bool)

accelmo.backend.madng.scripts.build_tracking_script(observables, *, include_start_derivatives=False)[source]

Build the tracking script for the requested observables.

include_start_derivatives also sends d{o}_dc0; the caller must set save_start_derivatives = true in MAD first.

Return type:

str

Parameters:
  • observables (tuple[str, ...])

  • include_start_derivatives (bool)

accelmo.backend.madng.scripts.build_tracking_preflight_script()[source]

Build the single-particle preflight script.

Tracks one particle through the configured range/turns with a counting atexit and reports how many BPM points were observed. The worker compares this against the allocated result-vector size (nbpms * n_run_turns) once, before the optimisation loop, so an observe/range misconfiguration fails with a clear message here instead of as an opaque seti index-out-of-bounds deep in a tracking run. Observable-independent: only the observation geometry matters.

Return type:

str

accelmo.backend.madng.scripts.build_validation_init_script(observables)[source]

Build the validation initialisation script without derivative storage.

Return type:

str

Parameters:

observables (tuple[str, ...])

accelmo.backend.madng.scripts.build_validation_script(observables)[source]

Build the validation tracking script without derivative returns.

Return type:

str

Parameters:

observables (tuple[str, ...])