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 (firstorder) dependencies, set the optional argument
direct
toTrue
.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=[])¶ Creates a matrix showing state variable dependency distances.
Dependencies can either be direct (a relies on b) or indirect (a relies on b which relies on c, but a does not rely on c directly). To show only direct dependencies, set
direct=True
, in this case the returned matrix will show the shape of the system’s Jacobian.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.

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.

myokit.lib.deps.
create_variable_dependency_graph
(model)¶ 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 nbyn 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

add_node
(node)¶ 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.

cg_layers_dag
(graph)¶ Returns a layering according to the CoffmanGraham ordering scheme.
Returns a list of lists, where each inner list represents a consecutive layer.
Will raise an exception if this digraph has cycles.

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

matrix
()¶ Returns a connectivity matrix for this graph.

meg_dag
()¶ 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 cycles.
 [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 1116

node
(uid)¶ Returns the node with this id

path_matrix
()¶ Returns a path matrix for this graph, showing which nodes are reachable from which.

remove_node
(node)¶ Removes a node from this graph.

text
(matrix=False)¶ Returns an ascii view of this graph

uid_or_node
(test)¶ Safely turns ‘test’ into a node. Throws exceptions if it can’t.


class
myokit.lib.deps.
Node
(uid)¶ Defines a node in a graph

add_edge_to
(node)¶ Ensures an edge from this node to another

clear_edges
()¶ Removes any edges leading from this node.

has_edge_from
(test)¶ Returns true if test points at this node

has_edge_to
(test)¶ Returns true if this node points at test

label
()¶ Returns a label derived from this node

outgoing
()¶ Returns a list of nodes pointed at by this one

remove_edge_to
(node)¶ Removes the edge from this node to the given node. An error is given if no such edge exists.

uid
()¶ Returns this node’s unique identifier


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.