Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relaxation of log concentration error #45

Open
svevol opened this issue Oct 12, 2020 · 1 comment
Open

Relaxation of log concentration error #45

svevol opened this issue Oct 12, 2020 · 1 comment

Comments

@svevol
Copy link

svevol commented Oct 12, 2020

Hi! Thanks for supporting this package,

I am trying to use relax_lc (same is in the example with relax_dgo). I am using EColi_BL21 from the package replicating the relax_dgo example. Is it possible to fix on my side?

Description of the error:

If I don't constrain the biomass function

mytfa.reactions.get_by_id(biomass_rxn).lower_bound = 0.0

I get the following error

ValueError                                Traceback (most recent call last)
<ipython-input-17-78e5fa8cc847> in <module>
      6 
      7     mytfa.reactions.get_by_id(biomass_rxn).lower_bound = 0.0*fba_value
----> 8     relaxed_model, slack_model, relax_table = relax_lc(mytfa)
      9 
     10     original_model, mytfa = mytfa, relaxed_model

/miniconda3/envs/rbcenv/lib/python3.7/site-packages/pytfa/optim/relaxation.py in relax_lc(tmodel, metabolites_to_ignore, solver)
    418                             'ub_change',
    419                             'lb_out',
--> 420                             'ub_out']
    421 
    422     tmodel.logger.info('\n' + relax_table.__str__())

/miniconda3/envs/rbcenv/lib/python3.7/site-packages/pandas/core/generic.py in __setattr__(self, name, value)
   5078         try:
   5079             object.__getattribute__(self, name)
-> 5080             return object.__setattr__(self, name, value)
   5081         except AttributeError:
   5082             pass

pandas/_libs/properties.pyx in pandas._libs.properties.AxisProperty.__set__()

/miniconda3/envs/rbcenv/lib/python3.7/site-packages/pandas/core/generic.py in _set_axis(self, axis, labels)
    636 
    637     def _set_axis(self, axis, labels):
--> 638         self._data.set_axis(axis, labels)
    639         self._clear_item_cache()
    640 

/miniconda3/envs/rbcenv/lib/python3.7/site-packages/pandas/core/internals/managers.py in set_axis(self, axis, new_labels)
    153             raise ValueError(
    154                 'Length mismatch: Expected axis has {old} elements, new '
--> 155                 'values have {new} elements'.format(old=old_len, new=new_len))
    156 
    157         self.axes[axis] = new_labels

ValueError: Length mismatch: Expected axis has 0 elements, new values have 6 elements

If I constrain the biomass reaction

mytfa.reactions.get_by_id(biomass_rxn).lower_bound = 0.5*fba_value

I got the following error

2020-10-12 13:09:42,209 - thermomodel_None - INFO - # Model initialized with units kcal/mol and temperature 298.15 K
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-18-a9a6b332d808> in <module>
      6 
      7     mytfa.reactions.get_by_id(biomass_rxn).lower_bound = 0.5*fba_value
----> 8     relaxed_model, slack_model, relax_table = relax_lc(mytfa)
      9 
     10     original_model, mytfa = mytfa, relaxed_model

/miniconda3/envs/rbcenv/lib/python3.7/site-packages/pytfa/optim/relaxation.py in relax_lc(tmodel, metabolites_to_ignore, solver)
    282     # Do not relax if cobra_model is already optimal
    283     try:
--> 284         solution = tmodel.optimize()
    285     except SolverError as SE:
    286         status = tmodel.solver.status

/miniconda3/envs/rbcenv/lib/python3.7/site-packages/pytfa/core/model.py in optimize(self, objective_sense, **kwargs)
    393         try:
    394             # self._hidden_optimize_call(kwargs)
--> 395             Model.optimize(self, **kwargs)
    396             solution = self.get_solution()
    397             self.solution = solution

/miniconda3/envs/rbcenv/lib/python3.7/site-packages/cobra/core/model.py in optimize(self, objective_sense, raise_error)
   1078                 objective_sense, original_direction)
   1079         self.slim_optimize()
-> 1080         solution = get_solution(self, raise_error=raise_error)
   1081         self.objective.direction = original_direction
   1082         return solution

/miniconda3/envs/rbcenv/lib/python3.7/site-packages/cobra/core/solution.py in get_solution(model, reactions, metabolites, raise_error)
    229     fluxes = empty(len(reactions))
    230     reduced = empty(len(reactions))
--> 231     var_primals = model.solver.primal_values
    232     shadow = empty(len(metabolites))
    233     if model.solver.is_integer:

/miniconda3/envs/rbcenv/lib/python3.7/site-packages/optlang/interface.py in primal_values(self)
   1234         """
   1235         return collections.OrderedDict(
-> 1236             zip(self._get_variables_names(), self._get_primal_values())
   1237         )
   1238 

/miniconda3/envs/rbcenv/lib/python3.7/site-packages/optlang/interface.py in _get_primal_values(self)
   1245         """
   1246         # Fallback, if nothing faster is available
-> 1247         return [variable.primal for variable in self.variables]
   1248 
   1249     @property

/miniconda3/envs/rbcenv/lib/python3.7/site-packages/optlang/interface.py in <listcomp>(.0)
   1245         """
   1246         # Fallback, if nothing faster is available
-> 1247         return [variable.primal for variable in self.variables]
   1248 
   1249     @property

/miniconda3/envs/rbcenv/lib/python3.7/site-packages/optlang/interface.py in primal(self)
    272         """The primal of variable (None if no solution exists)."""
    273         if self.problem:
--> 274             return self._get_primal()
    275         else:
    276             return None

/miniconda3/envs/rbcenv/lib/python3.7/site-packages/optlang/gurobi_interface.py in _get_primal(self)
    156 
    157     def _get_primal(self):
--> 158         return self._internal_variable.getAttr('X')
    159 
    160     @property

var.pxi in gurobipy.Var.getAttr()

attrutil.pxi in gurobipy.__getattr()

AttributeError: Unable to retrieve attribute 'X'
@psalvy
Copy link
Member

psalvy commented Oct 14, 2020

Good day Svetlana,

The second error is infeasibility with the Gurobi solver, mishandled by cobra. Probably the lower bound you ask for is higher than the achievable objective function in the TFA problem. Since this happens at the beginning of the relax_lc function, this suggests that your TFA model cannot achieve that high a growth rate.

The first error looks like it wants to relax 0 constraints, so the table has 0 elements and no columns, and the column name change is crashing because of that. That is because with a lower bound of 0, there is by definition no relaxation to be made.

These two items (infeasible model at the beginning of the function + no relaxation needed) seem to suggest the TFA model grows much slower than FBA predictions.

Could you try:

  1. Optimize the tfa model with no relaxation nor extra constraints. Report the solution value
  2. Ask for relaxation with a very low non-zero lower bound (1e-3 for example). What is the result ?
  3. When you get infeasibility, run the function debug_iis from the debugging module. This will give you a list of infeasible constraints / variable bounds. If there is around or less than 10 of each, can you post them here please ?
  4. Also, are you using DeltaG from eQuilibrator or from the provided `thermo_data' ? how much of your model is covered by thermodynamics ?

Cheers,
Pierre

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants