Skip to content

Add DisCoCirc extension to lambeq #297

Add DisCoCirc extension to lambeq

Add DisCoCirc extension to lambeq #297

Workflow file for this run

name: Build, lint and test package
on:
push:
branches:
- 'main'
- 'beta'
- 'release'
pull_request:
workflow_dispatch:
env:
SRC_DIR: lambeq
TEST_DIR: tests
jobs:
lint:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.10", "3.11", "3.12" ]
outputs:
error-check: ${{ steps.error-check.conclusion }}
steps:
- uses: actions/checkout@v3
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install linter
run: python -m pip install flake8 flake8-broken-line flake8-bugbear flake8-copyright flake8-import-order flake8-quotes
- name: Check for errors
id: error-check
run:
# stop the build if there are Python syntax errors or undefined names
flake8 ${{ env.SRC_DIR }} --count --isolated --select=E9,F63,F7,F82 --show-source --statistics
- name: Lint with flake8
run:
# max-doc-length should be 72 but the copyright notice is too wide for that, so we only error on >74 characters
flake8 ${{ env.SRC_DIR }} --max-doc-length=74
- name: Check doc line lengths and complexity
run:
# exit-zero treats all errors as warnings
flake8 ${{ env.SRC_DIR }} --count --exit-zero --isolated --max-complexity=10 --max-doc-length=72 --select=C901,W505 --statistics
build_and_test:
needs: lint
if: ${{ always() && needs.lint.outputs.error-check == 'success' }}
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.10", "3.11", "3.12" ]
steps:
- uses: actions/checkout@v3
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install base package
run: pip install .
- name: Check package import works
run: python -c 'import lambeq'
- name: Install extra dependencies and tester
run: pip install .[extras] .[test]
- name: Locate bobcat pre-trained model cache
id: loc-bobcat-cache
run: echo "dir=$(python -c 'from lambeq.text2diagram.model_downloader import ModelDownloader; print(ModelDownloader("bert").model_dir)')" >> $GITHUB_OUTPUT
- name: Restore bobcat pre-trained model from cache
id: bobcat-cache
uses: actions/cache@v2
with:
path: ${{ steps.loc-bobcat-cache.outputs.dir }}
key: bobcat-bert-v1
- name: Test with pytest
run: >
coverage run --source=${{ env.SRC_DIR }}
--module pytest -vvv ${{ env.TEST_DIR }}
--durations=50
--ignore=${{ env.TEST_DIR }}/text2diagram/test_depccg_parser.py
--ignore=${{ env.TEST_DIR }}/training/test_torchquantum_model.py
- name: Coverage report
run: coverage report -m
type_check:
needs: lint
if: ${{ always() && needs.lint.outputs.error-check == 'success' }}
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.10", "3.11", "3.12" ]
steps:
- uses: actions/checkout@v3
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies with type hints
run: python -m pip install "numpy<2.0" "matplotlib>=3.8" pytket spacy torch types-PyYAML types-Pillow ipython types-networkx
- name: Install type checker
run: python -m pip install mypy
- name: Type check with mypy
run: mypy ${{ env.SRC_DIR }} --exclude ${{ env.SRC_DIR }}/experimental/
- name: View strict type errors
continue-on-error: true # this is expected to fail but the job should still succeed
run: mypy --strict ${{ env.SRC_DIR }}