netlab 0.6.1__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 (71) hide show
  1. netlab-0.6.1/LICENSE +21 -0
  2. netlab-0.6.1/MANIFEST.in +1 -0
  3. netlab-0.6.1/PKG-INFO +274 -0
  4. netlab-0.6.1/README.md +233 -0
  5. netlab-0.6.1/netlab/__init__.py +10 -0
  6. netlab-0.6.1/netlab/artifacts.py +152 -0
  7. netlab-0.6.1/netlab/autoresearch/__init__.py +1 -0
  8. netlab-0.6.1/netlab/autoresearch/analysis_loop.py +134 -0
  9. netlab-0.6.1/netlab/autoresearch/backend.py +270 -0
  10. netlab-0.6.1/netlab/autoresearch/cli.py +295 -0
  11. netlab-0.6.1/netlab/autoresearch/dcbb_config.py +272 -0
  12. netlab-0.6.1/netlab/autoresearch/dcbb_failures.py +274 -0
  13. netlab-0.6.1/netlab/autoresearch/experiment_log.py +278 -0
  14. netlab-0.6.1/netlab/autoresearch/generation_loop.py +217 -0
  15. netlab-0.6.1/netlab/autoresearch/hypothesis.py +236 -0
  16. netlab-0.6.1/netlab/autoresearch/hypothesis_manager.py +199 -0
  17. netlab-0.6.1/netlab/autoresearch/memory.py +315 -0
  18. netlab-0.6.1/netlab/autoresearch/metrics_report.py +115 -0
  19. netlab-0.6.1/netlab/autoresearch/objective.py +170 -0
  20. netlab-0.6.1/netlab/autoresearch/prompt.py +288 -0
  21. netlab-0.6.1/netlab/autoresearch/runner.py +490 -0
  22. netlab-0.6.1/netlab/autoresearch/scenario_generator.py +380 -0
  23. netlab-0.6.1/netlab/autoresearch/scenario_validation.py +244 -0
  24. netlab-0.6.1/netlab/autoresearch/structural_analysis.py +297 -0
  25. netlab-0.6.1/netlab/autoresearch/sweep.py +570 -0
  26. netlab-0.6.1/netlab/cli.py +421 -0
  27. netlab-0.6.1/netlab/comparison.py +299 -0
  28. netlab-0.6.1/netlab/experiment.py +218 -0
  29. netlab-0.6.1/netlab/log_config.py +44 -0
  30. netlab-0.6.1/netlab/metrics/__init__.py +0 -0
  31. netlab-0.6.1/netlab/metrics/aggregate.py +22 -0
  32. netlab-0.6.1/netlab/metrics/analysis.py +89 -0
  33. netlab-0.6.1/netlab/metrics/bac.py +245 -0
  34. netlab-0.6.1/netlab/metrics/batch.py +706 -0
  35. netlab-0.6.1/netlab/metrics/common.py +87 -0
  36. netlab-0.6.1/netlab/metrics/comparisons.py +78 -0
  37. netlab-0.6.1/netlab/metrics/costpower.py +131 -0
  38. netlab-0.6.1/netlab/metrics/distributions.py +42 -0
  39. netlab-0.6.1/netlab/metrics/iterops.py +64 -0
  40. netlab-0.6.1/netlab/metrics/latency.py +295 -0
  41. netlab-0.6.1/netlab/metrics/matrixdump.py +108 -0
  42. netlab-0.6.1/netlab/metrics/msd.py +43 -0
  43. netlab-0.6.1/netlab/metrics/paired.py +84 -0
  44. netlab-0.6.1/netlab/metrics/plot_bac_delta_vs_baseline.py +197 -0
  45. netlab-0.6.1/netlab/metrics/plot_cross_seed_bac.py +168 -0
  46. netlab-0.6.1/netlab/metrics/plot_cross_seed_iterops.py +139 -0
  47. netlab-0.6.1/netlab/metrics/plot_cross_seed_latency.py +151 -0
  48. netlab-0.6.1/netlab/metrics/plot_significance_heatmap.py +120 -0
  49. netlab-0.6.1/netlab/metrics/reporting.py +347 -0
  50. netlab-0.6.1/netlab/metrics/seed_data.py +98 -0
  51. netlab-0.6.1/netlab/metrics/sps.py +115 -0
  52. netlab-0.6.1/netlab/metrics/summary.py +825 -0
  53. netlab-0.6.1/netlab/metrics/validation.py +193 -0
  54. netlab-0.6.1/netlab/metrics_failure.py +199 -0
  55. netlab-0.6.1/netlab/pipeline.py +207 -0
  56. netlab-0.6.1/netlab/results.py +240 -0
  57. netlab-0.6.1/netlab/run_record.py +46 -0
  58. netlab-0.6.1/netlab/runtime.py +54 -0
  59. netlab-0.6.1/netlab/scenario.py +162 -0
  60. netlab-0.6.1/netlab/simulation.py +284 -0
  61. netlab-0.6.1/netlab/tasks.py +58 -0
  62. netlab-0.6.1/netlab/topology.py +83 -0
  63. netlab-0.6.1/netlab/visualize.py +569 -0
  64. netlab-0.6.1/netlab.egg-info/PKG-INFO +274 -0
  65. netlab-0.6.1/netlab.egg-info/SOURCES.txt +69 -0
  66. netlab-0.6.1/netlab.egg-info/dependency_links.txt +1 -0
  67. netlab-0.6.1/netlab.egg-info/entry_points.txt +2 -0
  68. netlab-0.6.1/netlab.egg-info/requires.txt +24 -0
  69. netlab-0.6.1/netlab.egg-info/top_level.txt +1 -0
  70. netlab-0.6.1/pyproject.toml +121 -0
  71. netlab-0.6.1/setup.cfg +4 -0
