Skip to content

Commit 0a42d8b

Browse files
committed
Refactor notebook analysis components
1 parent 3e264cd commit 0a42d8b

22 files changed

Lines changed: 1172 additions & 1255 deletions

dev/generate_api_docs.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ def module_sort_key(module_name):
6161
elif len(parts) == 3 and parts[1] == "workflow": # ngraph.workflow.xxx
6262
return (3, parts[2])
6363

64-
# Then transform modules
65-
elif len(parts) == 3 and parts[1] == "transform": # ngraph.transform.xxx
66-
return (4, parts[2])
64+
# Then transform modules (under workflow)
65+
elif len(parts) == 4 and parts[1:3] == ["workflow", "transform"]:
66+
# ngraph.workflow.transform.xxx
67+
return (4, parts[3])
6768

6869
# Everything else at the end
6970
else:

docs/reference/api-full.md

Lines changed: 126 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ For a curated, example-driven API guide, see **[api.md](api.md)**.
1010
> - **[CLI Reference](cli.md)** - Command-line interface
1111
> - **[DSL Reference](dsl.md)** - YAML syntax guide
1212
13-
**Generated from source code on:** June 19, 2025 at 00:16 UTC
13+
**Generated from source code on:** June 19, 2025 at 02:05 UTC
1414

15-
**Modules auto-discovered:** 42
15+
**Modules auto-discovered:** 47
1616

1717
---
1818

@@ -2077,47 +2077,78 @@ Attributes:
20772077

20782078
---
20792079

2080-
## ngraph.workflow.notebook_analysis
2080+
## ngraph.workflow.notebook_export
2081+
2082+
Jupyter notebook export and generation functionality.
2083+
2084+
### NotebookExport
2085+
2086+
Export scenario results to a Jupyter notebook with external JSON data file.
2087+
2088+
Creates a Jupyter notebook containing analysis code and visualizations,
2089+
with results data stored in a separate JSON file. This separation improves
2090+
performance and maintainability for large datasets.
2091+
2092+
YAML Configuration:
2093+
```yaml
2094+
workflow:
2095+
- step_type: NotebookExport
2096+
name: "export_analysis" # Optional: Custom name for this step
2097+
notebook_path: "analysis.ipynb" # Optional: Notebook output path (default: "results.ipynb")
2098+
json_path: "results.json" # Optional: JSON data output path (default: "results.json")
2099+
allow_empty_results: false # Optional: Allow notebook creation with no results
2100+
```
2101+
2102+
Attributes:
2103+
notebook_path: Destination notebook file path (default: "results.ipynb").
2104+
json_path: Destination JSON data file path (default: "results.json").
2105+
allow_empty_results: Whether to create a notebook when no results exist (default: False).
2106+
If False, raises ValueError when results are empty.
2107+
2108+
**Attributes:**
2109+
2110+
- `name` (str)
2111+
- `notebook_path` (str) = results.ipynb
2112+
- `json_path` (str) = results.json
2113+
- `allow_empty_results` (bool) = False
2114+
2115+
**Methods:**
20812116

2082-
Notebook analysis components for NetGraph workflow results.
2117+
- `execute(self, scenario: "'Scenario'") -> 'None'`
2118+
- Execute the workflow step with automatic logging.
2119+
- `run(self, scenario: "'Scenario'") -> 'None'`
2120+
- Create notebook and JSON files with the current scenario results.
2121+
2122+
---
2123+
2124+
## ngraph.workflow.notebook_serializer
20832125

2084-
This module provides specialized analyzers for processing and visualizing network analysis
2085-
results in Jupyter notebooks. Each component handles specific data types and provides
2086-
both programmatic analysis and interactive display capabilities.
2126+
Code serialization for notebook generation.
20872127

2088-
Core Components:
2089-
NotebookAnalyzer: Abstract base class defining the analysis interface. All analyzers
2090-
implement analyze() for data processing and display_analysis() for notebook output.
2091-
Provides analyze_and_display() convenience method that chains analysis and display.
2128+
### NotebookCodeSerializer
20922129

2093-
AnalysisContext: Immutable dataclass containing execution context (step name, results,
2094-
config) passed between analysis components for state management.
2130+
Converts Python classes into notebook cells.
20952131

2096-
Utility Components:
2097-
PackageManager: Handles runtime dependency verification and installation. Checks
2098-
for required packages (itables, matplotlib) using importlib, installs missing
2099-
packages via subprocess, and configures visualization environments (seaborn
2100-
styling, itables display options, matplotlib backends).
2132+
**Methods:**
21012133

