fix: remove_redundant_facets mutates caller's lb/ub arrays (issue #83) - #137
Open
xovishnukosuri wants to merge 1 commit into
Open
xovishnukosuri wants to merge 1 commit into
xovishnukosuri wants to merge 1 commit into
Conversation
…mScale#83) The function modified the lb and ub arrays in-place when marking redundant facets and equality constraints. Any caller that passed model.lb and model.ub (as PolytopeSampler.get_polytope does) would find those arrays filled with sys.float_info.max/-sys.float_info.max after the first call, causing FBA/FVA and subsequent sampling runs to operate on corrupted bounds. Fix: copy lb and ub at the top of the function so all internal modifications are confined to local arrays. Add a regression test that verifies the model's lb/ub are unchanged after calling remove_redundant_facets.
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.
Problem
remove_redundant_facetsindingo/pyoptinterface_based_impl.pymodifies thelbandubarrays it receives in-place. It replaces values withsys.float_info.max/-sys.float_info.maxwhen marking redundant bounds and near-zero-width constraints.PolytopeSampler.get_polytope()passesself._metabolic_network.lbandself._metabolic_network.ubdirectly into this function. After the first sampling run those arrays on the model are corrupted. Any subsequent call — a secondgenerate_steady_states, an FBA, or an FVA on the same model — sees bounds like-1.79e+308instead of the original values.This is the root cause of the
UnboundLocalErrorreported in issue #83: the second FBA on the corrupted model returns a non-OPTIMAL status,optimum_solandoptimum_valuestay at their zero-initialised defaults, and downstream code that expects a real solution breaks.Fix
Copy
lbandubat the top ofremove_redundant_facetsso all internal modifications are confined to local arrays. Two lines added, no API change, no performance concern for normal model sizes.Test
Added
test_remove_redundant_facets_no_mutationtotests/fba.py. It snapshots the model'slbandubbefore the call and asserts they are byte-for-byte identical after it returns.Reproduction (before fix)
Closes #83