Skip to content

Commit

Permalink
Cache Terra/Aer wheel files in the CI (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
manoelmarques authored Apr 25, 2022
1 parent 15155ce commit 6ff781e
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 9 deletions.
109 changes: 100 additions & 9 deletions .github/actions/install-main-dependencies/action.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This code is part of Qiskit.
#
# (C) Copyright IBM 2021.
# (C) Copyright IBM 2021, 2022.
#
# This code is licensed under the Apache License, Version 2.0. You may
# obtain a copy of this license in the LICENSE.txt file in the root directory
Expand All @@ -16,25 +16,116 @@ inputs:
os:
description: 'OS'
required: true
python-version:
description: 'Python version'
required: true
runs:
using: "composite"
steps:
- name: Install Dependencies from Main
- name: Get main last commit ids
run: |
echo "TERRA_HASH=$(git ls-remote --heads https://github.com/Qiskit/qiskit-terra.git refs/heads/main | awk '{print $1}')" >> $GITHUB_ENV
echo "AER_HASH=$(git ls-remote --heads https://github.com/Qiskit/qiskit-aer.git refs/heads/main | awk '{print $1}')" >> $GITHUB_ENV
shell: bash
- name: Terra Cache
env:
CACHE_VERSION: v1
id: terra-cache
uses: actions/cache@v3
with:
path: terra-cache
key: terra-cache-${{ inputs.os }}-${{ inputs.python-version }}-${{ env.TERRA_HASH }}-${{ env.CACHE_VERSION }}
- name: Aer Cache
env:
CACHE_VERSION: v1
id: aer-cache
uses: actions/cache@v3
with:
path: aer-cache
key: aer-cache-${{ inputs.os }}-${{ inputs.python-version }}-${{ env.AER_HASH }}-${{ env.CACHE_VERSION }}
- name: Install Terra from Main
env:
MACOSX_DEPLOYMENT_TARGET: 10.9
run: |
echo 'Install Terra from Main'
BASE_DIR=terra-cache
build_from_main=true
cache_hit=${{ steps.terra-cache.outputs.cache-hit }}
echo "cache hit: ${cache_hit}"
if [ "$cache_hit" == "true" ]; then
pip_result=0
pushd "${BASE_DIR}"
python -m pip install *.whl && pip_result=$? || pip_result=$?
popd
if [ $pip_result == 0 ]; then
build_from_main=false
fi
else
mkdir -p ${BASE_DIR}
fi
if [ "$build_from_main" == "true" ]; then
echo 'Create wheel file from main'
pip install -U wheel setuptools_rust
git clone --depth 1 --branch main https://github.com/Qiskit/qiskit-terra.git /tmp/qiskit-terra
pushd /tmp/qiskit-terra
python setup.py bdist_wheel
popd
cp -rf /tmp/qiskit-terra/dist/*.whl "${BASE_DIR}"
pushd "${BASE_DIR}"
python -m pip install *.whl
popd
fi
shell: bash
- name: Install Aer from Main
env:
MACOSX_DEPLOYMENT_TARGET: 10.16
run: |
pip install git+https://github.com/Qiskit/qiskit-terra
echo 'Install Aer from Main'
if [ "${{ inputs.os }}" == "ubuntu-latest" ]; then
export DISABLE_CONAN=1
sudo apt-get -y install nlohmann-json3-dev
sudo apt-get -y install libspdlog-dev
sudo apt-get -y install libmuparserx-dev
fi
if [ "${{ inputs.os }}" == "windows-2019" ]; then
git clone https://github.com/Qiskit/qiskit-aer.git /tmp/qiskit-aer
pushd /tmp/qiskit-aer
python setup.py bdist_wheel -- -G 'Visual Studio 16 2019'
pip install --find-links=dist qiskit-aer
git clone --depth 1 --branch main https://github.com/Qiskit/qiskit-aer.git /tmp/qiskit-aer
BASE_DIR=aer-cache
build_from_main=true
cache_hit=${{ steps.aer-cache.outputs.cache-hit }}
echo "cache hit: ${cache_hit}"
if [ "$cache_hit" == "true" ]; then
pip_result=0
pushd "${BASE_DIR}"
python -m pip install *.whl && pip_result=$? || pip_result=$?
popd
if [ $pip_result == 0 ]; then
echo 'Verifying cached Aer with tools/verify_wheels.py ...'
verify_result=0
pushd /tmp/qiskit-aer
python tools/verify_wheels.py && verify_result=$? || verify_result=$?
popd
if [ $verify_result == 0 ]; then
echo 'Cached Aer passed verification.'
build_from_main=false
else
echo 'Cached Aer failed verification.'
fi
fi
else
pip install git+https://github.com/Qiskit/qiskit-aer
mkdir -p ${BASE_DIR}
fi
if [ "$build_from_main" == "true" ]; then
echo 'Create wheel file from main'
pip install -U wheel
pushd /tmp/qiskit-aer
if [ "${{ inputs.os }}" == "windows-2019" ]; then
python setup.py bdist_wheel -- -G 'Visual Studio 16 2019'
else
python setup.py bdist_wheel
fi
popd
cp -rf /tmp/qiskit-aer/dist/*.whl "${BASE_DIR}"
pushd "${BASE_DIR}"
python -m pip install *.whl
popd
fi
shell: bash
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
- uses: ./.github/actions/install-main-dependencies
with:
os: ${{ matrix.os }}
python-version: ${{ matrix.python-version }}
if: ${{ !startsWith(github.ref, 'refs/heads/stable') && !startsWith(github.base_ref, 'stable/') }}
- uses: ./.github/actions/install-machine-learning
- name: Install Dependencies
Expand Down Expand Up @@ -123,6 +124,7 @@ jobs:
- uses: ./.github/actions/install-main-dependencies
with:
os: ${{ matrix.os }}
python-version: ${{ matrix.python-version }}
if: ${{ !startsWith(github.ref, 'refs/heads/stable') && !startsWith(github.base_ref, 'stable/') }}
- uses: ./.github/actions/install-machine-learning
- run: make lint
Expand Down Expand Up @@ -184,6 +186,7 @@ jobs:
- uses: ./.github/actions/install-main-dependencies
with:
os: ${{ matrix.os }}
python-version: ${{ matrix.python-version }}
if: ${{ !startsWith(github.ref, 'refs/heads/stable') && !startsWith(github.base_ref, 'stable/') }}
- uses: ./.github/actions/install-machine-learning
- name: Install Dependencies
Expand Down

0 comments on commit 6ff781e

Please sign in to comment.