DiffSL

Myokit provides partial export of models to the DiffSL language.

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.

Only the model definition is exported. No inputs are provided, there is no protocol defined, and only state variables are output.

For details of the 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)

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

Not implemented!

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).

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.