Cap set-variant cartesian expansion (#40)#44
Merged
Conversation
…ns (#40) A complex whose internal-EntitySet combinations — or a reaction whose input/output combinations — exceed LNG_MAX_VARIANTS (default 512) are now bundled into a single opaque node instead of materializing the full cartesian product. This is enforced at both layers so they agree a given complex is one node: - matching (reaction_generator.get_broken_apart_ids): when the product exceeds the cap, merge all alternatives' components and emit one bundled combination via the existing get_uids_for_iterproduct_components path. - emission (logic_network_generator._complex_variant_leafsets): same cap; bundled complexes are tracked in _variant_capped so _map_annotated_entity_to_nodes names them by their plain stId (no giant ::variant::<all-leaves> id). Verified against Neo4j — the four catalog-scale blockers are tamed with the bundled node still carrying every alternative's components, and pathways below the threshold are byte-identical (cap branch never executes): Class_I_MHC 3,287,698 -> 61,278 edges Chromatin_modifying 1,391,200 -> 34,768 edges Cellular_Senescence 130,879 -> 20,050 edges Interferon_gamma hung 8.5h -> completes ~90s Signaling_by_ERBB2 9,067 edges, 0 cap hits (unchanged) Env-tunable via LNG_MAX_VARIANTS; <= 0 disables the cap. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
_expand_complex_variants — the negative-regulator decomposition path — did its own uncapped itertools.product, separate from the input/output caps added in the previous commit. A single inhibitor complex with large internal EntitySets fanned out into ~144k variant nodes, each wired to every reaction it inhibits: RAF_MAP_kinase_cascade produced 4,758,406 negative-regulator edges (4.77M edges total, 144,750 root inputs). Apply the same MAX_VARIANTS cap: when the variant cartesian exceeds the cap, return the complex as one opaque node [(complex_id, 1)]. Verified vs Neo4j: RAF_MAP_kinase_cascade 4,769,814 -> 18,210 edges (root inputs 144,750 -> 762) RUNX1 (163k edges) is unaffected — that pathway is genuinely large (65k catalyst + boundary edges via bounded additive subunit decomposition), not a cartesian explosion, so it is left as-is. Adds TestRegulatorVariantCap (over-cap bundles to one node; under-cap expands). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #40 — set-variant expansion produced catalog-scale explosions (and hangs) that blocked generating most of the pathway catalog.
Adds an env-tunable cap
LNG_MAX_VARIANTS(default 512,<=0disables). When a complex's internal-EntitySet combinations — or a reaction's input/output combinations — would exceed the cap, all alternatives are bundled into one opaque node (named by the plain stId, no giant::variant::<all-leaves>id) instead of materializing the full cartesian product.Three separate cartesian sites are now capped consistently:
reaction_generator.get_broken_apart_idslogic_network_generator._complex_variant_leafsets(+_variant_capped→ plain-stId naming)logic_network_generator._expand_complex_variantsVerified against Neo4j
The cap is inert below threshold: pathways whose variant counts are under 512 take the exact same code path as before, so their output is unchanged. RUNX1 (163k edges) is intentionally untouched — it's genuinely large (bounded additive subunit decomposition), not a cartesian explosion.
Impact
Unblocked a full held-out curator holdout across 69 pathways (previously ~18 were tractable): 81.10% (12,211/15,056) at the tuned classification cutoffs, including the previously-impossible large pathways (Chromatin 95.8%, Interferon_gamma 63.5%, Class_I_MHC 62.5%).
Tests
TestVariantCap(matching layer): over-cap bundles to one node carrying all components; under-cap still expands.TestRegulatorVariantCap(negative-regulator layer): over-cap bundles; under-cap expands.🤖 Generated with Claude Code