Network-Based Controllability and Observability Analysis in PythonThe nocad toolbox

Chapter 2
Foundations: controllability and observability of structured systems

This chapter collects the notions the rest of the book builds on: linear state-space models, controllability and observability with the tests of Kalman and of Popov, Belevitch and Hautus, structured systems and their generic properties, the network of the state variables, and Lin’s theorem, which reduces structural controllability to two conditions on that network. It also fixes the notation of the book and the conventions of the nocad API, and shows on two small examples why the network must be built from the state equations and where structural results end.

2.1 Problem and idea

A linear time-invariant system with N state variables, M inputs and K outputs is written as

𝐱˙(t)=𝐀𝐱(t)+𝐁𝐮(t),𝐲(t)=𝐂𝐱(t)+𝐃𝐮(t),(2.1)

with 𝐀∈ℝN×N, 𝐁∈ℝN×M, 𝐂∈ℝK×N and 𝐃∈ℝK×M. The entry aij tells how strongly the state variable xj influences the rate of change of xi. Forgetting the values and keeping only whether an entry is zero leaves a directed network: the nodes are the state variables, and an edge xj→xi is drawn whenever aij≠0 (fig. 2.1). The adjacency matrix of this network, whose row j lists the successors of xj, is the transpose of 𝐀. Inputs become extra nodes with edges into the states they act on, outputs extra nodes with edges from the states they measure.

Figure 2.1

Figure 2.1. From state equations to the network of the state variables. Every non-zero aij of the state matrix becomes an edge xj→xi, the diagonal entry a11 a self-loop; the input is an extra node with an edge into x1, the output an extra node fed by x4. The adjacency matrix of the network is the transpose of the pattern of 𝐀.

The idea of the structural approach is that many properties of eq. (2.1) depend on this network only, for almost all values of the non-zero entries. Controllability is such a property: Lin showed that it holds for almost all values if and only if every state can be reached from an input and no group of states depends on fewer states and inputs than it contains [5]. Both conditions are cheap to test on the network, which is what makes the analysis of large systems possible.

2.2 Theory

2.2.1 Controllability and observability

The system eq. (2.1) is controllable if for every initial state 𝐱(0) and every target 𝐱f there is an input that drives the state to 𝐱f in finite time, and observable if the initial state can be determined from the input and the output over a finite interval. Kalman’s criterion [4] reduces both to rank conditions,

rank𝒞=N,𝒞=[𝐁,𝐀𝐁,…,𝐀N−1𝐁], rank𝒪=N,𝒪=[𝐂𝖳,(𝐂𝐀)𝖳,…,(𝐂𝐀N−1)𝖳]𝖳. (2.2)

The column space of 𝒞 is the controllable subspace: the states that the inputs can reach from the origin. Observability of (𝐀,𝐂) is controllability of the dual pair (𝐀𝖳,𝐂𝖳), so every result on controllability has an observability counterpart obtained by reversing all edges of the network. The Popov–Belevitch–Hautus (PBH) test gives the same answer mode by mode: (𝐀,𝐁) is controllable iff rank[𝐀−λ𝐈,𝐁]=N for every eigenvalue λ of 𝐀; an eigenvalue that violates the condition is an uncontrollable mode.

Numerically, the Kalman matrix is a poor object: its columns are the powers of 𝐀 applied to 𝐁, which grow or shrink geometrically, and its rank is ill-determined for systems of more than a few dozen states. nocad computes the dimension of the controllable subspace with an orthogonal Krylov iteration instead: the space spanned by 𝐁,𝐀𝐁,… is built one orthonormal direction at a time, and the iteration stops when 𝐀 maps the current block into the space already found (algorithm 2.1). This is the controllability staircase of numerical linear algebra.

Algorithm\special {t4ht^+}

2.2.2 Structured systems

A structured matrix is a matrix whose entries are either fixed zeros or free parameters. A property of a structured system holds generically if it holds for all values of the free parameters except those on a proper algebraic variety, a set of measure zero. Controllability is generic in this sense: if it holds for one numerical realization of the pattern, it holds for almost all of them, and the system is then called structurally controllable [5, 6]. The generic rank rankg of a structured matrix is the rank of almost all its realizations; it equals the largest number of non-zero entries no two of which share a row or a column, the size of a maximum matching between the rows and the columns through the non-zero entries (König–Egerváry; see [8]). Likewise, the dimension of the controllable subspace takes one value for almost all realizations, its generic dimension, which Hosoe characterized by a graph-theoretic formula [27]. nocad evaluates it by algorithm 2.1 on a random realization of the pattern: with probability one the generic value is attained.

2.2.3 The network of the state variables

The state network 𝒢(𝐀)=(𝒱 ,E) has the state variables as nodes and an edge xj→xi for every aij≠0; a diagonal entry aii≠0 is a self-loop. Its adjacency matrix is 𝐖= 𝐀𝖳. The system graph 𝒢(𝐀,𝐁,𝐂) adds the inputs ul with edges ul→xi for bil≠0 and the outputs yk with edges xj→yk for ckj≠0. A state that receives an edge from an input is a driver node, a state that sends an edge to an output a sensor node. Paths, cycles, and strongly connected components are used in their usual sense: a strongly connected component (SCC) is a maximal set of nodes that can all be reached from each other, a source SCC receives no edge from outside, and a sink SCC sends none. Table 2.1 summarizes the notation of the book.

Table 2.1. Notation of the book, the docstrings, and the code.
Symbol

Meaning

Code
N,M,K

numbers of states, inputs, outputs

n_states
𝐀,𝐁,𝐂,𝐃

state-space matrices; aij≠0 iff xj appears in ẋi

A, B, C, D
𝐖= 𝐀𝖳

adjacency matrix of the state network, row j: successors of xj

adj
𝒢=(𝒱 ,E), 𝒢𝖳

state network and the reversed network

adj, adj.T
M

matching: edges without common start or end node

Matching
xi+,xi−

out-copy and in-copy of xi in the bipartite representation

—
𝒟,ND

driver nodes and their number

driver_nodes_
𝒮,NS

sensor nodes and their number

sensor_nodes_
𝒞1,…,𝒞p

strongly connected components

condensation
ℓij

length of the shortest path xi→⋯→xj (∞ if none)

geodesic_distances
rkl=ℓdlsk+1

relative degree of yk with respect to ul

relative_degree_matrix
ρiC,ρiO

control and observation depth of xi

control_depth
β

weight of the worst case in the placement cost

beta

2.2.4 Lin’s theorem

Two structural defects make a system uncontrollable for all parameter values. A state is inaccessible if no input can reach it in the system graph: its value is not influenced by the inputs at all. A set S of states contains a dilation if the set T(S) of nodes (states or inputs) with an edge into S is smaller than S: |T(S)|<|S|. Then the |S| rows of [𝐀,𝐁] that belong to S have their non-zeros in only |T(S)| columns, the matrix cannot have full rank, and some combination of the states in S cannot be steered independently. The simplest dilation is a star: one node x1 feeding x2 and x3, which have no other parents (fig. 2.2).

Definition 2.1 (structural controllability [5, 6]). The structured pair (𝐀,𝐁) is structurally controllable iff (i) every state is accessible from an input in 𝒢(𝐀,𝐁) and (ii) 𝒢(𝐀,𝐁) contains no dilation, equivalently rankg[𝐀,𝐁]=N.

Condition (ii) is a matching condition: rankg[𝐀,𝐁]=N means that a matching in the bipartite graph between the columns (states and inputs) and the rows (states) covers every row, so that every state can be assigned a distinct parent. Lin also gave a constructive form of the theorem. A stem is a directed path that starts at an input; a bud is a directed cycle together with one extra edge, the distinguished edge, that enters it from a node outside the cycle; a cactus is a stem with buds attached to it, each bud attached through its distinguished edge to a node of the stem or of a bud attached earlier.

