Fields and Elements¶
Fields and elements for use with model templates
- class condor.fields.Direction(*values)¶
Enum
used to indicate the direction of an element relative to a model
- class condor.fields.FieldValues¶
Base class for Field dataclasses
- flatten()¶
turn the bound values of this field instance into a single symbol – may be numeric or in the backend representation (symbol class)
- classmethod wrap(values)¶
turn a single symbol into a bound field dataclasss
- class condor.fields.Field(direction=None, name='', model=None, inherit_from=None, model_name='')¶
Base field
Model templates have field instances added to them which are parents of elements used in models.
How to create a new Field type:
Subclass
BaseElement
as needed. Will automatically try to findNameElement
forNameField
, or provide aselement_class
kwarg in subclass definitionUpdate
_init_kwargs
to define kwargs that should get passed during inheritance from Model templates to user modelsUntil a better API is designed & implemented, instance attributes created during
__init__
should start with a_
sosetattr
onAssignedField
can filter itUse
create_element
to create elements, passing**kwargs
to element dataclass as much as possible to keep DRY
- bind(name, model)¶
Bind an existing Field instance to a model
- bind_dataclass()¶
Bind dataclass module and name in an attempt to make pickle-able
- prepare(cls_dict)¶
Hook to pass reference of class dictionary to field to allow automatic name extraction and assignment
- inherit(model_name, field_type_name, **kwargs)¶
copy and re-assign name – used in ModelType.__prepare__ before model is available
- list_of(field_name)¶
Create a list of a particular element attribute for all elements in field
- get(*args, **kwargs)¶
Get a list of field elements where every field matches kwargs
If only one, return element without list wrapper.
- flat_index(of_element)¶
Helper to get the starting index of an element
- create_element(**kwargs)¶
Create an element
- create_dataclass()¶
Create the dataclass for this model and field with the current elements
- dataclass_of(attr='backend_repr')¶
construct a dataclass of the field where values are the attr of each element
- flatten(attr='backend_repr')¶
flatten the values into a single 1D array
- wrap(values)¶
wrap a flattened array into the elements of appropriate shape
- class condor.fields.FrontendElementData(field_type: condor.fields.Field, backend_repr: casadi.casadi.MX, name: str = '')¶
- class condor.fields.BaseElement(shape: tuple, symmetric: bool, diagonal: bool, field_type: condor.fields.Field, backend_repr: casadi.casadi.MX, name: str = '')¶
- class condor.fields.FreeElement(shape: tuple, symmetric: bool, diagonal: bool, field_type: Field, backend_repr: MX, name: str = '')¶
- class condor.fields.FreeField(direction=None, name='', model=None, inherit_from=None, model_name='')¶
Field that generates a symbol assigned to a class attribute during model definition.
- create_from(other, **aliases)¶
Get or create elements based on another field
Elements from other are created on this field unless it already exists or is supplied in aliases.
- Parameters:
other (Field) – Other field to get elements from
**aliases – Name-element aliases to use in place of elements of other
- Returns:
elem_map – Dictionary mapping element names to elements
- Return type:
dict
- element_class¶
alias of
FreeElement
- class condor.fields.FreeAssignedField(direction=None, name='', model=None, inherit_from=None, model_name='')¶
- element_class¶
alias of
FreeElement
- class condor.fields.WithDefaultElement(shape: tuple, symmetric: bool, diagonal: bool, field_type: Field, backend_repr: MX, name: str = '', default: float = 0.0)¶
Element with an optional default value
- default: float = 0.0¶
default value
- class condor.fields.WithDefaultField(direction=None, name='', model=None, inherit_from=None, model_name='')¶
- element_class¶
alias of
WithDefaultElement
- class condor.fields.BoundedElement(shape: tuple, symmetric: bool, diagonal: bool, field_type: Field, backend_repr: MX, name: str = '', upper_bound: float = inf, lower_bound: float = -inf)¶
Element with upper and lower bounds
- upper_bound: float = inf¶
upper bound
- lower_bound: float = -inf¶
lower bound
- class condor.fields.InitializedElement(shape: tuple, symmetric: bool, diagonal: bool, field_type: Field, backend_repr: MX, name: str = '', upper_bound: float = inf, lower_bound: float = -inf, initializer: float = 0.0, warm_start: bool = True)¶
Element with an initial value
- initializer: float = 0.0¶
initial value or expression depending on other existing elements
- warm_start: bool = True¶
whether the initial value should come from the implementation/solver
- class condor.fields.InitializedField(direction=None, name='', model=None, inherit_from=None, model_name='')¶
- element_class¶
alias of
InitializedElement
- class condor.fields.BoundedAssignmentField(direction=None, name='', model=None, inherit_from=None, model_name='')¶
- element_class¶
alias of
BoundedElement
- class condor.fields.TrajectoryOutputElement(shape: tuple, symmetric: bool, diagonal: bool, field_type: Field, backend_repr: MX, name: str = '', terminal_term: BaseElement = 0.0, integrand: BaseElement = 0.0)¶
Element with terminal and integrand terms for trajectory analysis
- terminal_term: BaseElement = 0.0¶
expression for the terminal term
- integrand: BaseElement = 0.0¶
expression for the integrand term
- class condor.fields.TrajectoryOutputField(direction=None, name='', model=None, inherit_from=None, model_name='')¶
- element_class¶
alias of
TrajectoryOutputElement
- class condor.fields.DependentElement(shape: tuple, symmetric: bool, diagonal: bool, field_type: Field, backend_repr: MX, name: str = '')¶
- class condor.fields.AssignedElement(shape: tuple, symmetric: bool, diagonal: bool, field_type: condor.fields.Field, backend_repr: casadi.casadi.MX, name: str = '')¶
- class condor.fields.AssignedField(direction=None, name='', model=None, inherit_from=None, model_name='')¶
- element_class¶
alias of
AssignedElement
- class condor.fields.MatchedElementMixin(match: condor.fields.BaseElement)¶
- class condor.fields.MatchedElement(match: BaseElement, shape: tuple, symmetric: bool, diagonal: bool, field_type: Field, backend_repr: MX, name: str = '')¶
Element matched with another element of another field
- class condor.fields.MatchedField(matched_to=None, default_factory=<function <lambda>>, **kwargs)¶
- element_class¶
alias of
MatchedElement
- dataclass_of(on_field=None)¶
construct a dataclass of the field where values are the attr of each element
- flatten(on_field=None)¶
flatten matches to the on_field, defaults tot he match.
on_field is used to override which field instance’s dataclass gets filled in; this is currently used during TrajectoryAnalysis construction which creates its own copies of the matching fields