Skip to content

Commit 39bcccd

Browse files
committed
Fix random seed bug. Change CapacityEnvelope to use frequency-based storage for capacity values.
1 parent b67aff0 commit 39bcccd

15 files changed

+850
-595
lines changed

docs/examples/network_view.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,33 @@ envelope = CapacityEnvelopeAnalysis(
9090
sink_path="^leaf.*",
9191
failure_policy="random_failures",
9292
iterations=1000,
93-
parallelism=8 # Safe concurrent execution
93+
parallelism=8, # Safe concurrent execution
94+
baseline=True, # Run first iteration without failures for comparison
95+
store_failure_patterns=True # Store failure patterns for analysis
9496
)
9597
```
9698

99+
### Baseline Analysis
100+
101+
The `baseline` parameter enables comparison between failure scenarios and no-failure baseline:
102+
103+
```yaml
104+
workflow:
105+
- step_type: CapacityEnvelopeAnalysis
106+
name: "capacity_analysis"
107+
source_path: "^datacenter.*"
108+
sink_path: "^edge.*"
109+
failure_policy: "random_failures"
110+
iterations: 1000
111+
baseline: true # First iteration runs without failures
112+
store_failure_patterns: true # Store patterns for detailed analysis
113+
```
114+
115+
This creates baseline capacity measurements alongside failure scenario results, enabling:
116+
- Comparison of degraded vs. normal network capacity
117+
- Analysis of failure impact magnitude
118+
- Identification of failure-resistant flow paths
119+
97120
## Key Benefits
98121
99122
1. **Immutability**: Base network remains unchanged during analysis

docs/reference/api-full.md

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ 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:** July 05, 2025 at 23:05 UTC
13+
**Generated from source code on:** July 06, 2025 at 02:10 UTC
1414

1515
**Modules auto-discovered:** 51
1616

@@ -892,35 +892,67 @@ CapacityEnvelope, TrafficMatrixSet, PlacementResultSet, and FailurePolicySet cla
892892

893893
### CapacityEnvelope
894894

895-
Range of max-flow values measured between two node groups.
895+
Frequency-based capacity envelope that stores capacity values as frequencies.
896896

897-
This immutable dataclass stores capacity measurements and automatically
898-
computes statistical measures in __post_init__.
897+
This approach is more memory-efficient for Monte Carlo analysis where we care
898+
about statistical distributions rather than individual sample order.
899899

900900
Attributes:
901-
source_pattern: Regex pattern for selecting source nodes.
902-
sink_pattern: Regex pattern for selecting sink nodes.
903-
mode: Flow computation mode (e.g., "combine").
904-
capacity_values: List of measured capacity values.
905-
min_capacity: Minimum capacity value (computed).
906-
max_capacity: Maximum capacity value (computed).
907-
mean_capacity: Mean capacity value (computed).
908-
stdev_capacity: Standard deviation of capacity values (computed).
901+
source_pattern: Regex pattern used to select source nodes.
902+
sink_pattern: Regex pattern used to select sink nodes.
903+
mode: Flow analysis mode ("combine" or "pairwise").
904+
frequencies: Dictionary mapping capacity values to their occurrence counts.
905+
min_capacity: Minimum observed capacity.
906+
max_capacity: Maximum observed capacity.
907+
mean_capacity: Mean capacity across all samples.
908+
stdev_capacity: Standard deviation of capacity values.
909+
total_samples: Total number of samples represented.
909910

910911
**Attributes:**
911912

912913
- `source_pattern` (str)
913914
- `sink_pattern` (str)
914-
- `mode` (str) = combine
915-
- `capacity_values` (list[float]) = []
915+
- `mode` (str)
916+
- `frequencies` (Dict[float, int])
916917
- `min_capacity` (float)
917918
- `max_capacity` (float)
918919
- `mean_capacity` (float)
919920
- `stdev_capacity` (float)
921+
- `total_samples` (int)
920922

921923
**Methods:**
922924

923-
- `to_dict(self) -> 'dict[str, Any]'`
925+
- `expand_to_values(self) -> 'List[float]'`
926+
- Expand frequency map back to individual values (for backward compatibility).
927+
- `from_values(source_pattern: 'str', sink_pattern: 'str', mode: 'str', values: 'List[float]') -> "'CapacityEnvelope'"`
928+
- Create frequency-based envelope from a list of capacity values.
929+
- `get_percentile(self, percentile: 'float') -> 'float'`
930+
- Calculate percentile from frequency distribution.
931+
- `to_dict(self) -> 'Dict[str, Any]'`
932+
- Convert to dictionary for JSON serialization.
933+
934+
### FailurePatternResult
935+
936+
Result for a unique failure pattern with associated capacity matrix.
937+
938+
Attributes:
939+
excluded_nodes: List of failed node IDs.
940+
excluded_links: List of failed link IDs.
941+
capacity_matrix: Dictionary mapping flow keys to capacity values.
942+
count: Number of times this pattern occurred.
943+
is_baseline: Whether this represents the baseline (no failures) case.
944+
945+
**Attributes:**
946+
947+
- `excluded_nodes` (List[str])
948+
- `excluded_links` (List[str])
949+
- `capacity_matrix` (Dict[str, float])
950+
- `count` (int)
951+
- `is_baseline` (bool) = False
952+
953+
**Methods:**
954+
955+
- `to_dict(self) -> 'Dict[str, Any]'`
924956
- Convert to dictionary for JSON serialization.
925957

926958
### FailurePolicySet
@@ -2199,6 +2231,8 @@ This implementation uses parallel processing for efficiency:
21992231
- NetworkView provides lightweight exclusion without deep copying
22002232
- Flow computations are cached within workers to avoid redundant calculations
22012233

2234+
All results are stored using frequency-based storage for memory efficiency.
2235+
22022236
YAML Configuration:
22032237
```yaml
22042238
workflow:
@@ -2214,11 +2248,13 @@ YAML Configuration:
22142248
flow_placement: "PROPORTIONAL" # Flow placement strategy
22152249
baseline: true # Optional: Run first iteration without failures
22162250
seed: 42 # Optional: Seed for reproducible results
2251+
store_failure_patterns: false # Optional: Store failure patterns in results
22172252
```
22182253

22192254
Results stored in scenario.results:
22202255
- `capacity_envelopes`: Dictionary mapping flow keys to CapacityEnvelope data
2221-
- `total_capacity_samples`: List of total capacity values per iteration
2256+
- `total_capacity_frequencies`: Frequency map of total capacity values
2257+
- `failure_pattern_results`: Frequency map of failure patterns (if store_failure_patterns=True)
22222258

22232259
Attributes:
22242260
source_path: Regex pattern to select source node groups.
@@ -2231,6 +2267,7 @@ Attributes:
22312267
flow_placement: Flow placement strategy (default: PROPORTIONAL).
22322268
baseline: If True, run first iteration without failures as baseline (default: False).
22332269
seed: Optional seed for deterministic results (for debugging).
2270+
store_failure_patterns: If True, store failure patterns in results (default: False).
22342271

22352272
**Attributes:**
22362273

@@ -2245,6 +2282,7 @@ Attributes:
22452282
- `shortest_path` (bool) = False
22462283
- `flow_placement` (FlowPlacement) = 1
22472284
- `baseline` (bool) = False
2285+
- `store_failure_patterns` (bool) = False
22482286

22492287
**Methods:**
22502288

@@ -2605,7 +2643,7 @@ Analyzes capacity envelope data and creates matrices.
26052643
- `analyze_and_display_flow_availability(self, results: 'Dict[str, Any]', step_name: 'str') -> 'None'`
26062644
- Analyse flow availability and render summary statistics & plots.
26072645
- `analyze_flow_availability(self, results: 'Dict[str, Any]', **kwargs) -> 'Dict[str, Any]'`
2608-
- Create CDF/availability distribution for *total_capacity_samples*.
2646+
- Create CDF/availability distribution for *total_capacity_frequencies*.
26092647
- `display_analysis(self, analysis: 'Dict[str, Any]', **kwargs) -> 'None'`
26102648
- Pretty-print *analysis* to the notebook/stdout.
26112649
- `get_description(self) -> 'str'`

docs/reference/dsl.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,15 @@ workflow:
483483
parallelism: P # Number of parallel worker processes (default: 1)
484484
shortest_path: true | false # Use shortest path only (default: false)
485485
flow_placement: "PROPORTIONAL" | "EQUAL_BALANCED" # Flow placement strategy
486+
baseline: true | false # Optional: Run first iteration without failures as baseline (default: false)
487+
store_failure_patterns: true | false # Optional: Store failure patterns in results (default: false)
486488
seed: S # Optional: Seed for deterministic results
489+
490+
- step_type: NotebookExport
491+
name: "export_analysis" # Optional: Custom name for this step
492+
notebook_path: "analysis.ipynb" # Optional: Notebook output path (default: "results.ipynb")
493+
json_path: "results.json" # Optional: JSON data output path (default: "results.json")
494+
allow_empty_results: false # Optional: Allow notebook creation with no results
487495
```
488496

489497
**Available Workflow Steps:**

0 commit comments

Comments
 (0)