tweedledum icon indicating copy to clipboard operation
tweedledum copied to clipboard

Import tweedledum failing on MacOS

Open Arihant-Joshi opened this issue 3 years ago • 11 comments

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

  • tweedledum version: 1.1.0
  • Python version: 3.8.10
  • Operating system: MacOS Mojave Version 10.14.6 (18G8022)

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.

Arihant-Joshi avatar Aug 04 '21 07:08 Arihant-Joshi

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.

eileen-kuehn avatar Aug 04 '21 13:08 eileen-kuehn

pip install tweedledum==1.0.0 fixed the problem for me

epelofske65537 avatar Aug 15 '21 01:08 epelofske65537

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.

boschmitt avatar Aug 23 '21 15:08 boschmitt

@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.

mtreinish avatar Aug 24 '21 14:08 mtreinish

@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.

boschmitt avatar Aug 25 '21 19:08 boschmitt

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

eileen-kuehn avatar Aug 30 '21 11:08 eileen-kuehn

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

cacosomoza avatar Sep 01 '21 16:09 cacosomoza

@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)

boschmitt avatar Sep 06 '21 09:09 boschmitt

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

eileen-kuehn avatar Sep 06 '21 12:09 eileen-kuehn

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.

boschmitt avatar Sep 08 '21 17:09 boschmitt

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!

eileen-kuehn avatar Sep 08 '21 18:09 eileen-kuehn