madgui.model.errors module

This module defines functions and classes to load and represent MAD-X model errors, such as alignment errors or field errors.

Errors are represented as strings such as:

'Δax_b3mu1'         # absolute error in parameter
'δax_b3mu1'         # relative error in parameter
'Δb3mu1v->kick'     # absolute error in element attribute
'g3mu1<dx>'         # alignment error

Functions

import_errors(model, spec)

Apply errors to a model defined by a dictionary {error: value} with types {str: float}.

apply_errors(model, errors, values)

Apply list of errors and list of corresponding values to a given model.

parse_error(name)

Instanciate a subtype of BaseError, depending on the format of name.

Classes

Param(name)

Error on a global variable (knob).

Ealign(select, attr)

Alignment error.

Efcomp(select, attr, value[, order, radius])

Field error.

ElemAttr(elem, attr)

Element attribute error.

InitTwiss(name)

Error in twiss initial condition (x, px, y, py).

ScaleAttr(elem, attr)

Relative element attribute error.

ScaleParam(name)

Relative global variable error.

BaseError(name)

Base class for model errors.

RelativeError(name)

Base class for relative errors.

class madgui.model.errors.BaseError(name)[source]

Bases: object

Base class for model errors.

Subclasses must implement get, set, and tinker.

In the simplest case, get returns the current value of the error, tinker returns the given step, and set sets a variable. However, this logic is not always available. In general, the following protocol must be implemented:

  • get(): return a backup value that will be later used to restore the current error value

  • tinker() returns a value that should be used to update the current value

  • set() is called with the return value of tinker() to change the value of the error, and later with the return value of get() to restore to the original state.

Methods

get(model, step)

Get a “backup” value that represents with what set() should be called to restore the current value.

is_defined_for(model)

Check whether this error is relevant for the given model.

set(model, value)

Update the error value.

tinker(value, step)

Return the value that should be passed to set() in order to increment the error by step.

vary(model, step)

Applies the error and returns a context manager that restores the error to its original value on exit.

Attributes

leader

str(object=’’) -> str

get(model, step)[source]

Get a “backup” value that represents with what set() should be called to restore the current value.

is_defined_for(model)[source]

Check whether this error is relevant for the given model.

leader = 'Δ'
set(model, value)[source]

Update the error value.

tinker(value, step)[source]

Return the value that should be passed to set() in order to increment the error by step. value is provided as the return value of get().

vary(model, step)[source]

Applies the error and returns a context manager that restores the error to its original value on exit.

class madgui.model.errors.Ealign(select, attr)[source]

Bases: madgui.model.errors.BaseError

Alignment error.

Methods

get(model, step)

Get a “backup” value that represents with what set() should be called to restore the current value.

is_defined_for(model)

Check whether this error is relevant for the given model.

set(model, value)

Update the error value.

tinker(value, step)

Return the value that should be passed to set() in order to increment the error by step.

get(model, step)[source]

Get a “backup” value that represents with what set() should be called to restore the current value.

is_defined_for(model)[source]

Check whether this error is relevant for the given model.

set(model, value)[source]

Update the error value.

tinker(value, step)[source]

Return the value that should be passed to set() in order to increment the error by step. value is provided as the return value of get().

class madgui.model.errors.Efcomp(select, attr, value, order=0, radius=1)[source]

Bases: madgui.model.errors.BaseError

Field error.

Methods

get(model, step)

Get a “backup” value that represents with what set() should be called to restore the current value.

is_defined_for(model)

Check whether this error is relevant for the given model.

set(model, value)

Update the error value.

tinker(value, step)

Return the value that should be passed to set() in order to increment the error by step.

get(model, step)[source]

Get a “backup” value that represents with what set() should be called to restore the current value.

is_defined_for(model)[source]

Check whether this error is relevant for the given model.

set(model, value)[source]

Update the error value.

tinker(value, step)[source]

Return the value that should be passed to set() in order to increment the error by step. value is provided as the return value of get().

class madgui.model.errors.ElemAttr(elem, attr)[source]

Bases: madgui.model.errors.BaseError

Element attribute error.

Methods

get(model, step)

Get a “backup” value that represents with what set() should be called to restore the current value.

is_defined_for(model)

Check whether this error is relevant for the given model.

set(model, value)

Update the error value.

get(model, step)[source]

Get a “backup” value that represents with what set() should be called to restore the current value.

is_defined_for(model)[source]

Check whether this error is relevant for the given model.

set(model, value)[source]

Update the error value.

class madgui.model.errors.InitTwiss(name)[source]

Bases: madgui.model.errors.BaseError

Error in twiss initial condition (x, px, y, py).

Methods

get(model, step)

Get a “backup” value that represents with what set() should be called to restore the current value.

set(model, value)

Update the error value.

get(model, step)[source]

Get a “backup” value that represents with what set() should be called to restore the current value.

set(model, value)[source]

Update the error value.

class madgui.model.errors.Param(name)[source]

Bases: madgui.model.errors.BaseError

Error on a global variable (knob).

Methods

get(model, step)

Get a “backup” value that represents with what set() should be called to restore the current value.

is_defined_for(model)

Check whether this error is relevant for the given model.

set(model, value)

Update the error value.

get(model, step)[source]

Get a “backup” value that represents with what set() should be called to restore the current value.

is_defined_for(model)[source]

Check whether this error is relevant for the given model.

set(model, value)[source]

Update the error value.

class madgui.model.errors.RelativeError(name)[source]

Bases: madgui.model.errors.BaseError

Base class for relative errors.

Attributes

leader

str(object=’’) -> str

Methods

tinker(value, step)

Return the value that should be passed to set() in order to increment the error by step.

leader = 'δ'
tinker(value, step)[source]

Return the value that should be passed to set() in order to increment the error by step. value is provided as the return value of get().

class madgui.model.errors.ScaleAttr(elem, attr)[source]

Bases: madgui.model.errors.RelativeError, madgui.model.errors.ElemAttr

Relative element attribute error.

class madgui.model.errors.ScaleParam(name)[source]

Bases: madgui.model.errors.RelativeError, madgui.model.errors.Param

Relative global variable error.

madgui.model.errors.apply_errors(model, errors, values)[source]

Apply list of errors and list of corresponding values to a given model.

madgui.model.errors.import_errors(model, spec: dict)[source]

Apply errors to a model defined by a dictionary {error: value} with types {str: float}. The error keys are parsed by parse_error.

madgui.model.errors.parse_error(name)[source]

Instanciate a subtype of BaseError, depending on the format of name. We currently understand the following formats:

x               -> InitTwiss
Δax_b3mu1       -> ElemAttr
δax_b3mu1       -> ScaleAttr
Δg3mu1->angle   -> Param
δg3mu1->angle   -> ScaleParam
g3mu1<dx>       -> Ealign