librascal
librascal copied to clipboard
Issues building librascal on Mac M1
Hey all,
Just trying to get librascal compiled on my new laptop, ran into some issues.
Output from mkdir build && cd build && cmake .. && make VERBOSE=1
:
-- Build type is: Release
-- The CXX compiler identification is AppleClang 13.0.0.13000029
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Downloading wigxjpf
-- Found PythonInterp: /opt/miniconda3/bin/python3 (found suitable version "3.9.5", minimum required is "3")
-- Found PythonLibs: /opt/miniconda3/lib/libpython3.9.dylib
-- Performing Test HAS_FLTO
-- Performing Test HAS_FLTO - Success
-- Performing Test HAS_FLTO_THIN
-- Performing Test HAS_FLTO_THIN - Success
-- Installation ROOT: /opt/miniconda3
-- Warning: this does not have an effect - use NO_SYSTEM_FROM_IMPORTED if using imported targets
-- cpplint parser: /opt/miniconda3/bin/cpplint
-- clang-format not found, so the pretty-cpp target is unavailable
-- BLACK auto formatter: /opt/miniconda3/bin/black
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/rca/source_installs/librascal/build
/opt/miniconda3/bin/cmake -S/Users/rca/source_installs/librascal -B/Users/rca/source_installs/librascal/build --check-build-system CMakeFiles/Makefile.cmake 0
/opt/miniconda3/bin/cmake -E cmake_progress_start /Users/rca/source_installs/librascal/build/CMakeFiles /Users/rca/source_installs/librascal/build//CMakeFiles/progress.marks
/Library/Developer/CommandLineTools/usr/bin/make -f CMakeFiles/Makefile2 all
/Library/Developer/CommandLineTools/usr/bin/make -f src/CMakeFiles/rascal.dir/build.make src/CMakeFiles/rascal.dir/depend
cd /Users/rca/source_installs/librascal/build && /opt/miniconda3/bin/cmake -E cmake_depends "Unix Makefiles" /Users/rca/source_installs/librascal /Users/rca/source_installs/librascal/src /Users/rca/source_installs/librascal/build /Users/rca/source_installs/librascal/build/src /Users/rca/source_installs/librascal/build/src/CMakeFiles/rascal.dir/DependInfo.cmake --color=
Dependee "/Users/rca/source_installs/librascal/build/src/CMakeFiles/rascal.dir/DependInfo.cmake" is newer than depender "/Users/rca/source_installs/librascal/build/src/CMakeFiles/rascal.dir/depend.internal".
Dependee "/Users/rca/source_installs/librascal/build/src/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender "/Users/rca/source_installs/librascal/build/src/CMakeFiles/rascal.dir/depend.internal".
Scanning dependencies of target rascal
/Library/Developer/CommandLineTools/usr/bin/make -f src/CMakeFiles/rascal.dir/build.make src/CMakeFiles/rascal.dir/build
[ 3%] Building CXX object src/CMakeFiles/rascal.dir/rascal/utils/json_io.cc.o
cd /Users/rca/source_installs/librascal/build/src && /Library/Developer/CommandLineTools/usr/bin/c++ -Drascal_EXPORTS -I/Users/rca/source_installs/librascal/src -isystem /opt/miniconda3/include/eigen3 -isystem /Users/rca/source_installs/librascal/build/external/wigxjpf/inc -isystem /Users/rca/source_installs/librascal/build/external/wigxjpf/cfg -Wall -Wextra -Weffc++ -Wno-non-virtual-dtor -O3 -DNDEBUG -march=native -arch x86_64 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX11.3.sdk -fPIC -Werror -std=gnu++14 -o CMakeFiles/rascal.dir/rascal/utils/json_io.cc.o -c /Users/rca/source_installs/librascal/src/rascal/utils/json_io.cc
error: unknown target CPU 'vortex'
note: valid target CPU values are: nocona, core2, penryn, bonnell, atom, silvermont, slm, goldmont, goldmont-plus, tremont, nehalem, corei7, westmere, sandybridge, corei7-avx, ivybridge, core-avx-i, haswell, core-avx2, broadwell, skylake, skylake-avx512, skx, cascadelake, cooperlake, cannonlake, icelake-client, icelake-server, tigerlake, sapphirerapids, alderlake, knl, knm, k8, athlon64, athlon-fx, opteron, k8-sse3, athlon64-sse3, opteron-sse3, amdfam10, barcelona, btver1, btver2, bdver1, bdver2, bdver3, bdver4, znver1, znver2, znver3, x86-64, x86-64-v2, x86-64-v3, x86-64-v4
make[2]: *** [src/CMakeFiles/rascal.dir/rascal/utils/json_io.cc.o] Error 1
make[1]: *** [src/CMakeFiles/rascal.dir/all] Error 2
make: *** [all] Error 2
@Luthaf gave me a short-term patch, but this should be fixed long-term. Have fun :)!
The compiler error comes from the interaction between -march=native
(which selects an ARM CPU) and -arch x86_64
which are both used as C++ compiler flag. The short term patch is to remove -march=native
from CMake.
The question is where does -arch x86_64
come from? Apple supports emulating x86_64 emulation on M1 CPU with Rosetta, which might be at the origin of the issue.
I confirmed with @rosecers that the Python she's using (/opt/miniconda3/bin/python3
) is an x86_64 binary, so linking to libpython
here https://github.com/cosmo-epfl/librascal/blob/db2e2445d34c196c94731249061740123f9fbc28/bindings/CMakeLists.txt#L45 might bring -arch x86_64
.
Alternatively, we might have to set some flags to request native ARM compilation, and by default we get a x86_64 compiler. I would be surprised by this, since with clang/LLVM cross-compilers are built in the same binary (in opposition to GCC where the cross-compilers are separate binaries)
This should be fixed by #403
This is not, in fact, fixed by #403 for me:
[ 58%] Linking CXX executable forwarding_of_property_requests
ld: warning: ignoring file CMakeFiles/forwarding_of_property_requests.dir/forwarding_of_property_requests.cc.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [examples/cpp/forwarding_of_property_requests] Error 1
make[1]: *** [examples/cpp/CMakeFiles/forwarding_of_property_requests.dir/all] Error 2
FWIW I recently migrated my old system to a new M1 laptop, so there might have been some libraries copied over that shouldn't have been. I'll try reinstalling some Python packages and see if that does anything.
This is a different error. #403 solved error: unknown target CPU 'vortex'
, this does look a lot like trying to link arm code with x86_64 Python:
building for macOS-x86_64 but attempting to link with file built for unknown-arm64
I would assume that you have an arm64 boost-test main
(maybe from homebrew?) but cmake is building librascal code for x86_64 (maybe because Python is x86_64?)
Fixed now, seems the issue was that it was linking to Intel libraries that were basically just copied over during the migration. The best remedy for this situation is either to reinstall Conda/Miniconda or create a new environment for the new architecture like this. I think it would be worth adding a note to the installation instructions warning about this possible issue and how to resolve it.
Hi! I'm still having issues compiling on M1 architecture -- installation seems fine, but then I get this upon import:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
Cell In[1], line 5
3 from ase.io import read
4 from matplotlib import pyplot as plt
----> 5 from rascal.representations import SphericalInvariants as SOAP
6 from mpl_toolkits import mplot3d
7 from mpl_toolkits.mplot3d.art3d import Poly3DCollection # New import
File /PATH/TO/python3.10/site-packages/rascal-0.0.0-py3.10-macosx-11.0-arm64.egg/rascal/representations/__init__.py:1
----> 1 from .coulomb_matrix import SortedCoulombMatrix
2 from .spherical_expansion import SphericalExpansion
3 from .spherical_invariants import SphericalInvariants
File /PATH/TO/python3.10/site-packages/rascal-0.0.0-py3.10-macosx-11.0-arm64.egg/rascal/representations/coulomb_matrix.py:4
1 import numpy as np
2 import json
----> 4 from ..neighbourlist import AtomsList
5 from .base import CalculatorFactory
6 from itertools import starmap
File /PATH/TO/python3.10/site-packages/rascal-0.0.0-py3.10-macosx-11.0-arm64.egg/rascal/neighbourlist/__init__.py:1
----> 1 from .structure_manager import (
2 AtomsList,
3 get_neighbourlist,
4 convert_to_structure_list,
5 )
File /PATH/TO/python3.10/site-packages/rascal-0.0.0-py3.10-macosx-11.0-arm64.egg/rascal/neighbourlist/structure_manager.py:10
7 from ase.geometry import wrap_positions
8 from ase import Atoms
---> 10 from ..lib import neighbour_list
11 from .base import (
12 NeighbourListFactory,
13 is_valid_structure,
14 adapt_structure,
15 StructureCollectionFactory,
16 )
19 class AtomsList(object):
File /PATH/TO/python3.10/site-packages/rascal-0.0.0-py3.10-macosx-11.0-arm64.egg/rascal/lib/__init__.py:1
----> 1 from ._rascal import neighbour_list, models, representation_calculators, utils
3 from ._rascal.models import (
4 kernels,
5 compute_sparse_kernel_gradients,
6 compute_sparse_kernel_neg_stress,
7 )
ImportError: dlopen(/PATH/TO/python3.10/site-packages/rascal-0.0.0-py3.10-macosx-11.0-arm64.egg/rascal/lib/_rascal.cpython-310-darwin.so, 2): Symbol not found: _wig3jj
Referenced from: /PATH/TO/python3.10/site-packages/rascal-0.0.0-py3.10-macosx-11.0-arm64.egg/rascal/lib/_rascal.cpython-310-darwin.so
Expected in: flat namespace
in /PATH/TO/python3.10/site-packages/rascal-0.0.0-py3.10-macosx-11.0-arm64.egg/rascal/lib/_rascal.cpython-310-darwin.so
What's the exact command you used to install librascal?
8405cbdc0b5c72a5f0b0c93593100dde348bb95f fixed some of the errors when cross-compiling on CI. You should be able to git pull and install again, but make sure to wipe your build
and _skbuild
folders (or even start with a fresh clone of librascal).