boschmitt / tweedledum

C++17 Library for analysis, compilation/synthesis, and optimization of quantum circuits
MIT License
97 stars 36 forks source link

Import tweedledum failing on MacOS #159

Open Arihant-Joshi opened 3 years ago

Arihant-Joshi commented 3 years ago

Describe the bug

Whenever I'm trying to import something from the tweedledum module, it throws an ImportError. e.g. from tweedledum.classical import simulate or import tweedledum fail with the following stacktrace-

>>> from tweedledum.classical import simulate
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/arihant/opt/anaconda3/envs/qiskit/lib/python3.8/site-packages/tweedledum/__init__.py", line 5, in <module>
    from ._tweedledum import *
ImportError: dlopen(/Users/arihant/opt/anaconda3/envs/qiskit/lib/python3.8/site-packages/tweedledum/_tweedledum.cpython-38-darwin.so, 2): Symbol not found: _aligned_alloc
  Referenced from: /Users/arihant/opt/anaconda3/envs/qiskit/lib/python3.8/site-packages/tweedledum/_tweedledum.cpython-38-darwin.so
  Expected in: /usr/lib/libSystem.B.dylib
 in /Users/arihant/opt/anaconda3/envs/qiskit/lib/python3.8/site-packages/tweedledum/_tweedledum.cpython-38-darwin.so

Expected behavior

The libraries get imported.

Information

Additional context

I'm running it from a conda environment - conda 4.10.1.(which I have tried re-installing to try fixing this)

EDIT: The same works on my windows machine, so might be a MacOS specific issue.

eileen-kuehn commented 3 years ago

Same here, MacOS 10.14.5, Apple LLVM version 10.0.1 (clang-1001.0.46.4). Tested with pip install tweedledum for Python 3.8.11 in a clean venv setup and Python 3.7.9. I also failed to install tweedledum==1.1.0 via pip install tweedledum==1.1.0 --no-binary tweedledum. Installation of version 1.0.0 seems to work fine.

epelofske65537 commented 3 years ago

pip install tweedledum==1.0.0 fixed the problem for me

boschmitt commented 3 years ago

Seems like the problem is that I'm building on MacOS 10.15 (Catalina), and using the MacOS 10.9 SDK while building. Furthermore, I'm using GCC 10 while linking against libstdc++, which Apples seems to discourage in favor of libc++.

There might be some problem with my CI build script, I will try to fix it. Unfortunately, I don't have means to test a possible solution on my side.

mtreinish commented 3 years ago

@boschmitt one way we can test this is to have the ci job on the fix PR and upload the wheel to artifacts and then ask @eileen-kuehn or @Arihant-Joshi (or any other users experiencing the issue) to test that wheel file locally. That's what I normally do in these situations where there are platform specific issues and I don't have access to the platform.

boschmitt commented 3 years ago

@boschmitt one way we can test this is to have the ci job on the fix PR and upload the wheel to artifacts and then ask @eileen-kuehn or @Arihant-Joshi (or any other users experiencing the issue) to test that wheel file locally. That's what I normally do in these situations where there are platform specific issues and I don't have access to the platform.

Thanks @mtreinish! I was planning on trying fixes on tweedledum-dev, having them test it, and then do a patch to the main package. However, now I realized that I actually have access to some old mac computers. I just didn't had the time to get them to debug this problem. On the CI it's passing all tests, which I believe might be because it have homebrew gcc installed.

eileen-kuehn commented 3 years ago

@boschmitt, I am happy to do some tests for you as soon as you let me know :)

cacosomoza commented 3 years ago

Hi all, I've been facing the same issue on High Sierra 10.13.6 and conda 4.10.3. Unfortunately downgrading to tweedledum 1.0.0 didn't do the trick for me:

ImportError: dlopen(/Users/Caco/anaconda3/envs/NEW_QISKIT/lib/python3.8/site-packages/tweedledum/_tweedledum.cpython-38-darwin.so, 2): Symbol not found: _aligned_alloc Referenced from: /Users/Caco/anaconda3/envs/NEW_QISKIT/lib/python3.8/site-packages/tweedledum/_tweedledum.cpython-38-darwin.so Expected in: /usr/lib/libSystem.B.dylib in /Users/Caco/anaconda3/envs/NEW_QISKIT/lib/python3.8/site-packages/tweedledum/_tweedledum.cpython-38-darwin.so

boschmitt commented 3 years ago

@boschmitt, I am happy to do some tests for you as soon as you let me know :)

Hi @eileen-kuehn, Thanks. Could you try installing tweedledum-dev and see if it works. (You will need to uninstall tweedledum or install it in a new env)

eileen-kuehn commented 3 years ago

@boschmitt, the tweedledum-dev package is working great for me šŸ‘ I cannot see any issues anymore.

boschmitt commented 3 years ago

After much thought, I decided to drop support for macOS High Sierra (10.13) and macOS Mojave (10.14). From now on, I will support both systems on a best-effort basis. Meaning that some I won't build wheels for all releases. The reason is simple: I was not able to successfully build these wheels using a GitHub workflow.

The workaround is to install tweedledum directly from source:

CC=gcc-10 CXX=g++-10 CXXFLAGS="-static-libgcc -static-libstdc++" pip install tweedledum --no-binary :all:

Note that this requires a gcc that has been build for the specific macOS you are using. (This should work with any version with C++17 support, but I only tested with gcc10 and gcc11.) Indeed, the CI box has various gcc versions installed, but they were all built for macOS 10.15. Currently, even if I set the deployment target to be 10.9 (or 10.13) and statically link against standard libraries, the compiler/linker still assumes that the aligned_alloc function will be provided by some other library.

eileen-kuehn commented 3 years ago

The workaround is to install tweedledum directly from source:

CC=gcc-10 CXX=g++-10 CXXFLAGS="-static-libgcc -static-libstdc++" pip install tweedledum --no-binary :all:

In my case, the workaround is perfectly fine šŸ‘ and I am happy to install tweedledum like this. Thanks a lot for your efforts!