17.1.1.1.1.11. cobra.core.solution

Provide unified interfaces to optimization solutions.

17.1.1.1.1.11.1. Module Contents

17.1.1.1.1.11.1.1. Classes

Solution

A unified interface to a cobra.Model optimization solution.

LegacySolution

Legacy support for an interface to a cobra.Model optimization solution.

17.1.1.1.1.11.1.2. Functions

get_solution(model, reactions=None, metabolites=None, raise_error=False)

Generate a solution representation of the current solver state.

class cobra.core.solution.Solution(objective_value, status, fluxes, reduced_costs=None, shadow_prices=None, **kwargs)[source]

Bases: object

A unified interface to a cobra.Model optimization solution.

Notes

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

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

get_primal_by_id[source]
__repr__(self)[source]

String representation of the solution instance.

_repr_html_(self)[source]
__getitem__(self, reaction_id)[source]

Return the flux of a reaction.

Parameters

reaction (str) – A model reaction ID.

to_frame(self)[source]

Return the fluxes and reduced costs as a data frame

class cobra.core.solution.LegacySolution(f, x=None, x_dict=None, y=None, y_dict=None, solver=None, the_time=0, status='NA', **kwargs)[source]

Bases: object

Legacy support for an interface to a cobra.Model optimization solution.

f

The objective value

Type

float

solver

A string indicating which solver package was used.

Type

str

x

List or Array of the fluxes (primal values).

Type

iterable

x_dict

A dictionary of reaction IDs that maps to the respective primal values.

Type

dict

y

List or Array of the dual values.

Type

iterable

y_dict

A dictionary of reaction IDs that maps to the respective dual values.

Type

dict

Warning

The LegacySolution class and its interface is deprecated.

__repr__(self)[source]

String representation of the solution instance.

__getitem__(self, reaction_id)[source]

Return the flux of a reaction.

Parameters

reaction_id (str) – A reaction ID.

dress_results(self, model)[source]

Method could be intended as a decorator.

Warning

deprecated

cobra.core.solution.get_solution(model, reactions=None, metabolites=None, raise_error=False)[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 by default.

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

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

Returns

Return type

cobra.Solution

Note

This is only intended for the optlang solver interfaces and not the legacy solvers.