You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
我在尝试测试我的模型,但我发现当我在一个ipynb中多次优化时,从第二个开始就会提示ContainerAlreadyContains: Container '<optlang.container.Container object at 0x000002286E0D5DC0>' already contains an object with name 'bio1'.只有重启整个ipynb才可以。
Code sample
Code run:
import cobra
import sys
sys.path.append(r'./script/')
ecModel_file="./model/eciLC858_v3.0.json"
model = cobra.io.json.load_json_model(ecModel_file)
cobra.flux_analysis.pfba(model)
Traceback:
---------------------------------------------------------------------------
ContainerAlreadyContains Traceback (most recent call last)
Cell In[2], [line 8](vscode-notebook-cell:?execution_count=2&line=8)
[6](vscode-notebook-cell:?execution_count=2&line=6) ecModel_file="./model/eciLC858_v3.0.json"
[7](vscode-notebook-cell:?execution_count=2&line=7) model = cobra.io.json.load_json_model(ecModel_file)
----> [8](vscode-notebook-cell:?execution_count=2&line=8) cobra.flux_analysis.pfba(model)
File c:\ProgramData\Anaconda3\envs\ECMpy2\lib\site-packages\cobra\flux_analysis\parsimonious.py:70, in pfba(model, fraction_of_optimum, objective, reactions)
[68](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/cobra/flux_analysis/parsimonious.py:68) add_pfba(m, objective=objective, fraction_of_optimum=fraction_of_optimum)
[69](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/cobra/flux_analysis/parsimonious.py:69) m.slim_optimize(error_value=None)
---> [70](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/cobra/flux_analysis/parsimonious.py:70) solution = get_solution(m, reactions=reactions)
[71](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/cobra/flux_analysis/parsimonious.py:71) return solution
File c:\ProgramData\Anaconda3\envs\ECMpy2\lib\site-packages\cobra\core\model.py:1246, in Model.__exit__(self, type, value, traceback)
[1244](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/cobra/core/model.py:1244) """Pop the top context manager and trigger the undo functions"""
[1245](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/cobra/core/model.py:1245) context = self._contexts.pop()
-> [1246](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/cobra/core/model.py:1246) context.reset()
File c:\ProgramData\Anaconda3\envs\ECMpy2\lib\site-packages\cobra\util\context.py:42, in HistoryManager.reset(self)
[40](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/cobra/util/context.py:40) while self._history:
[41](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/cobra/util/context.py:41) entry = self._history.pop()
---> [42](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/cobra/util/context.py:42) entry()
File c:\ProgramData\Anaconda3\envs\ECMpy2\lib\site-packages\cobra\util\solver.py:204, in set_objective.<locals>.reset()
[203](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/cobra/util/solver.py:203) def reset():
--> [204](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/cobra/util/solver.py:204) model.solver.objective = reverse_value
[205](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/cobra/util/solver.py:205) model.solver.objective.direction = reverse_value.direction
File c:\ProgramData\Anaconda3\envs\ECMpy2\lib\site-packages\optlang\glpk_interface.py:623, in Model.objective(self, value)
[621](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/glpk_interface.py:621) if variable._index is not None:
[622](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/glpk_interface.py:622) glp_set_obj_coef(self.problem, variable._index, 0.)
--> [623](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/glpk_interface.py:623) super(Model, self.__class__).objective.fset(self, value)
[624](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/glpk_interface.py:624) self.update()
[626](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/glpk_interface.py:626) offset, coef_dict, _ = parse_optimization_expression(value, linear=True)
File c:\ProgramData\Anaconda3\envs\ECMpy2\lib\site-packages\optlang\interface.py:1194, in Model.objective(self, value)
[1192](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/interface.py:1192) if isinstance(atom, Variable) and (atom.problem is None or atom.problem != self):
[1193](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/interface.py:1193) self._pending_modifications.add_var.append(atom)
-> [1194](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/interface.py:1194) self.update()
[1195](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/interface.py:1195) if self._objective is not None:
[1196](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/interface.py:1196) self._objective.problem = None
File c:\ProgramData\Anaconda3\envs\ECMpy2\lib\site-packages\optlang\interface.py:1422, in Model.update(self, callback)
[1420](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/interface.py:1420) add_var = self._pending_modifications.add_var
[1421](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/interface.py:1421) if len(add_var) > 0:
-> [1422](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/interface.py:1422) self._add_variables(add_var)
[1423](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/interface.py:1423) self._pending_modifications.add_var = []
[1424](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/interface.py:1424) callback()
File c:\ProgramData\Anaconda3\envs\ECMpy2\lib\site-packages\optlang\glpk_interface.py:732, in Model._add_variables(self, variables)
[730](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/glpk_interface.py:730) self._glpk_set_col_bounds(variable)
[731](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/glpk_interface.py:731) glp_set_col_kind(self.problem, variable._index, _VTYPE_TO_GLPK_VTYPE[variable.type])
--> [732](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/glpk_interface.py:732) super(Model, self)._add_variables(variables)
File c:\ProgramData\Anaconda3\envs\ECMpy2\lib\site-packages\optlang\interface.py:1491, in Model._add_variables(self, variables)
[1489](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/interface.py:1489) def _add_variables(self, variables):
[1490](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/interface.py:1490) for variable in variables:
-> [1491](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/interface.py:1491) self._variables.append(variable)
[1492](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/interface.py:1492) self._variables_to_constraints_mapping[variable.name] = set([])
[1493](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/interface.py:1493) variable.problem = self
File c:\ProgramData\Anaconda3\envs\ECMpy2\lib\site-packages\optlang\container.py:172, in Container.append(self, value)
[170](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/container.py:170) name = value.name
[171](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/container.py:171) if name in self._dict:
--> [172](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/container.py:172) raise ContainerAlreadyContains("Container '%s' already contains an object with name '%s'." % (self, value.name))
[173](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/container.py:173) self._indices[name] = len(self)
[174](file:///C:/ProgramData/Anaconda3/envs/ECMpy2/lib/site-packages/optlang/container.py:174) self._object_list.append(value)
ContainerAlreadyContains: Container '<optlang.container.Container object at 0x0000021F93DA5CA0>' already contains an object with name 'bio1'.
Environment
Anything else?
No response
The text was updated successfully, but these errors were encountered:
Hi, thanks for the report. Can you fill out the rest of the issue template, espcially the environment part so we can check which versions that affects?
Please paste the output of running depinfo --markdown cobra in your environment between the details tags below.
Is there an existing issue for this?
Problem description
我在尝试测试我的模型,但我发现当我在一个ipynb中多次优化时,从第二个开始就会提示ContainerAlreadyContains: Container '<optlang.container.Container object at 0x000002286E0D5DC0>' already contains an object with name 'bio1'.只有重启整个ipynb才可以。
Code sample
Code run:
Traceback:
Environment
Anything else?
No response
The text was updated successfully, but these errors were encountered: