6.1.1.4.1.7. pytfa.optim.utils

Relaxation of models with constraint too tight

6.1.1.4.1.7.1. Module Contents

6.1.1.4.1.7.1.1. Functions

get_all_subclasses(cls)

Given a variable or constraint class, get all the subclassses

chunk_sum(variables)

This functions handles the sum of many sympy variables by chunks, which

symbol_sum(variables)

``` python

get_solution_value_for_variables(solution, these_vars, index_by_reaction=False)

compare_solutions(models)

returns the solution dictionnary for each cobra_model

evaluate_constraint_at_solution(constraint, solution)

param expression

get_active_use_variables(tmodel, solution)

Returns the active use variables in a solution. Use Variables are binary

get_direction_use_variables(tmodel, solution)

Returns the active use variables in a solution. Use Variables are binary

get_primal(tmodel, vartype, index_by_reactions=False)

Returns the primal value of the cobra_model for variables of a given type

strip_from_integer_variables(tmodel)

Removes all integer and binary variables of a cobra_model, to make it sample-able

copy_solver_configuration(source, target)

Copies the solver configuration from a source model to a target model

6.1.1.4.1.7.1.2. Attributes

SYMPY_ADD_CHUNKSIZE

INTEGER_VARIABLE_TYPES

pytfa.SYMPY_ADD_CHUNKSIZE = 100
pytfa.INTEGER_VARIABLE_TYPES = ['binary', 'integer']
pytfa.get_all_subclasses(cls)

Given a variable or constraint class, get all the subclassses that inherit from it

Parameters

cls

Returns

pytfa.chunk_sum(variables)

This functions handles the sum of many sympy variables by chunks, which somehow increases the speed of the computation

You can test it in IPython: ```python a = sympy.symbols(‘a0:100’) %timeit (sum(a)) # >>> 198 µs ± 11.4 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)

b = sympy.symbols(‘b0:1000’) %timeit (sum(b)) # >>> 1.85 ms ± 356 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)

c = sympy.symbols(‘c0:3000’) %timeit (sum(c)) # >>> 5min 7s ± 2.57 s per loop (mean ± std. dev. of 7 runs, 1 loop each) ```

See the github thread

Parameters

variables

Returns

pytfa.symbol_sum(variables)

``` python a = symbols(‘a0:100’)

%timeit Add(*a) # >>> 10000 loops, best of 3: 34.1 µs per loop

b = symbols(‘b0:1000’)

%timeit Add(*b) # >>> 1000 loops, best of 3: 343 µs per loop

c = symbols(‘c0:3000’)

%timeit Add(*c) # >>> 1 loops, best of 3: 1.03 ms per loop ```

See the github thread :param variables: :return:

pytfa.get_solution_value_for_variables(solution, these_vars, index_by_reaction=False)
pytfa.compare_solutions(models)

returns the solution dictionnary for each cobra_model :param (iterable (pytfa.thermo.ThermoModel)) models: :return:

pytfa.evaluate_constraint_at_solution(constraint, solution)
Parameters
  • expression

  • solution – pandas.DataFrame, with index as variable names

Returns

pytfa.get_active_use_variables(tmodel, solution)

Returns the active use variables in a solution. Use Variables are binary variables that control the directionality of the reaction

ex: FU_ACALDt BU_PFK

Parameters
  • tmodel (pytfa.core.ThermoModel) –

  • solution

Returns

pytfa.get_direction_use_variables(tmodel, solution)

Returns the active use variables in a solution. Use Variables are binary variables that control the directionality of the reaction The difference with get_active_use_variables is that variables with both UseVariables at 0 will return as going forwards. This is to ensure that the output size of the function is equal to the number of FDPs

ex: FU_ACALDt BU_PFK

Parameters
  • tmodel (pytfa.core.ThermoModel) –

  • solution

Returns

pytfa.get_primal(tmodel, vartype, index_by_reactions=False)

Returns the primal value of the cobra_model for variables of a given type :param tmodel: :param vartype: Class of variable. Ex: pytfa.optim.variables.ThermoDisplacement :param index_by_reactions: Set to true to get reaction names as index instead of

variables. Useful for Escher export

Returns

pytfa.strip_from_integer_variables(tmodel)

Removes all integer and binary variables of a cobra_model, to make it sample-able :param tmodel: :return:

pytfa.copy_solver_configuration(source, target)

Copies the solver configuration from a source model to a target model :param source: :param target: :return: