Skip to content

Commit 510d5f3

Browse files
committed
fix(ogit_bridge): drop is_ancestor MAX_VISITS cap + rustfmt collapse (codex P2)
Two CI fixes on PR #193: 1) Codex P2 — Drop the MAX_VISITS=4096 hard cap in `is_ancestor`. The previous cap could produce false-negatives on large biomedical ontologies (FMA: 75k classes; ChEBI: 200k+ classes) where a descendant has more than 4096 reachable superclass nodes before the target ancestor is popped. Termination is still guaranteed by the `visited: HashSet<&str>`: every parent IRI enters at most once, frontier pushes are gated on `visited.insert(...)`, so the total work bound is O(unique IRIs reachable from descendant) — finite by the schema's own finiteness. No explicit cap needed. 2) Rustfmt 1.95.0 collapse on the new `make_probability_mask_at_half_is_bernoulli_half` test assertion — same canonical-fmt collapse as prior hotfixes. No behavioral change beyond removing the artificial cap.
1 parent 6a6acdf commit 510d5f3

2 files changed

Lines changed: 18 additions & 16 deletions

File tree

src/hpc/dn_tree.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,10 +580,7 @@ mod tests {
580580
let mean = total as f64 / N as f64;
581581
// σ per word = sqrt(64 * 0.5 * 0.5) = 4; mean's SE = 4 / √N = 0.125.
582582
// Tolerance 2.0 ≈ 16 SEs — comfortable margin against flakes.
583-
assert!(
584-
(mean - 32.0).abs() < 2.0,
585-
"make_probability_mask(0.5) mean popcount {mean:.4} not near 32"
586-
);
583+
assert!((mean - 32.0).abs() < 2.0, "make_probability_mask(0.5) mean popcount {mean:.4} not near 32");
587584
}
588585

589586
#[test]

src/hpc/ogit_bridge/schema.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -684,24 +684,29 @@ impl OntologySchema {
684684
// linear chain via `EntityClass.parent` alone — correct for
685685
// single-inheritance schemas but missed ancestors reachable
686686
// only through `EntityClass.extra_parents` (OWL multi-inheritance,
687-
// common in FMA / ChEBI). MAX_VISITS bounds total work for any
688-
// cycle that slipped past upstream antisymmetry checks.
689-
const MAX_VISITS: usize = 4096;
687+
// common in FMA / ChEBI).
688+
//
689+
// # Termination
690+
//
691+
// `visited` is a monotonically-growing `HashSet<&str>` keyed by
692+
// IRI; each parent IRI enters the set at most once. Frontier
693+
// pushes are gated on `visited.insert(...)`, so every IRI is
694+
// pushed at most once across the entire walk. Total work is
695+
// therefore O(unique IRIs reachable from descendant) — finite
696+
// by the schema's finiteness, regardless of branching factor
697+
// or depth. No explicit visit cap is needed; previous codex P2
698+
// pointed out that a hard cap would produce false-negatives on
699+
// large biomedical ontologies (FMA: 75k classes; ChEBI: 200k+).
690700
let mut frontier: Vec<&str> = vec![descendant];
691701
let mut visited: std::collections::HashSet<&str> = std::collections::HashSet::new();
692702
visited.insert(descendant);
693-
let mut visits = 0usize;
694703
while let Some(current) = frontier.pop() {
695-
visits += 1;
696-
if visits > MAX_VISITS {
697-
return false;
698-
}
699704
let entity = match self.entities.get(current) {
700705
Some(e) => e,
701-
// Walk hit an unknown IRI mid-chain — that subtree of the
702-
// closure terminates here. Continue exploring siblings
703-
// rather than aborting, since other parents may yet reach
704-
// `ancestor`.
706+
// Walk hit an unknown IRI mid-chain — that subtree of
707+
// the closure terminates here. Continue exploring
708+
// siblings rather than aborting, since other parents
709+
// may yet reach `ancestor`.
705710
None => continue,
706711
};
707712
for parent in entity.parents() {

0 commit comments

Comments
 (0)