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

Installation on mac m1 #193

Open
abaillod opened this issue Oct 9, 2023 · 16 comments
Open

Installation on mac m1 #193

abaillod opened this issue Oct 9, 2023 · 16 comments
Assignees

Comments

@abaillod
Copy link
Collaborator

abaillod commented Oct 9, 2023

Hi!

Has anyone successfully installed SPEC python wrappers on a mac M1 using anaconda? I get the following error message when running python setup.py bdist_wheel...

/opt/homebrew/Caskroom/miniconda/base/envs/simsopt/lib/python3.8/site-packages/setuptools/_distutils/cmd.py:66: SetuptoolsDeprecationWarning: setup.py install is deprecated.
!!

        ********************************************************************************
        Please avoid running ``setup.py`` directly.
        Instead, use pypa/build, pypa/installer, pypa/build or
        other standards-based tools.

        See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details.
        ********************************************************************************

!!
  self.initialize_options()
error: unknown file type '.tbd' (from '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libpthread.tbd')
ninja: build stopped: subcommand failed.
Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/miniconda/base/envs/simsopt/lib/python3.8/site-packages/skbuild/setuptools_wrap.py", line 674, in setup
    cmkr.make(make_args, install_target=cmake_install_target, env=env)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/simsopt/lib/python3.8/site-packages/skbuild/cmaker.py", line 697, in make
    self.make_impl(clargs=clargs, config=config, source_dir=source_dir, install_target=install_target, env=env)
  File "/opt/homebrew/Caskroom/miniconda/base/envs/simsopt/lib/python3.8/site-packages/skbuild/cmaker.py", line 742, in make_impl
    raise SKBuildError(msg)

An error occurred while building with CMake.
  Command:
    /opt/homebrew/Caskroom/miniconda/base/envs/simsopt/bin/cmake --build . --target install --config Release --
  Install target:
    install
  Source directory:
    /Users/antoinebaillod/Github/SPEC
  Working directory:
    /Users/antoinebaillod/Github/SPEC/_skbuild/macosx-14.0-arm64-3.8/cmake-build
Please check the install target is valid and see CMake's output for more information.\
@smiet
Copy link
Collaborator

smiet commented Oct 10, 2023

Hi Antoine,

This problem is originating with ninja, I am encountering a similar problem trying to compile with intel compilers on JED... it has trouble linking another file.

error: unknown file type '' (from 'hdf5_fortran-shared')

Is this the full output? (i.e. have you removed the _skbuild folder?)

