15.1.1.1.1.8. cobra.core.solution

Provide unified interfaces to optimization solutions.

15.1.1.1.1.8.1. Module Contents

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

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

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).

shadow_prices

pandas.Series – Contains metabolite shadow prices (dual values of constraints).

Deprecated Attributes
---------------------
f

float – Use objective_value instead.

x

list – Use fluxes.values instead.

x_dict

pandas.Series – Use fluxes instead.

y

list – Use reduced_costs.values instead.

y_dict

pandas.Series – Use reduced_costs instead.

__init__(objective_value, status, fluxes, reduced_costs=None, shadow_prices=None, **kwargs)[source]

Initialize a Solution from its components.

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).
  • shadow_prices (pandas.Series) – Contains metabolite shadow prices (dual values of constraints).
__repr__()[source]

String representation of the solution instance.

_repr_html_()[source]
__dir__()[source]

Hide deprecated attributes and methods from the public interface.

__getitem__(reaction_id)[source]

Return the flux of a reaction.

Parameters:reaction (str) – A model reaction ID.
f()

Deprecated property for getting the objective value.

x_dict()

Deprecated property for getting fluxes.

x_dict(fluxes)

Deprecated property for setting fluxes.

x()

Deprecated property for getting flux values.

y_dict()

Deprecated property for getting reduced costs.

y_dict(costs)

Deprecated property for setting reduced costs.

y()

Deprecated property for getting reduced cost values.

to_frame()[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]

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

f

float – The objective value

solver

str – A string indicating which solver package was used.

x

iterable – List or Array of the fluxes (primal values).

x_dict

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

y

iterable – List or Array of the dual values.

y_dict

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

Warning

The LegacySolution class and its interface is deprecated.

__init__(f, x=None, x_dict=None, y=None, y_dict=None, solver=None, the_time=0, status="NA", **kwargs)[source]

Initialize a LegacySolution from an objective value.

Parameters:
  • f (float) – Objective value.
  • solver (str, optional) – A string indicating which solver package was used.
  • x (iterable, optional) – List or Array of the fluxes (primal values).
  • x_dict (dict, optional) – A dictionary of reaction IDs that maps to the respective primal values.
  • y (iterable, optional) – List or Array of the dual values.
  • y_dict (dict, optional) – A dictionary of reaction IDs that maps to the respective dual values.
  • the_time (int, optional) –
  • status (str, optional) –

:param .. warning :: deprecated:

__repr__()[source]

String representation of the solution instance.

__getitem__(reaction_id)[source]

Return the flux of a reaction.

Parameters:reaction_id (str) – A reaction ID.
dress_results(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.