Don't crash h_abstraction() on empty product_dicts - #993
Open
alongd wants to merge 1 commit into
Open
Conversation
h_abstraction() indexed reaction.product_dicts[0] before the loop that iterates over the same list, so an empty product_dicts (no matching H_Abstraction family products identified for the reaction) raised an unguarded IndexError instead of yielding no TS guesses. That crash propagated out of Scheduler.__init__ and killed an entire multi-hour ARC run. Return an empty guess list with a warning instead, so other TS search methods can still be attempted.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #993 +/- ##
==========================================
+ Coverage 64.20% 64.23% +0.02%
==========================================
Files 119 119
Lines 39578 39580 +2
Branches 10266 10266
==========================================
+ Hits 25412 25424 +12
+ Misses 11196 11186 -10
Partials 2970 2970
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
The crash
h_abstraction()inarc/job/adapters/ts/heuristics.pyindexesreaction.product_dicts[0]before the loop that iterates over the samelist:
When
reaction.product_dictsis empty (no matching H_Abstraction familyproducts were identified for the reaction), the
forloop below wouldsimply not execute and leave
xyz_guessesempty — a correct "no guesses"outcome. But the unguarded
[0]on the preceding line raisesIndexError: list index out of rangefirst, turning "no guesses" into afatal crash.
Real-run evidence
Observed in a multi-hour T3 PDep→QM ARC run. The exception propagated all
the way up through
Scheduler.__init__and killed the whole run:Root cause of empty
product_dictsARCReaction.product_dictslazily callsget_product_dicts()→get_reaction_family_products(), which returns an empty list whenever noRMG reaction-family template matches the reaction (e.g. atom-mapping
ambiguity, an unusual/edge-case reaction, or a family that legitimately
doesn't apply). This is an expected, already-handled emptiness elsewhere in
the file:
get_products_and_check_families()(around line 981) has its ownif not product_dicts:branch for the case where a specifically-requestedfamily produced no products. There's no evidence of a deeper upstream defect
here — a TS-guess heuristic simply has to tolerate "no guesses could be
constructed" as a valid outcome rather than treating it as fatal, since ARC
has other TS search methods to fall back on.
Fix
Guard the
[0]access: ifreaction.product_dictsis empty, log a warningnaming the reaction and return an empty guess list immediately, before ever
touching
[0]. This matches the existing logging/docstring style in thefile (
logger.warning, numpydoc-ishReturnssection).Sibling-pattern search
Searched the rest of
heuristics.pyfor the same "unguarded[0]-indexbefore a loop over the same list" pattern in the other family heuristic
functions (
hydrolysis,get_products_and_check_families,get_reaction_family_products, etc.). None found —h_abstraction()wasthe only function with this defect.
Tests
Added
test_h_abstraction_with_empty_product_dictstoarc/job/adapters/ts/heuristics_test.py, which builds a real H_AbstractionARCReaction, forcesproduct_dicts = []via the existing setter, callsh_abstraction()directly, and asserts it returns[]instead of raising.Baseline (before fix):
43 passed(heuristics_test.py)After fix:
44 passed(heuristics_test.py)Test plan
python -m pytest arc/job/adapters/ts/heuristics_test.py -q— 44 passed (was 43 before this change; new test added)