quantumlib / Stim

A fast stabilizer circuit library.
Apache License 2.0
336 stars 97 forks source link

Fails to build Python API on aarch64 platform #294

Open steve-jeffrey opened 2 years ago

steve-jeffrey commented 2 years ago

What happened?

Building the Python API failed because the sse2 and avx2 extensions are not relevant in the aarch64 environment.

How to reproduce the issue

git clone https://github.com/quantumlib/Stim.git
cd Stim/
cmake .
make stim
python -m venv stim_env 3.8
. ./stim_env/bin/activate
pip install --upgrade pip pybind11 pytest
python setup.py bdist

Relevant log output

running bdist
running bdist_dumb
running build
running build_py
creating python_build_stim
creating python_build_stim/lib.linux-aarch64-3.8
creating python_build_stim/lib.linux-aarch64-3.8/stim
copying glue/python/src/stim/_main_argv.py -> python_build_stim/lib.linux-aarch64-3.8/stim
copying glue/python/src/stim/__init__.py -> python_build_stim/lib.linux-aarch64-3.8/stim
running egg_info
creating stim.egg-info
writing stim.egg-info/PKG-INFO
writing dependency_links to stim.egg-info/dependency_links.txt
writing entry points to stim.egg-info/entry_points.txt
writing requirements to stim.egg-info/requires.txt
writing top-level names to stim.egg-info/top_level.txt
writing manifest file 'stim.egg-info/SOURCES.txt'
reading manifest file 'stim.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'stim.egg-info/SOURCES.txt'
copying glue/python/src/stim/__init__.pyi -> python_build_stim/lib.linux-aarch64-3.8/stim
running build_ext
building 'stim._detect_machine_architecture' extension
creating python_build_stim/temp.linux-aarch64-3.8
creating python_build_stim/temp.linux-aarch64-3.8/src
creating python_build_stim/temp.linux-aarch64-3.8/src/stim
creating python_build_stim/temp.linux-aarch64-3.8/src/stim/py
aarch64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I<site-packages>/pybind11/include -Isrc -I./stim_env/include -I/usr/include/python3.8 -c src/stim/py/march.pybind.cc -o python_build_stim/temp.linux-aarch64-3.8/src/stim/py/march.pybind.o -std=c++11 -fno-strict-aliasing -O3 -g0 -DVERSION_INFO=1.10.dev0 -mno-sse2 -mno-avx2
aarch64-linux-gnu-gcc: error: unrecognized command line option ‘-mno-sse2’
aarch64-linux-gnu-gcc: error: unrecognized command line option ‘-mno-avx2’
error: command 'aarch64-linux-gnu-gcc' failed with exit status 1

Other information If the sse2 and avx2 sections in setup.py are removed, the API build successfully and all tests pass.

To remove those sections, apply the attached setup.py_patch.txt: patch setup.py setup.py_patch.txt

Environment Stim commit 81142ac

Ubuntu 20.04, GCC 9.4.0, Ampere Altra Max without SSE, SSE2, AVX and AVX2

Note: the issue does not occur in this environment: Fedora 35, GCC 11.3.1, Intel architecture with SSE, SSE2, AVX and AVX2

Strilanc commented 2 years ago

This seems really difficult to fix. The purpose of building the three modules is to allow runtime machine architecture detection, and is necessary in order to distribute binary wheels that work across machines. Removing the -mno-avx2 argument could result in bad wheels.

You might be able to use the bazel dev wheel build as a workaround?

steve-jeffrey commented 1 year ago

Yes, bazel can build the wheel on aarch64:

 bazel build stim_dev_wheel

Are there similar commands for building the cirq, zx and sinter packages using bazel? The developer_documentation.md file provides pip commands for building those packages, but not bazel commands.