DiffSL

Myokit provides export of models to the DiffSL language.

Model-only export produces a standard DiffSL ODE in u_i/F_i/out_i form.

Protocol export generates a hybrid ODE model using DiffSL’s N and stop constructs, see the DiffSL hybrid ODE documentation.

The protocol argument can be either a single myokit.Protocol for the pace binding or a dict mapping binding names to protocols. Protocol entries for bindings that are not present in the model are ignored. When multiple bindings are provided, the exporter expands them to a shared segmented timeline with one emitted *_i schedule block tensor per binding (i.e. containing the dosing levels) and one shared stop_i block for the transition times between the scheduled blocks.

Periodic protocol events are expanded to an explicit list of one-off dose transitions. If a protocol is provided, a final_time must be passed to DiffSLExporter.model() so this expansion is always finite.

Exporters and expression writers

myokit.formats.diffsl.exporters()

Returns a dict of all exporters available in this module.

class myokit.formats.diffsl.DiffSLExporter

This Exporter generates a DiffSL implementation of a Myokit model.

For details of the DiffSL language, see https://martinjrobins.github.io/diffsl/

get_state_index(variable)

Returns the index of a state variable in the DiffSL state vector.

This method can be called after model() to determine the position of a state variable in the exported DiffSL state vector.

Arguments:

variable

A myokit.Variable from the model that was exported.

Returns the zero-based index of the variable in the state vector if it is a state variable, or None if it is not a state variable.

Note: The state vector order in DiffSL follows the order returned by myokit.Model.states() from the exported model.

model(path, model, protocol=None, convert_units=True, inputs=None, outputs=None, final_time=None)

Exports a myokit.Model in DiffSL format, writing the result to the file indicated by path.

A myokit.ExportError will be raised if any errors occur. Warnings will be generated if unsupported functions (e.g. atan) are used in the model. For a full list, see myokit.formats.diffsl.DiffSLExpressionWriter.

Arguments:

path

The path to write the generated model to.

model

The myokit.Model to export.

protocol

An optional myokit.Protocol or dict mapping binding names to myokit.Protocol objects that define pacing or dosing schedules. If a map is not given then the binding name is assumed to be pace. When given, the exporter generates a hybrid ODE model using DiffSL’s N and stop constructs. All events are expanded to one-off transitions; periodic events require final_time to be set. Protocol entries whose binding names are not present in the model are ignored.

convert_units

If set to True (default), the method will attempt to convert to preferred units for voltage (mV), current (A/F), and time (ms).

inputs

Optional list of model variables to include in the input parameter list (in = [ … ]). If None (default), an empty input list will be generated. All input variables must be constants.

outputs

Optional list of model variables to include in the output list (out_i { … }). If None (default), all state variables will be included in alphabetical order. All output variables must be time-varying (not constants).

final_time

Required when protocol is provided. Events are expanded up to (but not including) this time. Must be a finite positive number. Ignored when protocol is None.

post_export_info()

Optional method that returns a string containing information about this exporter, to be shown after the export is completed.

runnable(path, model, protocol=None, *args)

Exports a myokit.Model and optionally a myokit.Protocol to something that can be run or compiled.

The output will be stored in the directory path. A myokit.ExportError will be raised if any errors occur.

supports_model()

See myokit.formats.Exporter.supports_model().

supports_runnable()

Returns True if this exporter supports export of a model and optional protocol to a runnable piece of code.

myokit.formats.diffsl.ewriters()

Returns a dict of all expression writers available in this module.

class myokit.formats.diffsl.DiffSLExpressionWriter

This ExpressionWriter writes equations for variables in DiffSL syntax.

For details of the language, see https://martinjrobins.github.io/diffsl/.

Warnings will be generated if unsupported functions are used in the model. Unsupported functions: acos, asin, atan, ceil, floor.

Support for logic expressions is implemented with heaviside functions. For example, (a >= b) is converted to heaviside(a - b).

eq(q)

Converts a myokit.Equation to a string.

ex(e)

Converts a myokit.Expression to a string.

set_lhs_function(f)
Sets a naming function, will be called to get the variable name from a

myokit.LhsExpression object.

The argument f should be a function that takes an LhsExpression as input and returns a string.