Remark 2.1 (cactus theorem). (𝐀,𝐁) is structurally controllable iff the system graph is spanned by a disjoint union of cacti [5]. A design found by maximum matching contains such a spanning set: its matched edges form the stems and the cycles, and an unmatched edge anchors every cycle (section 4.2.3).

Figure 2.2

Figure 2.2. The two defects of Lin’s theorem and a cactus. (a) A dilation: two states depend on a single parent, so one input cannot steer them independently. (b) An inaccessible state: x3 is not reachable from the input. (c) A cactus: a stem (blue) with a bud (a cycle of the matching, green) attached by its distinguished edge (orange, dashed); a system spanned by cacti is structurally controllable.

Lin’s two conditions are tested in linear time: a breadth-first search from the driver nodes decides accessibility, and a maximum bipartite matching between the columns and the rows of [𝐀,𝐁] decides the generic rank (algorithm 2.2). Observability is tested on the reversed network with the outputs as inputs.

Algorithm\special {t4ht^+}

In a nutshell: Structural controllability

  • A structured system is structurally controllable if almost all realizations of its pattern are controllable.
  • Lin’s theorem: every state accessible from an input, and rankg[𝐀,𝐁]=N (no dilation).
  • Equivalently, the system graph is spanned by disjoint cacti: stems from the inputs with buds attached.
  • Both conditions are checked in O(|E|N) time; observability is the same test on the reversed network.
  • Special parameter values (identical subsystems) can still destroy controllability: check numerically when symmetries are expected.

2.3 Using it in nocad

The conventions of the package mirror those of the MATLAB toolbox and of the book. A network is passed as its adjacency matrix adj (a NumPy array, a SciPy sparse matrix, a NetworkX DiGraph, or a square pandas DataFrame); nocad.as_adjacency converts any of these to a boolean sparse matrix. Functions of a network take adj; functions of a system take the state matrix A=adj.T and the input or output matrix: driver_nodes(adj) but is_controllable(A, B). Nodes are numbered from zero. Estimators follow the scikit-learn style: parameters in the constructor, fit(adj) returns the estimator, results are attributes with a trailing underscore. Plotting functions take an optional ax and return the axes; layout algorithms return node positions that can be reused across panels.

nocad.is_controllable(A, B, method="structural") / is_observable(A, C, ...)

method="structural": Lin’s test on the zero patterns (exact, linear time); "kalman": dimension of the controllable subspace of the given numerical matrices (algorithm 2.1); "generic": the same on a random realization of the patterns. Related functions: is_structurally_controllable, structural_rank, controllable_subspace_dimension, generic_controllable_dimension, pbh_uncontrollable_modes, adjacency_to_state_matrix.

The water tanks of section 2.4 are built and designed as follows:

variants = { 
    "physical (pipes only)": make_water_tanks(3, "branch", "physical"), 
    "free outflow (self-loops)": make_water_tanks(3, "branch", "free_outflow"), 
    "connected vessels (loops + pairs)": make_water_tanks(3, "branch", "connected"), 
} 
for name, tanks in variants.items(): 
    A = nocad.adjacency_to_state_matrix(tanks.adj).toarray().astype(int)  # A = W^T 
    design = nocad.InputOutputDesign().fit(tanks.adj) 
    print(f"{name:34s} drivers={design.driver_nodes_ + 1} sensors={design.sensor_nodes_ + 1}")
   

and Lin’s test is compared with the numerical test on a star:

for name, net in (("star", star), ("star with self-loops", loops)): 
    A = net.T                                     # state matrix of the network 
    print(f"{name:22s} structurally controllable: {is_structurally_controllable(A, b)}") 
A_same = loops.T.copy() 
A_same[np.arange(1, n_leaves + 1), np.arange(1, n_leaves + 1)] = -1.0   # identical leaves 
print("identical leaves, Kalman dimension:", controllable_subspace_dimension(A_same, b)) 
A_diff = A_same.copy() 
A_diff[np.arange(1, n_leaves + 1), np.arange(1, n_leaves + 1)] = [-1.0, -2.0, -3.0] 
print("distinct leaves,  Kalman dimension:", controllable_subspace_dimension(A_diff, b))
   

2.3.1 Import, export and role annotations

Networks come from other software and results go back to it, so nocad keeps the names of the nodes and converts in both directions. A NetworkX graph, a pandas data frame or an igraph graph can be passed wherever a network is expected; its node names become the labels of every table and figure, and an estimator stores them as labels_. Positions may be NetworkX pos dictionaries, and default_layout offers the NetworkX layouts besides the layouts of chapter 4. The function nocad.annotate collects in two pandas tables everything the toolbox knows about a configuration: for every node whether it is a driver or sensor node and through which input or output, its role across all maximum matchings, its driver or sensor type, its strongly connected component and level in the hierarchy, its control and observation depth and region, and its part in the cacti; for every edge whether it is matched, its class across all maximum matchings, its part in the cacti and its connection type. Every export carries these columns as attributes, so that other tools can filter and style the network by the same roles, and every file written by nocad is read back with its configuration (table 2.2).

Table 2.2. File formats of nocad.io.read and write, chosen by the extension.
format extension read write

typical use

GraphML .graphml yes yes

yEd, Cytoscape, NetworkX, igraph

GEXF .gexf yes yes

Gephi, with role colors and positions

GML .gml yes yes

igraph and other network tools

Cytoscape JSON .cyjs yes yes

Cytoscape and Cytoscape.js, with role classes and positions

node-link JSON .json yes yes

D3.js and web applications

DOT .dot — yes

Graphviz; components of one level share a rank

Pajek .net yes yes

Pajek

edge list .edgelist yes yes

plain text with the node order in a header

CSV, TSV .csv, .tsv yes yes

spreadsheets; node table in *_nodes.csv

Excel .xlsx yes yes

node, edge and summary sheets

MATLAB .mat yes yes

the NOCAD MATLAB toolbox: 𝐀,𝐁,𝐂,𝐃 and labels

NumPy .npz yes yes

compact binary storage

nocad.io and nocad.annotation

read_network(path) and write_network(obj, path, layout="hierarchy") (aliases of io.read, io.write); from_networkx(G, weight), to_networkx(adj, labels, annotate=True), from_igraph, to_igraph, from_pandas_edgelist, to_pandas, from_state_space(A, B, C, D), from_control(sys) and to_control(design) for python-control, read_mat, write_mat, to_dot; annotate(adj, design, drivers, sensors, centrality, robustness) returns nodes, edges and graph; InputOutputDesign.annotate(), .to_networkx() and .write(path) do the same for a fitted design; nocad.viz.plot_annotation(adj, column) colors the nodes by any column.

A process network built in NetworkX is designed, annotated, exported and read back:

design = nocad.InputOutputDesign("minimum").fit(G)  # node names are kept 
print("drivers:", [design.labels_[v] for v in design.driver_nodes_], 
      " sensors:", [design.labels_[v] for v in design.sensor_nodes_]) 
ann = design.annotate()                             # node and edge tables (pandas) 
print(ann.nodes[["label", "io_role", "control_role", "scc", "control_level", "control_depth", 
                 "control_cactus"]].to_string(index=False)) 
out = pathlib.Path(tempfile.mkdtemp()) 
for ext in (".graphml", ".gexf", ".cyjs", ".dot", ".csv", ".xlsx", ".mat"): 
    files = design.write(out / f"process{ext}")    # annotations become attributes 
    print(f"{ext:9s}", ", ".join(f"{p.name} ({p.stat().st_size} B)" for p in files)) 
net = nocad.read_network(out / "process.graphml")   # the configuration comes back 
print("read back:", net.labels, "drivers", net.drivers.tolist(), "sensors", net.sensors.tolist())
   

2.4 Examples

2.4.1 Pipes are not state equations

