Skip to content

analysis: fix getMinNrFluxes crash on all-non-negative scores, drop dead code - #729

Merged
edkerk merged 1 commit into
develop3from
fix/getminnrfluxes-cleanup
Sep 4, 2026
Merged

analysis: fix getMinNrFluxes crash on all-non-negative scores, drop dead code#729
edkerk merged 1 commit into
develop3from
fix/getminnrfluxes-cleanup

Conversation

@edkerk

@edkerk edkerk commented Sep 4, 2026

Copy link
Copy Markdown
Member

Summary

Found while porting getMinNrFluxes to raven-toolbox (SysBioChalmers/raven-gecko-parity#42, SysBioChalmers/raven-toolbox#128): two issues worth fixing independently of the port itself.

Crash on an all-non-negative scores input. scores(scores>=0)=max(scores(scores<0)) evaluates the right-hand side to an empty array whenever nothing is negative. Unlike the literal [] MATLAB treats as element deletion, an empty array computed by max() doesn't delete anything — it just errors on the resulting size mismatch (scores has 3 elements selected, 0 provided), verified directly:

>> scores = [1;2;3];
>> scores(scores>=0) = max(scores(scores<0));
Unable to perform assignment because the left and right sides have a different number of elements.

Clamped to 0 in that case instead (every reaction becomes equally, un-weighted) — matching the choice made for the same edge case in the Python port.

Dead code. A fully commented-out Mosek-only branch, guarded by a stale TODO: modify for cobra/gurobi, could never execute (Mosek support was dropped from RAVEN entirely back in 2.3.0). Removed it along with the docstring's matching -2: optimization time out exit case, which was never actually reachable.

No change to the MILP formulation itself, and no change to any input that previously worked.

Test plan

…ead code

Found while porting getMinNrFluxes to raven-toolbox
(SysBioChalmers/raven-gecko-parity#42): passing a scores vector with no
negative entry crashed outright. scores(scores>=0)=max(scores(scores<0))
evaluates the right-hand side to an empty array when nothing is negative,
and unlike the literal [] MATLAB treats as element deletion, an empty
array computed by max() just errors on the size mismatch instead. Clamp
to 0 in that case instead, matching the port's own choice for the same
edge case.

Also removes a fully commented-out Mosek-only exitFlag=-2 branch (guarded
by a stale "TODO: modify for cobra/gurobi") that could never execute, and
the docstring's matching "-2: optimization time out" case, which was
never actually reachable.

No change to the MILP formulation itself or to any previously-working
input.
edkerk added a commit to SysBioChalmers/raven-gecko-parity that referenced this pull request Sep 4, 2026
Empirically verified the failure mode is an outright size-mismatch error,
not the silent array-shrinking the note originally guessed at; also notes
SysBioChalmers/RAVEN#729, which fixes it upstream.
@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown

Function test results

306 tests   279 ✅  1m 7s ⏱️
 25 suites   27 💤
  1 files      0 ❌

Results for commit 959b970.

@edkerk
edkerk merged commit 0669acc into develop3 Sep 4, 2026
4 checks passed
@edkerk
edkerk deleted the fix/getminnrfluxes-cleanup branch September 4, 2026 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant