nocad 1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. nocad-1.0/.gitignore +47 -0
  2. nocad-1.0/CHANGELOG.md +12 -0
  3. nocad-1.0/CITATION.cff +56 -0
  4. nocad-1.0/LICENSE +21 -0
  5. nocad-1.0/PKG-INFO +203 -0
  6. nocad-1.0/README.md +132 -0
  7. nocad-1.0/examples/01_basics/README.rst +3 -0
  8. nocad-1.0/examples/01_basics/plot_01_state_space_network.py +85 -0
  9. nocad-1.0/examples/01_basics/plot_02_maximum_matching.py +89 -0
  10. nocad-1.0/examples/01_basics/plot_03_path_finding_signal_sharing.py +102 -0
  11. nocad-1.0/examples/01_basics/plot_04_structural_vs_numeric.py +87 -0
  12. nocad-1.0/examples/01_basics/plot_05_interoperability.py +110 -0
  13. nocad-1.0/examples/02_visualization/README.rst +3 -0
  14. nocad-1.0/examples/02_visualization/plot_01_scc_hierarchy.py +82 -0
  15. nocad-1.0/examples/02_visualization/plot_02_bipartite_view.py +81 -0
  16. nocad-1.0/examples/02_visualization/plot_03_control_cacti.py +65 -0
  17. nocad-1.0/examples/02_visualization/plot_04_structure_matrix.py +48 -0
  18. nocad-1.0/examples/02_visualization/plot_05_depth_maps.py +75 -0
  19. nocad-1.0/examples/02_visualization/plot_06_operability_plane.py +45 -0
  20. nocad-1.0/examples/02_visualization/plot_07_dashboard.py +39 -0
  21. nocad-1.0/examples/03_roles_robustness/README.rst +3 -0
  22. nocad-1.0/examples/03_roles_robustness/plot_01_node_roles.py +63 -0
  23. nocad-1.0/examples/03_roles_robustness/plot_02_control_profiles.py +55 -0
  24. nocad-1.0/examples/03_roles_robustness/plot_03_driver_types.py +62 -0
  25. nocad-1.0/examples/03_roles_robustness/plot_04_robustness.py +67 -0
  26. nocad-1.0/examples/04_connection_types/README.rst +3 -0
  27. nocad-1.0/examples/04_connection_types/plot_01_connection_types.py +74 -0
  28. nocad-1.0/examples/04_connection_types/plot_02_network_sets.py +77 -0
  29. nocad-1.0/examples/04_connection_types/plot_03_dynamics_heatmap.py +43 -0
  30. nocad-1.0/examples/05_measures/README.rst +3 -0
  31. nocad-1.0/examples/05_measures/plot_01_network_measures.py +84 -0
  32. nocad-1.0/examples/05_measures/plot_02_control_centrality.py +63 -0
  33. nocad-1.0/examples/05_measures/plot_03_similarity.py +84 -0
  34. nocad-1.0/examples/06_placement/README.rst +3 -0
  35. nocad-1.0/examples/06_placement/plot_01_relative_degree.py +88 -0
  36. nocad-1.0/examples/06_placement/plot_02_heuristics.py +86 -0
  37. nocad-1.0/examples/06_placement/plot_03_annealing.py +74 -0
  38. nocad-1.0/examples/06_placement/plot_04_method_comparison.py +60 -0
  39. nocad-1.0/examples/07_applications/README.rst +3 -0
  40. nocad-1.0/examples/07_applications/plot_01_heat_exchanger_network.py +71 -0
  41. nocad-1.0/examples/07_applications/plot_02_celegans.py +56 -0
  42. nocad-1.0/examples/07_applications/plot_03_dynamical_benchmarks.py +58 -0
  43. nocad-1.0/examples/README.rst +6 -0
  44. nocad-1.0/pyproject.toml +80 -0
  45. nocad-1.0/src/nocad/__init__.py +162 -0
  46. nocad-1.0/src/nocad/_graph.py +165 -0
  47. nocad-1.0/src/nocad/_utils.py +122 -0
  48. nocad-1.0/src/nocad/annotation.py +376 -0
  49. nocad-1.0/src/nocad/components.py +204 -0
  50. nocad-1.0/src/nocad/connection.py +263 -0
  51. nocad-1.0/src/nocad/data/__init__.py +1 -0
  52. nocad-1.0/src/nocad/data/networks.npz +0 -0
  53. nocad-1.0/src/nocad/datasets.py +432 -0
  54. nocad-1.0/src/nocad/design.py +512 -0
  55. nocad-1.0/src/nocad/distances.py +241 -0
  56. nocad-1.0/src/nocad/io.py +771 -0
  57. nocad-1.0/src/nocad/matching.py +323 -0
  58. nocad-1.0/src/nocad/measures/__init__.py +65 -0
  59. nocad-1.0/src/nocad/measures/network.py +258 -0
  60. nocad-1.0/src/nocad/measures/similarity.py +171 -0
  61. nocad-1.0/src/nocad/measures/summary.py +217 -0
  62. nocad-1.0/src/nocad/placement/__init__.py +208 -0
  63. nocad-1.0/src/nocad/placement/annealing.py +180 -0
  64. nocad-1.0/src/nocad/placement/heuristics.py +155 -0
  65. nocad-1.0/src/nocad/plotting.py +561 -0
  66. nocad-1.0/src/nocad/profiles.py +153 -0
  67. nocad-1.0/src/nocad/robustness.py +145 -0
  68. nocad-1.0/src/nocad/structural.py +354 -0
  69. nocad-1.0/src/nocad/viz/__init__.py +63 -0
  70. nocad-1.0/src/nocad/viz/layouts.py +474 -0
  71. nocad-1.0/src/nocad/viz/maps.py +580 -0
  72. nocad-1.0/src/nocad/viz/structure.py +527 -0
  73. nocad-1.0/src/nocad/viz/studies.py +207 -0
  74. nocad-1.0/tests/conftest.py +23 -0
  75. nocad-1.0/tests/test_analysis.py +139 -0
  76. nocad-1.0/tests/test_design.py +109 -0
  77. nocad-1.0/tests/test_io.py +247 -0
  78. nocad-1.0/tests/test_matching.py +77 -0
  79. nocad-1.0/tests/test_measures.py +84 -0
  80. nocad-1.0/tests/test_structural.py +64 -0
  81. nocad-1.0/tests/test_viz.py +86 -0
nocad-1.0/.gitignore ADDED
@@ -0,0 +1,47 @@
1
+ __pycache__/
2
+ *.pyc
3
+ *.egg-info/
4
+ dist/
5
+ build/
6
+ .pytest_cache/
7
+ .ruff_cache/
8
+ docs/_build/
9
+ docs/auto_examples/
10
+ docs/gen_modules/
11
+ docs/sg_execution_times.rst
12
+ book/figures/
13
+ book/*.aux
14
+ book/*.log
15
+ book/*.out
16
+ book/*.toc
17
+ book/*.bbl
18
+ book/*.bcf
19
+ book/*.blg
20
+ book/*.run.xml
21
+ book/*.idx
22
+ book/*.ilg
23
+ book/*.ind
24
+ book/*.fls
25
+ book/*.fdb_latexmk
26
+ book/*.synctex.gz
27
+ book/main.pdf
28
+ *.ipynb_checkpoints
29
+ book/_check_tmp/
30
+ book/_check.tex
31
+ docs/_build/
32
+ docs/api/generated/
33
+ docs/_build_log.txt
34
+ book/_build/
35
+ .coverage
36
+ book/_build_new/
37
+ book/_check_*.tex
38
+ book/cover/*.aux
39
+ book/cover/*.log
40
+ book/cover/*.fls
41
+ book/cover/*.fdb_latexmk
42
+ book/cover/*.pdf
43
+ book/cover/*.png
44
+ book/cover/logo.svg
45
+ *.blg
46
+ book/_build_epub/
47
+ book/_build_web/
nocad-1.0/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ ## 1.0 (2026-11-28) — first release of the Python toolbox
4
+
5
+ * Python successor of the NOCAD toolbox for MATLAB and Octave (Leitold, Vathy-Fogarassy, Abonyi, 2017–2019): all functions of its three modules (network mapping, system characterisation, improvement and robustness).
6
+ * Exact structural tests (Lin's theorem) instead of the structural rank of the numerical Kalman matrix; control centrality as the generic dimension of the controllable subspace.
7
+ * New: the exact minimum of dedicated inputs (`method="minimum"`), node roles and edge classes across all maximum matchings, control profiles, edge-removal robustness.
8
+ * New visualization module `nocad.viz`: SCC hierarchy layout, bipartite matching view, control and observation cacti, block-triangular system matrix, control/observation depth maps and regions, operability plane, profile triangles, heat maps, placement curves and an operability dashboard.
9
+ * Data exchange (`nocad.io`, `nocad.annotation`): NetworkX, igraph, pandas, state-space and python-control conversions; GraphML, GEXF, GML, Cytoscape JSON, node-link JSON, DOT, Pajek, edge list, CSV, Excel, MATLAB and NumPy files; node and edge tables with the role of every element, carried as attributes by every export and restored on import; node names flow through designs, tables and figures; NetworkX layouts and `pos` dictionaries in all views.
10
+ * Driver and sensor types also detect internal dilations that the MATLAB closure test misses (Kőnig's theorem).
11
+ * Bundled networks of the NOCAD study (sets I–III), the C. elegans frontal network, generators of water tanks and heat exchanger networks.
12
+ * 29 gallery examples, Sphinx documentation and the companion book (PDF, EPUB and web edition) *Network-Based Controllability and Observability Analysis in Python*.
nocad-1.0/CITATION.cff ADDED
@@ -0,0 +1,56 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use nocad, please cite it as below, together with the original publications of the methods you use."
3
+ type: software
4
+ title: "nocad: network-based observability and controllability analysis of dynamical systems in Python"
5
+ version: "1.0"
6
+ date-released: 2026-11-28
7
+ license: MIT
8
+ repository-code: "https://github.com/ComplexSystemsIntelligence/nocad"
9
+ url: "https://complexsystemsintelligence.github.io/nocad"
10
+ authors:
11
+ - family-names: Abonyi
12
+ given-names: János
13
+ affiliation: "University of Pannonia, Veszprém, Hungary"
14
+ orcid: "https://orcid.org/0000-0001-8593-1493"
15
+ - family-names: Leitold
16
+ given-names: Dániel
17
+ - family-names: Vathy-Fogarassy
18
+ given-names: Ágnes
19
+ affiliation: "University of Pannonia, Veszprém, Hungary"
20
+ keywords:
21
+ - structural controllability
22
+ - observability
23
+ - maximum matching
24
+ - driver nodes
25
+ - sensor placement
26
+ - network science
27
+ - dynamical systems
28
+ references:
29
+ - type: article
30
+ title: "Controllability and observability in complex networks – the effect of connection types"
31
+ authors:
32
+ - family-names: Leitold
33
+ given-names: Dániel
34
+ - family-names: Vathy-Fogarassy
35
+ given-names: Ágnes
36
+ - family-names: Abonyi
37
+ given-names: János
38
+ journal: "Scientific Reports"
39
+ volume: 7
40
+ start: 151
41
+ year: 2017
42
+ doi: 10.1038/s41598-017-00160-5
43
+ - type: article
44
+ title: "Network-based observability and controllability analysis of dynamical systems: the NOCAD toolbox"
45
+ authors:
46
+ - family-names: Leitold
47
+ given-names: Dániel
48
+ - family-names: Vathy-Fogarassy
49
+ given-names: Ágnes
50
+ - family-names: Abonyi
51
+ given-names: János
52
+ journal: "F1000Research"
53
+ volume: 8
54
+ start: 646
55
+ year: 2019
56
+ doi: 10.12688/f1000research.19029.2
nocad-1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 János Abonyi, Dániel Leitold, Ágnes Vathy-Fogarassy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
nocad-1.0/PKG-INFO ADDED
@@ -0,0 +1,203 @@
1
+ Metadata-Version: 2.5
2
+ Name: nocad
3
+ Version: 1.0
4
+ Summary: Network-based observability and controllability analysis of dynamical systems: maximum matching, driver and sensor nodes, structural controllability, relative degree, sensor placement and visualization.
5
+ Project-URL: Homepage, https://github.com/ComplexSystemsIntelligence/nocad
6
+ Project-URL: Documentation, https://complexsystemsintelligence.github.io/nocad
7
+ Project-URL: Repository, https://github.com/ComplexSystemsIntelligence/nocad
8
+ Project-URL: Issues, https://github.com/ComplexSystemsIntelligence/nocad/issues
9
+ Project-URL: Changelog, https://github.com/ComplexSystemsIntelligence/nocad/blob/main/CHANGELOG.md
10
+ Project-URL: Book (PDF), https://complexsystemsintelligence.github.io/nocad/nocad-book.pdf
11
+ Author: Dániel Leitold, Ágnes Vathy-Fogarassy
12
+ Author-email: János Abonyi <janos@abonyilab.com>
13
+ License-Expression: MIT
14
+ License-File: LICENSE
15
+ Keywords: complex networks,driver nodes,dynamical systems,maximum matching,network science,observability,sensor placement,structural controllability
16
+ Classifier: Development Status :: 5 - Production/Stable
17
+ Classifier: Intended Audience :: Science/Research
18
+ Classifier: License :: OSI Approved :: MIT License
19
+ Classifier: Operating System :: OS Independent
20
+ Classifier: Programming Language :: Python :: 3
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Programming Language :: Python :: 3.13
25
+ Classifier: Topic :: Scientific/Engineering
26
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
27
+ Requires-Python: >=3.10
28
+ Requires-Dist: matplotlib>=3.7
29
+ Requires-Dist: networkx>=3.0
30
+ Requires-Dist: numpy>=1.24
31
+ Requires-Dist: pandas>=2.0
32
+ Requires-Dist: scipy>=1.11
33
+ Provides-Extra: book
34
+ Requires-Dist: beautifulsoup4>=4.12; extra == 'book'
35
+ Requires-Dist: lxml; extra == 'book'
36
+ Requires-Dist: pillow; extra == 'book'
37
+ Provides-Extra: dev
38
+ Requires-Dist: build; extra == 'dev'
39
+ Requires-Dist: control>=0.10; extra == 'dev'
40
+ Requires-Dist: igraph>=0.11; extra == 'dev'
41
+ Requires-Dist: myst-parser; extra == 'dev'
42
+ Requires-Dist: numpydoc; extra == 'dev'
43
+ Requires-Dist: openpyxl>=3.1; extra == 'dev'
44
+ Requires-Dist: pydata-sphinx-theme; extra == 'dev'
45
+ Requires-Dist: pytest-cov; extra == 'dev'
46
+ Requires-Dist: pytest>=7; extra == 'dev'
47
+ Requires-Dist: ruff; extra == 'dev'
48
+ Requires-Dist: sphinx-copybutton; extra == 'dev'
49
+ Requires-Dist: sphinx-design; extra == 'dev'
50
+ Requires-Dist: sphinx-gallery>=0.15; extra == 'dev'
51
+ Requires-Dist: sphinx>=7; extra == 'dev'
52
+ Requires-Dist: twine; extra == 'dev'
53
+ Provides-Extra: docs
54
+ Requires-Dist: myst-parser; extra == 'docs'
55
+ Requires-Dist: numpydoc; extra == 'docs'
56
+ Requires-Dist: openpyxl>=3.1; extra == 'docs'
57
+ Requires-Dist: pydata-sphinx-theme; extra == 'docs'
58
+ Requires-Dist: sphinx-copybutton; extra == 'docs'
59
+ Requires-Dist: sphinx-design; extra == 'docs'
60
+ Requires-Dist: sphinx-gallery>=0.15; extra == 'docs'
61
+ Requires-Dist: sphinx>=7; extra == 'docs'
62
+ Provides-Extra: interop
63
+ Requires-Dist: control>=0.10; extra == 'interop'
64
+ Requires-Dist: igraph>=0.11; extra == 'interop'
65
+ Requires-Dist: openpyxl>=3.1; extra == 'interop'
66
+ Provides-Extra: test
67
+ Requires-Dist: openpyxl>=3.1; extra == 'test'
68
+ Requires-Dist: pytest-cov; extra == 'test'
69
+ Requires-Dist: pytest>=7; extra == 'test'
70
+ Description-Content-Type: text/markdown
71
+
72
+ <p align="center"><img src="https://raw.githubusercontent.com/ComplexSystemsIntelligence/nocad/main/docs/_static/banner.png" alt="nocad: network-based controllability and observability analysis in Python"></p>
73
+
74
+ # nocad: network-based controllability and observability analysis in Python
75
+
76
+ [![tests](https://github.com/ComplexSystemsIntelligence/nocad/actions/workflows/ci.yml/badge.svg)](https://github.com/ComplexSystemsIntelligence/nocad/actions/workflows/ci.yml)
77
+ [![docs](https://img.shields.io/badge/docs-gallery%20%2B%20API-285780)](https://complexsystemsintelligence.github.io/nocad)
78
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/ComplexSystemsIntelligence/nocad/blob/main/LICENSE)
79
+
80
+ **nocad** analyses the controllability and observability of dynamical systems on
81
+ the network of their state variables. It succeeds the *NOCAD — Network-based
82
+ Observability and Controllability Analysis of Dynamical systems* toolbox for MATLAB
83
+ (Leitold, Vathy-Fogarassy, Abonyi) and implements its three modules — network
84
+ mapping, system characterisation, and the improvement of input and output
85
+ configurations — together with new methods: the exact minimum of dedicated inputs,
86
+ node roles and edge classes, control profiles, robustness analysis, and a
87
+ visualization module whose layouts make the structural conditions of
88
+ controllability visible.
89
+
90
+ | Module | Contents |
91
+ |---|---|
92
+ | `nocad.design`, `nocad.matching` | maximum matching (Hopcroft–Karp), path finding, signal sharing, exact minimum of dedicated inputs; driver and sensor nodes; generation of B, C, D; node roles and edge classes |
93
+ | `nocad.structural`, `nocad.components` | Lin's structural test, generic dimension of the controllable subspace (orthogonal Krylov iteration), Kalman and PBH tests, control and observe centrality; strongly connected components and condensation |
94
+ | `nocad.distances` | geodesic distances, control and observation depth and regions, relative degree, placement cost |
95
+ | `nocad.profiles`, `nocad.robustness` | driver and sensor types, control profiles; robustness against node and edge removal |
96
+ | `nocad.connection` | the seven connection types, node and edge dynamics, dynamics heat maps |
97
+ | `nocad.measures` | about fifty network, node, configuration and edge measures as pandas tables |
98
+ | `nocad.placement` | grassroot and retrofit set covering, centrality-based retrofit, mCLASA and GDFCMSA simulated annealing (`Placement` estimator) |
99
+ | `nocad.io`, `nocad.annotation` | import and export: NetworkX, igraph, pandas, state-space matrices, python-control; GraphML, GEXF (Gephi), GML, Cytoscape JSON, node-link JSON, Graphviz DOT, Pajek, edge lists, CSV, Excel, MATLAB (NOCAD toolbox), NumPy; node and edge tables with the role of every element, carried as attributes by every export and restored on import |
100
+ | `nocad.viz` | SCC hierarchy layout, bipartite matching view, control cacti, block-triangular structure matrix, depth maps with network-Voronoi regions, operability plane, role and robustness maps, dashboards |
101
+ | `nocad.datasets`, `nocad.plotting` | the networks of the NOCAD studies (Sets I–III, *C. elegans* frontal network), generators (random, water tanks, heat exchanger networks), drawing primitives |
102
+
103
+ ## Installation
104
+
105
+ ```bash
106
+ pip install nocad
107
+ ```
108
+
109
+ Python ≥ 3.10; depends on numpy, scipy, networkx, pandas and matplotlib.
110
+ `pip install "nocad[interop]"` adds python-control, igraph and openpyxl for the
111
+ corresponding conversions.
112
+
113
+ ## Quick start
114
+
115
+ ```python
116
+ import nocad
117
+ from nocad.datasets import load_nocad_example
118
+ from nocad.viz import plot_control_cacti, plot_operability_summary
119
+
120
+ adj = load_nocad_example().adj # network of the state variables (W = A^T)
121
+
122
+ design = nocad.InputOutputDesign(method="path_finding").fit(adj)
123
+ design.driver_nodes_, design.sensor_nodes_ # where the inputs and outputs go
124
+ A, B, C, D = design.matrices() # structured state-space matrices
125
+ design.is_controllable(), design.is_observable()
126
+
127
+ nocad.InputOutputDesign(method="minimum").fit(adj).n_inputs_ # exact minimum
128
+
129
+ plot_control_cacti(adj) # Lin's cacti: why the design works
130
+ plot_operability_summary(adj) # hierarchy, depth maps, operability plane
131
+
132
+ ann = design.annotate() # role of every node and edge (pandas tables)
133
+ design.write("example.gexf") # Gephi, with role colors and positions
134
+ G = design.to_networkx() # annotated networkx.DiGraph
135
+ net = nocad.read_network("example.gexf") # network and configuration come back
136
+ ```
137
+
138
+ Estimators follow the scikit-learn conventions (`fit`, fitted attributes with a
139
+ trailing underscore, `get_params`/`set_params`); networks are accepted as NumPy
140
+ arrays, SciPy sparse matrices, NetworkX digraphs, igraph graphs or pandas DataFrames,
141
+ and node names are kept in every table, file and figure.
142
+
143
+ ## Documentation, examples, book
144
+
145
+ * **Documentation and example gallery**: <https://complexsystemsintelligence.github.io/nocad>.
146
+ 29 runnable examples in seven sections; each generates or loads its own network,
147
+ explains the method and ends with a study of its parameters. Every example is also
148
+ a Jupyter notebook.
149
+ * **Book**: *Network-Based Controllability and Observability Analysis in Python: The
150
+ nocad toolbox*: [read online](https://complexsystemsintelligence.github.io/nocad/book/),
151
+ [PDF](https://complexsystemsintelligence.github.io/nocad/nocad-book.pdf) (136 pages) and
152
+ [EPUB](https://complexsystemsintelligence.github.io/nocad/nocad-book.epub), CC BY 4.0;
153
+ LaTeX source in `book/`, built by `book/build.sh` (PDF), `book/epub/make_epub.py`
154
+ and `book/web/make_web.py`. Theory in one notation, algorithm boxes, propositions with proofs,
155
+ and the gallery examples as case studies.
156
+ * **Migration from the MATLAB toolbox**: Appendix B of the book and
157
+ `docs/migration.rst`.
158
+
159
+ ## Development
160
+
161
+ ```bash
162
+ git clone https://github.com/ComplexSystemsIntelligence/nocad.git && cd nocad
163
+ pip install -e ".[dev]"
164
+ pytest # unit tests and doctests
165
+ ruff check src tests tools examples
166
+ python docs/build_api_pages.py && sphinx-build -b html docs docs/_build/html
167
+ book/build.sh # cover, figures, appendices, PDF
168
+ python book/epub/make_epub.py # EPUB edition (tex4ebook)
169
+ python book/web/make_web.py # web edition (make4ht) -> book/_build_web/site
170
+ ```
171
+
172
+ `DESIGN.md` sets the conventions for the code, the docstrings, the examples and the
173
+ book (notation, API contract, layout, templates).
174
+
175
+ ## Citing
176
+
177
+ Please cite the software through `CITATION.cff` (a Zenodo DOI is assigned with the
178
+ first release) and the original publications of the methods you use, in
179
+ particular
180
+
181
+ * D. Leitold, Á. Vathy-Fogarassy, J. Abonyi: Controllability and observability in
182
+ complex networks – the effect of connection types. *Scientific Reports* 7, 151
183
+ (2017), doi:10.1038/s41598-017-00160-5;
184
+ * D. Leitold, Á. Vathy-Fogarassy, J. Abonyi: Network-based observability and
185
+ controllability analysis of dynamical systems: the NOCAD toolbox.
186
+ *F1000Research* 8:646 (2019), doi:10.12688/f1000research.19029.2.
187
+
188
+ Every docstring and chapter lists the publications behind its methods.
189
+
190
+ ## About
191
+
192
+ nocad is developed by the HUN-REN–PE Complex Systems Monitoring Research Group
193
+ ([AbonyiLab](https://www.abonyilab.com)) at the University of Pannonia, Veszprém,
194
+ Hungary. The group's open textbooks and software are collected at
195
+ [complexsystemsintelligence.github.io](https://complexsystemsintelligence.github.io/).
196
+ The work was supported by the National Research, Development and Innovation Office
197
+ of Hungary (NKFIH) through the OTKA 143482 project.
198
+
199
+ ## License
200
+
201
+ Code: MIT. Book: CC BY 4.0. Authors: János Abonyi, Dániel Leitold and Ágnes
202
+ Vathy-Fogarassy (University of Pannonia), who also wrote the MATLAB toolbox this
203
+ project succeeds.
nocad-1.0/README.md ADDED
@@ -0,0 +1,132 @@
1
+ <p align="center"><img src="https://raw.githubusercontent.com/ComplexSystemsIntelligence/nocad/main/docs/_static/banner.png" alt="nocad: network-based controllability and observability analysis in Python"></p>
2
+
3
+ # nocad: network-based controllability and observability analysis in Python
4
+
5
+ [![tests](https://github.com/ComplexSystemsIntelligence/nocad/actions/workflows/ci.yml/badge.svg)](https://github.com/ComplexSystemsIntelligence/nocad/actions/workflows/ci.yml)
6
+ [![docs](https://img.shields.io/badge/docs-gallery%20%2B%20API-285780)](https://complexsystemsintelligence.github.io/nocad)
7
+ [![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/ComplexSystemsIntelligence/nocad/blob/main/LICENSE)
8
+
9
+ **nocad** analyses the controllability and observability of dynamical systems on
10
+ the network of their state variables. It succeeds the *NOCAD — Network-based
11
+ Observability and Controllability Analysis of Dynamical systems* toolbox for MATLAB
12
+ (Leitold, Vathy-Fogarassy, Abonyi) and implements its three modules — network
13
+ mapping, system characterisation, and the improvement of input and output
14
+ configurations — together with new methods: the exact minimum of dedicated inputs,
15
+ node roles and edge classes, control profiles, robustness analysis, and a
16
+ visualization module whose layouts make the structural conditions of
17
+ controllability visible.
18
+
19
+ | Module | Contents |
20
+ |---|---|
21
+ | `nocad.design`, `nocad.matching` | maximum matching (Hopcroft–Karp), path finding, signal sharing, exact minimum of dedicated inputs; driver and sensor nodes; generation of B, C, D; node roles and edge classes |
22
+ | `nocad.structural`, `nocad.components` | Lin's structural test, generic dimension of the controllable subspace (orthogonal Krylov iteration), Kalman and PBH tests, control and observe centrality; strongly connected components and condensation |
23
+ | `nocad.distances` | geodesic distances, control and observation depth and regions, relative degree, placement cost |
24
+ | `nocad.profiles`, `nocad.robustness` | driver and sensor types, control profiles; robustness against node and edge removal |
25
+ | `nocad.connection` | the seven connection types, node and edge dynamics, dynamics heat maps |
26
+ | `nocad.measures` | about fifty network, node, configuration and edge measures as pandas tables |
27
+ | `nocad.placement` | grassroot and retrofit set covering, centrality-based retrofit, mCLASA and GDFCMSA simulated annealing (`Placement` estimator) |
28
+ | `nocad.io`, `nocad.annotation` | import and export: NetworkX, igraph, pandas, state-space matrices, python-control; GraphML, GEXF (Gephi), GML, Cytoscape JSON, node-link JSON, Graphviz DOT, Pajek, edge lists, CSV, Excel, MATLAB (NOCAD toolbox), NumPy; node and edge tables with the role of every element, carried as attributes by every export and restored on import |
29
+ | `nocad.viz` | SCC hierarchy layout, bipartite matching view, control cacti, block-triangular structure matrix, depth maps with network-Voronoi regions, operability plane, role and robustness maps, dashboards |
30
+ | `nocad.datasets`, `nocad.plotting` | the networks of the NOCAD studies (Sets I–III, *C. elegans* frontal network), generators (random, water tanks, heat exchanger networks), drawing primitives |
31
+
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install nocad
36
+ ```
37
+
38
+ Python ≥ 3.10; depends on numpy, scipy, networkx, pandas and matplotlib.
39
+ `pip install "nocad[interop]"` adds python-control, igraph and openpyxl for the
40
+ corresponding conversions.
41
+
42
+ ## Quick start
43
+
44
+ ```python
45
+ import nocad
46
+ from nocad.datasets import load_nocad_example
47
+ from nocad.viz import plot_control_cacti, plot_operability_summary
48
+
49
+ adj = load_nocad_example().adj # network of the state variables (W = A^T)
50
+
51
+ design = nocad.InputOutputDesign(method="path_finding").fit(adj)
52
+ design.driver_nodes_, design.sensor_nodes_ # where the inputs and outputs go
53
+ A, B, C, D = design.matrices() # structured state-space matrices
54
+ design.is_controllable(), design.is_observable()
55
+
56
+ nocad.InputOutputDesign(method="minimum").fit(adj).n_inputs_ # exact minimum
57
+
58
+ plot_control_cacti(adj) # Lin's cacti: why the design works
59
+ plot_operability_summary(adj) # hierarchy, depth maps, operability plane
60
+
61
+ ann = design.annotate() # role of every node and edge (pandas tables)
62
+ design.write("example.gexf") # Gephi, with role colors and positions
63
+ G = design.to_networkx() # annotated networkx.DiGraph
64
+ net = nocad.read_network("example.gexf") # network and configuration come back
65
+ ```
66
+
67
+ Estimators follow the scikit-learn conventions (`fit`, fitted attributes with a
68
+ trailing underscore, `get_params`/`set_params`); networks are accepted as NumPy
69
+ arrays, SciPy sparse matrices, NetworkX digraphs, igraph graphs or pandas DataFrames,
70
+ and node names are kept in every table, file and figure.
71
+
72
+ ## Documentation, examples, book
73
+
74
+ * **Documentation and example gallery**: <https://complexsystemsintelligence.github.io/nocad>.
75
+ 29 runnable examples in seven sections; each generates or loads its own network,
76
+ explains the method and ends with a study of its parameters. Every example is also
77
+ a Jupyter notebook.
78
+ * **Book**: *Network-Based Controllability and Observability Analysis in Python: The
79
+ nocad toolbox*: [read online](https://complexsystemsintelligence.github.io/nocad/book/),
80
+ [PDF](https://complexsystemsintelligence.github.io/nocad/nocad-book.pdf) (136 pages) and
81
+ [EPUB](https://complexsystemsintelligence.github.io/nocad/nocad-book.epub), CC BY 4.0;
82
+ LaTeX source in `book/`, built by `book/build.sh` (PDF), `book/epub/make_epub.py`
83
+ and `book/web/make_web.py`. Theory in one notation, algorithm boxes, propositions with proofs,
84
+ and the gallery examples as case studies.
85
+ * **Migration from the MATLAB toolbox**: Appendix B of the book and
86
+ `docs/migration.rst`.
87
+
88
+ ## Development
89
+
90
+ ```bash
91
+ git clone https://github.com/ComplexSystemsIntelligence/nocad.git && cd nocad
92
+ pip install -e ".[dev]"
93
+ pytest # unit tests and doctests
94
+ ruff check src tests tools examples
95
+ python docs/build_api_pages.py && sphinx-build -b html docs docs/_build/html
96
+ book/build.sh # cover, figures, appendices, PDF
97
+ python book/epub/make_epub.py # EPUB edition (tex4ebook)
98
+ python book/web/make_web.py # web edition (make4ht) -> book/_build_web/site
99
+ ```
100
+
101
+ `DESIGN.md` sets the conventions for the code, the docstrings, the examples and the
102
+ book (notation, API contract, layout, templates).
103
+
104
+ ## Citing
105
+
106
+ Please cite the software through `CITATION.cff` (a Zenodo DOI is assigned with the
107
+ first release) and the original publications of the methods you use, in
108
+ particular
109
+
110
+ * D. Leitold, Á. Vathy-Fogarassy, J. Abonyi: Controllability and observability in
111
+ complex networks – the effect of connection types. *Scientific Reports* 7, 151
112
+ (2017), doi:10.1038/s41598-017-00160-5;
113
+ * D. Leitold, Á. Vathy-Fogarassy, J. Abonyi: Network-based observability and
114
+ controllability analysis of dynamical systems: the NOCAD toolbox.
115
+ *F1000Research* 8:646 (2019), doi:10.12688/f1000research.19029.2.
116
+
117
+ Every docstring and chapter lists the publications behind its methods.
118
+
119
+ ## About
120
+
121
+ nocad is developed by the HUN-REN–PE Complex Systems Monitoring Research Group
122
+ ([AbonyiLab](https://www.abonyilab.com)) at the University of Pannonia, Veszprém,
123
+ Hungary. The group's open textbooks and software are collected at
124
+ [complexsystemsintelligence.github.io](https://complexsystemsintelligence.github.io/).
125
+ The work was supported by the National Research, Development and Innovation Office
126
+ of Hungary (NKFIH) through the OTKA 143482 project.
127
+
128
+ ## License
129
+
130
+ Code: MIT. Book: CC BY 4.0. Authors: János Abonyi, Dániel Leitold and Ágnes
131
+ Vathy-Fogarassy (University of Pannonia), who also wrote the MATLAB toolbox this
132
+ project succeeds.
@@ -0,0 +1,3 @@
1
+ Networks, matchings and input/output design
2
+ -------------------------------------------
3
+
@@ -0,0 +1,85 @@
1
+ """
2
+ From a state-space model to the network of its state variables
3
+ ===============================================================
4
+
5
+ A linear system :math:`\\dot{\\mathbf{x}}=\\mathbf{A}\\mathbf{x}+\\mathbf{B}\\mathbf{u}` is
6
+ turned into a network by drawing an edge :math:`x_j\\to x_i` for every non-zero
7
+ :math:`a_{ij}`: the adjacency matrix is :math:`\\mathbf{A}^{\\mathsf T}`. Three water tanks,
8
+ the first feeding the other two, show why the *physical* topology (the pipes) is not
9
+ the network of the state variables: if the outflow of a tank depends on its level, every
10
+ state has a self-loop; if the tanks are connected vessels, the flow depends on both
11
+ levels and every pipe gives a pair of edges. The driver and sensor nodes, computed by
12
+ maximum matching, change accordingly.
13
+ """
14
+
15
+ # %%
16
+ # Three ways to read the same pipes
17
+ # ---------------------------------
18
+ import matplotlib.pyplot as plt
19
+ import numpy as np
20
+
21
+ import nocad
22
+ from nocad.datasets import make_water_tanks
23
+ from nocad.plotting import draw_network
24
+
25
+ # [snippet:tanks]
26
+ variants = {
27
+ "physical (pipes only)": make_water_tanks(3, "branch", "physical"),
28
+ "free outflow (self-loops)": make_water_tanks(3, "branch", "free_outflow"),
29
+ "connected vessels (loops + pairs)": make_water_tanks(3, "branch", "connected"),
30
+ }
31
+ for name, tanks in variants.items():
32
+ A = nocad.adjacency_to_state_matrix(tanks.adj).toarray().astype(int) # A = W^T
33
+ design = nocad.InputOutputDesign().fit(tanks.adj)
34
+ print(f"{name:34s} drivers={design.driver_nodes_ + 1} sensors={design.sensor_nodes_ + 1}")
35
+ # [/snippet:tanks]
36
+
37
+ pos = np.array([[0.0, 0.55], [-0.6, -0.45], [0.6, -0.45]])
38
+ fig, axes = plt.subplots(1, 3, figsize=(9.6, 3.3))
39
+ for ax, (name, tanks) in zip(axes, variants.items(), strict=True):
40
+ design = nocad.InputOutputDesign().fit(tanks.adj)
41
+ draw_network(tanks.adj, pos, ax=ax, labels=tanks.labels, drivers=design.driver_nodes_,
42
+ sensors=design.sensor_nodes_, node_size=420, font_size=9, draw_loops="arc")
43
+ ax.set_title(f"{name}\n$N_D$ = {design.n_drivers_}, $N_S$ = {design.n_sensors_}", fontsize=9)
44
+ fig.tight_layout()
45
+
46
+ # %%
47
+ # The state matrix and its network
48
+ # --------------------------------
49
+ # For the connected vessels the state matrix has the pattern below; the network is
50
+ # its transpose, which is what the code stores as ``adj``.
51
+ A = nocad.adjacency_to_state_matrix(variants["connected vessels (loops + pairs)"].adj)
52
+ print(A.toarray().astype(int))
53
+
54
+ # %%
55
+ # Parameter study: more tanks
56
+ # ---------------------------
57
+ # With a branching topology every extra tank is a new sink of the physical network, so
58
+ # the numbers of driver and sensor nodes grow with the number of tanks. Self-loops
59
+ # remove every dilation (a state can be "matched" by its own loop), so one input
60
+ # controls any number of tanks, but every tank is still a sink and needs its own
61
+ # sensor. With connected vessels the network is strongly connected and a single input
62
+ # and a single output suffice.
63
+ sizes = np.arange(2, 11)
64
+ fig, ax = plt.subplots(figsize=(5.4, 3.5))
65
+ for k, connection in enumerate(["physical", "free_outflow", "connected"]):
66
+ nets = [make_water_tanks(n, "branch", connection).adj for n in sizes]
67
+ nd = [nocad.n_driver_nodes(a) for a in nets]
68
+ ns = [nocad.sensor_nodes(a).size for a in nets]
69
+ col = nocad.plotting.PALETTE[k]
70
+ ax.plot(sizes, nd, marker="osD"[k], ms=4, lw=1.5, color=col, label=f"{connection}: $N_D$")
71
+ ax.plot(sizes + 0.08 * (k - 1), ns, marker="osD"[k], ms=4, lw=1.2, ls="--", color=col, mfc="white",
72
+ label=f"{connection}: $N_S$")
73
+ ax.set_xlabel("number of tanks")
74
+ ax.set_ylabel("driver / sensor nodes")
75
+ ax.set_title("branching tanks: inputs and outputs by connection type", fontsize=10)
76
+ ax.grid(True, color="0.9")
77
+ ax.legend(frameon=False, fontsize=7, ncol=1)
78
+ fig.tight_layout()
79
+
80
+ # %%
81
+ # **Take-away.** The network of a dynamical system has to be built from its state
82
+ # equations, not from its piping diagram: self-influence removes the dilations that
83
+ # force an input at every branch, and interactions make the network strongly
84
+ # connected, so that one input and one output make the system controllable and
85
+ # observable.
@@ -0,0 +1,89 @@
1
+ """
2
+ Maximum matching and the minimum number of driver nodes
3
+ =======================================================
4
+
5
+ A matching is a set of edges without common start or end nodes; a node is matched when
6
+ a matching edge ends in it. Liu, Slotine and Barabási proved that the unmatched nodes of
7
+ a *maximum* matching form a minimum set of driver nodes (the minimum input theorem). The
8
+ four-node network of the NOCAD manual, a three-cycle with a tail, has several maximum
9
+ matchings: the number of driver nodes is fixed, their positions are not. On random
10
+ networks the share of driver nodes falls with the mean degree, the classical result of
11
+ network controllability.
12
+ """
13
+
14
+ # %%
15
+ # One matching, two pictures
16
+ # --------------------------
17
+ import matplotlib.pyplot as plt
18
+ import numpy as np
19
+
20
+ import nocad
21
+ from nocad.datasets import load_four_node_example, make_random_network
22
+ from nocad.plotting import draw_network
23
+ from nocad.viz import plot_bipartite_matching
24
+
25
+ # [snippet:matching]
26
+ adj = load_four_node_example().adj
27
+ m = nocad.maximum_matching(adj)
28
+ print("size of the matching:", m.size)
29
+ print("matched edges (start, end):", (m.edges + 1).tolist())
30
+ print("unmatched (driver) nodes:", m.unmatched + 1)
31
+ # [/snippet:matching]
32
+
33
+ pos = np.array([[-0.55, 0.65], [0.55, 0.65], [0.0, -0.25], [0.0, -1.1]])
34
+ fig, axes = plt.subplots(1, 2, figsize=(7.2, 3.4), gridspec_kw={"width_ratios": [1.1, 1]})
35
+ hl = {(int(a), int(b)): {"color": nocad.plotting.ROLE_COLORS["matched"], "lw": 2.6} for a, b in m.edges}
36
+ draw_network(adj, pos, ax=axes[0], highlight=hl, drivers=m.unmatched, node_size=420, font_size=9)
37
+ axes[0].set_title("directed network: matched edges green", fontsize=9)
38
+ plot_bipartite_matching(adj, m, ax=axes[1], title="bipartite representation")
39
+ fig.tight_layout()
40
+
41
+ # %%
42
+ # All maximum matchings
43
+ # ---------------------
44
+ # The small network has two maximum matchings. Each leaves exactly one node unmatched,
45
+ # but a different one: :math:`x_4` when the cycle is matched by itself and the tail is
46
+ # left over, :math:`x_1` when the stem runs through the cycle into the tail. Nodes
47
+ # :math:`x_1` and :math:`x_4` are therefore *intermittent* driver nodes, :math:`x_2` and
48
+ # :math:`x_3` are never driver nodes (*redundant*).
49
+ # [snippet:enumerate]
50
+ all_m = nocad.all_maximum_matchings(adj)
51
+ for k, mm in enumerate(all_m, start=1):
52
+ print(f"matching {k}: edges {(mm.edges + 1).tolist()} drivers {mm.unmatched + 1}")
53
+ print("node roles:", nocad.node_roles(adj))
54
+ # [/snippet:enumerate]
55
+ fig, axes = plt.subplots(1, len(all_m), figsize=(3.0 * len(all_m), 2.9))
56
+ for k, (ax, mm) in enumerate(zip(np.atleast_1d(axes), all_m, strict=True), start=1):
57
+ hl = {(int(a), int(b)): {"color": nocad.plotting.ROLE_COLORS["matched"], "lw": 2.6} for a, b in mm.edges}
58
+ draw_network(adj, pos, ax=ax, highlight=hl, drivers=mm.unmatched, node_size=380, font_size=9)
59
+ ax.set_title(f"maximum matching {k}: driver $x_{{{mm.unmatched[0] + 1}}}$", fontsize=9)
60
+ fig.tight_layout()
61
+
62
+ # %%
63
+ # Parameter study: mean degree
64
+ # ----------------------------
65
+ # The share of driver nodes :math:`n_D=N_D/N` of Erdős--Rényi and scale-free networks with
66
+ # :math:`N=300` nodes. Sparse networks need many inputs because of their many sources,
67
+ # sinks and dilations; the heterogeneous scale-free networks need more than random ones
68
+ # of the same mean degree.
69
+ degrees = np.linspace(0.5, 8, 14)
70
+ fig, ax = plt.subplots(figsize=(5.2, 3.4))
71
+ for k, kind in enumerate(["erdos_renyi", "scale_free"]):
72
+ share = []
73
+ for kd in degrees:
74
+ vals = [nocad.n_driver_nodes(make_random_network(300, kd, kind=kind, random_state=s).adj, "matching") / 300
75
+ for s in range(3)]
76
+ share.append(np.mean(vals))
77
+ ax.plot(degrees, share, marker="os"[k], ms=4, lw=1.5, color=nocad.plotting.PALETTE[k],
78
+ label=kind.replace("_", "-"))
79
+ ax.set_xlabel(r"mean degree $\langle k\rangle$")
80
+ ax.set_ylabel("share of driver nodes $n_D$")
81
+ ax.set_title("driver nodes of random networks (N = 300)", fontsize=10)
82
+ ax.grid(True, color="0.9")
83
+ ax.legend(frameon=False, fontsize=8)
84
+ fig.tight_layout()
85
+
86
+ # %%
87
+ # **Take-away.** Maximum matching fixes how many driver nodes are needed, not which
88
+ # ones; denser and more homogeneous networks are controlled by a smaller share of
89
+ # their nodes.