Skip to content

Commit 0eb90d4

Browse files
authored
fix(core): catch missing reduced costs and shadow prices. (#1383)
* fix(core): catch missing reduced costs and shadow prices. Fixes #1381 and #1372 * Added fix to next release
1 parent d6632a4 commit 0eb90d4

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

release-notes/next-release.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
## Fixes
66

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

910
## Other
1011

src/cobra/core/solution.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,15 @@ def get_solution(
174174
reduced = np.empty(len(reactions))
175175
var_primals = model.solver.primal_values
176176
shadow = np.empty(len(metabolites))
177-
if model.solver.is_integer:
177+
178+
try:
179+
var_duals = model.solver.reduced_costs
180+
constr_duals = model.solver.shadow_prices
181+
duals_available = True
182+
except Exception:
183+
duals_available = False
184+
185+
if model.solver.is_integer or not duals_available:
178186
reduced.fill(np.nan)
179187
shadow.fill(np.nan)
180188
for i, rxn in enumerate(reactions):

0 commit comments

Comments
 (0)