Skip to content

Commit

Permalink
Add CI jobs to cross-build arm64 macOS wheels (#1362)
Browse files Browse the repository at this point in the history
This PR adds CI jobs to build qiskit-aer wheels on arm64 macOS wheels. Since no CI system provides native arm64
macOS environments these CI jobs are configured to cross compile arm64 binaries from an x86_64 macOS
environment. This has the limitation of not letting us execute the binaries but we can at least test building them in
PR CI and publish the built binaries at release time. The two jobs added here do just that, the first is run as part
of the Build workflow that runs on every proposed commit to test that we can at least compile on arm64 macOS
(for supported python versions). The second job is a release publishing job that will build and publish arm64
macOS wheels to PyPI whenever there is a release.

Fixes #1286
Fixes #1397
  • Loading branch information
mtreinish authored and hhorii committed Feb 9, 2022
1 parent ed72099 commit 2eb6bb6
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 18 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,24 @@ jobs:
- uses: actions/upload-artifact@v2
with:
path: ./wheelhouse/*.whl
wheel-arm64:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: ["macOS-latest"]
steps:
- uses: actions/checkout@v2
- name: Set up Python Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install deps
run: python -m pip install -U cibuildwheel==2.1.2
- name: Build Wheels
env:
CIBW_SKIP: "cp310-* pp*"
CIBW_ARCHS_MACOS: arm64
run: cibuildwheel --output-dir wheelhouse
- uses: actions/upload-artifact@v2
with:
path: ./wheelhouse/*.whl
27 changes: 27 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,33 @@ jobs:
env:
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
TWINE_USERNAME: qiskit
wheel-arm64-macos:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: ["macOS-latest"]
steps:
- uses: actions/checkout@v2
- name: Set up Python Python 3.8
uses: actions/setup-python@v2
with:
python-version: 3.8
- name: Install deps
run: python -m pip install -U cibuildwheel==2.1.2 twine
- name: Build Wheels
env:
CIBW_SKIP: "cp310-* pp*"
CIBW_ARCHS_MACOS: arm64
run: cibuildwheel --output-dir wheelhouse
- uses: actions/upload-artifact@v2
with:
path: ./wheelhouse/*.whl
- name: Upload to PyPI
run: twine upload ./wheelhouse/*.whl
env:
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
TWINE_USERNAME: qiskit
sdist:
name: Publish qiskit-aer sdist
runs-on: ubuntu-latest
Expand Down
18 changes: 11 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,11 @@ endif()
message(STATUS "BLAS library found: ${BLAS_LIBRARIES}")

if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64")
if(APPLE OR UNIX)
set(SIMD_FLAGS_LIST "-mfma;-mavx2")
enable_cxx_compiler_flag_if_supported("-mpopcnt")
if(APPLE OR UNIX)
if (NOT CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
set(SIMD_FLAGS_LIST "-mfma;-mavx2")
enable_cxx_compiler_flag_if_supported("-mpopcnt")
endif()
elseif(MSVC)
set(SIMD_FLAGS_LIST "/arch:AVX2")
endif()
Expand Down Expand Up @@ -321,10 +323,12 @@ if(SKBUILD) # Terra Addon build
add_subdirectory(src/open_pulse)
else() # Standalone build

if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64")
# We build SIMD filed separately, because they will be reached only if the
# machine running the code has SIMD support
set(SIMD_SOURCE_FILE "${PROJECT_SOURCE_DIR}/src/simulators/statevector/qv_avx2.cpp")
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64")
if (NOT CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
# We build SIMD filed separately, because they will be reached only if the
# machine running the code has SIMD support
set(SIMD_SOURCE_FILE "${PROJECT_SOURCE_DIR}/src/simulators/statevector/qv_avx2.cpp")
endif()
endif()

set(AER_SIMULATOR_SOURCES "${PROJECT_SOURCE_DIR}/contrib/standalone/qasm_simulator.cpp")
Expand Down
27 changes: 19 additions & 8 deletions cmake/conan_utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,25 @@ macro(setup_conan)
set(REQUIREMENTS ${REQUIREMENTS} catch2/2.13.6)
list(APPEND AER_CONAN_LIBS catch2)
endif()

conan_cmake_run(REQUIRES ${REQUIREMENTS}
OPTIONS ${CONAN_OPTIONS}
ENV CONAN_CMAKE_PROGRAM=${CMAKE_COMMAND}
BASIC_SETUP
CMAKE_TARGETS
KEEP_RPATHS
BUILD missing)
if (CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
conan_cmake_run(REQUIRES ${REQUIREMENTS}
OPTIONS ${CONAN_OPTIONS}
ENV CONAN_CMAKE_PROGRAM=${CMAKE_COMMAND}
BASIC_SETUP
CMAKE_TARGETS
KEEP_RPATHS
ARCH armv8
SETTINGS arch_build=armv8
BUILD missing)
else()
conan_cmake_run(REQUIRES ${REQUIREMENTS}
OPTIONS ${CONAN_OPTIONS}
ENV CONAN_CMAKE_PROGRAM=${CMAKE_COMMAND}
BASIC_SETUP
CMAKE_TARGETS
KEEP_RPATHS
BUILD missing)
endif()

# Headers includes
if(AER_THRUST_BACKEND AND NOT AER_THRUST_BACKEND STREQUAL "CUDA")
Expand Down
8 changes: 5 additions & 3 deletions qiskit/providers/aer/backends/wrappers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ find_package(Pybind11 REQUIRED)
string(REPLACE " -static " "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")

if(CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "x86_64" OR CMAKE_HOST_SYSTEM_PROCESSOR STREQUAL "AMD64")
# We build SIMD filed separately, because they will be reached only if the
# machine running the code has SIMD support
set(SIMD_SOURCE_FILE "../../../../../src/simulators/statevector/qv_avx2.cpp")
if (NOT CMAKE_OSX_ARCHITECTURES STREQUAL "arm64")
# We build SIMD filed separately, because they will be reached only if the
# machine running the code has SIMD support
set(SIMD_SOURCE_FILE "${PROJECT_SOURCE_DIR}/src/simulators/statevector/qv_avx2.cpp")
endif()
endif()

set(AER_SIMULATOR_SOURCES "bindings.cc" "${SIMD_SOURCE_FILE}")
Expand Down
6 changes: 6 additions & 0 deletions releasenotes/notes/arm64-macos-wheels-3778e83a8d036168.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
features:
- |
Added support for M1 macOS systems. Precompiled binaries for supported
Python versions >=3.8 on arm64 macOS will now be published on PyPI for this
and future releases.

0 comments on commit 2eb6bb6

Please sign in to comment.