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
Exportergenerates 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:
variableA
myokit.Variablefrom the model that was exported.
Returns the zero-based index of the variable in the state vector if it is a state variable, or
Noneif 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.Modelin DiffSL format, writing the result to the file indicated bypath.A
myokit.ExportErrorwill 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, seemyokit.formats.diffsl.DiffSLExpressionWriter.Arguments:
pathThe path to write the generated model to.
modelThe
myokit.Modelto export.protocolNot implemented!
convert_unitsIf set to
True(default), the method will attempt to convert to preferred units for voltage (mV), current (A/F), and time (ms).inputsOptional 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.outputsOptional 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.Modeland optionally amyokit.Protocolto something that can be run or compiled.The output will be stored in the directory
path. Amyokit.ExportErrorwill be raised if any errors occur.
- supports_model()¶
- supports_runnable()¶
Returns
Trueif 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
ExpressionWriterwrites 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.Equationto a string.
- ex(e)¶
Converts a
myokit.Expressionto a string.
- set_lhs_function(f)¶
- Sets a naming function, will be called to get the variable name from a
myokit.LhsExpressionobject.
The argument
fshould be a function that takes anLhsExpressionas input and returns a string.