dynamics

classes.dynamics

Dynamics models.

The public import location for :class:Dynamics, alongside the helpers that read a model out of the ontology.

There is no wrapper class: a model’s own methods live in tvbo.behaviour.dynamics and are attached to the generated class itself, so a Dynamics carries them however it was built — loaded through LinkML, validated through Pydantic, or resolved onto an edge. The equations live on a SymbolicSystem, one per model.

Examples

from tvbo import Dynamics

lorenz = Dynamics(
    parameters={"sigma": {"value": 10.0}, "rho": {"value": 28.0},
                "beta": {"value": 8/3}},
    state_variables={
        "X": {"equation": {"rhs": "sigma * (Y - X)"}},
        "Y": {"equation": {"rhs": "X * (rho - Z) - Y"}},
        "Z": {"equation": {"rhs": "X * Y - beta * Z"}},
    },
)

rww = Dynamics.from_db("ReducedWongWangExcInh")
rww = Dynamics(iri="tvbo:ReducedWongWangExcInh")

See the writing-models skill for the YAML form and equation conventions.

Attributes

Name Description
DynamicalSystem
Model Former runtime subclasses of the generated Dynamics, now the class itself.
TEMPLATES
logger

Functions

Name Description
class2metadata Populate a Dynamics metadata object from an owlready2 ontology class.
clean_code Replace Unicode infinity () with the Python literal inf.
ontology_class The ontology neural mass model labelled name, or None.
order_by_equations Orders the derived_variables dictionary based on the key order of the dependent_equations dictionary.
populate_from_ontology Fill model’s unset schema fields from ontoclass.
update_parameters Update a model’s parameters from the ontology.

class2metadata

classes.dynamics.class2metadata(ontoclass, metadata)

Populate a Dynamics metadata object from an owlready2 ontology class.

Fills in description, state variables (with equations, boundaries, and coupling-variable flags), derived variables, and parameters by querying the TVB-O ontology for the corresponding semantic annotations.

Every name in the model is put into a local_dict as a plain Symbol before any equation is parsed. Without it, sympy reads e as Euler’s number and I as the imaginary unit, so neither turns up in free_symbols and the parameters behind them are dropped in silence. An ontology coupling term is added only where a state equation actually requires it.

Parameters

Name Type Description Default
ontoclass Any The owlready2 class to read from. required
metadata Any The Dynamics instance to populate in place. required

clean_code

classes.dynamics.clean_code(code)

Replace Unicode infinity () with the Python literal inf.

Generated model code occasionally carries the ∞ glyph from upstream ontology labels; SymPy and most backends can’t parse it.

ontology_class

classes.dynamics.ontology_class(name)

The ontology neural mass model labelled name, or None.

Restricted to that branch on purpose: the ontology holds classes of every kind under one label space, and a model must not be filled from a coupling function or an integrator that happens to share its name.

order_by_equations

classes.dynamics.order_by_equations(derived_variables, dependent_equations)

Orders the derived_variables dictionary based on the key order of the dependent_equations dictionary.

Parameters: derived_variables (dict): Dictionary to be ordered. dependent_equations (dict): Dictionary providing the key order for sorting.

Returns: dict: A new dictionary ordered by the key order from dependent_equations.

populate_from_ontology

classes.dynamics.populate_from_ontology(model, ontoclass, **kwargs)

Fill model’s unset schema fields from ontoclass.

The one implementation behind both ways in: Dynamics.from_ontology, which is handed the class, and enrich(source="ontology"), which resolves it from what the model names. Nothing runtime-only is written, so the model stays serializable.

update_parameters

classes.dynamics.update_parameters(
    metadata,
    ontoclass,
    verbose=0,
    only_used=True,
    **kwargs,
)

Update a model’s parameters from the ontology.

As in class2metadata, every model name is bound as a plain Symbol first, so e and I are not read as Euler’s number and the imaginary unit and their parameters silently lost.

Parameters

metadata : Dynamics Model metadata to update ontoclass : owlready2.ThingClass Ontology class verbose : int Verbosity level only_used : bool If True (default), only add parameters that are referenced in equations. If False, add all parameters from ontology (legacy behavior). **kwargs : dict Parameter overrides