It will probably still error, but there will be more useful output to look at if you could give me the output ( python setup.py build_ext >> compile.log 2>&1

Working on it, and I let you know when I find a solution on my end!

@mbkumar, you are our ninja-expert (or 'ninja'-ninja!) Do you know where these errors can stem from?

@abaillod
Copy link
Collaborator Author

Here is the full output!

compile.log

@mbkumar
Copy link
Collaborator

mbkumar commented Oct 10, 2023 via email

@smiet
Copy link
Collaborator

smiet commented Oct 11, 2023

Hi Antoine,

I have been struggling with the similar error on my side, but from your log it seems that your CMAKE finds both BLAS and LAPACK from your system:

- -Found BLAS: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Accelerate.framework  

and

-- Found LAPACK: /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Accelerate.framework;-lm;-ldl 

Make sure you install them using Conda (conda install openBLAS (?) ), and set the -DBLA_VENDOR variable in your cmake_config.json to the right value.

If it still is not working after this change, send the compile output and your cmake_config.json file

@smiet
Copy link
Collaborator

smiet commented Oct 11, 2023

@mbkumar, let me also jump on this thread by asking you what is happening on my system (intel compilers on EPFL cluster).

the root CMakelists finds my hdf5:

  -- Found HDF5: hdf5-shared;hdf5_fortran-shared (found version "1.12.2") found components: C Fortran HL
  -- HDF5 libraries found: TRUE
  -- HDF5 C include directors : /ssoft/spack/syrah/v1/opt/spack/linux-rhel8-icelake/intel-2021.6.0/hdf5-1.12.2-zzzj5gufyadodktq6xdrcvkgb2eazrfj/include
  -- HDF5 Fortran include directors : /ssoft/spack/syrah/v1/opt/spack/linux-rhel8-icelake/intel-2021.6.0/hdf5-1.12.2-zzzj5gufyadodktq6xdrcvkgb2eazrfj/include

but as you can read from the first line, the variables HDF5_Fortran_LIBRARIES and HDF5_C_LIBRARIES are not populated with a list of library files, but only the names of the libraries.

[In Antoine's code these variables were populated with:

-- Found HDF5: /opt/homebrew/Caskroom/miniconda/base/envs/simsopt/lib/libhdf5.dylib;/opt/homebrew/Caskroom/miniconda/base/envs/simsopt/lib/libcrypto.dylib;/opt/homebrew/Caskroom/miniconda/base/envs/simsopt/lib/libcurl.dylib;/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libpthread.tbd;/opt/homebrew/Caskroom/miniconda/base/envs/simsopt/lib/libsz.dylib;/opt/homebrew/Caskroom/miniconda/base/envs/simsopt/lib/libz.dylib;/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libdl.tbd;/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libm.tbd;/opt/homebrew/Caskroom/miniconda/base/envs/simsopt/lib/libhdf5_fortran.dylib;/opt/homebrew/Caskroom/miniconda/base/envs/simsopt/lib/libhdf5.dylib;/opt/homebrew/Caskroom/miniconda/base/envs/simsopt/lib/libcrypto.dylib;/opt/homebrew/Caskroom/miniconda/base/envs/simsopt/lib/libcurl.dylib;/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libpthread.tbd;/opt/homebrew/Caskroom/miniconda/base/envs/simsopt/lib/libsz.dylib;/opt/homebrew/Caskroom/miniconda/base/envs/simsopt/lib/libz.dylib;/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libdl.tbd;/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib/libm.tbd (found version "1.14.0") found components: C Fortran HL 

This then causes an error in linking, as this is passed directly to the f2py command when the wrapper is installed, giving the error

  error: unknown file type '' (from 'hdf5_fortran-shared')

as it is not a list of library files that it is given.

Do you know of a way to force cmake find_hdf5 to populate these variables with a list of files, and not the library names? Or to make target_link_libraries in the python_wrapper cmake actually expand the names into files, instead of plopping them straight in the list and confusing f2py?

@mbkumar
Copy link
Collaborator

mbkumar commented Oct 11, 2023 via email

@smiet
Copy link
Collaborator

smiet commented Oct 16, 2023

Hi, just an update as I made some progress on this and was able to install on my system:

Passing the setting -DHDF5_NO_FIND_PACKAGE_CONFIG_FILE=TRUE skips the FindHDF5.cmake file and searches directly, therefore ommitting the code that generates a separate cmake target, (hdf5-shared) which then errors when it is directly passed ty F2PY to compile the wrappers.

Antoine, can you add that to your cmake_config.yml file? I doubt that it will help, but it might cause cmake not to include the .tbd files in your HDF5_[C/Fortran]_LIBRARIES.

The issue seems to be a numpy/F2PY issue where the allowable extensions for libraries are hard-coded in a list, and do not include .tbd files.

@smiet
Copy link
Collaborator

smiet commented Oct 27, 2023

Hi @abaillod, just touching base to see if the issue still persists?

With the fixes to py_spec and the simsopt docker, can you run on your mac now?

Still leaving it open as we do need to make a change to the build to make it run on newer versions of macOS which require linking against .tbd and not .dylib (and f2py refusing to link against the newer .tbd library format)
https://discourse.cmake.org/t/newer-versions-of-macos-require-linking-against-tbd-files-and-not-old-system-paths-to-dylib/6871/6

@abaillod
Copy link
Collaborator Author

The docker does not work on my system:

docker run -it --rm -v $PWD:/my_mount hiddensymmetries/simsopt
root@5a0390184d65:/# python
Python 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from simsopt.mhd import Spec
s =Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/venv/lib/python3.10/site-packages/simsopt/__init__.py", line 13, in <module>
    from ._core import make_optimizable, load, save
  File "/venv/lib/python3.10/site-packages/simsopt/_core/__init__.py", line 3, in <module>
    from .optimizable import *
  File "/venv/lib/python3.10/site-packages/simsopt/_core/optimizable.py", line 31, in <module>
    from .json import GSONable, SIMSON, GSONDecoder, GSONEncoder
  File "/venv/lib/python3.10/site-packages/simsopt/_core/json.py", line 25, in <module>
    import jax
  File "/venv/lib/python3.10/site-packages/jax/__init__.py", line 39, in <module>
    from jax import config as _config_module
  File "/venv/lib/python3.10/site-packages/jax/config.py", line 17, in <module>
    from jax._src.config import config  # noqa: F401
  File "/venv/lib/python3.10/site-packages/jax/_src/config.py", line 27, in <module>
    from jax._src import lib
  File "/venv/lib/python3.10/site-packages/jax/_src/lib/__init__.py", line 83, in <module>
    cpu_feature_guard.check_cpu_features()
RuntimeError: This version of jaxlib was built using AVX instructions, which your CPU and/or operating system do not support. You may be able work around this issue by building jaxlib from source.

Trying to installing the python wrappers with anaconda I get a bunch of errors. First I get the numpy.distutils error when installing f90wrap:

❯ pip install -U git+https://github.com/zhucaoxiang/f90wrap
Collecting git+https://github.com/zhucaoxiang/f90wrap
  Cloning https://github.com/zhucaoxiang/f90wrap to /private/var/folders/2t/kl_73rbx6v5g_wjy89yslg7r0000gn/T/pip-req-build-iemx08nw
  Running command git clone --filter=blob:none --quiet https://github.com/zhucaoxiang/f90wrap /private/var/folders/2t/kl_73rbx6v5g_wjy89yslg7r0000gn/T/pip-req-build-iemx08nw
  Resolved https://github.com/zhucaoxiang/f90wrap to commit 27f5f31ff8f5c1761403c6d77f5bab7d2aa21b0e
  Installing build dependencies ... done
  Getting requirements to build wheel ... error
  error: subprocess-exited-with-error
  
  × Getting requirements to build wheel did not run successfully.
  │ exit code: 1
  ╰─> [18 lines of output]
      Traceback (most recent call last):
        File "/opt/homebrew/Caskroom/miniconda/base/envs/spec_env/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 353, in <module>
          main()
        File "/opt/homebrew/Caskroom/miniconda/base/envs/spec_env/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 335, in main
          json_out['return_val'] = hook(**hook_input['kwargs'])
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/opt/homebrew/Caskroom/miniconda/base/envs/spec_env/lib/python3.12/site-packages/pip/_vendor/pyproject_hooks/_in_process/_in_process.py", line 118, in get_requires_for_build_wheel
          return hook(config_settings)
                 ^^^^^^^^^^^^^^^^^^^^^
        File "/private/var/folders/2t/kl_73rbx6v5g_wjy89yslg7r0000gn/T/pip-build-env-1fcug50a/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 355, in get_requires_for_build_wheel
          return self._get_build_requires(config_settings, requirements=['wheel'])
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "/private/var/folders/2t/kl_73rbx6v5g_wjy89yslg7r0000gn/T/pip-build-env-1fcug50a/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 325, in _get_build_requires
          self.run_setup()
        File "/private/var/folders/2t/kl_73rbx6v5g_wjy89yslg7r0000gn/T/pip-build-env-1fcug50a/overlay/lib/python3.12/site-packages/setuptools/build_meta.py", line 341, in run_setup
          exec(code, locals())
        File "<string>", line 38, in <module>
      ModuleNotFoundError: No module named 'numpy.distutils'
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× Getting requirements to build wheel did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.

Downgrading numpy to an earlier version (1.21.5) and using python 3.8, I can get f90wrap installed but then I get the same issue with the .tbd files related to the HDF5 library, despite including the -DHDF5_NO_FIND_PACKAGE_CONFIG_FILE=TRUE option in cmake_config.yml.

@mbkumar
Copy link
Collaborator

mbkumar commented Oct 27, 2023 via email

@abaillod
Copy link
Collaborator Author

Hi Bharat. This is the output:

❯ docker run -it --rm -v $PWD:/my_mount hiddensymmetries/simsopt
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
root@5ddbe7e68119:/# cat /proc/cpuinfo
processor	: 0
BogoMIPS	: 48.00
Features	: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm ssbs sb paca pacg dcpodp flagm2 frint
CPU implementer	: 0x00
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0x000
CPU revision	: 0

processor	: 1
BogoMIPS	: 48.00
Features	: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm ssbs sb paca pacg dcpodp flagm2 frint
CPU implementer	: 0x00
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0x000
CPU revision	: 0

processor	: 2
BogoMIPS	: 48.00
Features	: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm ssbs sb paca pacg dcpodp flagm2 frint
CPU implementer	: 0x00
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0x000
CPU revision	: 0

processor	: 3
BogoMIPS	: 48.00
Features	: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm ssbs sb paca pacg dcpodp flagm2 frint
CPU implementer	: 0x00
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0x000
CPU revision	: 0

processor	: 4
BogoMIPS	: 48.00
Features	: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm ssbs sb paca pacg dcpodp flagm2 frint
CPU implementer	: 0x00
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0x000
CPU revision	: 0

processor	: 5
BogoMIPS	: 48.00
Features	: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm ssbs sb paca pacg dcpodp flagm2 frint
CPU implementer	: 0x00
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0x000
CPU revision	: 0

processor	: 6
BogoMIPS	: 48.00
Features	: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm ssbs sb paca pacg dcpodp flagm2 frint
CPU implementer	: 0x00
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0x000
CPU revision	: 0

processor	: 7
BogoMIPS	: 48.00
Features	: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm ssbs sb paca pacg dcpodp flagm2 frint
CPU implementer	: 0x00
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0x000
CPU revision	: 0

processor	: 8
BogoMIPS	: 48.00
Features	: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm ssbs sb paca pacg dcpodp flagm2 frint
CPU implementer	: 0x00
CPU architecture: 8
CPU variant	: 0x0
CPU part	: 0x000
CPU revision	: 0

@mbkumar
Copy link
Collaborator

mbkumar commented Oct 27, 2023 via email

@abaillod
Copy link
Collaborator Author

Hi,

Did we find a solution to this issue? I still can't install SPEC python wrappers on my Mac.

Hi, just an update as I made some progress on this and was able to install on my system:

Passing the setting -DHDF5_NO_FIND_PACKAGE_CONFIG_FILE=TRUE skips the FindHDF5.cmake file and searches directly, therefore ommitting the code that generates a separate cmake target, (hdf5-shared) which then errors when it is directly passed ty F2PY to compile the wrappers.

Antoine, can you add that to your cmake_config.yml file? I doubt that it will help, but it might cause cmake not to include the .tbd files in your HDF5_[C/Fortran]_LIBRARIES.

The issue seems to be a numpy/F2PY issue where the allowable extensions for libraries are hard-coded in a list, and do not include .tbd files.

@smiet
Copy link
Collaborator

smiet commented Nov 21, 2023

Recap: issue is Mac's 'new' .tbd library format, won't compile because of that

To directly install, I think there are two things to try:

Add to config.json

DCMAKE_OSX_DEPLOYMENT_TARGET=10.9

To try to force cmake to link the old way and skip tbds for Dylibs, see: https://discourse.cmake.org/t/newer-versions-of-macos-require-linking-against-tbd-files-and-not-old-system-paths-to-dylib/6871/4

Or install an older Mac SDK, and force Conda to use it (though it might not work with your new processor)
CONDA_BUILD_SYSROOT="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.REST.OF.PATH

Probably need to completely recreate Conda env

See second comment from https://developer.apple.com/forums/thread/713368

As noted there, the intersection of Mac Monterey users and F2PY users is probably small, and the issue is with how F2PY doesn't support mac's 'new' library format.

If it doesn't work, Best hope is to open an issue with Numpy... Don't think we can fix this

@landreman
Copy link
Collaborator

Yeah, due to this unknown file type '.tbd' error, I have not been able to get the spec python wrapper installed on either my M1 or M2 macbook. I've tried both sonoma and ventura, tried the recommended "conda toolchain only" approach for installing packages on M1/M2 from the wiki as well as using compilers from homebrew, and tried various versions of f90wrap, but always hit that .tbd error.

@mbkumar Back in 2020, there was a similar unknown file type f2py error for the extension .dylib, where you had to make a pull request to numpy itself. Would a similar change help here?

@mbkumar
Copy link
Collaborator

mbkumar commented Nov 22, 2023

If I remember correctly, I figured out how to get rid of .tbd error on Mac. I am able to compile VMEC on Mac. SPEC build is very similar. My gut feeling is it should be installable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants