integrator

behaviour.integrator

Ontology-backed metadata, code generation and factories for :class:Integrator.

Attached to the generated classes by name (IntegratorBehaviour -> Integrator). Only schema fields are ever stored; everything derived from the ontology is a property, so an integrator can be serialized at any point without carrying runtime state.

Population from the ontology is NOT done at construction. It is :meth:IntegratorBehaviour.enrich, called explicitly and idempotent, so that resolving an integrator against the ontology stays an act the caller asks for rather than the cost of naming one. The wrapper this replaces called it from __init__, which meant it ran for a directly constructed integrator and not for a loaded one; the loaded path compensated with its own call, and that call is now the only one.

A mixin can hook construction — see :mod:tvbo.behaviour on __post_init__, which :class:CouplingBehaviour uses. This one deliberately does not.

Classes

Name Description
IntegratorBehaviour Ontology metadata, rendering and loading for an integrator.

IntegratorBehaviour

behaviour.integrator.IntegratorBehaviour()

Ontology metadata, rendering and loading for an integrator.

Attributes

Name Description
class_name The generated integrator class name, suffixed with Stochastic when noisy.
current_step The current integration step, a stateless default of 0.
info The code-generation metadata dict for this integrator’s ontology class.
metadata The integrator itself, exposed for backward compatibility.
noise_wrapper The noise as a runtime Noise wrapper, or None when non-stochastic.
ontoclass The ontology class for this integrator, resolved from method.
stochastic Whether the integrator is stochastic, i.e. has a noise component.

Methods

Name Description
enrich Fill the ontology-derived fields that are still unset. Idempotent.
execute Render, execute, and instantiate the integrator backend object.
from_db Load an Integrator by name from the tvbo database.
from_file Load an Integrator from a YAML file.
list_db List available integrators in the tvbo database.
render_code Render the integrator as source code for the requested backend.
to_yaml Serialize the integrator to YAML, optionally writing it to a file.
enrich
behaviour.integrator.IntegratorBehaviour.enrich(source=None)

Fill the ontology-derived fields that are still unset. Idempotent.

The same verb as :meth:IriEnrichable.enrich, and the same gap-filling contract, but its own implementation and no key: an integrator names an ontology method rather than a curated entity, so there is nothing for the database to answer and nothing to redirect the lookup at.

execute
behaviour.integrator.IntegratorBehaviour.execute(format='tvb')

Render, execute, and instantiate the integrator backend object.

For the tvb backend the integrator class is instantiated, wiring in an executed noise object when stochastic; for other backends the generated class is returned.

Parameters
Name Type Description Default
format Target backend passed through to code generation. 'tvb'
Returns
Name Type Description
The executed backend integrator object or class.
from_db
behaviour.integrator.IntegratorBehaviour.from_db(name)

Load an Integrator by name from the tvbo database.

from_file
behaviour.integrator.IntegratorBehaviour.from_file(filepath)

Load an Integrator from a YAML file.

list_db
behaviour.integrator.IntegratorBehaviour.list_db()

List available integrators in the tvbo database.

render_code
behaviour.integrator.IntegratorBehaviour.render_code(format='tvb', **kwargs)

Render the integrator as source code for the requested backend.

Parameters
Name Type Description Default
format Target backend; "tvb" selects the TVB template, while "autodiff" or "jax" selects the JAX template. 'tvb'
**kwargs Extra values forwarded to the JAX template render context. {}
Returns
Name Type Description
The rendered source code as a string.
Raises
Name Type Description
ValueError If format is not a recognized backend.
to_yaml
behaviour.integrator.IntegratorBehaviour.to_yaml(filepath=None)

Serialize the integrator to YAML, optionally writing it to a file.

Parameters
Name Type Description Default
filepath str | None Destination path to write to; when None, the YAML is returned instead. None
Returns
Name Type Description
The YAML string, or the result of writing to filepath.