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

Troppo_tutorial_GIMME seem to have problems #42

Open
Ananas-bio opened this issue Nov 22, 2024 · 2 comments
Open

Troppo_tutorial_GIMME seem to have problems #42

Ananas-bio opened this issue Nov 22, 2024 · 2 comments

Comments

@Ananas-bio
Copy link

Ananas-bio commented Nov 22, 2024

Hello! I was attempting to run the troppo tutorial on GIMME to make sure everything worked fine and first:
The solver CPLEX does not seem to exist, so I used the GLPK (out of two: GLPK or SCIPY). Unsure if it's relevant for the following issue but:
In gimme.run a typeError occured:

` ---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[9], 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 model_gimme = gimme.run()
14 print(model_gimme)

File ~/anaconda3/lib/python3.9/site-packages/troppo/methods/reconstruction/gimme.py:289, 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 ~/anaconda3/lib/python3.9/site-packages/troppo/methods/reconstruction/gimme.py:107, 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 ~/anaconda3/lib/python3.9/site-packages/cobamp/core/models.py:566, 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 ~/anaconda3/lib/python3.9/site-packages/cobamp/core/linear_systems.py:474, 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 ~/anaconda3/lib/python3.9/site-packages/optlang/interface.py:1491, 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 ~/anaconda3/lib/python3.9/site-packages/optlang/glpk_interface.py:753, in Model._remove_variables(self, variables)
751 num = intArray(len(variables) + 1)
752 for i, variable in enumerate(variables):
--> 753 num[i + 1] = variable._index
754 glp_del_cols(self.problem, len(variables), num)
756 for variable in variables:

File ~/anaconda3/lib/python3.9/site-packages/swiglpk/swiglpk.py:1069, in intArray.setitem(self, index, value)
1068 def setitem(self, index, value):
-> 1069 return swiglpk.intArray___setitem_(self, index, value)

TypeError: in method 'intArray___setitem__', argument 3 of type 'int' `

I only altered the solver and I'm unsure why this error would occur? I'm unsure of how I can solve this I've experimented a bit but got stuck.
Of note I had some trouble with another environment Troppo package where the GIMMEproperties did not have all the current arguments (i.e. solver), could this be similar installation problem despite having worked well up until this point?

Thanks in advance!

Edit:
I tried to install troppo in Google Colab and see if it's a problem from my Anaconda installation. What happened is that the in the Solver CPLEX still didn't exist, GLPK still made the same TypeError but I had the option of using SCIPY or OSQP (one more than in my installed environments).
OSQP did in fact finish the model! (SciPy was taking too long so I had to kill it). So it may be a problem with the GLPK solver itself for some reason?

Edir 2:
Tried the iMAT and a TypeError also happens there (this one ">=" not supported between instances of 'list' and 'float') again, I changed nothing of the script except location of files.

@ao60337
Copy link
Contributor

ao60337 commented Dec 4, 2024

Hello! What version of Python are you currently using in your environment? I’ve encountered similar issues when working with more recent versions of Python. The root of the problem is that Troppo is optimized for Python 3.7, however, it may not function as expected with later versions. To resolve this, we recommend creating an environment specifically for Python 3.7, as Troppo has not yet been updated to fully support newer versions.
I also noticed that this compatibility information isn’t mentioned anywhere on the page and on readthedocks. I’ll make sure to add it as soon as possible to avoid further confusion. Thank you for bringing this up!

@Ananas-bio
Copy link
Author

Hello! Thank you for answering. I was trying with several versions (3.8 to 3.10) where I did manage to install troppo. Today I installed python 3.7 in a new environment (using UV package manager and Anaconda later out of curiosity) as suggested however it is not allowing for installation of a dependency related with the cobamp. Specifically I got this message:

`uv pip install cobamp==0.2.1

Using Python 3.7.9 environment at t3.7
Resolved 26 packages in 3.11s
× Failed to download and build swiglpk==5.0.12
╰─▶ Build backend failed to determine requirements with build_wheel() (exit status: 1)

  [stdout]
  ==============================
  BUILDING SWIGLPK FROM SOURCE.
  If you are installing SWIGLPK via pip, this means that no wheels are offered for your platform or Python version
  yet.
  This can be the case if you adopt a new Python version early.
  A source build requires GLPK, SWIG, and GMP (Linux/Mac) to be installed!
  ==============================
  Looking for glpk.h...

  [stderr]
  Traceback (most recent call last):
    File "<string>", line 123, in <module>
    File "<string>", line 104, in find_glpk_header
  FileNotFoundError: Failed to locate glpk.h.

  The above exception was the direct cause of the following exception:

  Traceback (most recent call last):
    File "<string>", line 14, in <module>
    File "/home/patricia/.cache/uv/builds-v0/.tmpiCG7QH/lib/python3.7/site-packages/setuptools/build_meta.py",
  line 341, in get_requires_for_build_wheel
      return self._get_build_requires(config_settings, requirements=['wheel'])
    File "/home/patricia/.cache/uv/builds-v0/.tmpiCG7QH/lib/python3.7/site-packages/setuptools/build_meta.py",
  line 323, in _get_build_requires
      self.run_setup()
    File "/home/patricia/.cache/uv/builds-v0/.tmpiCG7QH/lib/python3.7/site-packages/setuptools/build_meta.py",
  line 488, in run_setup
      self).run_setup(setup_script=setup_script)
    File "/home/patricia/.cache/uv/builds-v0/.tmpiCG7QH/lib/python3.7/site-packages/setuptools/build_meta.py",
  line 338, in run_setup
      exec(code, locals())
    File "<string>", line 130, in <module>
  RuntimeError: A source build of SWIGLPK requires GLPK to be installed but we could not find glpk.h. You may put
  glpk.h inside the current directory or link to its parent folder via GLPK_HEADER_PATH.

help: swiglpk was included because cobamp==0.2.1 depends on optlang==1.5.2 which depends on swiglpk `

I did try the earliest version of python 3.7.7 available in uv after this but it gave the same error unfortunately. Seems like the error now is from cobamp. Unless there's a wheel for an earlier version of 3.7.7 or we can use another version of cobamp maybe?

I know troppo has been used this summer on a workshop so maybe there were new versions from the dependencies (in this case within cobamp) that came out recently?

Thanks!

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