madgui.model.madx module

MAD-X backend for madgui.

Classes

Model(madx, data, *[, filename, undo_stack, …])

Contains the whole global state of a MAD-X instance and (possibly) loaded metadata.

TwissTable(name, libmadx[, _check])

Provide the following features on top of cpymad.madx.Table:

Functions

reverse_sequence(madx, name, elements)

Create a direction reversed copy of the sequence.

reverse_sequence_inplace(madx, seq_name)

class madgui.model.madx.Model(madx, data, *, filename=None, undo_stack=None, interpolate=0)[source]

Bases: object

Contains the whole global state of a MAD-X instance and (possibly) loaded metadata.

Variables
  • madx (Madx) – CPyMAD interpreter

  • Model.data (dict) – loaded model data

  • path (str) – base folder

Attributes

ELEM_KNOBS

dict() -> new empty dictionary

beam

Get the beam parameter dictionary.

continuous_matching

bool(x) -> bool

globals

Return dict-like global variables.

libmadx

Access to the low level cpymad API.

twiss_args

Return the dictionary of parameters for the MAD-X TWISS command.

twiss_columns

list() -> new empty list

updated

Signal<>

Methods

adjust_match_pos(el, pos)

backtrack(**twiss_init)

Backtrack final orbit through the reversed sequence.

call(name)

can_match_at(element)

contains(element)

destroy()

Annihilate current model.

el_pos(el)

Position for matching / output.

ex()

export_beam()

export_globals([var_type])

export_twiss()

ey()

fetch_beam()

fetch_twiss()

get_best_match_pos(pos)

Find optics element by longitudinal position.

get_elem_knobs(elem)

get_elem_sigma(elem)

get_elem_twiss(elem)

get_element_by_position(pos)

Find optics element by longitudinal position.

get_knobs()

Get list of knobs.

get_orbit_response_matrix(monitors, knobs[, …])

Compute the orbit response matrix Δx/Δφ numerically (by varying knobs) and return as M×2×K matrix (monitors × x|y × knobs).

get_transfer_maps(elems[, interval])

Get the transfer matrices R(i,j) between the given elements.

get_twiss(elem, name, pos)

Return beam envelope at element.

invalidate()

Invalidate twiss and sectormap computations.

load_file(filename[, madx, undo_stack, …])

Load model from .madx or .yml file and pass additional arguments to the Model constructor.

load_strengths(filename)

match(vary, constraints[, mirror_mode])

model_data()

Return model data as dictionary.

parse_range(range)

Convert a range str/tuple to a tuple of Element.

read_monitor(name)

Mitigates read access to a monitor.

read_param(expr)

Read element attribute.

reverse()

save(filename)

Save model to file.

sector()

Compute sectormaps of all elements.

sectormap(elem_from[, elem_to, interval])

Return SECTORMAP|KICKS in the closed range [from,to] as 7x7 matrix.

set_element_attribute(elem, attr, value)

survey()

Recalculate survey coordinates.

track_one([x, px, y, py, range])

Track a particle through the sequence.

twiss(**kwargs)

Recalculate TWISS parameters.

update_beam(beam[, text])

update_element(data, elem_index[, text])

update_globals(globals[, text])

update_twiss_args(twiss[, text])

write_params(globals[, text])

ELEM_KNOBS = {'hkicker': ['kick'], 'kicker': ['hkick', 'vkick'], 'multipole': ['knl', 'ksl'], 'quadrupole': ['k1', 'k1s'], 'sbend': ['angle', 'k0'], 'solenoid': ['ks'], 'srotation': ['angle'], 'vkicker': ['kick']}
adjust_match_pos(el, pos)[source]
backseq = None
backtrack(**twiss_init)[source]

Backtrack final orbit through the reversed sequence.

property beam

Get the beam parameter dictionary.

call(name)[source]
can_match_at(element)[source]
contains(element)[source]
continuous_matching = False
destroy()[source]

Annihilate current model. Stop interpreter.

el_pos(el)[source]

Position for matching / output.

ex()[source]
export_beam()[source]
export_globals(var_type=1)[source]
export_twiss()[source]
ey()[source]
fetch_beam()[source]
fetch_twiss()[source]
get_best_match_pos(pos)[source]

