iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🪐

Playing with Qiskit (14) — Qiskit Aer GPU Part 2

に公開

Purpose

I want to update Playing with Qiskit (7) — Qiskit Aer GPU as it has become outdated.

Using Docker

This policy remains unchanged. Setting up a build environment is time-consuming, and from the perspective of reproducibility, choosing an environment that gets increasingly cluttered as a build environment is not desirable.

This time, I will attempt a GPU-enabled build of Qiskit Aer 0.12.1 for an Ubuntu 22.04 + Python 3.11 + CUDA 11.8 environment. Although I used FROM nvidia/cuda:11.8.0-devel-ubuntu22.04 below, FROM nvidia/cuda:11.8.0-devel-ubuntu20.04 is also fine.

The build is basically as described in CONTRIBUTING.md. I felt that installing cuQuantum and cuTENSOR from tarballs was easier as it allowed me to determine paths and other settings myself.

Installing Python 3.11 also follows the Python Developer’s Guide. Prepare with Install dependencies and then build. Rather than having an unknown version installed, I prefer to build from source code by specifying the version.

FROM nvidia/cuda:11.8.0-devel-ubuntu22.04

ENV DEBIAN_FRONTEND noninteractive
ENV CUQUANTUM_ROOT /opt/nvidia/cuquantum
ENV CUTENSOR_ROOT=/opt/nvidia/cutensor
ENV LD_LIBRARY_PATH $CUQUANTUM_ROOT/lib/11:$CUTENSOR_ROOT/lib/11:$LD_LIBRARY_PATH

RUN apt-get update && \
    apt-get install -y git wget && \
    cd /opt/nvidia && \
    wget https://developer.download.nvidia.com/compute/cuquantum/redist/cuquantum/linux-x86_64/cuquantum-linux-x86_64-23.03.0.20-archive.tar.xz && \
    tar -xvf cuquantum-linux-x86_64-23.03.0.20-archive.tar.xz && ln -s cuquantum-linux-x86_64-23.03.0.20-archive cuquantum && rm cuquantum-linux-x86_64-23.03.0.20-archive.tar.xz && \
    wget https://developer.download.nvidia.com/compute/cutensor/redist/libcutensor/linux-x86_64/libcutensor-linux-x86_64-1.7.0.1-archive.tar.xz && \
    tar -xvf libcutensor-linux-x86_64-1.7.0.1-archive.tar.xz && ln -s libcutensor-linux-x86_64-1.7.0.1-archive cutensor && rm libcutensor-linux-x86_64-1.7.0.1-archive.tar.xz && \
    cd /
RUN apt install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev wget libbz2-dev && \
    wget https://www.python.org/ftp/python/3.11.4/Python-3.11.4.tgz && \
    tar -xzvf Python-3.11.4.tgz && \
    cd Python-3.11.4 && ./configure --enable-optimizations && \
    make -j 8 && make altinstall && \
    ln -s /usr/local/bin/python3.11 /usr/bin/python && \
    rm -f /usr/bin/python3 && ln -s /usr/local/bin/python3.11 /usr/bin/python3 && \
    rm -f /usr/bin/pip && wget https://bootstrap.pypa.io/get-pip.py && python get-pip.py && \
    ln -s /usr/local/bin/pip /usr/bin/pip
RUN apt install -y cmake && pip install pybind11 pluginbase patch-ng node-semver==0.6.1 bottle PyJWT fasteners distro colorama conan==1.59.0 scikit-build && \
    apt-get install -y libopenblas-dev && \
    pip install "qiskit[all]==0.43.1" && \
    pip uninstall -y qiskit-aer && \
    cd / && git clone https://github.com/Qiskit/qiskit-aer/ && \
    cd qiskit-aer && git checkout 0.12.1 && \
    python ./setup.py bdist_wheel -- -DAER_THRUST_BACKEND=CUDA -DAER_CUDA_ARCH="7.0; 7.5; 8.0" -DCUQUANTUM_ROOT=/opt/nvidia/cuquantum -DCUTENSOR_ROOT=/opt/nvidia/cutensor -DAER_ENABLE_CUQUANTUM=true -DCUQUANTUM_STATIC=true --

WORKDIR /workdir

VOLUME ["/workdir"]

CMD ["bash"]

Basically, this is sufficient.

Do Not Expect Too Much from the Computing Environment

When building a GPU-enabled Qiskit Aer, several dependency libraries are required, and these might not be installed in the computing environment, or the user might not be allowed to install additional libraries. In such cases, you need to have Qiskit Aer bundle the dependency libraries.

This stems from an actual past issue, Unable to compile a statically linked wheel; without OpenBLAS installed in the computing environment, the previously mentioned build will not run. In response to this, Building a statically linked wheel was added to CONTRIBUTING.md, so we will follow that.

Specifically, add the following to the Dockerfile:

RUN pip install auditwheel patchelf && \
    cd qiskit-aer && \
    auditwheel repair --plat linux_x86_64 dist/qiskit_aer*.whl --exclude libva-drm.so.2 --exclude linux-vdso.so.1 --exclude libpthread.so.0 --exclude librt.so.1 --exclude libdl.so.2 --exclude libstdc++.so.6 --exclude libm.so.6 --exclude libgomp.so.1 --exclude libgcc_s.so.1 --exclude libc.so.6 --exclude ld-linux-x86-64.so.2 --exclude libquadmath.so.0

I added several dependency libraries using auditwheel, but I also removed unnecessary ones. I referred to qiskit-aer-gpu 0.11.2 for what to exclude. Using --exclude to remove libraries serves to prevent bundling everything indiscriminately, but it also helps avoid runtime issues. It's likely that bundled libraries might cause version mismatches with the libraries they themselves depend on, and there were cases where the behavior of Qiskit Aer's C++ layer was suspicious. Therefore, I've designed it to dynamically link with the computing environment's libraries by default, while only including the absolutely necessary ones in the wheel.

With this, it should be robust enough to run in various computing environments.

Summary

I have updated the previous article. I also expanded the content regarding execution in a wider range of computing environments.

However, there are of course downsides. Statically linking as much as possible to ensure it works out-of-the-box and including necessary libraries in the wheel means that this wheel becomes quite large. Following the steps above, it will likely exceed 500MB.

GitHubで編集を提案

Discussion