Skip to content

Commit

Permalink
fix(core): catch missing reduced costs and shadow prices. (#1383)
Browse files Browse the repository at this point in the history
* fix(core): catch missing reduced costs and shadow prices. Fixes #1381 and #1372

* Added fix to next release
  • Loading branch information
Palaract authored Apr 8, 2024
1 parent d6632a4 commit 0eb90d4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions release-notes/next-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## Fixes

* Fixes the incorrect bounds in the CycleFree loop removal.
* Fixes reduced costs and shadow prices not available when using non-convex models.

## Other

Expand Down
10 changes: 9 additions & 1 deletion src/cobra/core/solution.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,15 @@ def get_solution(
reduced = np.empty(len(reactions))
var_primals = model.solver.primal_values
shadow = np.empty(len(metabolites))
if model.solver.is_integer:

try:
var_duals = model.solver.reduced_costs
constr_duals = model.solver.shadow_prices
duals_available = True
except Exception:
duals_available = False

if model.solver.is_integer or not duals_available:
reduced.fill(np.nan)
shadow.fill(np.nan)
for i, rxn in enumerate(reactions):
Expand Down

0 comments on commit 0eb90d4

Please sign in to comment.