diff --git a/release-notes/next-release.md b/release-notes/next-release.md index 843063be5..36ef2f5a0 100644 --- a/release-notes/next-release.md +++ b/release-notes/next-release.md @@ -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 diff --git a/src/cobra/core/solution.py b/src/cobra/core/solution.py index a23d86db8..6f6689078 100644 --- a/src/cobra/core/solution.py +++ b/src/cobra/core/solution.py @@ -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):