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

scVIIntegration Issue with jax Module #7275

Closed
B198096-2022 opened this issue May 4, 2023 · 3 comments
Closed

scVIIntegration Issue with jax Module #7275

B198096-2022 opened this issue May 4, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@B198096-2022
Copy link

Hello Everyone,

I've been having some trouble getting scVIIntegration to work on Seurat v5. I am trying to get the vignette example with the pbmcsca data set to run (https://satijalab.org/seurat/articles/seurat5_integration.html), and will then swap in my own data set.

I was originally getting the error at the beginning of this thread (#7164): object 'scVIIntegration' not found, and was able to resolve this as well as update scanpy in my conda env, so thank you to everyone in that thread for finding the solutions to those errors!!!

I am now able to get scVIIntegration running, but it quickly throws the following error:

Global seed set to 0
Error: AttributeError: module 'jax' has no attribute 'Device'

I have tried resetting RStudio and running everything in a clean environment, but it did not resolve the error.

I am just running the code that is presented in the vignette, but I had to make a few changes due to errors.

1st I added UpdateSeuratObject(object = obj) after loading in the object. This is because I was getting the following error when running subset(obj, nFeature_RNA > 1000):
Error in slot(object = object, name = s) :
no slot of name "images" for this object of class "Seurat"
Upon adding the UpdateSeuratObject step this error was resolved

I also skipped the RunAzimuth step as it was throwing the following error:
Error in validObject(object = object) :
invalid class “DimReduc” object: colnames for ‘feature.loadings’ must start with reduction key (refdr_)

With these changes, I was able to run RPCAIntegration just fine, both on the example data set as well as my own data. So I tried using the same pre-processing code and running scVIIntegration, which I pasted below:

library(dplyr)
library(Seurat)
library(SeuratData)
library(patchwork)
library(sctransform)
library(celda)
library(DoubletFinder)
library(tidyverse)
library(Azimuth)
library(ggplot2)
library(glmGamPoi)
library(reticulate)
library(sceasy)
library(R.utils)
library(SeuratWrappers)

obj <- LoadData("pbmcsca")
obj <- UpdateSeuratObject(object = obj)
obj <- subset(obj, nFeature_RNA > 1000)
#Skip RunAzimuth
#obj <- RunAzimuth(obj, reference = "pbmcref")

obj[["RNA"]] <- split(obj[["RNA"]], f = obj$Method)
#obj <- SCTransform(obj)
obj <- NormalizeData(obj)
obj <- FindVariableFeatures(obj)
obj <- ScaleData(obj)
obj <- RunPCA(obj)
obj <- FindNeighbors(obj, dims = 1:30, reduction = "pca")
obj <- FindClusters(obj, resolution = 2, cluster.name = "unintegrated_clusters")
obj <- RunUMAP(obj, dims = 1:30, reduction = "pca", reduction.name = "umap.unintegrated")
DimPlot(obj, reduction = "umap.unintegrated", group.by = c("Method"))

obj <- IntegrateLayers(
  object = obj, method = scVIIntegration,
  new.reduction = "integrated.scvi",
  conda_env = "/Users/maxhammer/anaconda3/envs/scvi-env"
)

And when I run this everything seems fine until IntegrateLayers returns the error:
Global seed set to 0
Error: AttributeError: module 'jax' has no attribute 'Device'

Do any of you have any ideas as to what could be causing this error? I checked and both jax and jaxlib are installed in my scvi-env (both version 0.3.25) which is the only thing I can think of. I installed scvi-tools using conda per their installation tutorial (linked in the vignette) and then installed scanpy in the scvi-env, and the jax module was installed in the environment as a result of this.

Thanks :)
Max

Session infro below:

> sessionInfo()
R version 4.2.3 (2023-03-15)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.6

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats4    stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] SeuratWrappers_0.3.19       R.utils_2.12.2              R.oo_1.25.0                
 [4] R.methodsS3_1.8.2           sceasy_0.0.7                reticulate_1.28            
 [7] glmGamPoi_1.9.0             Azimuth_0.4.6               shinyBS_0.61.1             
