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
Exportergenerates 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:
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, final_time=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.protocolAn optional
myokit.Protocolordictmapping binding names tomyokit.Protocolobjects that define pacing or dosing schedules. If a map is not given then the binding name is assumed to bepace. When given, the exporter generates a hybrid ODE model using DiffSL’sNandstopconstructs. All events are expanded to one-off transitions; periodic events requirefinal_timeto be set. Protocol entries whose binding names are not present in the model are ignored.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).final_timeRequired when
protocolis provided. Events are expanded up to (but not including) this time. Must be a finite positive number. Ignored whenprotocolisNone.
- 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.