TheoreticalEcology / s-jSDM

Scalable joint species distribution modeling
https://cran.r-project.org/web/packages/sjSDM/index.html
GNU General Public License v3.0
68 stars 14 forks source link

installation on M1 Pro Mac #92

Closed dougwyu closed 2 years ago

dougwyu commented 2 years ago

Hi Max,

I have a brand new MBP M1 Pro (macOS 12.1), and I tried to install sjSDM today, but no luck. I am doing a clean installation on this Mac, so nothing has been brought over from my Intel Mac.

  1. I installed Anaconda x386 (running under Rosetta2)
  2. I ran install_sjSDM(version = c("cpu"))
  3. I ran the following:
> set.seed(42)
> community <- simulate_SDM(sites = 100, species = 10, 
+                           env = 3, se = TRUE)
> Env <- community$env_weights
> Occ <- community$response
> SP <- matrix(rnorm(200, 0, 0.3), 100, 2) # spatial coordinates (no effect on species occurences)
> model <- sjSDM(Y = Occ, 
+                env = linear(data = Env, 
+                             formula = ~X1+X2+X3), 
+                spatial = linear(data = SP, formula = ~0+X1:X2), 
+                se = TRUE, family=binomial("probit"), 
+                sampling = 100L)
── Attaching sjSDM ───────────────────────────────────────────────────────── 1.0.0 ──
x torch 
x torch_optimizer 
x pyro 
x madgrad 

Torch or other dependencies not found:
    1. Use install_sjSDM() to install Pytorch and conda automatically 
    2. Installation trouble shooting guide: ?installation_help 
    3. If 1) and 2) did not help, please create an issue on <https://github.com/TheoreticalEcology/s-jSDM/issues> (see ?install_diagnostic) 
Error: PyTorch not installed
  1. I tried manually installing, but i got an error
    conda create --name r-sjsdm python=3.7
    conda activate r-sjsdm
    python -m pip install torch torchvision torchaudio 
    python -m pip install pyro-ppl torch_optimizer madgrad
(r-sjsdm) douglasyu@Douglass-MBP Downloads % python -m pip install torch torchvision torchaudio
/System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: No module named pip
  1. So I ran install_diagnostic(), and there is an X86/ARM error
> install_diagnostic()
     name                                                 python
1    base              /Users/douglasyu/opt/anaconda3/bin/python
2 r-sjsdm /Users/douglasyu/opt/anaconda3/envs/r-sjsdm/bin/python

ENV: base

torch:
# packages in environment at /Users/douglasyu/opt/anaconda3:
#
# Name                    Version                   Build  Channel

numpy:
# packages in environment at /Users/douglasyu/opt/anaconda3:
#
# Name                    Version                   Build  Channel
numpy                     1.20.3           py39h4b4dc7a_0  
numpy-base                1.20.3           py39he0bd621_0  
numpydoc                  1.1.0              pyhd3eb1b0_1  

ENV: r-sjsdm

torch:
# packages in environment at /Users/douglasyu/opt/anaconda3/envs/r-sjsdm:
#
# Name                    Version                   Build  Channel

numpy:
# packages in environment at /Users/douglasyu/opt/anaconda3/envs/r-sjsdm:
#
# Name                    Version                   Build  Channel

Error in py_initialize(config$python, config$libpython, config$pythonhome,  : 
  /Users/douglasyu/opt/anaconda3/envs/r-sjsdm/lib/libpython3.7m.dylib - dlopen(/Users/douglasyu/opt/anaconda3/envs/r-sjsdm/lib/libpython3.7m.dylib, 0x000A): tried: '/Users/douglasyu/opt/anaconda3/envs/r-sjsdm/lib/libpython3.7m.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/lib/libpython3.7m.dylib' (no such file)
MaximilianPi commented 2 years ago

Hi Doug,

I guess you have the arm R version installed?

It seems that the R-arm version cannot load/start a x86_64 python run time( (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/lib/libpython3.7m.dylib' (no such file) ).

The problem is that R-arm works perfectly now but most python libraries/dependencies still don't have support for arm... so I guess if you want to run sjSDM on your M1 you have to install the R x86_64 version (https://cran.r-project.org/bin/macosx/) .

Btw, I have reworked the automatic installation and it should work properly now without the need to install anaconda beforehand (but only with the R x86_64 version).

So in short:

dougwyu commented 2 years ago

ah, thanks. i'll use the sjsdm server version that we already have installed. R-arm is very nice.

dougwyu commented 2 years ago

i gave in and installed R x86_64. sjSDM runs now.

the example in Dependencies vignette seems to be in error.

library(sjSDM)
community <- simulate_SDM(sites = 100, species = 10, env = 5)
Env <- community$env_weights
Occ <- community$response

model <- sjSDM(X = Env, Y = Occ, formula = ~0+X1*X2 + X3 + X4)
summary(model)

did you mean something like:

model <- sjSDM(Y = Occ, env = linear(Env, formula = ~0+X1*X2 + X3 + X4))
summary(model)
MaximilianPi commented 2 years ago

oh yes, thanks!