Find optics element by longitudinal position.

get_elem_knobs(elem)[source]
get_elem_sigma(elem)[source]
get_elem_twiss(elem)[source]
get_element_by_position(pos)[source]

Find optics element by longitudinal position.

get_knobs()[source]

Get list of knobs.

get_orbit_response_matrix(monitors, knobs, errors=(), values=()) → numpy.array[source]

Compute the orbit response matrix Δx/Δφ numerically (by varying knobs) and return as M×2×K matrix (monitors × x|y × knobs).

get_transfer_maps(elems, interval=1, 1)[source]

Get the transfer matrices R(i,j) between the given elements.

The interval parameter can be used to select open/closedness of the individual intervals between the elements by adding offsets to the first and second element in every interval, counted from the entry end of the element.

For example, by setting the interval parameter, the call get_transfer_maps([e0, e1, e2], interval) will retrieve the transfer maps in the following intervals:

  • interval=(0, 0) retrieves [e0, e1) and [e1, e2)

  • interval=(0, 1) retrieves [e0, e1] and [e1, e2]

  • interval=(1, 0) retrieves (e0, e1) and (e1, e2)

  • interval=(1, 1) retrieves (e0, e1] and (e1, e2]

get_twiss(elem, name, pos)[source]

Return beam envelope at element.

property globals

Return dict-like global variables.

invalidate()[source]

Invalidate twiss and sectormap computations. Initiate recomputation.

property libmadx

Access to the low level cpymad API.

classmethod load_file(filename, madx=None, *, undo_stack=None, interpolate=0, **madx_kwargs)[source]

Load model from .madx or .yml file and pass additional arguments to the Model constructor.

load_strengths(filename)[source]
match(vary, constraints, mirror_mode=True, **kwargs)[source]
model_data()[source]

Return model data as dictionary.

parse_range(range)[source]

Convert a range str/tuple to a tuple of Element.

read_monitor(name)[source]

Mitigates read access to a monitor.

read_param(expr)[source]

Read element attribute. Return numeric value.

reverse()[source]
save(filename)[source]

Save model to file.

sector()[source]

Compute sectormaps of all elements.

sectormap(elem_from, elem_to=None, interval=None)[source]

Return SECTORMAP|KICKS in the closed range [from,to] as 7x7 matrix.

If only one parameter is given, return its transfer map.

Elements can be specified by name or index.

For a description of the interval parameter, see get_transfer_maps().

set_element_attribute(elem, attr, value)[source]
survey()[source]

Recalculate survey coordinates.

track_one(x=0, px=0, y=0, py=0, range='#s/#e', **kwargs)[source]

Track a particle through the sequence. Handles backward tracking (sort of) by specifying a negative range.

Currently uses TWISS for tracking internally (to allow tracking through thick sequences). This might change.

twiss(**kwargs)[source]

Recalculate TWISS parameters.

property twiss_args

Return the dictionary of parameters for the MAD-X TWISS command.

twiss_columns = ['alfx', 'alfy', 'betx', 'bety', 'gamx', 'gamy', 'ex', 'ey', 'x', 'y', 'px', 'py', 'envx', 'envy']
update_beam(beam, text='Change beam: {}')[source]
update_element(data, elem_index, text=None)[source]
update_globals(globals, text='Change knobs: {}')[source]
update_twiss_args(twiss, text='Change twiss args: {}')[source]
updated

Signal<>

write_params(globals, text='Change knobs: {}')
class madgui.model.madx.TwissTable(name, libmadx, _check=True)[source]

Bases: cpymad.madx.Table

Provide the following features on top of cpymad.madx.Table:

  • add columns for one-sigma beam envelopes: envx, envy

  • add columns for gamma optical function: gamx, gamy

  • add aliases for beam position: posx, posy

  • override twiss alfa/beta parameters and emittances from the sigma matrix, i.e. in the local reference rather than normal coordinates.

madgui.model.madx.reverse_sequence(madx, name, elements)[source]

Create a direction reversed copy of the sequence.

Parameters
  • madx (Madx) –

  • name (str) – name of the reversed sequence

  • elements (list) – list of elements

madgui.model.madx.reverse_sequence_inplace(madx, seq_name)[source]