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
|
Apply errors to a model defined by a dictionary |
|
Apply list of errors and list of corresponding values to a given model. |
|
Instanciate a subtype of |
Classes
|
Error on a global variable (knob). |
|
Alignment error. |
|
Field error. |
|
Element attribute error. |
|
Error in twiss initial condition (x, px, y, py). |
|
Relative element attribute error. |
|
Relative global variable error. |
|
Base class for model errors. |
|
Base class for relative errors. |
-
class
madgui.model.errors.BaseError(name)[source]¶ Bases:
objectBase class for model errors.
Subclasses must implement
get,set, andtinker.In the simplest case,
getreturns the current value of the error,tinkerreturns the given step, andsetsets 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 valuetinker()returns a value that should be used to update the current valueset()is called with the return value oftinker()to change the value of the error, and later with the return value ofget()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 bystep.vary(model, step)Applies the error and returns a context manager that restores the error to its original value on exit.
Attributes
str(object=’’) -> str
-
get(model, step)[source]¶ Get a “backup” value that represents with what
set()should be called to restore the current value.
-
leader= 'Δ'¶
-
class
madgui.model.errors.Ealign(select, attr)[source]¶ Bases:
madgui.model.errors.BaseErrorAlignment 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 bystep.
-
class
madgui.model.errors.Efcomp(select, attr, value, order=0, radius=1)[source]¶ Bases:
madgui.model.errors.BaseErrorField 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 bystep.
-
class
madgui.model.errors.ElemAttr(elem, attr)[source]¶ Bases:
madgui.model.errors.BaseErrorElement 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.
-
class
madgui.model.errors.InitTwiss(name)[source]¶ Bases:
madgui.model.errors.BaseErrorError 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.
-
class
madgui.model.errors.Param(name)[source]¶ Bases:
madgui.model.errors.BaseErrorError 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.
-
class
madgui.model.errors.RelativeError(name)[source]¶ Bases:
madgui.model.errors.BaseErrorBase class for relative errors.
Attributes
str(object=’’) -> str
Methods
tinker(value, step)Return the value that should be passed to
set()in order to increment the error bystep.-
leader= 'δ'¶
-
-
class
madgui.model.errors.ScaleAttr(elem, attr)[source]¶ Bases:
madgui.model.errors.RelativeError,madgui.model.errors.ElemAttrRelative element attribute error.
-
class
madgui.model.errors.ScaleParam(name)[source]¶ Bases:
madgui.model.errors.RelativeError,madgui.model.errors.ParamRelative 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.