[10] lubridate_1.9.2             forcats_1.0.0               stringr_1.5.0              
[13] purrr_1.0.1                 readr_2.1.4                 tidyr_1.3.0                
[16] tibble_3.2.1                ggplot2_3.4.2               tidyverse_2.0.0            
[19] DoubletFinder_2.0.3         celda_1.14.2                Matrix_1.5-4               
[22] SingleCellExperiment_1.20.1 SummarizedExperiment_1.28.0 Biobase_2.58.0             
[25] GenomicRanges_1.50.2        GenomeInfoDb_1.34.9         IRanges_2.32.0             
[28] S4Vectors_0.36.2            BiocGenerics_0.44.0         MatrixGenerics_1.10.0      
[31] matrixStats_0.63.0          sctransform_0.3.5           patchwork_1.1.2            
[34] pbmcsca.SeuratData_3.0.0    pbmcref.SeuratData_1.0.0    SeuratData_0.2.2           
[37] Seurat_4.9.9.9042           SeuratObject_4.9.9.9084     sp_1.6-0                   
[40] dplyr_1.1.1                

loaded via a namespace (and not attached):
  [1] shinydashboard_0.7.2       utf8_1.2.3                 spatstat.explore_3.1-0    
  [4] tidyselect_1.2.0           htmlwidgets_1.6.2          grid_4.2.3                
  [7] combinat_0.0-8             Rtsne_0.16                 munsell_0.5.0             
 [10] codetools_0.2-19           ica_1.0-3                  DT_0.27                   
 [13] future_1.32.0              miniUI_0.1.1.1             withr_2.5.0               
 [16] spatstat.random_3.1-4      colorspace_2.1-0           progressr_0.13.0          
 [19] knitr_1.42                 rstudioapi_0.14            ROCR_1.0-11               
 [22] assertive.base_0.0-9       tensor_1.5                 listenv_0.9.0             
 [25] labeling_0.4.2             GenomeInfoDbData_1.2.9     polyclip_1.10-4           
 [28] farver_2.1.1               bit64_4.0.5                rprojroot_2.0.3           
 [31] parallelly_1.35.0          vctrs_0.6.2                generics_0.1.3            
 [34] xfun_0.38                  timechange_0.2.0           R6_2.5.1                  
 [37] doParallel_1.0.17          rsvd_1.0.5                 RcppEigen_0.3.3.9.3       
 [40] hdf5r_1.3.8                bitops_1.0-7               spatstat.utils_3.0-2      
 [43] gridGraphics_0.5-1         DelayedArray_0.24.0        promises_1.2.0.1          
 [46] scales_1.2.1               googlesheets4_1.1.0        gtable_0.3.3              
 [49] globals_0.16.2             goftest_1.2-3              spam_2.9-1                
 [52] rlang_1.1.0                splines_4.2.3              lazyeval_0.2.2            
 [55] gargle_1.3.0               spatstat.geom_3.1-0        BiocManager_1.30.20       
 [58] yaml_2.3.7                 reshape2_1.4.4             abind_1.4-5               
 [61] httpuv_1.6.9               SeuratDisk_0.0.0.9020      tools_4.2.3               
 [64] ellipsis_0.3.2             RColorBrewer_1.1-3         ggridges_0.5.4            
 [67] Rcpp_1.0.10                plyr_1.8.8                 zlibbioc_1.44.0           
 [70] RCurl_1.98-1.12            deldir_1.0-6               pbapply_1.7-0             
 [73] cowplot_1.1.1              zoo_1.8-11                 ggrepel_0.9.3             
 [76] cluster_2.1.4              here_1.0.1                 fs_1.6.1                  
 [79] magrittr_2.0.3             data.table_1.14.8          RSpectra_0.16-1           
 [82] magick_2.7.4               scattermore_0.8            lmtest_0.9-40             
 [85] RANN_2.6.1                 googledrive_2.1.0          fitdistrplus_1.1-8        
 [88] shinyjs_2.1.0              hms_1.1.3                  mime_0.12                 
 [91] evaluate_0.20              xtable_1.8-4               fastDummies_1.6.3         
 [94] gridExtra_2.3              compiler_4.2.3             KernSmooth_2.23-20        
 [97] crayon_1.5.2               htmltools_0.5.5            later_1.3.0               
