Component

class myokit.Component(model, name)

A Component acts as a container of variables.

Variables can be accessed using the comp['var_name'] syntax or through the iterator methods.

Meta-data properties can be accessed via the property meta, for example model.meta['key']= 'value'.

add_alias(name, variable)

Adds an alias to this component. The alias name will be refer to the Variable object given as variable.

Aliases can only be created for variables of other components.

add_variable(name)

Adds a child variable with the given name to this VarOwner.

add_variable_allow_renaming(name)

Attempts to add a child variable with the given name to this VarOwner, but uses a different name if this causes any conflicts.

The new variable’s name will be modified by appending _1, _2, etc. until the conflict is resolved.

This method can be used when symbolically manipulating a model in situations where the exact names are unimportant.

Returns the newly created variable.

alias(name)

Returns the Variable referred to using the alias name.

alias_for(variable)

Returns an alias for the Variable variable. Raises a KeyError if no such alias is found.

can_add_variable(name, variable_whitelist=None)

Returns True if a variable can be added to this VarOwner under the given name.

This method is automatically called by add_variable() and move_variable(), there is no need to call it before using these methods.

To ignore clashes with known variables, a list variable_whitelist can be passed in.

code()

Returns this object in mmt syntax.

count_equations(const=None, inter=None, state=None, bound=None, deep=False)

Returns the number of equations matching the given criteria. See equations() for an explanation of the arguments.

count_variables(const=None, inter=None, state=None, bound=None, deep=False)

Returns the number of variables matching the given criteria. See variables() for an explanation of the arguments.

equations(const=None, inter=None, state=None, bound=None, deep=False)

Creates and returns a filtered iterator over the equations of this object’s variables.

The returned values can be filtered using the following arguments:

const=True|False|None

Set to True to return only constants’ equations. False to exclude all constants and any other value to ignore this check.

For a definition of “constant variable” see variables().

inter=True|False|None

Set to True to return only intermediary variables’ equations, False to exclude all intermediary variables and any other value to ignore this check.

For a definition of “intermediary variable” see variables().

state=True|False|None
Set to True to return only state variables’ equations, False to exclude all state variables and any other value to ignore this check.
bound=True|False|None
Set to True to return only bound variables’ equations, False to exclude all bound variables and any other value to ignore this check.
deep=True|False (by default it’s False)
Set to True to include the equations of nested variables meeting all other criteria.
get(name, class_filter=None)

Searches for a variable with the given qname and returns it.

To return only objects of a certain class, pass it in as class_filter.

The qnames are specified relative to the VarOwner. For example, in a model with a component ina and a variable ina.h we expect the following results

>>> import myokit
>>> m = myokit.load_model('example')
>>> c = m.get('ina')        # Retrieves the component <ina>
>>> h = c.get('h')          # Retrieves the variable <ina.h>
>>> x = c.get('ina.h')      # Searches for <ina.ina.h>: KeyError!
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'ina'
has_alias(name)

Returns True if this Component contains an alias with the given name.

has_alias_for(variable)

Returns True if this Component has an alias for the given Variable.

has_ancestor(obj)

Returns True if the given object obj is an ancestor of this ModelPart.

has_equations(const=None, inter=None, state=None, bound=None, deep=False)

Returns True if there are any equations that can be returned by calling :meth:equations with the same arguments.

has_variable(name)

Returns True if the given name corresponds to a variable in this object. Accepts both single names x and qualified names x.y as input.

This function performs the same search as variable, so in most cases it will be more efficient to call variable() in a try-catch block rather than checking for existence explicitly.

has_variables(const=None, inter=None, state=None, bound=None, deep=False)

Returns True if there are any variables that can be returned by calling :meth:variables with the same arguments.

is_ancestor(obj)

Returns True if this object is an ancestor of the given ModelPart` object.

model()

Returns the model this object belongs to (if set).

move_variable(variable, new_parent, new_name=None)

Moves the given variable to another VarOwner new_parent. In addition, this method can be used to rename variables (either with or without moving them).

name()

Returns this object’s name.

parent(kind=None)

Returns this object’s parent.

If the optional variable kind is set, the method will scan until an instance of the requested type is found.

qname(hide=None)

A component’s qname is simply its name. No model name is prefixed.

remove_alias(name)

Removes an alias from this Component.

remove_aliases_for(var)

Removes any alias for the given variable from this Component.

remove_variable(variable, recursive=False)

Removes the given variable from this VarOwner and from the model.

If recursive is True, any child variables will be deleted as well.

uname()

Returns a globally unique name for this object.

validate()

Attempts to check component validity, raises errors if it isn’t.

var(name)

Searches for the given variable and returns it if found. Accepts both single names x and qualified names x.y as input.

variables(const=None, inter=None, state=None, bound=None, deep=False, sort=False)

Creates and returns a filtered iterator over the contained variables.

The returned values can be filtered using the following arguments:

const=True|False|None

Constants are defined as variables that do not depend on state variables or derivatives. In other words, any variable whose value can be determined before starting an ODE solving routine.

Set to True to return only constants, False to exclude all constants and any other value to ignore this check.

inter=True|False|None

Intermediary variables are those variables that are not constant but are not part of the state. In other words, intermediary variables are the variables that need to be calculated at every step of an ODE solving routine before calculating the ODE derivatives and updating the state.

Set to True to return only intermediary variables, False to exclude all intermediary variables and any other value to ignore this check.

state=True|False|None
Set to True to return only state variables, False to exclude all state variables and any other value to ignore this check.
bound=True|False|None
Set to True to return only variables bound to an external value, False to exclude all bound variables and any other value to forgo this check.
deep=True|False (by default it’s False)
Set to True to return nested variables meeting all other criteria.
sort=True|False (by default it’s False)
Set to True to return the variables in a consistent order. (Note that this does _not_ mean alphabetical sorting of all variables, just that the order is consistent between calls!)