BioSystemsUM / troppo

Reconstruction algorithms for Python
GNU General Public License v3.0
22 stars 5 forks source link

GurobiError: Item to be removed not a Var, Constr, SOS, QConstr, or GenConstr #38

Open peiyilu168 opened 4 weeks ago

peiyilu168 commented 4 weeks ago

I encountered an issue when running the GIMME algorithm with the example model and expression data. The detail is given below:

---------------------------------------------------------------------------
GurobiError                               Traceback (most recent call last)
Cell In[16], line 12
      9 # Run the GIMME algorithm.
     10 gimme = GIMME(S=model_wrapper.S, lb=model_wrapper.lb, ub=model_wrapper.ub, properties=properties)
---> 12 gimme_run = gimme.run()

File [~/miniconda3/envs/troppo/lib/python3.10/site-packages/troppo/methods/reconstruction/gimme.py:289](http://localhost:8889/lab/tree/miniconda3/envs/troppo/lib/python3.10/site-packages/troppo/methods/reconstruction/gimme.py#line=288), in GIMME.run(self)
    280 def run(self):
    281     """
    282     Run GIMME algorithm
    283 
   (...)
    287 
    288     """
--> 289     sol = self.gm.optimize_gimme(
    290         exp_vector=self.properties['exp_vector'],
    291         objectives=self.properties['objectives'],
    292         obj_frac=self.properties['obj_frac'],
    293         flux_thres=self.properties['flux_threshold']
    294     )
    295     self.sol = sol
    296     return sol.get_reaction_activity(self.properties['flux_threshold'])

File [~/miniconda3/envs/troppo/lib/python3.10/site-packages/troppo/methods/reconstruction/gimme.py:107](http://localhost:8889/lab/tree/miniconda3/envs/troppo/lib/python3.10/site-packages/troppo/methods/reconstruction/gimme.py#line=106), in GIMMEModel.optimize_gimme(self, exp_vector, objectives, obj_frac, flux_thres)
    104 for idx, lb in zip(objective_ids, lbs_id):
    105     self.set_reaction_bounds(idx, lb=lb, temporary=True)
--> 107 self.set_objective(gimme_model_objective, True)
    108 sol = self.optimize()
    109 self.revert_to_original_bounds()

File [~/miniconda3/envs/troppo/lib/python3.10/site-packages/cobamp/core/models.py:566](http://localhost:8889/lab/tree/miniconda3/envs/troppo/lib/python3.10/site-packages/cobamp/core/models.py#line=565), in ConstraintBasedModel.set_objective(self, coef_dict, minimize)
    564     self.model.set_objective(self.c, minimize)
    565 elif isinstance(coef_dict, ndarray):
--> 566     self.model.set_objective(coef_dict, minimize)
    567 else:
    568     raise TypeError('`coef_dict` must either be a dict or an ndarray')

File [~/miniconda3/envs/troppo/lib/python3.10/site-packages/cobamp/core/linear_systems.py:474](http://localhost:8889/lab/tree/miniconda3/envs/troppo/lib/python3.10/site-packages/cobamp/core/linear_systems.py#line=473), in LinearSystem.set_objective(self, coefficients, minimize, vars)
    472 self.model.remove(dummy)
    473 self.model.objective.direction = SENSE_MINIMIZE if minimize else SENSE_MAXIMIZE
--> 474 self.model.update()

File [~/miniconda3/envs/troppo/lib/python3.10/site-packages/optlang/gurobi_interface.py:671](http://localhost:8889/lab/tree/miniconda3/envs/troppo/lib/python3.10/site-packages/optlang/gurobi_interface.py#line=670), in Model.update(self)
    670 def update(self):
--> 671     super(Model, self).update(callback=self.problem.update)

File [~/miniconda3/envs/troppo/lib/python3.10/site-packages/optlang/interface.py:1491](http://localhost:8889/lab/tree/miniconda3/envs/troppo/lib/python3.10/site-packages/optlang/interface.py#line=1490), in Model.update(self, callback)
   1489 rm_var = self._pending_modifications.rm_var
   1490 if len(rm_var) > 0:
-> 1491     self._remove_variables(rm_var)
   1492     self._pending_modifications.rm_var = []
   1493 callback()

File [~/miniconda3/envs/troppo/lib/python3.10/site-packages/optlang/gurobi_interface.py:707](http://localhost:8889/lab/tree/miniconda3/envs/troppo/lib/python3.10/site-packages/optlang/gurobi_interface.py#line=706), in Model._remove_variables(self, variables)
    705 variable.problem = None
    706 del self._variables[variable.name]
--> 707 self.problem.remove(internal_variable)

File src/gurobipy/model.pxi:1096, in gurobipy.Model.remove()

File src/gurobipy/model.pxi:1101, in gurobipy.Model._removeone()

GurobiError: Item to be removed not a Var, Constr, SOS, QConstr, or GenConstr