[100] tzdb_0.3.0                 MCMCprecision_0.4.0        assertive.files_0.0-2     
[103] MASS_7.3-58.3              rappdirs_0.3.3             assertive.numbers_0.0-2   
[106] cli_3.6.1                  assertive.types_0.0-3      parallel_4.2.3            
[109] dotCall64_1.0-2            igraph_1.4.2               pkgconfig_2.0.3           
[112] plotly_4.10.1              spatstat.sparse_3.0-1      foreach_1.5.2             
[115] XVector_0.38.0             digest_0.6.31              RcppAnnoy_0.0.20          
[118] spatstat.data_3.0-1        cellranger_1.1.0           rmarkdown_2.21            
[121] leiden_0.4.3               enrichR_3.1                uwot_0.1.14               
[124] curl_5.0.0                 shiny_1.7.4                rjson_0.2.21              
[127] lifecycle_1.0.3            nlme_3.1-162               jsonlite_1.8.4            
[130] viridisLite_0.4.1          fansi_1.0.4                pillar_1.9.0              
[133] lattice_0.21-8             fastmap_1.1.1              httr_1.4.5                
[136] survival_3.5-5             remotes_2.4.2              glue_1.6.2                
[139] png_0.1-8                  iterators_1.0.14           multipanelfigure_2.1.2    
[142] bit_4.0.5                  presto_1.0.0               assertive.properties_0.0-5
[145] stringi_1.7.12             RcppHNSW_0.4.1             irlba_2.3.5.1             
[148] future.apply_1.10.0     
@B198096-2022 B198096-2022 added the bug Something isn't working label May 4, 2023
@B198096-2022
Copy link
Author

I think that I solved my own problem, but want to leave this up in case anybody else has a similar issue.

The problem was that jax and jaxlib were not recent enough versions. I used conda install for scvi-tools and scanpy, which downloads version 0.3.25. However, scvi-tools requires version 0.4.3 or higher. I tried conda uninstall to remove jax and jaxlib and then manually conda installed them, but this did not solve the problem. It wasn't until I used pip3 install jax and pip3 install jaxlib that versions 0.4.8 and 0.4.7 were installed, respectively.

Lastly, after jax and jaxlib were updated, I encountered a similar error with requests, and after using pip3 install requests I was able to run scVIIntegration.

@cathalgking
Copy link

Hi @B198096-2022
I had a similar issue as you described above. I tried installing those packages with pip3 but not sure if this is the cause. The error I am getting is:

Error: /Users/SCVI_2/lib/libpython3.11.dylib - dlopen(/Users/anaconda3/envs/SCVI_2/lib/libpython3.11.dylib, 0x000A): tried: '/Users/opt/anaconda3/envs/SCVI_2/lib/libpython3.11.dylib' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e)))

Have you any ideas on how to get past this? I am using a Mac with M1 chip

@ollieeknight
Copy link

This is how I generated the environment which is currently working for me:

mamba create -y -n sc_python python=3.9 macs2 leidenalg scanpy
conda activate sc_python
mamba install -c conda-forge scvi-tools

and then in R

Sys.setenv(RETICULATE_MINICONDA_PATH = '~/work/bin/miniconda3/')
library(reticulate)
use_miniconda('~/work/bin/miniconda3/envs/sc_python')

alldata[["RNA"]] <- as(alldata[["RNA"]], Class = "Assay5")
alldata[["RNA"]] <- split(alldata[["RNA"]], f = alldata$orig.ident)
# run pca etc and then
alldata <- IntegrateLayers(alldata, method = scVIIntegration,
  orig.reduction = 'pca', new.reduction = "integrated_scvi", assay = 'RNA',
  conda_env = "~/work/bin/miniconda3/envs/sc_python", verbose = TRUE)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants