Skip to content

Commit 0044cbd

Browse files
committed
mode-based failure policy API
1 parent 971ca47 commit 0044cbd

File tree

9 files changed

+3
-48
lines changed

9 files changed

+3
-48
lines changed

docs/reference/api-full.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,13 +2068,7 @@ The main entry point is `apply_failures`, which:
20682068
4) Collect the union of all failed entities across all rules.
20692069
5) Optionally expand failures by shared-risk groups or sub-risks.
20702070

2071-
Large-scale performance:
20722071

2073-
- If you set `use_cache=True`, matched sets for each rule are cached,
2074-
2075-
so repeated calls to `apply_failures` can skip re-matching if the
2076-
network hasn't changed. If your network changes between calls,
2077-
you should clear the cache or re-initialize the policy.
20782072

20792073
Example YAML configuration:
20802074
```yaml
@@ -2129,10 +2123,6 @@ Attributes:
21292123
fail_risk_group_children (bool):
21302124
If True, and if a risk_group is marked as failed, expand to
21312125
children risk_groups recursively.
2132-
use_cache (bool):
2133-
If True, match results for each rule are cached to speed up
2134-
repeated calls. If the network changes, the cached results
2135-
may be stale.
21362126
seed (Optional[int]):
21372127
Seed for reproducible random operations. If None, operations
21382128
will be non-deterministic.
@@ -2142,10 +2132,8 @@ Attributes:
21422132
- `attrs` (Dict[str, Any]) = {}
21432133
- `fail_risk_groups` (bool) = False
21442134
- `fail_risk_group_children` (bool) = False
2145-
- `use_cache` (bool) = False
21462135
- `seed` (Optional[int])
21472136
- `modes` (List[FailureMode]) = []
2148-
- `_match_cache` (Dict[int, Set[str]]) = {}
21492137

21502138
**Methods:**
21512139

docs/reference/dsl.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,6 @@ failure_policy_set:
384384
385385
random_failures:
386386
fail_risk_groups: true
387-
use_cache: true
388387
rules:
389388
- entity_scope: "node"
390389
rule_type: "random"

ngraph/failure/policy.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,6 @@ class FailurePolicy:
120120
4) Collect the union of all failed entities across all rules.
121121
5) Optionally expand failures by shared-risk groups or sub-risks.
122122
123-
Large-scale performance:
124-
- If you set `use_cache=True`, matched sets for each rule are cached,
125-
so repeated calls to `apply_failures` can skip re-matching if the
126-
network hasn't changed. If your network changes between calls,
127-
you should clear the cache or re-initialize the policy.
128-
129123
Example YAML configuration:
130124
```yaml
131125
failure_policy:
@@ -173,10 +167,6 @@ class FailurePolicy:
173167
fail_risk_group_children (bool):
174168
If True, and if a risk_group is marked as failed, expand to
175169
children risk_groups recursively.
176-
use_cache (bool):
177-
If True, match results for each rule are cached to speed up
178-
repeated calls. If the network changes, the cached results
179-
may be stale.
180170
seed (Optional[int]):
181171
Seed for reproducible random operations. If None, operations
182172
will be non-deterministic.
@@ -186,13 +176,9 @@ class FailurePolicy:
186176
attrs: Dict[str, Any] = field(default_factory=dict)
187177
fail_risk_groups: bool = False
188178
fail_risk_group_children: bool = False
189-
use_cache: bool = False
190179
seed: Optional[int] = None
191180
modes: List[FailureMode] = field(default_factory=list)
192181