2102-
DataLoader: Provides robust JSON file loading with comprehensive error handling.
2103-
Validates file existence, JSON format correctness, and expected data structure.
2104-
Returns detailed status information including step counts and validation results.
2134+
- `create_capacity_analysis_cell() -> nbformat.notebooknode.NotebookNode`
2135+
- Create capacity analysis cell.
2136+
- `create_data_loading_cell(json_path: str) -> nbformat.notebooknode.NotebookNode`
2137+
- Create data loading cell.
2138+
- `create_flow_analysis_cell() -> nbformat.notebooknode.NotebookNode`
2139+
- Create flow analysis cell.
2140+
- `create_flow_availability_cells() -> List[nbformat.notebooknode.NotebookNode]`
2141+
- Create flow availability analysis cells (markdown header + code).
2142+
- `create_setup_cell() -> nbformat.notebooknode.NotebookNode`
2143+
- Create setup cell.
2144+
- `create_summary_cell() -> nbformat.notebooknode.NotebookNode`
2145+
- Create analysis summary cell.
21052146

2106-
Data Analyzers:
2107-
CapacityMatrixAnalyzer: Processes capacity envelope data from network flow analysis.
2108-
Extracts flow path information (source->destination, bidirectional), parses
2109-
capacity values from various data structures, creates pivot tables for matrix
2110-
visualization, and calculates flow density statistics. Handles self-loop exclusion
2111-
and zero-flow inclusion for accurate network topology representation.
2147+
---
21122148

2113-
FlowAnalyzer: Processes maximum flow calculation results. Extracts flow paths and
2114-
values from workflow step data, computes flow statistics (min/max/avg/total),
2115-
and generates comparative visualizations across multiple analysis steps using
2116-
matplotlib bar charts.
2149+
## ngraph.workflow.analysis.base
21172150

2118-
SummaryAnalyzer: Aggregates results across all workflow steps. Categorizes steps
2119-
by analysis type (capacity envelopes, flow calculations, other), provides
2120-
high-level metrics for workflow completion status and data distribution.
2151+
Base classes for notebook analysis components.
21212152

21222153
### AnalysisContext
21232154

@@ -2129,27 +2160,57 @@ Context information for analysis execution.
21292160
- `results` (Dict)
21302161
- `config` (Dict)
21312162

2132-
### CapacityMatrixAnalyzer
2163+
### NotebookAnalyzer
21332164

2134-
Analyzes capacity envelope data and creates matrices.
2165+
Base class for notebook analysis components.
21352166

21362167
**Methods:**
21372168

21382169
- `analyze(self, results: Dict[str, Any], **kwargs) -> Dict[str, Any]`
2139-
- Analyze capacity envelopes and create matrix visualization.
2170+
- Perform the analysis and return results.
21402171
- `analyze_and_display(self, results: Dict[str, Any], **kwargs) -> None`
21412172
- Analyze results and display them in notebook format.
2142-
- `analyze_and_display_all_steps(self, results: Dict[str, Any]) -> None`
2143-
- Analyze and display capacity matrices for all relevant steps.
2144-
- `analyze_and_display_flow_availability(self, results: Dict[str, Any], step_name: str) -> None`
2145-
- Analyze and display flow availability distribution with CDF visualization.
2146-
- `analyze_flow_availability(self, results: Dict[str, Any], **kwargs) -> Dict[str, Any]`
2147-
- Analyze total flow samples to create flow availability distribution (CDF).
21482173
- `display_analysis(self, analysis: Dict[str, Any], **kwargs) -> None`
2149-
- Display capacity matrix analysis results.
2174+
- Display analysis results in notebook format.
21502175
- `get_description(self) -> str`
21512176
- Get a description of what this analyzer does.
21522177

2178+
---
2179+
2180+
## ngraph.workflow.analysis.capacity_matrix
2181+
2182+
Capacity envelope analysis utilities.
2183+
2184+
This module contains `CapacityMatrixAnalyzer`, responsible for processing capacity
2185+
envelope results, computing comprehensive statistics, and generating notebook-friendly
2186+
visualizations.
2187+
2188+
### CapacityMatrixAnalyzer
2189+
2190+
Analyzes capacity envelope data and creates matrices.
2191+
2192+
**Methods:**
2193+
2194+
- `analyze(self, results: 'Dict[str, Any]', **kwargs) -> 'Dict[str, Any]'`
2195+
- Analyze capacity envelopes and create matrix visualisation.
2196+
- `analyze_and_display(self, results: Dict[str, Any], **kwargs) -> None`
2197+
- Analyze results and display them in notebook format.
2198+
- `analyze_and_display_all_steps(self, results: 'Dict[str, Any]') -> 'None'`
2199+
- Run analyse/display on every step containing *capacity_envelopes*.
2200+
- `analyze_and_display_flow_availability(self, results: 'Dict[str, Any]', step_name: 'str') -> 'None'`
2201+
- `analyze_flow_availability(self, results: 'Dict[str, Any]', **kwargs) -> 'Dict[str, Any]'`
2202+
- Create CDF/availability distribution for *total_capacity_samples*.
2203+
- `display_analysis(self, analysis: 'Dict[str, Any]', **kwargs) -> 'None'`
2204+
- Pretty-print *analysis* to the notebook/stdout.
2205+
- `get_description(self) -> 'str'`
2206+
- Get a description of what this analyzer does.
2207+
2208+
---
2209+
2210+
## ngraph.workflow.analysis.data_loader
2211+
2212+
Data loading utilities for notebook analysis.
2213+
21532214
### DataLoader
21542215

21552216
Handles loading and validation of analysis results.
@@ -2159,6 +2220,12 @@ Handles loading and validation of analysis results.
21592220
- `load_results(json_path: Union[str, pathlib._local.Path]) -> Dict[str, Any]`
21602221
- Load results from JSON file with comprehensive error handling.
21612222

2223+
---
2224+
2225+
## ngraph.workflow.analysis.flow_analyzer
2226+
2227+
Flow analysis for notebook results.
2228+
21622229
### FlowAnalyzer
21632230

21642231
Analyzes maximum flow results.
@@ -2176,20 +2243,11 @@ Analyzes maximum flow results.
21762243
- `get_description(self) -> str`
21772244
- Get a description of what this analyzer does.
21782245

2179-
### NotebookAnalyzer
2246+
---
21802247

2181-
Base class for notebook analysis components.
2248+
## ngraph.workflow.analysis.package_manager
21822249

2183-
**Methods:**
2184-
2185-
- `analyze(self, results: Dict[str, Any], **kwargs) -> Dict[str, Any]`
2186-
- Perform the analysis and return results.
2187-
- `analyze_and_display(self, results: Dict[str, Any], **kwargs) -> None`
2188-
- Analyze results and display them in notebook format.
2189-
- `display_analysis(self, analysis: Dict[str, Any], **kwargs) -> None`
2190-
- Display analysis results in notebook format.
2191-
- `get_description(self) -> str`
2192-
- Get a description of what this analyzer does.
2250+
Package management for notebook analysis components.
21932251

21942252
### PackageManager
21952253

@@ -2202,6 +2260,12 @@ Manages package installation and imports for notebooks.
22022260
- `setup_environment() -> Dict[str, Any]`
22032261
- Set up the complete notebook environment.
22042262

2263+
---
2264+
2265+
## ngraph.workflow.analysis.summary
2266+
2267+
Summary analysis for notebook results.
2268+
22052269
### SummaryAnalyzer
22062270

22072271
Provides summary analysis of all results.
@@ -2221,76 +2285,7 @@ Provides summary analysis of all results.
22212285

22222286
---
22232287

