MatteoLacki / IsoSpec

Libraries for fine isotopic structure calculator.
Other
35 stars 10 forks source link

Compile error on M2 pro chip #52

Closed MKoesters closed 6 months ago

MKoesters commented 6 months ago

Hi,

I'm trying to install IsoSpecPy from pypi. It errors out with:

error: unknown target CPU 'apple-m1'
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, rocketlake, 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
error: command '/usr/bin/clang' failed with exit code 1

I get the same error when downloading the source and compiling.

Is IsoSpecPy even supported on Apples ARM chips?

Best, Manuel

MatteoLacki commented 6 months ago

Hi,

I just installed it on Mac with M2 chip (don't have a simulator for M1 though, not even the real thing) and successfully run. Just to be sure: did you install x-tools command line tools with xcode-select install in the terminal? For me, without it the first install failed, albeit because of a different error than yours.

Best,

MKoesters commented 6 months ago

Hi,

I'm also using a Mac with a M2 chip, however the error mentions M1 (I guess its just about the ARM arch). xcode is installed and up to date, I'll assume its a issue of my machine/setup/whatever and try to fix it somehow.

Edit: This is the compile command which is failing:

clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/Headers -arch arm64 -arch x86_64 -Werror=implicit-function-declaration -Wno-error=unreachable-code -I/Users/manuel/.virtualenvs/ursgal2/include -I/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/Headers -c IsoSpec++/python-build.cpp -o build/temp.macosx-10.9-universal2-cpython-39/IsoSpec++/python-build.o -mtune=native -march=native -O3 -std=c++17

-arch is used twice, once with arm64, once with x86_64. If I remove the x86_64 part, it is working. Maybe Rosetta is interfering somehow and wants it as x86?

Best, Manuel

MatteoLacki commented 6 months ago

OK, please send an update if it wokrs I literally just installed these x-tools and pip install in a virtualenv.

Mateusz Krzysztof Łącki

tel. +49 159 01681376

GitHub: MatteoLacki https://github.com/MatteoLacki

On Thu, Feb 22, 2024 at 12:19 PM Manuel @.***> wrote:

Hi,

I'm also using a Mac with a M2 chip, however the error mentions M1 (I guess its just about the ARM arch). xcode is installed and up to date, I'll assume its a issue of my machine/setup/whatever and try to fix it somehow.

Best, Manuel

— Reply to this email directly, view it on GitHub https://github.com/MatteoLacki/IsoSpec/issues/52#issuecomment-1959240865, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA6H2AA6TZ5RMMYO7QDO52TYU4SUFAVCNFSM6AAAAABDPQBDWSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNJZGI2DAOBWGU . You are receiving this because you commented.Message ID: @.***>

michalsta commented 6 months ago

Okay, it definitely looks like some sort of compiler misconfiguration. We definitely didn't code the build system to deal with Rosetta, so that'll probably need to be fixed. But: what exactly are you trying to achieve, that is what's the use-case here? Are you trying to compile it natively on Apple silicon (which should work BTW) and Rosetta (apparently) is getting in the way, or are you trying to produce something that can work inside Rosetta?

MKoesters commented 6 months ago

I'm simply trying to install IsoSpecPy via pip (and via setup.py after cloning this repo) Both resulted in the same error. Here is the full code I'm running

mkvirtualenv IsoSpecPy --python 3.9
pip install isospecpy # (or pip install . for the source code)
Collecting isospecpy
  Using cached IsoSpecPy-2.2.1.tar.gz (2.2 MB)
  Preparing metadata (setup.py) ... done
Collecting cffi (from isospecpy)
  Using cached cffi-1.16.0-cp39-cp39-macosx_11_0_arm64.whl.metadata (1.5 kB)
Collecting pycparser (from cffi->isospecpy)
  Using cached pycparser-2.21-py2.py3-none-any.whl (118 kB)
Using cached cffi-1.16.0-cp39-cp39-macosx_11_0_arm64.whl (176 kB)
Building wheels for collected packages: isospecpy
  Building wheel for isospecpy (setup.py) ... error
  error: subprocess-exited-with-error

  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [29 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.macosx-10.9-universal2-cpython-39
      creating build/lib.macosx-10.9-universal2-cpython-39/IsoSpecPy
      copying IsoSpecPy/Formulas.py -> build/lib.macosx-10.9-universal2-cpython-39/IsoSpecPy
      copying IsoSpecPy/Advanced.py -> build/lib.macosx-10.9-universal2-cpython-39/IsoSpecPy
      copying IsoSpecPy/PeriodicTbl.py -> build/lib.macosx-10.9-universal2-cpython-39/IsoSpecPy
      copying IsoSpecPy/confs_passthrough.py -> build/lib.macosx-10.9-universal2-cpython-39/IsoSpecPy
      copying IsoSpecPy/IsoSpecPyOld.py -> build/lib.macosx-10.9-universal2-cpython-39/IsoSpecPy
      copying IsoSpecPy/__init__.py -> build/lib.macosx-10.9-universal2-cpython-39/IsoSpecPy
      copying IsoSpecPy/IsoSpecPy.py -> build/lib.macosx-10.9-universal2-cpython-39/IsoSpecPy
      copying IsoSpecPy/Distributions.py -> build/lib.macosx-10.9-universal2-cpython-39/IsoSpecPy
      copying IsoSpecPy/isoFFI.py -> build/lib.macosx-10.9-universal2-cpython-39/IsoSpecPy
      copying IsoSpecPy/approximations.py -> build/lib.macosx-10.9-universal2-cpython-39/IsoSpecPy
      running build_ext
      Check flags: True []
      Check flags: True ['-mtune=native']
      Check flags: True ['-mtune=native', '-march=native']
      Check flags: True ['-mtune=native', '-march=native', '-O3']
      Check flags: True ['-mtune=native', '-march=native', '-O3', '-std=c++17']
      building 'IsoSpecCppPy' extension
      creating build/temp.macosx-10.9-universal2-cpython-39
      creating build/temp.macosx-10.9-universal2-cpython-39/IsoSpec++
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/Headers -arch arm64 -arch x86_64 -Werror=implicit-function-declaration -Wno-error=unreachable-code -I/Users/manuel/.virtualenvs/IsoSpecPy/include -I/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.9/Headers -c IsoSpec++/python-build.cpp -o build/temp.macosx-10.9-universal2-cpython-39/IsoSpec++/python-build.o -mtune=native -march=native -O3 -std=c++17
      error: unknown target CPU 'apple-m1'
      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, rocketlake, 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
      error: command '/usr/bin/clang' failed with exit code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for isospecpy
  Running setup.py clean for isospecpy
Failed to build isospecpy
ERROR: Could not build wheels for isospecpy, which is required to install pyproject.toml-based projects

[notice] A new release of pip is available: 23.3.2 -> 24.0
[notice] To update, run: pip install --upgrade pip
MatteoLacki commented 6 months ago

Maybe the version of python you have is not for ARM but x86 and that is why rosetta kicks in?

MKoesters commented 6 months ago

Maybe the version of python you have is not for ARM but x86 and that is why rosetta kicks in?

Guess its both

(IsoSpecPy) ➜  ~ file `which python`
/Users/manuel/.virtualenvs/IsoSpecPy/bin/python: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64:Mach-O 64-bit executable arm64]
/Users/manuel/.virtualenvs/IsoSpecPy/bin/python (for architecture x86_64):  Mach-O 64-bit executable x86_64
/Users/manuel/.virtualenvs/IsoSpecPy/bin/python (for architecture arm64):   Mach-O 64-bit executable arm64

I'll see when I have time to fix this, when I'll do, I'll make sure to post the fix and the reasons why this happened to me

MatteoLacki commented 6 months ago

On my wife's mac:

@.*** ~ % file which python3 /opt/homebrew/bin/python3: Mach-O 64-bit executable arm64

best,

Mateusz Krzysztof Łącki

tel. +49 159 01681376

GitHub: MatteoLacki https://github.com/MatteoLacki

On Fri, Feb 23, 2024 at 7:11 PM Manuel @.***> wrote:

Maybe the version of python you have is not for ARM but x86 and that is why rosetta kicks in?

Guess its both

(IsoSpecPy) ➜ ~ file which python /Users/manuel/.virtualenvs/IsoSpecPy/bin/python: Mach-O universal binary with 2 architectures: [x86_64:Mach-O 64-bit executable x86_64] [arm64:Mach-O 64-bit executable arm64] /Users/manuel/.virtualenvs/IsoSpecPy/bin/python (for architecture x86_64): Mach-O 64-bit executable x86_64 /Users/manuel/.virtualenvs/IsoSpecPy/bin/python (for architecture arm64): Mach-O 64-bit executable arm64

I'll see when I have time to fix this, when I'll do, I'll make sure to post the fix and the reasons why this happened to me

— Reply to this email directly, view it on GitHub https://github.com/MatteoLacki/IsoSpec/issues/52#issuecomment-1961778380, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA6H2ACWMNXJ4EZZBM3QK2TYVDLUPAVCNFSM6AAAAABDPQBDWSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRRG43TQMZYGA . You are receiving this because you commented.Message ID: @.***>

michalsta commented 6 months ago

OK, I think I see what's going on now: the build system is trying to produce a multiarch binary, and the march/mtune=native messes up the cross-compilation for x86. I've removed these flags on MacOS: well, it's not exactly a server system so squeezing every last bit of performance isn't as important there.

Can you try checking out the current version2_2 branch, and seeing if it works now?

MKoesters commented 6 months ago

OK, I think I see what's going on now: the build system is trying to produce a multiarch binary, and the march/mtune=native messes up the cross-compilation for x86. I've removed these flags on MacOS: well, it's not exactly a server system so squeezing every last bit of performance isn't as important there.

Can you try checking out the current version2_2 branch, and seeing if it works now?

Yes, that branch works without any problems. Thanks for the quick fix :)