193-
# Internal cache for matched sets: (rule_index -> set_of_entities)
194-
_match_cache: Dict[int, Set[str]] = field(default_factory=dict, init=False)
195-
196182
def apply_failures(
197183
self,
198184
network_nodes: Dict[str, Any],
@@ -286,9 +272,6 @@ def _match_scope(
286272
"""Get the set of IDs matched by the given rule, either from cache
287273
or by performing a fresh match over the relevant entity type.
288274
"""
289-
if self.use_cache and rule_idx in self._match_cache:
290-
return self._match_cache[rule_idx]
291-
292275
# Decide which mapping to iterate
293276
if rule.entity_scope == "node":
294277
matched = self._match_entities(network_nodes, rule.conditions, rule.logic)
@@ -298,9 +281,6 @@ def _match_scope(
298281
matched = self._match_entities(
299282
network_risk_groups, rule.conditions, rule.logic
300283
)
301-
302-
if self.use_cache:
303-
self._match_cache[rule_idx] = matched
304284
return matched
305285

306286
def _match_entities(
@@ -610,7 +590,6 @@ def to_dict(self) -> Dict[str, Any]:
610590
"attrs": self.attrs,
611591
"fail_risk_groups": self.fail_risk_groups,
612592
"fail_risk_group_children": self.fail_risk_group_children,
613-
"use_cache": self.use_cache,
614593
"seed": self.seed,
615594
}
616595
if self.modes:

ngraph/scenario.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,14 +240,13 @@ def _build_failure_policy(
240240
) -> FailurePolicy:
241241
"""Constructs a FailurePolicy from data that may specify multiple rules plus
242242
optional top-level fields like fail_risk_groups, fail_risk_group_children,
243-
use_cache, and attrs.
243+
and attrs.
244244
245245
Example:
246246
failure_policy_set:
247247
default:
248248
fail_risk_groups: true
249249
fail_risk_group_children: false
250-
use_cache: true
251250
attrs:
252251
custom_key: custom_val
253252
rules:
@@ -273,7 +272,6 @@ def _build_failure_policy(
273272
"""
274273
fail_srg = fp_data.get("fail_risk_groups", False)
275274
fail_rg_children = fp_data.get("fail_risk_group_children", False)
276-
use_cache = fp_data.get("use_cache", False)
277275
attrs = normalize_yaml_dict_keys(fp_data.get("attrs", {}))
278276

279277
def build_rules(rule_dicts: List[Dict[str, Any]]) -> List[FailureRule]:
@@ -333,7 +331,6 @@ def build_rules(rule_dicts: List[Dict[str, Any]]) -> List[FailureRule]:
333331
attrs=attrs,
334332
fail_risk_groups=fail_srg,
335333
fail_risk_group_children=fail_rg_children,
336-
use_cache=use_cache,
337334
seed=policy_seed,
338335
modes=modes,
339336
)

scenarios/nsfnet.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ failure_policy_set:
162162
ENSS router has ~99.95 % availability (p=0.0005 failure).
163163
fail_risk_groups: false
164164
fail_risk_group_children: false
165-
use_cache: false
166165
modes:
167166
- weight: 1.0
168167
rules:

schemas/scenario.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,10 +346,7 @@
346346
"type": "boolean",
347347
"description": "Whether to recursively fail risk group children"
348348
},
349-
"use_cache": {
350-
"type": "boolean",
351-
"description": "Whether to use caching for failure calculations"
352-
},
349+
353350
"modes": {
354351
"type": "array",
355352
"description": "Weighted mode list; exactly one mode is chosen per iteration.",

tests/dsl/test_examples.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,6 @@ def test_failure_policy_example():
255255
default:
256256
fail_risk_groups: true
257257
fail_risk_group_children: false
258-
use_cache: true
259258
attrs:
260259
custom_key: "value"
261260
modes:

tests/failure/test_policy_set.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ def test_to_dict_serialization(self):
6060
modes=[FailureMode(weight=1.0, rules=[rule])],
6161
attrs={"name": "test_policy", "description": "Test policy"},
6262
fail_risk_groups=True,
63-
use_cache=False,
6463
)
6564

6665
fps.add("test", policy)
@@ -71,7 +70,6 @@ def test_to_dict_serialization(self):
7170
assert "modes" in result["test"]
7271
assert "attrs" in result["test"]
7372
assert result["test"]["fail_risk_groups"] is True
74-
assert result["test"]["use_cache"] is False
7573
# Modes present
7674
assert "modes" in result["test"] and len(result["test"]["modes"]) == 1
7775

tests/scenario/test_scenario.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ def valid_scenario_yaml() -> str:
9898
description: "Testing modal policy."
9999
fail_risk_groups: false
100100
fail_risk_group_children: false
101-
use_cache: false
102101
modes:
103102
- weight: 1.0
104103
rules:
@@ -291,7 +290,7 @@ def test_scenario_from_yaml_valid(valid_scenario_yaml: str) -> None:
291290
assert isinstance(simple_policy, FailurePolicy)
292291
assert not simple_policy.fail_risk_groups
293292
assert not simple_policy.fail_risk_group_children
294-
assert not simple_policy.use_cache
293+
# use_cache was removed
295294

296295
assert len(simple_policy.modes) == 1
297296
assert simple_policy.attrs.get("name") == "multi_rule_example"

0 commit comments

Comments
 (0)