2224-
## ngraph.workflow.notebook_export
2225-
2226-
Jupyter notebook export and generation functionality.
2227-
2228-
### NotebookExport
2229-
2230-
Export scenario results to a Jupyter notebook with external JSON data file.
2231-
2232-
Creates a Jupyter notebook containing analysis code and visualizations,
2233-
with results data stored in a separate JSON file. This separation improves
2234-
performance and maintainability for large datasets.
2235-
2236-
YAML Configuration:
2237-
```yaml
2238-
workflow:
2239-
- step_type: NotebookExport
2240-
name: "export_analysis" # Optional: Custom name for this step
2241-
notebook_path: "analysis.ipynb" # Optional: Notebook output path (default: "results.ipynb")
2242-
json_path: "results.json" # Optional: JSON data output path (default: "results.json")
2243-
allow_empty_results: false # Optional: Allow notebook creation with no results
2244-
```
2245-
2246-
Attributes:
2247-
notebook_path: Destination notebook file path (default: "results.ipynb").
2248-
json_path: Destination JSON data file path (default: "results.json").
2249-
allow_empty_results: Whether to create a notebook when no results exist (default: False).
2250-
If False, raises ValueError when results are empty.
2251-
2252-
**Attributes:**
2253-
2254-
- `name` (str)
2255-
- `notebook_path` (str) = results.ipynb
2256-
- `json_path` (str) = results.json
2257-
- `allow_empty_results` (bool) = False
2258-
2259-
**Methods:**
2260-
2261-
- `execute(self, scenario: "'Scenario'") -> 'None'`
2262-
- Execute the workflow step with automatic logging.
2263-
- `run(self, scenario: "'Scenario'") -> 'None'`
2264-
- Create notebook and JSON files with the current scenario results.
2265-
2266-
---
2267-
2268-
## ngraph.workflow.notebook_serializer
2269-
2270-
Code serialization for notebook generation.
2271-
2272-
### NotebookCodeSerializer
2273-
2274-
Converts Python classes into notebook cells.
2275-
2276-
**Methods:**
2277-
2278-
- `create_capacity_analysis_cell() -> nbformat.notebooknode.NotebookNode`
2279-
- Create capacity analysis cell.
2280-
- `create_data_loading_cell(json_path: str) -> nbformat.notebooknode.NotebookNode`
2281-
- Create data loading cell.
2282-
- `create_flow_analysis_cell() -> nbformat.notebooknode.NotebookNode`
2283-
- Create flow analysis cell.
2284-
- `create_flow_availability_cells() -> List[nbformat.notebooknode.NotebookNode]`
2285-
- Create flow availability analysis cells (markdown header + code).
2286-
- `create_setup_cell() -> nbformat.notebooknode.NotebookNode`
2287-
- Create setup cell.
2288-
- `create_summary_cell() -> nbformat.notebooknode.NotebookNode`
2289-
- Create analysis summary cell.
2290-
2291-
---
2292-
2293-
## ngraph.transform.base
2288+
## ngraph.workflow.transform.base
22942289

22952290
Base classes for network transformations.
22962291

@@ -2317,7 +2312,7 @@ Attributes:
23172312

23182313
**Methods:**
23192314

2320-
- `apply(self, scenario: 'Scenario') -> 'None'`
2315+
- `apply(self, scenario: "'Scenario'") -> 'None'`
23212316
- Modify *scenario.network* in-place.
23222317
- `create(step_type: 'str', **kwargs: 'Any') -> 'Self'`
23232318
- Instantiate a registered transform by *step_type*.
@@ -2335,7 +2330,7 @@ Raises:
23352330

23362331
---
23372332

2338-
## ngraph.transform.distribute_external
2333+
## ngraph.workflow.transform.distribute_external
23392334

23402335
Network transformation for distributing external connectivity.
23412336

@@ -2371,14 +2366,14 @@ Args:
23712366

23722367
**Methods:**
23732368

2374-
- `apply(self, scenario: ngraph.scenario.Scenario) -> None`
2369+
- `apply(self, scenario: 'Scenario') -> None`
23752370
- Modify *scenario.network* in-place.
23762371
- `create(step_type: 'str', **kwargs: 'Any') -> 'Self'`
23772372
- Instantiate a registered transform by *step_type*.
23782373

23792374
---
23802375

2381-
## ngraph.transform.enable_nodes
2376+
## ngraph.workflow.transform.enable_nodes
23822377

23832378
Network transformation for enabling/disabling nodes.
23842379

@@ -2408,7 +2403,7 @@ Args:
24082403

24092404
**Methods:**
24102405

2411-
- `apply(self, scenario: 'Scenario') -> 'None'`
2406+
- `apply(self, scenario: "'Scenario'") -> 'None'`
24122407
- Modify *scenario.network* in-place.
24132408
- `create(step_type: 'str', **kwargs: 'Any') -> 'Self'`
24142409
- Instantiate a registered transform by *step_type*.

ngraph/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77

88
from __future__ import annotations
99

10-
from . import cli, config, logging, transform
10+
from . import cli, config, logging
1111
from .results_artifacts import CapacityEnvelope, PlacementResultSet, TrafficMatrixSet
1212

1313
__all__ = [
1414
"cli",
1515
"config",
1616
"logging",
17-
"transform",
1817
"CapacityEnvelope",
1918
"PlacementResultSet",
2019
"TrafficMatrixSet",

0 commit comments

Comments
 (0)