Dependency analysis

Using these functions from myokit.lib you can perform simple dependency analysis algorithms on Myokit models.

This module uses matplotlib for visualisation.

myokit.lib.deps.plot_state_dependency_matrix(model, direct=False, knockout=[], axes=None)

Creates a matrix showing state variable dependency distances.

To show only direct (first-order) dependencies, set the optional argument direct to True.

Variables can be “knocked out” by adding them to the list in the knockout parameter. If x depends on y and y depends on z, knocking out y will prevent the method from findind x’s dependency on z.

Returns a matplotlib axes object.

myokit.lib.deps.create_state_dependency_matrix(model, direct=False, knockout=None)

Creates a matrix showing state variable dependency distances.

A distance of 1 from state x to state y means that dot(x) depends on y. A distance of 2 means that dot(x) does not depend on y, but does depend on another state whose derivative depends directly on y.

State variables can be “knocked out” by adding them to the knockout list. The rows and columns for knocked out variables will be set to zero, and knocked out variables won’t be taken into account when calculating indirect dependencies (distance>1).


The model to create a matrix for.
True if only direct dependencies (distance=1) should be shown. In this case, the returned matrix will show the shape of the jacobian.
A list of state variables or state variable names to “knock-out”.
myokit.lib.deps.plot_component_dependency_graph(model, axes=None, omit_states=True, omit_constants=False)

Draws a graph showing the dependencies between a model’s components.

Returns a matplotlib axes object.

myokit.lib.deps.create_component_dependency_graph(model, omit_states=True, omit_constants=False)

Creates and returns a component dependency graph.

myokit.lib.deps.plot_variable_dependency_graph(model, axes=None)

Draws a graph showing the dependencies between a model’s variables.

Returns a matplotlib axes object.


Creates a dependency graph from the given model

(Doesn’t include constants)

Internally, these functions make use of a tiny DiGraph class.

class myokit.lib.deps.DiGraph(matrix=None)

A simple directed graph implementation.

If desired, a digraph can be created from an n-by-n connectivity matrix, for example matrix=[[0, 1, 1], [0, 1, 0], [0, 0, 0]]

add_edge(node1, node2)

Adds an edge from node1 to node2


Adds a node. You can pass an existing Node object or an object to use as a new node’s id.

build_from_matrix(matrix, edges_only=False)

Replaces this graph’s structure with the graph defined by the given n by n connectivity matrix.

If edges_only is set to True, the matrix must have the same size as the current number of nodes. In this, all existing edges will be removed and replaced by the ones given in the connectivity matrix.


Returns a layering according to the Coffman-Graham ordering scheme.

Returns a list of lists, where each inner list represents a consecutive layer.

Will raise an exception if this digraph has cycles.


Changes the x,y coordinates of this graph’s node resulting in a layered layout.


Returns a connectivity matrix for this graph.


Finds a Minimal Equivalent Graph (MEG) of a Directed Acyclic Graph (DAG) using the algorithm by Harry Hsu [1].

Will raise an exception if this digraph has self-referencing nodes.

[1] An algorithm for finding a minimal equivalent graph of a digraph.
Harry T. Hsu (1975) Journal of the Assoclatlon for Computing Machinery, Vol 22, No. 1, January 1975, pp 11-16

Returns the node with this id


Returns a path matrix for this graph, showing which nodes are reachable from which.


Removes a node from this graph.


Returns an ascii view of this graph


Safely turns ‘test’ into a node. Throws exceptions if it can’t.

class myokit.lib.deps.Node(uid)

Defines a node in a graph


Ensures an edge from this node to another


Removes any edges leading from this node.


Returns true if this node points at test

myokit.lib.deps.plot_digraph(graph, axes=None, r_node=None)

Returns a DiGraph object to a set of matplotlib axes.

Returns a matplotlib axes object.