bioFAM / MOFA2

Multi-Omics Factor Analysis

Home Page:https://biofam.github.io/MOFA2/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AttributeError: Module 'scipy' has no attribute 'random'

ahucke opened this issue · comments

I am running into an issue when trying to follow the tutorial provided by the creator. It states that "AttributeError: Module 'scipy' has no attribute 'random'".

This are my python configurations:
python: /miniconda3/envs/mofa/bin/python
libpython: /miniconda3/envs/mofa/lib/libpython3.11.so
pythonhome: /miniconda3/envs/mofa:/miniconda3/envs/mofa
version: 3.11.0 | packaged by conda-forge | (main, Jan 14 2023, 12:27:40) [GCC 11.3.0]
numpy: /miniconda3/envs/mofa/lib/python3.11/site-packages/numpy
numpy_version: 1.24.2

And this is my code:

----message=FALSE------------------------------------------------------------

library(data.table)
library(MOFA2)
library(reticulate)

Sys.setenv(OMP_NUM_THREADS="1")
reticulate::use_condaenv('/miniconda3/envs/mofa/')
reticulate::py_config()

-----------------------------------------------------------------------------

data <- make_example_data(
n_views = 2,
n_samples = 200,
n_features = 1000,
n_factors = 10
)[[1]]

lapply(data,dim)

----message=FALSE------------------------------------------------------------

MOFAobject <- create_mofa(data)

-----------------------------------------------------------------------------

plot_data_overview(MOFAobject)

----message=FALSE------------------------------------------------------------

N = ncol(data[[1]])
groups = c(rep("A",N/2), rep("B",N/2))

MOFAobject <- create_mofa(data, groups=groups)

-----------------------------------------------------------------------------

plot_data_overview(MOFAobject)

-----------------------------------------------------------------------------

filepath <- system.file("extdata", "test_data.RData", package = "MOFA2")
load(filepath)

head(dt)

-----------------------------------------------------------------------------

MOFAobject <- create_mofa(dt)
print(MOFAobject)

----out.width = "80%"--------------------------------------------------------

plot_data_overview(MOFAobject)

-----------------------------------------------------------------------------

data_opts <- get_default_data_options(MOFAobject)
head(data_opts)

-----------------------------------------------------------------------------

model_opts <- get_default_model_options(MOFAobject)
model_opts$num_factors <- 10
head(model_opts)

-----------------------------------------------------------------------------

train_opts <- get_default_training_options(MOFAobject)
train_opts

----message=FALSE------------------------------------------------------------

MOFAobject <- prepare_mofa(
object = MOFAobject,
data_options = data_opts,
model_options = model_opts,
training_options = train_opts
)

-----------------------------------------------------------------------------

outfile = file.path("/MOFA/model.hdf5")
MOFAobject.trained <- run_mofa(MOFAobject, outfile)

-----------------------------------------------------------------------------

sessionInfo()

This is the result of sessionInfo:
R version 4.1.2 (2021-11-01)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux Server 7.9 (Maipo)

Matrix products: default
BLAS: /usr/lib64/libblas.so.3.4.2
LAPACK: /usr/lib64/liblapack.so.3.4.2

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=C LC_COLLATE=C LC_MONETARY=C LC_MESSAGES=C
[7] LC_PAPER=C LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C LC_MEASUREMENT=C LC_IDENTIFICATION=C

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

other attached packages:
[1] BiocManager_1.30.19 RColorBrewer_1.1-3 tibble_3.1.8 ggrepel_0.9.2 dplyr_1.0.10 tidyr_1.2.1
[7] ggplot2_3.4.0 readxl_1.4.1 reticulate_1.28-9000 data.table_1.14.6 MOFA2_1.4.0

loaded via a namespace (and not attached):
[1] Rcpp_1.0.10 here_1.0.1 dir.expiry_1.2.0 lattice_0.20-45 png_0.1-8 assertthat_0.2.1
[7] rprojroot_2.0.3 utf8_1.2.2 R6_2.5.1 cellranger_1.1.0 plyr_1.8.8 stats4_4.1.2
[13] pillar_1.8.1 basilisk_1.6.0 rlang_1.0.6 rstudioapi_0.14 S4Vectors_0.32.4 Matrix_1.5-3
[19] Rtsne_0.16 stringr_1.4.1 pheatmap_1.0.12 munsell_0.5.0 uwot_0.1.14 DelayedArray_0.20.0
[25] HDF5Array_1.22.1 compiler_4.1.2 pkgconfig_2.0.3 BiocGenerics_0.40.0 tidyselect_1.2.0 IRanges_2.28.0
[31] matrixStats_0.62.0 fansi_1.0.3 withr_2.5.0 rhdf5filters_1.6.0 basilisk.utils_1.6.0 grid_4.1.2
[37] jsonlite_1.8.4 gtable_0.3.1 lifecycle_1.0.3 DBI_1.1.3 magrittr_2.0.3 scales_1.2.1
[43] cli_3.4.1 stringi_1.7.8 farver_2.1.1 reshape2_1.4.4 filelock_1.0.2 generics_0.1.3
[49] vctrs_0.5.2 cowplot_1.1.1 Rhdf5lib_1.16.0 tools_4.1.2 forcats_0.5.2 glue_1.6.2
[55] purrr_1.0.1 MatrixGenerics_1.9.1 parallel_4.1.2 colorspace_2.0-3 rhdf5_2.38.1 corrplot_0.92

Previously, I ran into an issue that said that I should use the most recent version of mofapy2 (0.6.4) while I was trying to use mofapy2 (0.6.7). I solved this by force installing the requested version with py_install("mofapy2 == 0.6.4").

Thanks for the help!

Looking around, it could be the MOFA2 version that I am using. My RStudio is locked with R 4.1.2, so I will try to find a workaround

Update: gave up on trying on R 4.1 and moved to R 4.2 locally. Did a fresh install of MOFA2 and mofapy2 and now the error moved from scipy to numpy as follows:

Error: AttributeError: module 'numpy' has no attribute 'float'.
np.float was a deprecated alias for the builtin float. To avoid this error in existing code, use float by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.float64 here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

New session info:

image

Edit: spelling.

Edit: it seems to be an issue when saving the output file. The training was completed.

Another update: tried running with the most recent mofapy2 (version 0.7.0) and got this error:

image

Edit: previous comment error was with mofapy2 version 0.6.7

I am also having the same problem with R version 4.2.1 :(

i think the "AttributeError: Module 'scipy' has no attribute 'random'" is solved here already
reticulate::py_install("scipy==1.7.0")
#108