netlab-0.6.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-2026 Andrey Golovanov
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.
@@ -0,0 +1 @@
1
+ prune tests
netlab-0.6.1/PKG-INFO ADDED
@@ -0,0 +1,274 @@
1
+ Metadata-Version: 2.4
2
+ Name: netlab
3
+ Version: 0.6.1
4
+ Summary: Metrics and analysis tools for NetGraph scenarios.
5
+ Author: Andrey Golovanov
6
+ License-Expression: MIT
7
+ Project-URL: Repository, https://github.com/networmix/NetLab
8
+ Project-URL: Changelog, https://github.com/networmix/NetLab/blob/main/CHANGELOG.md
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Operating System :: OS Independent
14
+ Requires-Python: >=3.11
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: numpy>=1.24
18
+ Requires-Dist: pandas>=2.0
19
+ Requires-Dist: matplotlib>=3.7
20
+ Requires-Dist: seaborn>=0.13
21
+ Requires-Dist: scipy>=1.11
22
+ Requires-Dist: rich>=13.0
23
+ Requires-Dist: ngraph<0.27,>=0.26.0
24
+ Requires-Dist: netlab-topogen<0.7,>=0.6.1
25
+ Requires-Dist: pebble<6,>=5.2.0
26
+ Requires-Dist: pyyaml>=6
27
+ Requires-Dist: cairosvg>=2.7
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=8; extra == "dev"
30
+ Requires-Dist: pytest-cov; extra == "dev"
31
+ Requires-Dist: pytest-benchmark; extra == "dev"
32
+ Requires-Dist: pytest-mock; extra == "dev"
33
+ Requires-Dist: pytest-timeout; extra == "dev"
34
+ Requires-Dist: ruff==0.11.13; extra == "dev"
35
+ Requires-Dist: pyright==1.1.401; extra == "dev"
36
+ Requires-Dist: pandas-stubs; extra == "dev"
37
+ Requires-Dist: pre-commit; extra == "dev"
38
+ Requires-Dist: build; extra == "dev"
39
+ Requires-Dist: twine; extra == "dev"
40
+ Dynamic: license-file
41
+
42
+ # NetLab
43
+
44
+ NetLab builds network scenarios with
45
+ [NetLab-TopoGen](https://github.com/networmix/NetLab-TopoGen), runs them with
46
+ [NetGraph](https://github.com/networmix/NetGraph), and compares the results. It
47
+ reports how much traffic survives failures, how path costs change, and how much
48
+ the modeled equipment costs and consumes.
49
+
50
+ You can run several configurations and random seeds in one batch. NetLab also
51
+ supports parameter searches and experiments proposed by a language model.
52
+
53
+ ## Install
54
+
55
+ Use Python 3.11 or later in a virtual environment of its own. To install the command:
56
+
57
+ ```bash
58
+ python -m pip install netlab
59
+ ```
60
+
61
+ The command also installs NetGraph (`ngraph`), NetLab-TopoGen
62
+ (`netlab-topogen`) and the other dependencies from PyPI;
63
+ [pyproject.toml](https://github.com/networmix/NetLab/blob/main/pyproject.toml) lists their supported versions.
64
+
65
+ ipSpace's `networklab` package installs a command of the same name, so use separate environments for the two tools.
66
+
67
+ To use the included examples, clone the repository with Git and create its environment:
68
+
69
+ ```bash
70
+ git clone https://github.com/networmix/NetLab
71
+ cd NetLab
72
+ make dev
73
+ source venv/bin/activate
74
+ ```
75
+
76
+ Run the commands below from the repository root.
77
+
78
+ ## Run an example
79
+
80
+ This example uses saved geographic routes, so no Census download is needed. It
81
+ still needs network access: the build draws a site map for each scenario from
82
+ downloaded map tiles. To build offline, set `visualization.site_graph.export:
83
+ false` in a copy of the configuration.
84
+
85
+ ```bash
86
+ netlab run topogen_configs_small/small_baseline.yml --seeds 11 12 \
87
+ --graphs-dir tests/data/scenarios/small_baseline/small_baseline \
88
+ --scenarios-dir scenarios
89
+ netlab metrics scenarios/
90
+ ```
91
+
92
+ The first command builds a network for each seed and runs its NetGraph workflow.
93
+ A **seed** is the scenario's random seed. It drives NetLab-TopoGen's random traffic
94
+ choices and NetGraph's failure sampling, so the same seed repeats the same
95
+ experiment. The second command calculates metrics and renders comparison figures.
96
+
97
+ | Location | Contents |
98
+ | --- | --- |
99
+ | `scenarios/<config>/<config>__seed<N>/` | Scenario YAML, NetGraph results and NetLab's run record |
100
+ | `scenarios/<config>/<config>_integrated_graph.json` | Geography generated when `--graphs-dir` is omitted |
101
+ | `scenarios/provenance.json` | Input hashes, settings, package versions and outcomes of the last batch |
102
+ | `scenarios_metrics/project.csv` | One summary row per configuration |
103
+ | `scenarios_metrics/BAC.png` | How often each delivered bandwidth was met or exceeded |
104
+ | `scenarios_metrics/<config>/seed<N>/` | Metrics for one seed |
105
+
106
+ To build without simulating, use `netlab build` with the same input arguments.
107
+ To generate geography yourself, omit `--graphs-dir` and first download the
108
+ [data required by NetLab-TopoGen](https://github.com/networmix/NetLab-TopoGen#readme).
109
+ The `data/` and `lib/` paths are relative to your working directory. From the
110
+ repository root, `lib/workflows.yml` replaces NetLab-TopoGen's `design_analysis_brief`
111
+ workflow with NetLab's version, and `lib/failure_policies.yml` adds `mc_hard`.
112
+
113
+ Saved geography must be a corridor `MultiGraph`: a graph that can keep several
114
+ routes between the same metro pair. Each file is named
115
+ `<config>_integrated_graph.json`. The `topogen_configs/` directory contains larger
116
+ designs; `topogen_configs_small/` contains smaller versions for experimentation.
117
+
118
+ ## Control a batch
119
+
120
+ | Option | Effect |
121
+ | --- | --- |
122
+ | `--build-jobs`, `--run-jobs` | Number of build and simulation tasks allowed to run at once |
123
+ | `--build-timeout` | Time limit for each geography or scenario build task |
124
+ | `--run-timeout` | Time limit for each simulation; defaults to 600 seconds |
125
+ | `--force-run` | Run simulations again even when cached results match |
126
+ | `--force` | Rerun simulations and regenerate geography, unless `--graphs-dir` supplies it |
127
+
128
+ Time limits start when a task starts running. Scenario assembly runs every time.
129
+ NetLab reuses saved work only when a hash of its inputs still matches; a hash
130
+ identifies file contents, so any change to the inputs invalidates the cache.
131
+ Generated geography is reused while the configuration, data files and package
132
+ versions are unchanged. A simulation result is reused while the scenario,
133
+ package versions, the saved result file and its run record are unchanged.
134
+ Failed tasks make the command return a failure status; independent tasks continue.
135
+ Each run's outcome and the wall time of each workflow step are saved in a run
136
+ record, `<name>.results.run.json`, beside the results; a reused result keeps the
137
+ times of the run that produced it.
138
+
139
+ ## Read and compare metrics
140
+
141
+ ```bash
142
+ netlab metrics scenarios/ --no-plots
143
+ netlab metrics scenarios/ --only small_baseline
144
+ netlab metrics scenarios/ --summary
145
+ ```
146
+
147
+ `--no-plots` calculates tables without figures. `--only` takes a comma-separated
148
+ list of configuration names, such as `small_baseline,small_clos`.
149
+ `--summary` reads the saved tables and renders figures.
150
+ A calculation replaces the complete report directory, even with `--only`.
151
+ If calculation fails, the existing report is kept.
152
+
153
+ The workflow must include these step names:
154
+
155
+ | Step name | NetGraph analysis |
156
+ | --- | --- |
157
+ | `msd_baseline` | `MaximumSupportedDemand`, which searches for a traffic multiplier |
158
+ | `tm_placement` | `TrafficMatrixPlacement` with `alpha_from_step: msd_baseline`, and `outputs: {cost_distribution: true}` for latency |
159
+ | `network_statistics` | `NetworkStats`, which counts network objects |
160
+
161
+ `--enable-maxflow` also needs a `node_to_node_capacity_matrix` step for pairwise
162
+ capacity analysis. Each result needs the run record NetLab writes beside it.
163
+ See [metrics.md](https://github.com/networmix/NetLab/blob/main/metrics.md) for definitions, required fields, worked examples
164
+ and output files. Failure statistics describe the configured
165
+ experiment; they are not measurements of network uptime.
166
+
167
+ To compare two configurations with matching seeds:
168
+
169
+ ```bash
170
+ netlab test scenarios/ small_baseline small_clos
171
+ ```
172
+
173
+ Both configurations must have been analyzed. The statistical test needs at least
174
+ three matching finite seed results; the two-seed quick start is for running the
175
+ pipeline, not statistical inference.
176
+
177
+ ## Python API
178
+
179
+ Save this as a script and point it to a NetGraph scenario:
180
+
181
+ ```python
182
+ from pathlib import Path
183
+ from netlab.simulation import run_simulation
184
+
185
+ if __name__ == "__main__":
186
+ outcome = run_simulation(Path("scenario.yml"), timeout=60)
187
+ print(outcome.status, outcome.error)
188
+ ```
189
+
190
+ `run_simulation` runs in a local worker process. A successful run saves
191
+ `scenario.results.json` next to the scenario; every run records its status and
192
+ the wall time of each step it ran in `scenario.results.run.json`. The `__main__`
193
+ guard keeps a spawned worker from running the script again. Use `simulate(yaml_text)` to run in the calling
194
+ process, or `inspect_scenario(yaml_text)` to validate and count network objects.
195
+ See [architecture and batch APIs](https://github.com/networmix/NetLab/blob/main/dev/ARCHITECTURE.md).
196
+
197
+ Metric functions read a saved result dictionary:
198
+
199
+ ```python
200
+ import json
201
+ from netlab.metrics.bac import compute_bac
202
+ from netlab.metrics.latency import compute_latency_stretch
203
+ from netlab.metrics.msd import compute_alpha_star
204
+
205
+ with open("scenario.results.json") as f:
206
+ results = json.load(f)
207
+
208
+ print(compute_alpha_star(results).alpha_star)
209
+ print(compute_bac(results, step_name="tm_placement").auc_normalized)
210
+ print(compute_latency_stretch(results).failures.get("p99"))
211
+ ```
212
+
213
+ They return the per-seed values described in [metrics.md](https://github.com/networmix/NetLab/blob/main/metrics.md).
214
+ `netlab metrics` also checks the result arithmetic before it computes them.
215
+
216
+ ## Automated experiments
217
+
218
+ An autoresearch project gives a language model a task description
219
+ (`program.md`), the parameters it may change (`hypothesis_template.yml`) and the
220
+ metric to optimize (`objective.yml`). `init` copies a base scenario that has a
221
+ `MaximumSupportedDemand` step and at least one `${{name}}` placeholder. Each
222
+ placeholder becomes a parameter, and the objective maximizes
223
+ `steps.msd_baseline.result.alpha_feasible.value`, the multiplier of the step named
224
+ `msd_baseline`. A candidate whose search finds no feasible multiplier fails; it
225
+ never scores zero. Review the generated files before a run:
226
+
227
+ ```bash
228
+ netlab autoresearch init --base-scenario scenario.yml --output project/
229
+ netlab autoresearch run project/ --backend mock --max-experiments 1
230
+ ```
231
+
232
+ The `mock` backend is for testing the workflow. To use an external model, select
233
+ `claude-cli`, `codex-cli` or `openai` and configure that backend's credentials.
234
+ CLI backends need their executable installed and signed in.
235
+ `HypothesisManager` can also turn a free-text hypothesis into a scenario, run it
236
+ and request an interpretation. Those cycle files are saved under `<project>/cycles/`.
237
+
238
+ Run one writer per project; nothing locks the files. A project directory is tied
239
+ to its input files, seed and installed package versions. A sweep output directory
240
+ is tied to its sweep type, seed, iteration count and package versions. If any of
241
+ them changes, NetLab refuses to continue there; start a new directory.
242
+ Rerunning a sweep in its directory skips successful entries and retries failed
243
+ ones. Higher scores rank better; candidates that fail the configured constraints
244
+ cannot become best.
245
+
246
+ For data-center-to-backbone designs, see the
247
+ [research project](https://github.com/networmix/NetLab/blob/main/research_projects/dc-bb-autoresearch/program.md) and
248
+ [included interconnect experiments](https://github.com/networmix/NetLab/blob/main/experiments/dc-bb-interconnect/README.md).
249
+
250
+ ## Development
251
+
252
+ ```bash
253
+ make check-ci
254
+ ```
255
+
256
+ This checks formatting, lint, types and tests, including NetLab-TopoGen → NetGraph →
257
+ metrics runs using saved geography. See [fixture regeneration](https://github.com/networmix/NetLab/blob/main/tests/data/README.md)
258
+ and [metric verification](https://github.com/networmix/NetLab/blob/main/dev/METRICS_VERIFICATION.md).
259
+
260
+ In Superset, `bash .superset/workspace.sh setup` creates a `venv`, installs the
261
+ development dependencies and copies missing untracked `.env` files from the root
262
+ checkout. The Run button executes `make check-ci`.
263
+
264
+ To test local checkouts of all three dependencies:
265
+
266
+ ```bash
267
+ bash dev/check_ngraph_integration.sh /path/to/NetGraph /path/to/NetGraph-Core /path/to/NetLab-TopoGen
268
+ ```
269
+
270
+ Replace the paths with your checkouts. The script builds Core and runs checks in
271
+ a temporary environment. It saves source revisions, dependency versions and
272
+ results under `build/ngraph-integration/`.
273
+
274
+ [Changelog](https://github.com/networmix/NetLab/blob/main/CHANGELOG.md) · [MIT license](https://github.com/networmix/NetLab/blob/main/LICENSE)
netlab-0.6.1/README.md ADDED
@@ -0,0 +1,233 @@
1
+ # NetLab
2
+
3
+ NetLab builds network scenarios with
4
+ [NetLab-TopoGen](https://github.com/networmix/NetLab-TopoGen), runs them with
5
+ [NetGraph](https://github.com/networmix/NetGraph), and compares the results. It
6
+ reports how much traffic survives failures, how path costs change, and how much
7
+ the modeled equipment costs and consumes.
8
+
9
+ You can run several configurations and random seeds in one batch. NetLab also
10
+ supports parameter searches and experiments proposed by a language model.
11
+
12
+ ## Install
13
+
14
+ Use Python 3.11 or later in a virtual environment of its own. To install the command:
15
+
16
+ ```bash
17
+ python -m pip install netlab
18
+ ```
19
+
20
+ The command also installs NetGraph (`ngraph`), NetLab-TopoGen
21
+ (`netlab-topogen`) and the other dependencies from PyPI;
22
+ [pyproject.toml](https://github.com/networmix/NetLab/blob/main/pyproject.toml) lists their supported versions.
23
+
24
+ ipSpace's `networklab` package installs a command of the same name, so use separate environments for the two tools.
25
+
26
+ To use the included examples, clone the repository with Git and create its environment:
27
+
28
+ ```bash
29
+ git clone https://github.com/networmix/NetLab
30
+ cd NetLab
31
+ make dev
32
+ source venv/bin/activate
33
+ ```
34
+
35
+ Run the commands below from the repository root.
36
+
37
+ ## Run an example
38
+
39
+ This example uses saved geographic routes, so no Census download is needed. It
40
+ still needs network access: the build draws a site map for each scenario from
41
+ downloaded map tiles. To build offline, set `visualization.site_graph.export:
42
+ false` in a copy of the configuration.
43
+
44
+ ```bash
45
+ netlab run topogen_configs_small/small_baseline.yml --seeds 11 12 \
46
+ --graphs-dir tests/data/scenarios/small_baseline/small_baseline \
47
+ --scenarios-dir scenarios
48
+ netlab metrics scenarios/
49
+ ```
50
+
51
+ The first command builds a network for each seed and runs its NetGraph workflow.
52
+ A **seed** is the scenario's random seed. It drives NetLab-TopoGen's random traffic
53
+ choices and NetGraph's failure sampling, so the same seed repeats the same
54
+ experiment. The second command calculates metrics and renders comparison figures.
55
+
56
+ | Location | Contents |
57
+ | --- | --- |
58
+ | `scenarios/<config>/<config>__seed<N>/` | Scenario YAML, NetGraph results and NetLab's run record |
59
+ | `scenarios/<config>/<config>_integrated_graph.json` | Geography generated when `--graphs-dir` is omitted |
60
+ | `scenarios/provenance.json` | Input hashes, settings, package versions and outcomes of the last batch |
61
+ | `scenarios_metrics/project.csv` | One summary row per configuration |
62
+ | `scenarios_metrics/BAC.png` | How often each delivered bandwidth was met or exceeded |
63
+ | `scenarios_metrics/<config>/seed<N>/` | Metrics for one seed |
64
+
65
+ To build without simulating, use `netlab build` with the same input arguments.
66
+ To generate geography yourself, omit `--graphs-dir` and first download the
67
+ [data required by NetLab-TopoGen](https://github.com/networmix/NetLab-TopoGen#readme).
68
+ The `data/` and `lib/` paths are relative to your working directory. From the
69
+ repository root, `lib/workflows.yml` replaces NetLab-TopoGen's `design_analysis_brief`
70
+ workflow with NetLab's version, and `lib/failure_policies.yml` adds `mc_hard`.
71
+
72
+ Saved geography must be a corridor `MultiGraph`: a graph that can keep several
73
+ routes between the same metro pair. Each file is named
74
+ `<config>_integrated_graph.json`. The `topogen_configs/` directory contains larger
75
+ designs; `topogen_configs_small/` contains smaller versions for experimentation.
76
+
77
+ ## Control a batch
78
+
79
+ | Option | Effect |
80
+ | --- | --- |
81
+ | `--build-jobs`, `--run-jobs` | Number of build and simulation tasks allowed to run at once |
82
+ | `--build-timeout` | Time limit for each geography or scenario build task |
83
+ | `--run-timeout` | Time limit for each simulation; defaults to 600 seconds |
84
+ | `--force-run` | Run simulations again even when cached results match |
85
+ | `--force` | Rerun simulations and regenerate geography, unless `--graphs-dir` supplies it |
86
+
87
+ Time limits start when a task starts running. Scenario assembly runs every time.
88
+ NetLab reuses saved work only when a hash of its inputs still matches; a hash
89
+ identifies file contents, so any change to the inputs invalidates the cache.
90
+ Generated geography is reused while the configuration, data files and package
91
+ versions are unchanged. A simulation result is reused while the scenario,
92
+ package versions, the saved result file and its run record are unchanged.
93
+ Failed tasks make the command return a failure status; independent tasks continue.
94
+ Each run's outcome and the wall time of each workflow step are saved in a run
95
+ record, `<name>.results.run.json`, beside the results; a reused result keeps the
96
+ times of the run that produced it.
97
+
98
+ ## Read and compare metrics
99
+
100
+ ```bash
101
+ netlab metrics scenarios/ --no-plots
102
+ netlab metrics scenarios/ --only small_baseline
103
+ netlab metrics scenarios/ --summary
104
+ ```
105
+
106
+ `--no-plots` calculates tables without figures. `--only` takes a comma-separated
107
+ list of configuration names, such as `small_baseline,small_clos`.
108
+ `--summary` reads the saved tables and renders figures.
109
+ A calculation replaces the complete report directory, even with `--only`.
110
+ If calculation fails, the existing report is kept.
111
+
112
+ The workflow must include these step names:
113
+
114
+ | Step name | NetGraph analysis |
115
+ | --- | --- |
116
+ | `msd_baseline` | `MaximumSupportedDemand`, which searches for a traffic multiplier |
117
+ | `tm_placement` | `TrafficMatrixPlacement` with `alpha_from_step: msd_baseline`, and `outputs: {cost_distribution: true}` for latency |
118
+ | `network_statistics` | `NetworkStats`, which counts network objects |
119
+
120
+ `--enable-maxflow` also needs a `node_to_node_capacity_matrix` step for pairwise
121
+ capacity analysis. Each result needs the run record NetLab writes beside it.
122
+ See [metrics.md](https://github.com/networmix/NetLab/blob/main/metrics.md) for definitions, required fields, worked examples
123
+ and output files. Failure statistics describe the configured
124
+ experiment; they are not measurements of network uptime.
125
+
126
+ To compare two configurations with matching seeds:
127
+
128
+ ```bash
129
+ netlab test scenarios/ small_baseline small_clos
130
+ ```
131
+
132
+ Both configurations must have been analyzed. The statistical test needs at least
133
+ three matching finite seed results; the two-seed quick start is for running the
134
+ pipeline, not statistical inference.
135
+
136
+ ## Python API
137
+
138
+ Save this as a script and point it to a NetGraph scenario:
139
+
140
+ ```python
141
+ from pathlib import Path
142
+ from netlab.simulation import run_simulation
143
+
144
+ if __name__ == "__main__":
145
+ outcome = run_simulation(Path("scenario.yml"), timeout=60)
146
+ print(outcome.status, outcome.error)
147
+ ```
148
+
149
+ `run_simulation` runs in a local worker process. A successful run saves
150
+ `scenario.results.json` next to the scenario; every run records its status and
151
+ the wall time of each step it ran in `scenario.results.run.json`. The `__main__`
152
+ guard keeps a spawned worker from running the script again. Use `simulate(yaml_text)` to run in the calling
153
+ process, or `inspect_scenario(yaml_text)` to validate and count network objects.
154
+ See [architecture and batch APIs](https://github.com/networmix/NetLab/blob/main/dev/ARCHITECTURE.md).
155
+
156
+ Metric functions read a saved result dictionary:
157
+
158
+ ```python
159
+ import json
160
+ from netlab.metrics.bac import compute_bac
161
+ from netlab.metrics.latency import compute_latency_stretch
162
+ from netlab.metrics.msd import compute_alpha_star
163
+
164
+ with open("scenario.results.json") as f:
165
+ results = json.load(f)
166
+
167
+ print(compute_alpha_star(results).alpha_star)
168
+ print(compute_bac(results, step_name="tm_placement").auc_normalized)
169
+ print(compute_latency_stretch(results).failures.get("p99"))
170
+ ```
171
+
172
+ They return the per-seed values described in [metrics.md](https://github.com/networmix/NetLab/blob/main/metrics.md).
173
+ `netlab metrics` also checks the result arithmetic before it computes them.
174
+
175
+ ## Automated experiments
176
+
177
+ An autoresearch project gives a language model a task description
178
+ (`program.md`), the parameters it may change (`hypothesis_template.yml`) and the
179
+ metric to optimize (`objective.yml`). `init` copies a base scenario that has a
180
+ `MaximumSupportedDemand` step and at least one `${{name}}` placeholder. Each
181
+ placeholder becomes a parameter, and the objective maximizes
182
+ `steps.msd_baseline.result.alpha_feasible.value`, the multiplier of the step named
183
+ `msd_baseline`. A candidate whose search finds no feasible multiplier fails; it
184
+ never scores zero. Review the generated files before a run:
185
+
186
+ ```bash
187
+ netlab autoresearch init --base-scenario scenario.yml --output project/
188
+ netlab autoresearch run project/ --backend mock --max-experiments 1
189
+ ```
190
+
191
+ The `mock` backend is for testing the workflow. To use an external model, select
192
+ `claude-cli`, `codex-cli` or `openai` and configure that backend's credentials.
193
+ CLI backends need their executable installed and signed in.
194
+ `HypothesisManager` can also turn a free-text hypothesis into a scenario, run it
195
+ and request an interpretation. Those cycle files are saved under `<project>/cycles/`.
196
+
197
+ Run one writer per project; nothing locks the files. A project directory is tied
198
+ to its input files, seed and installed package versions. A sweep output directory
199
+ is tied to its sweep type, seed, iteration count and package versions. If any of
200
+ them changes, NetLab refuses to continue there; start a new directory.
201
+ Rerunning a sweep in its directory skips successful entries and retries failed
202
+ ones. Higher scores rank better; candidates that fail the configured constraints
203
+ cannot become best.
204
+
205
+ For data-center-to-backbone designs, see the
206
+ [research project](https://github.com/networmix/NetLab/blob/main/research_projects/dc-bb-autoresearch/program.md) and
207
+ [included interconnect experiments](https://github.com/networmix/NetLab/blob/main/experiments/dc-bb-interconnect/README.md).
208
+
209
+ ## Development
210
+
211
+ ```bash
212
+ make check-ci
213
+ ```
214
+
215
+ This checks formatting, lint, types and tests, including NetLab-TopoGen → NetGraph →
216
+ metrics runs using saved geography. See [fixture regeneration](https://github.com/networmix/NetLab/blob/main/tests/data/README.md)
217
+ and [metric verification](https://github.com/networmix/NetLab/blob/main/dev/METRICS_VERIFICATION.md).
218
+
219
+ In Superset, `bash .superset/workspace.sh setup` creates a `venv`, installs the
220
+ development dependencies and copies missing untracked `.env` files from the root
221
+ checkout. The Run button executes `make check-ci`.
222
+
223
+ To test local checkouts of all three dependencies:
224
+
225
+ ```bash
226
+ bash dev/check_ngraph_integration.sh /path/to/NetGraph /path/to/NetGraph-Core /path/to/NetLab-TopoGen
227
+ ```
228
+
229
+ Replace the paths with your checkouts. The script builds Core and runs checks in
230
+ a temporary environment. It saves source revisions, dependency versions and
231
+ results under `build/ngraph-integration/`.
232
+
233
+ [Changelog](https://github.com/networmix/NetLab/blob/main/CHANGELOG.md) · [MIT license](https://github.com/networmix/NetLab/blob/main/LICENSE)
@@ -0,0 +1,10 @@
1
+ """NetLab: metrics and experiment tooling for NetGraph scenarios."""
2
+
3
+ from importlib.metadata import PackageNotFoundError, version
4
+
5
+ try:
6
+ __version__ = version("netlab")
7
+ except PackageNotFoundError:
8
+ __version__ = "0.0.0.dev" # Package metadata is unavailable before installation.
9
+
10
+ __all__ = ["__version__"]