Skip to content

Machine Learning Unit Tests #5089

Machine Learning Unit Tests

Machine Learning Unit Tests #5089

Workflow file for this run

# This code is part of a Qiskit project.
#
# (C) Copyright IBM 2021, 2024.
#
# 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
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
#
# Any modifications or derivative works of this code must retain this
# copyright notice, and modified files need to carry a notice indicating
# that they have been altered from the originals.
name: Machine Learning Unit Tests
on:
push:
branches:
- main
- 'stable/**'
pull_request:
branches:
- main
- 'stable/**'
schedule:
# run every day at 1AM
- cron: '0 1 * * *'
concurrency:
group: ${{ github.repository }}-${{ github.ref }}-${{ github.head_ref }}-${{ github.workflow }}
cancel-in-progress: true
jobs:
Checks:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: [3.9]
steps:
- name: Print Concurrency Group
env:
CONCURRENCY_GROUP: ${{ github.repository }}-${{ github.ref }}-${{ github.head_ref }}-${{ github.workflow }}
run: |
echo -e "\033[31;1;4mConcurrency Group\033[0m"
echo -e "$CONCURRENCY_GROUP\n"
shell: bash
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: |
setup.py
requirements.txt
requirements-dev.txt
- uses: ./.github/actions/install-main-dependencies
with:
os: ${{ matrix.os }}
python-version: ${{ matrix.python-version }}
qiskit-main: "false"
if: ${{ !startsWith(github.ref, 'refs/heads/stable') && !startsWith(github.base_ref, 'stable/') }}
- uses: ./.github/actions/install-machine-learning
- name: Install Dependencies
run: |
pip install torchvision
sudo apt-get -y install pandoc graphviz
sudo apt-get -y install python3-enchant
sudo apt-get -y install hunspell-en-us
pip install pyenchant
echo "earliest_version: 0.1.0" >> releasenotes/config.yaml
shell: bash
- run: pip check
if: ${{ !cancelled() }}
shell: bash
- name: Copyright Check
run: |
python tools/check_copyright.py -check
if: ${{ !cancelled() }}
shell: bash
- run: make spell
if: ${{ !cancelled() }}
shell: bash
- name: Style Check
run: |
make clean_sphinx
make style
if: ${{ !cancelled() }}
shell: bash
- name: Run make html
run: |
make clean_sphinx
make html
cd docs/_build/html
mkdir artifacts
tar -zcvf artifacts/documentation.tar.gz --exclude=./artifacts .
if: ${{ !cancelled() }}
shell: bash
- name: Run upload documentation
uses: actions/upload-artifact@v4
with:
name: documentation
path: docs/_build/html/artifacts/documentation.tar.gz
if: ${{ !cancelled() }}
- run: make doctest
if: ${{ !cancelled() }}
shell: bash
MachineLearning:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: [3.9, '3.10', 3.11, 3.12]
include:
# macos-latest is an Arm64 image
- os: macos-latest
python-version: 3.9
- os: macos-latest
python-version: 3.12
- os: windows-latest
python-version: 3.9
- os: windows-latest
python-version: 3.12
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: |
setup.py
requirements.txt
requirements-dev.txt
- 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
shell: bash
- run: make mypy
if: ${{ !cancelled() }}
shell: bash
- name: Machine Learning Unit Tests under Python ${{ matrix.python-version }}
uses: ./.github/actions/run-tests
with:
os: ${{ matrix.os }}
event-name: ${{ github.event_name }}
run-slow: ${{ contains(github.event.pull_request.labels.*.name, 'run_slow') }}
python-version: ${{ matrix.python-version }}
if: ${{ !cancelled() }}
- name: Deprecation Messages
run: |
mkdir ./ci-artifact-data
python tools/extract_deprecation.py -file out.txt -output ./ci-artifact-data/ml.dep
shell: bash
- name: Coverage combine
run: |
coverage3 combine
mv .coverage ./ci-artifact-data/ml.dat
if: ${{ matrix.os == 'ubuntu-latest' && matrix.python-version == 3.9 }}
shell: bash
- uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}-${{ matrix.python-version }}
path: ./ci-artifact-data/*
- name: Machine Learning Unit Tests without torch/sparse under Python ${{ matrix.python-version }}
env:
PYTHONWARNINGS: default
run: |
pip uninstall -y torch sparse
if [ "${{ github.event_name }}" == "schedule" ] || [ "${{ contains(github.event.pull_request.labels.*.name, 'run_slow') }}" == "true" ]; then
export QISKIT_TESTS="run_slow"
fi
stestr --test-path test run
if: ${{ !cancelled() }}
shell: bash
Tutorials:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: [3.9, 3.12]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: |
setup.py
requirements.txt
requirements-dev.txt
- 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
run: |
pip install jupyter
pip install torchvision
sudo apt-get install -y pandoc graphviz
shell: bash
- name: Run Machine Learning Tutorials
env:
QISKIT_PARALLEL: False
QISKIT_DOCS_BUILD_TUTORIALS: 'always'
run: |
echo "earliest_version: 0.1.0" >> releasenotes/config.yaml
make html
cd docs/_build/html
mkdir artifacts
tar -zcvf artifacts/tutorials.tar.gz --exclude=./artifacts .
shell: bash
- name: Run upload tutorials
uses: actions/upload-artifact@v4
with:
name: tutorials${{ matrix.python-version }}
path: docs/_build/html/artifacts/tutorials.tar.gz
# - name: Run stable tutorials
# env:
# QISKIT_PARALLEL: False
# QISKIT_DOCS_BUILD_TUTORIALS: 'always'
# run: |
# # clean last sphinx output
# make clean_sphinx
# # get current version
# version=$(pip show qiskit-machine-learning | awk -F. '/^Version:/ { print substr($1,10), $2-1 }' OFS=.)
# # download stable version
# wget https://codeload.github.com/qiskit-community/qiskit-machine-learning/zip/stable/$version -O /tmp/repo.zip
# unzip /tmp/repo.zip -d /tmp/
# # copy stable tutorials to main tutorials
# cp -R /tmp/qiskit-machine-learning-stable-$version/docs/tutorials/* docs/tutorials
# # run tutorials and zip results
# echo "earliest_version: 0.1.0" >> releasenotes/config.yaml
# # ignore unreleased/untagged notes
# tools/ignore_untagged_notes.sh
# make html
# cd docs/_build/html
# mkdir artifacts
# tar -zcvf artifacts/tutorials.tar.gz --exclude=./artifacts .
# if: ${{ matrix.python-version == 3.9 && !startsWith(github.ref, 'refs/heads/stable') && !startsWith(github.base_ref, 'stable/') }}
# shell: bash
# - name: Run upload stable tutorials
# uses: actions/upload-artifact@v4
# with:
# name: tutorials-stable${{ matrix.python-version }}
# path: docs/_build/html/artifacts/tutorials.tar.gz
# if: ${{ matrix.python-version == 3.9 && !startsWith(github.ref, 'refs/heads/stable') && !startsWith(github.base_ref, 'stable/') }}
Deprecation_Messages_and_Coverage:
needs: [Checks, MachineLearning, Tutorials]
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.9]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- uses: actions/download-artifact@v4
with:
name: ubuntu-latest-3.9
path: /tmp/u39
- uses: actions/download-artifact@v4
with:
name: ubuntu-latest-3.10
path: /tmp/u310
- uses: actions/download-artifact@v4
with:
name: ubuntu-latest-3.11
path: /tmp/u311
- uses: actions/download-artifact@v4
with:
name: ubuntu-latest-3.12
path: /tmp/u312
- uses: actions/download-artifact@v4
with:
name: macos-latest-3.9
path: /tmp/m39
- uses: actions/download-artifact@v4
with:
name: macos-latest-3.12
path: /tmp/m312
- uses: actions/download-artifact@v4
with:
name: windows-latest-3.9
path: /tmp/w39
- uses: actions/download-artifact@v4
with:
name: windows-latest-3.12
path: /tmp/w312
- name: Install Dependencies
run: pip install -U coverage coveralls diff-cover
shell: bash
- name: Combined Deprecation Messages
run: |
sort -f -u /tmp/u39/ml.dep /tmp/u310/ml.dep /tmp/u311/ml.dep /tmp/u312/ml.dep /tmp/m39/ml.dep /tmp/m312/ml.dep /tmp/w39/ml.dep /tmp/w312/ml.dep || true
shell: bash
- name: Coverage combine
run: coverage3 combine /tmp/u39/ml.dat
shell: bash
- name: Upload to Coveralls
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: coveralls --service=github
shell: bash