Export to an OpenCL simulation. A driver is provided to run cable simulations and a quick plot script is included.


  • The generated code requires OpenCL enabled drivers for the GPU or CPU it’s runnning on to be pre-installed, as well as an implementation of the OpenCL libraries. These can be downloaded from various hardware manufacturers’ websites.


The standard interface for exporting and accessing expression writers is provided:


Returns a dict of all exporters available in this module.

class myokit.formats.opencl.OpenCLExporter

This Exporter creates a cable simulation that can run on any OpenCL environment (GPU or CPU).

A value must be bound to diffusion_current which represents the current flowing from cell to cell. This is defined as positive when the cell is acting as a source, negative when it acts like a sink. In other words, it is defined as an outward current.

The membrane potential must be labelled as membrane_potential.

By default, the simulation is set to log all state variables. This is nice to explore results with, but quite slow…

Please keep in mind that CellML and other downloaded formats are typically not directly suitable for GPU simulation. Specifically, when simulating on single-precision devices a lot of divide-by-zero errors might crop up that remain hidden when using double precision single cell simulations on the CPU.

class myokit.formats.opencl.OpenCLRLExporter

Like OpenCLExporter but uses a Rush-Larsen update step where applicable.


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

class myokit.formats.opencl.OpenCLExpressionWriter(precision=32, native_math=True)

This ExpressionWriter translates Myokit expressions to OpenCL syntax.



By default, numbers are shown as e.g. 1.23f, denoting single precision literals. To use double precision instead, set precision to myokit.DOUBLE_PRECISION.


By default, the software implementations of functions like log and exp are used. To use the native version instead, set native_math to True.


Converts a myokit.Equation to a string.


Converts a myokit.Expression to a string.

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.