qiskit-aer: Unable to compile a statically linked wheel

Please apologize the length of this bug report in advance, but I am trying to provide as much information as possible.

Informations

  • Qiskit Aer version: master
  • Python version: 3.6.9
  • Operating system: uname -a provides:
Linux qt00 4.15.0-112-generic #113-Ubuntu SMP Thu Jul 9 23:41:39 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

To provide some context: I am trying to compile Aer from source on a compute server to allow multiple users to access the same master-branch installation from a centrally managed virtualenv. While doing so I ran into the problem of not being able to produce a correctly statically linked wheel. Specifically this means that I log in onto a login node, create a virtualenv there and expect all computations on the respective compute nodes to work normally.

I am using the following Python script for testing:

import sys
print(sys.version)
from qiskit.providers.aer import Aer
print(Aer)

and the following bash script for testing the execution on the compute nodes:

#!/bin/bash
locate libopenblas.so.0
source ~/path/to/venv/bin/activate
which python
which pip
pip list | grep qiskit
python test.py  # this is the above script

What is the current behavior?

In order to explain the problem at hand I will step through a number of different scenarios and explain the results which I have achieved with each:

A stable installation using pip install qiskit-terra qiskit-aer

Starting from a clean virtualenv and running the above pip installation command everything works fine. On the login node I obtain:

3.6.9 (default, Oct  8 2020, 12:12:24)
[GCC 8.4.0]
/home/a/oss/software/qiskit-stable/venv/lib/python3.6/site-packages/qiskit/__init__.py:75: RuntimeWarning: Could not import the IBMQ provider from the qiskit-ibmq-provider package. Install qiskit-ibmq-provider or check your installation.
  RuntimeWarning)
AerProvider

And on the compute nodes:

/path/to/stable/venv/bin/python
/path/to/stable/venv/bin/pip
qiskit-aer         0.7.0
qiskit-terra       0.16.0
/home/a/oss/software/qiskit-stable/venv/lib/python3.6/site-packages/qiskit/__init__.py:75: RuntimeWarning: Could not import the IBMQ provider from the qiskit-ibmq-provider package. Install qiskit-ibmq-provider or check your installation.
  RuntimeWarning)
3.6.9 (default, Oct  8 2020, 12:12:24)
[GCC 8.4.0]
AerProvider

A master installation using python setup.py bdist_wheel

When trying to compile Aer manually from master everything works as expected on the login node (i.e. same as above) but on the compute node I obtain the following error:

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    from qiskit.providers.aer import Aer
  File "/home/a/oss/software/qiskit-master/venv/lib/python3.6/site-packages/qiskit/providers/aer/__init__.py", line 64, in <module>
    from .aerprovider import AerProvider
  File "/home/a/oss/software/qiskit-master/venv/lib/python3.6/site-packages/qiskit/providers/aer/aerprovider.py", line 20, in <module>
    from .backends.qasm_simulator import QasmSimulator
  File "/home/a/oss/software/qiskit-master/venv/lib/python3.6/site-packages/qiskit/providers/aer/backends/__init__.py", line 17, in <module>
    from .qasm_simulator import QasmSimulator
  File "/home/a/oss/software/qiskit-master/venv/lib/python3.6/site-packages/qiskit/providers/aer/backends/qasm_simulator.py", line 25, in <module>
    from .controller_wrappers import qasm_controller_execute
ImportError: libopenblas.so.0: cannot open shared object file: No such file or directory

This was to be expected as the first line of the bash script (locate libopenblas.so.0) does not return anything which shows that OpenBLAS cannot be found on the compute nodes (while it is available normally on the login node). Having talked to the system administrator, we agreed that it would be best if, thus, we can compile Aer with static linking (as this appears to work with the stable installation using pip install which ships a Python wheel bundled with libopenblas).

Static linking: python setup.py bdist_wheel -- -DSTATIC_LINKING=True

This attempt causes even the installation on the login node to break with the following error:

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    from qiskit.providers.aer import Aer
  File "/home/a/oss/software/qiskit-master/venv/lib/python3.6/site-packages/qiskit/providers/aer/__init__.py", line 64, in <module>
    from .aerprovider import AerProvider
  File "/home/a/oss/software/qiskit-master/venv/lib/python3.6/site-packages/qiskit/providers/aer/aerprovider.py", line 20, in <module>
    from .backends.qasm_simulator import QasmSimulator
  File "/home/a/oss/software/qiskit-master/venv/lib/python3.6/site-packages/qiskit/providers/aer/backends/__init__.py", line 17, in <module>
    from .qasm_simulator import QasmSimulator
  File "/home/a/oss/software/qiskit-master/venv/lib/python3.6/site-packages/qiskit/providers/aer/backends/qasm_simulator.py", line 25, in <module>
    from .controller_wrappers import qasm_controller_execute
ImportError: /home/a/oss/software/qiskit-master/venv/lib/python3.6/site-packages/qiskit/providers/aer/backends/controller_wrappers.cpython-36m-x86_64-linux-gnu.so: undefined symbol: _gfortran_concat_string

Static linking with FindBLAS.cmake.fix-static-linking

I then found out about this patch: https://github.com/Qiskit/qiskit-aer/blob/master/cmake/FindBLAS.cmake.fix-static-linking But after applying that and trying the same -DSTATIC_LINKING=True compilation as above, I still obtain the same error.

Steps to reproduce the problem

The following summarizes the steps necessary to reproduce this issue. However, your mileage may vary as I have tried to reproduce this on my Fedora laptop where I am unable to do so. Both of the last two steps do not result in the problem but I am not sure how to verify that this is because the static linking was successful or whether it falls back to dynamic linking. The Fedora laptop specs are:

$ uname -a
Linux pulsano 5.8.15-201.fc32.x86_64 #1 SMP Thu Oct 15 15:56:44 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
$ python --version
Python 3.6.12  # the same works with Python 3.8.6
$ gcc --version
gcc (GCC) 9.3.0
$ cmake --version
cmake version 3.18.2  # same as on the server
mkdir tmp
cd tmp
python3 -m virtualenv venv
source venv/bin/activate
git clone https://github.com/Qiskit/qiskit-terra.git
cd qiskit-terra
pip install -c constraints.txt -r requirements.txt -r requirements-dev.txt
pip install -e .
cd ..
git clone https://github.com/Qiskit/qiskit-aer.git
cd qiskit-aer
pip install -c constraints.txt -r requirements-dev.txt
python setup.py bdist_wheel -- -DSTATIC_LINKING=True
cd ..
python
% from qiskit.providers.aer import Aer

What is the expected behavior?

I would expect to be able to compile a statically linked Python wheel of Aer

Suggested solutions

I am at a loss to be honest, which is why I came here 🙂

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (15 by maintainers)

Commits related to this issue

Most upvoted comments

Okay I think I found the solution. The same happened to another user of auditwheel here: https://github.com/pypa/auditwheel/issues/103 As he outlines in the first comment this patch from patchelf (https://github.com/NixOS/patchelf/pull/85) fixes this but the Ubuntu version is still fixed at 0.9 (prior to that PR).

I will compile patchelf from source and try again. Should this finally work I will close this issue without further comment. Please excuse the excessive commenting/spamming in the past hour…