cobra.core.solution

Provide unified interfaces to optimization solutions.

Module Contents

Classes

Solution

A unified interface to a cobra.Model optimization solution.

Functions

get_solution(→ Solution)

Generate a solution representation of the current solver state.

class cobra.core.solution.Solution(objective_value: float, status: str, fluxes: pandas.Series, reduced_costs: Optional[pandas.Series] = None, shadow_prices: Optional[pandas.Series] = None, **kwargs)[source]

A unified interface to a cobra.Model optimization solution.

Parameters
  • objective_value (float) – The (optimal) value for the objective function.

  • status (str) – The solver status related to the solution.

  • fluxes (pandas.Series) – Contains the reaction fluxes (primal values of variables).

  • reduced_costs (pandas.Series) – Contains reaction reduced costs (dual values of variables) (default None).

  • shadow_prices (pandas.Series) – Contains metabolite shadow prices (dual values of constraints) (default None).

objective_value

The (optimal) value for the objective function.

Type

float

status

The solver status related to the solution.

Type

str

fluxes

Contains the reaction fluxes (primal values of variables).

Type

pandas.Series

reduced_costs

Contains reaction reduced costs (dual values of variables).

Type

pandas.Series

shadow_prices

Contains metabolite shadow prices (dual values of constraints).

Type

pandas.Series

Notes

Solution is meant to be constructed by get_solution please look at that function to fully understand the Solution class.

get_primal_by_id[source]
__repr__() str[source]

Return a string representation of the solution instance.

_repr_html_() str[source]

Return a rich HTML representation of the solution.

__getitem__(reaction_id: str) float[source]

Return the flux of a reaction.

Parameters

reaction_id (str) – A model reaction ID.

Returns

The flux of the reaction with ID reaction_id.

Return type

float

to_frame() pandas.DataFrame[source]

Return the fluxes and reduced costs as a pandas DataFrame.

Returns

The fluxes and reduced cost.

Return type

pandas.DataFrame

cobra.core.solution.get_solution(model: cobra.Model, reactions: Optional[Iterable[cobra.Reaction]] = None, metabolites: Optional[Iterable[cobra.Metabolite]] = None, raise_error: bool = False) Solution[source]

Generate a solution representation of the current solver state.

Parameters
  • model (cobra.Model) – The model whose reactions to retrieve values for.

  • reactions (list, optional) – An iterable of cobra.Reaction objects. Uses model.reactions if None (default None).

  • metabolites (list, optional) – An iterable of cobra.Metabolite objects. Uses model.metabolites if None (default None).

  • raise_error (bool) – If True, raise an OptimizationError if solver status is not optimal (default False).

Return type

cobra.Solution