Three tanks, the first feeding the other two, are read in three ways (fig. 2.3). The physical topology has one edge per pipe; it contains a dilation at h1 and two sinks, so two inputs and two outputs are needed. If the outflow of every tank depends on its own level, every state has a self-loop. A self-loop lets a state be matched by itself, which removes the dilation: one input at h1 controls all three tanks. The two sinks remain, and with them the two outputs. If the tanks are connected vessels, the flow through a pipe depends on the levels at both ends, every pipe contributes a pair of edges, and the network becomes strongly connected: one input and one output suffice. Figure 2.4 repeats the comparison for up to ten tanks. The physical reading needs an input and an output for nearly every tank, the dynamical readings need one input, and only the connected vessels also need just one output.

Figure 2.3

Figure 2.3. Three readings of the same three tanks. Left: the pipes only; middle: free outflow, every level depends on itself; right: connected vessels, flows depend on both levels. Blue arrows are inputs, vermilion arrows outputs, computed by path finding (chapter 3).

Open in ColabExample plot_01_state_space_network.py in the gallery

Figure 2.4

Figure 2.4. Numbers of driver nodes (solid) and sensor nodes (dashed) of branching tanks: the physical topology needs an input and an output for nearly every tank, self-loops reduce the inputs to one, and connected vessels need a single input and a single output.

2.4.2 Structurally controllable, numerically not always

A hub x1 driving three leaves is the textbook dilation (fig. 2.5, left): one input at the hub cannot control the leaves independently, and Lin’s test fails. Self-loops on the leaves remove the dilation and the pattern becomes structurally controllable (right). Whether a particular realization is controllable depends on the values: when the three leaves have the same dynamics (aii=−1), the input acts on them identically and the controllable subspace has dimension two only, whereas distinct values (−1,−2,−3) give the full dimension four. Figure 2.6 quantifies the effect. When the leaf dynamics are drawn from a small set of values, coincidences are frequent and many realizations are uncontrollable. With continuous random values every realization is controllable, as the generic nature of the property promises.

Figure 2.5

Figure 2.5. A star driven from its hub is not structurally controllable (left: a dilation); with self-loops on the leaves it is (right).

Open in ColabExample plot_04_structural_vs_numeric.py in the gallery

Figure 2.6

Figure 2.6. Share of controllable realizations of the self-looped star when the leaf dynamics take one of k values: coincidences make realizations uncontrollable, continuous random values never do.

2.4.3 A named process network, from NetworkX and back

The process of the snippet above, a reactor with a cooling jacket and a separator whose bottom stream is recycled, has seven states named after the variables they stand for. The exact minimum needs one input, at the separator level hS, and one output, at the product concentration cP. The annotated graph that design.to_networkx() returns carries enough information for NetworkX to draw the hierarchy on its own (fig. 2.7): the multipartite layout takes the levels of the condensation from the control_level attribute, the colors from io_role, the thick edges from control_matched. Every node is intermittent, since the self-loops and the recycle leave many maximum matchings. Figure 2.8 shows two further columns of the table with plot_annotation on a NetworkX layout: the control depth, which reaches four at the jacket temperature TJ, and the part of the control cactus, a stem u1→hS→cS→cP with the other states on buds hanging from it. For the frontal neurons of C. elegans the same tables show at once that the ten critical neurons all start stems, and that the two driver nodes which are not source neurons are internal dilations.

Figure 2.7

Figure 2.7. The annotated process network drawn by NetworkX alone: layers from the control_level attribute, colors from io_role, matched edges (green, self-loops included) from control_matched.

Open in ColabExample plot_05_interoperability.py in the gallery

Figure 2.8

Figure 2.8. Two columns of the annotation table drawn with plot_annotation on a NetworkX layout: the control depth of every node (left) and its part in the control cactus (right).

2.5 Further reading

Kalman’s paper [4] and any textbook of linear systems cover the rank tests. Lin [5] introduced structural controllability for single inputs, Shields and Pearson [6] extended it to several inputs, and Hosoe [27] gave the generic dimension of the controllable subspace. Reinschke [7] and Murota [8] develop the graph and matroid theory of structured systems, and the survey of Dion, Commault and van der Woude [9] collects the generic properties of structured systems and their graph characterizations. The role of the balance equations in the structure of process models is explained by Hangos and Cameron [26].