theislab / cpa

The Compositional Perturbation Autoencoder (CPA) is a deep generative framework to learn effects of perturbations at the single-cell level. CPA performs OOD predictions of unseen combinations of drugs, learns interpretable embeddings, estimates dose-response curves, and provides uncertainty estimates.
BSD 3-Clause "New" or "Revised" License
83 stars 17 forks source link

Incompatible packages make me unable to use CPA outside of Colab #51

Closed ZaneDash closed 1 month ago

ZaneDash commented 3 months ago

ImportError: cannot import name 'stats' from 'jax.scipy' (/lfs/ampere6/0/zanedash/env/micromamba/envs/cpa/lib/python3.9/site-packages/jax/scipy/init.py)

AttributeError: module 'scipy.linalg' has no attribute 'tril'

please advise, thanks

ArianAmani commented 3 months ago

Thanks for your interest in CPA. Could you provide the full error and the environment you are using? There has been some changes in the version 1.13.0 of scipy. This will be most likely solved by installing these versions: Jax: 0.4.23 Scipy: 1.12.0

ArianAmani commented 3 months ago

I am closing this issue due to inactivity. Please feel free to comment if the problem persists.

MEFarhadieh commented 1 month ago

Hi CPA Development Team,

Thank you for your suggestion regarding the versions of Jax and Scipy. I followed your instructions to install Jax 0.4.23 and Scipy 1.12.0, but I am still encountering several issues when trying to import and use CPA in Google Colab (but not in docker and my local machine). Here’s a detailed breakdown of the problems:

  1. Installation Issues:

    • I successfully installed Jax 0.4.23 and Scipy 1.12.0 as recommended. However, during the process, I encountered several dependency conflicts and errors, particularly with other packages like osqp that require Scipy >= 1.12.0.
    • Additionally, when trying to install Jax 0.3.25, which seemed to be more compatible with other dependencies, I encountered an error stating that no matching distribution was found for jaxlib==0.3.25.
  2. Runtime Errors:

    • After resolving the installation issues, I still get an error when importing CPA:
      AttributeError: module 'jax.random' has no attribute 'KeyArray'

      This seems to indicate some incompatibility between Jax and CPA.

  3. Environment Details:

    • I am using Google Colab with Python 3.10. The runtime environment is freshly initialized, and I have followed your instructions carefully to install the specified versions.
  4. Repeated Errors:

    • Even after reinstalling the environment and following your suggested steps, I keep encountering persistent errors related to package incompatibilities and missing modules, such as:
      ModuleNotFoundError: No module named 'pkg_resources._vendor'

Given these issues, I would greatly appreciate any further guidance you could provide on resolving these conflicts. Specifically, is there a tested and recommended setup for using CPA within Google Colab, including precise versions of Jax, Scipy, and any other dependencies?

JeanRadig commented 1 month ago

@ZaneDash I am encountering the same issue. @MEFarhadieh you say you managed to get it running in docker. Can you tell the image you have used and the packages installed (could you send the content of your dockerfile?). My Dockerfile contains:

But I still get the incompatibility issues. Thanks in advance!

ArianAmani commented 1 month ago

Thank you all for your interest in CPA.

The version changes of some default packages in Google Colab made the installation problematic by default. The problems were apparently related to these 2 packages and these versions fix the problems:

!pip install setuptools==70.0.0
!pip install scipy==1.12.0

I updated the dependency versions on the main branch and also on PyPI. The installation should work on Google Colab without any problems now by just installing the CPA package itself:

!pip install cpa-tools

or

!pip install git+https://github.com/theislab/cpa

This has been tested and works well on Colab as of today.

p.s. There will be incompatibility errors shown at the end when installing in Colab, which is due to Colab containing several pre-installed packages and the errors are referring to version conflicts for those packages that are not used by the CPA package, therefore, it shouldn't be a problem.

Feel free to ask if any of the problems persist.

JeanRadig commented 1 month ago

Works as well outside of google colab now. Thank you very much!

MEFarhadieh commented 1 month ago

Dear @ArianAmani thank you very much, It works now in Colab!

Dear @JeanRadig I used version v0.5.0 of CPA, which was released on June 9, 2023. Additionally, I made sure to use related dependencies from that time, such as scanpy==1.9.1. You can download and install this specific version directly from the following link:

https://github.com/theislab/cpa/archive/refs/tags/v0.5.0.tar.gz

However, with the recent update, it makes more sense to use the current version cpa-tools.