Skip to content

Commit 5d1c6b9

Browse files
authored
Merge pull request #554 from AdaWorldAPI/claude/perturbation-sim-nan-hardening
perturbation-sim: NaN/panic hardening sweep (total_cmp + cascade NaN-abort + stats guard) before the kanban/jitson wiring
2 parents 2e84972 + ebd2468 commit 5d1c6b9

18 files changed

Lines changed: 120 additions & 26 deletions

crates/perturbation-sim/examples/buffer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ fn main() {
214214
let mut weakest: Vec<(usize, f64, f64)> = (0..comps.len())
215215
.map(|ci| (ci, mean_buf[ci], lam2s[ci]))
216216
.collect();
217-
weakest.sort_by(|a, b| a.1.partial_cmp(&b.1).unwrap());
217+
weakest.sort_by(|a, b| a.1.total_cmp(&b.1));
218218
let mut first_yield = None;
219219
for (ci, buf, l2) in &weakest {
220220
let y = ketchup_yield(impulse, *buf);

crates/perturbation-sim/examples/calibrate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn quantize_rank_bits(col: &[f64], bits: u32) -> Vec<f64> {
8888
let n = col.len();
8989
let bins = (1usize << bits).min(n.max(1));
9090
let mut idx: Vec<usize> = (0..n).collect();
91-
idx.sort_by(|&a, &b| col[a].partial_cmp(&col[b]).unwrap());
91+
idx.sort_by(|&a, &b| col[a].total_cmp(&col[b]));
9292
let mut out = vec![0.0; n];
9393
for b in 0..bins {
9494
let s = b * n / bins;
@@ -142,7 +142,7 @@ fn main() {
142142
(e, d * d * grid.edges[e].susceptance)
143143
})
144144
.collect();
145-
sens.sort_by(|a, b| b.1.partial_cmp(&a.1).unwrap());
145+
sens.sort_by(|a, b| b.1.total_cmp(&a.1));
146146
let k = 24.min(m);
147147
let step = (m / k).max(1);
148148
let cand: Vec<usize> = (0..k).map(|i| sens[(i * step).min(m - 1)].0).collect();

crates/perturbation-sim/examples/explore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ fn main() {
338338
(e, d * d * grid.edges[e].susceptance)
339339
})
340340
.collect();
341-
sens.sort_by(|a, b| b.1.partial_cmp(&a.1).unwrap());
341+
sens.sort_by(|a, b| b.1.total_cmp(&a.1));
342342
let top: Vec<usize> = sens.iter().take(12).map(|x| x.0).collect();
343343
let lam2_0 = gl[1];
344344
let dl1: std::collections::HashMap<usize, f64> = top

crates/perturbation-sim/examples/hhtl_levels.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ fn median(mut v: Vec<f64>) -> f64 {
7474
if v.is_empty() {
7575
return 0.0;
7676
}
77-
v.sort_by(|a, b| a.partial_cmp(b).unwrap());
77+
v.sort_by(|a, b| a.total_cmp(b));
7878
v[v.len() / 2]
7979
}
8080

crates/perturbation-sim/examples/hhtl_resident.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ fn main() {
150150
let seed = base
151151
.iter()
152152
.enumerate()
153-
.max_by(|x, y| x.1.abs().partial_cmp(&y.1.abs()).unwrap())
153+
.max_by(|x, y| x.1.abs().total_cmp(&y.1.abs()))
154154
.map(|(i, _)| i)
155155
.unwrap_or(0);
156156
let infight = simulate_outage(&sub, &p, seed, cfg).fraction_tripped;

crates/perturbation-sim/examples/iberian.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ fn main() {
115115
let seed = base
116116
.iter()
117117
.enumerate()
118-
.max_by(|a, b| a.1.abs().partial_cmp(&b.1.abs()).unwrap())
118+
.max_by(|a, b| a.1.abs().total_cmp(&b.1.abs()))
119119
.map(|(i, _)| i)
120120
.unwrap();
121121

crates/perturbation-sim/examples/meta_hops.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fn median(mut v: Vec<f64>) -> f64 {
9595
if v.is_empty() {
9696
return 0.0;
9797
}
98-
v.sort_by(|a, b| a.partial_cmp(b).unwrap());
98+
v.sort_by(|a, b| a.total_cmp(b));
9999
v[v.len() / 2]
100100
}
101101

@@ -169,7 +169,7 @@ fn main() {
169169
let seed = base
170170
.iter()
171171
.enumerate()
172-
.max_by(|x, y| x.1.abs().partial_cmp(&y.1.abs()).unwrap())
172+
.max_by(|x, y| x.1.abs().total_cmp(&y.1.abs()))
173173
.map(|(i, _)| i)
174174
.unwrap_or(0);
175175
infs.push(simulate_outage(&sub, &p, seed, cfg).fraction_tripped);

crates/perturbation-sim/examples/modifier_validity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ fn main() {
131131
(e, d * d * grid.edges[e].susceptance)
132132
})
133133
.collect();
134-
sens.sort_by(|x, y| y.1.partial_cmp(&x.1).unwrap());
134+
sens.sort_by(|x, y| y.1.total_cmp(&x.1));
135135
let k = 30.min(m);
136136
let step = (m / k).max(1);
137137
let cand: Vec<usize> = (0..k).map(|i| sens[(i * step).min(m - 1)].0).collect();

crates/perturbation-sim/examples/reinforce.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fn main() {
9595
}
9696
}
9797
}
98-
cands.sort_by(|x, y| y.2.partial_cmp(&x.2).unwrap());
98+
cands.sort_by(|x, y| y.2.total_cmp(&x.2));
9999

100100
println!("\n== Reinforcement: optimal 3rd corridor across the Cheeger seam ==");
101101
println!(" base λ₂ = {lam2:.3e} (new-line susceptance b = {w_new:.3})");
@@ -141,7 +141,7 @@ fn main() {
141141
.collect();
142142
let seed = *seam
143143
.iter()
144-
.max_by(|&&x, &&y| base[x].abs().partial_cmp(&base[y].abs()).unwrap())
144+
.max_by(|&&x, &&y| base[x].abs().total_cmp(&base[y].abs()))
145145
.unwrap_or(&0);
146146
let cfg = CascadeConfig {
147147
max_rounds: 16,

crates/perturbation-sim/examples/resilience.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ fn main() {
131131
.map(|(i, b)| (i, cert(&induced(&grid, b))))
132132
.collect();
133133
// Weakest compartment first = smallest λ₂ margin.
134-
certs.sort_by(|a, b| a.1.lambda2.partial_cmp(&b.1.lambda2).unwrap());
134+
certs.sort_by(|a, b| a.1.lambda2.total_cmp(&b.1.lambda2));
135135

136136
println!(
137137
"\n== Per-compartment certificate ({} compartments, weakest λ₂ first) ==",

0 commit comments

Comments
 (0)