Skip to content

Commit

Permalink
feat(hugr-py): python hugr builder (#1098)
Browse files Browse the repository at this point in the history
First steps of #486

- Uses cli tool to validate.
- Just covers DFG building for now but should be extensible in
principle.
- Op types are declared explicitly, no "inference".
- `Hugr` does some light stable index maintenance, but rewriting is not
prioritised as a use-case.
- Both inline nested graph building and full graph insertion are
expected use cases so are demonstrated.

---------

Co-authored-by: Agustín Borgna <121866228+aborgna-q@users.noreply.github.com>
  • Loading branch information
ss2165 and aborgna-q authored May 31, 2024
1 parent 96cd3e3 commit 23408b5
Show file tree
Hide file tree
Showing 7 changed files with 931 additions and 8 deletions.
69 changes: 65 additions & 4 deletions .github/workflows/ci-py.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ on:

env:
SCCACHE_GHA_ENABLED: "true"
HUGR_BIN_DIR: ${{ github.workspace }}/target/debug
HUGR_BIN: ${{ github.workspace }}/target/debug/hugr

jobs:
# Check if changes were made to the relevant files.
Expand Down Expand Up @@ -68,8 +70,59 @@ jobs:
- name: Lint with ruff
run: poetry run ruff check

build_binary:
needs: changes
if: ${{ needs.changes.outputs.python == 'true' }}

name: Build HUGR binary
runs-on: ubuntu-latest
env:
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"

steps:
- uses: actions/checkout@v4
- uses: mozilla-actions/sccache-action@v0.0.4
- name: Install stable toolchain
uses: dtolnay/rust-toolchain@stable
- name: Build HUGR binary
run: cargo build -p hugr-cli
- name: Upload the binary to the artifacts
uses: actions/upload-artifact@v4
with:
name: hugr_binary
path: target/debug/hugr
test:
needs: [changes, build_binary]
if: ${{ needs.changes.outputs.python == 'true' }}
name: check python ${{ matrix.python-version }}
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ['3.10', '3.12']
steps:
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: "poetry"

- name: Install the project libraries
run: poetry install
- name: Download the hugr binary
uses: actions/download-artifact@v4
with:
name: hugr_binary
path: ${{env.HUGR_BIN_DIR}}

- name: Run tests
run: poetry run pytest
run: |
chmod +x $HUGR_BIN
poetry run pytest
# Ensure that the serialization schema is up to date
serialization-schema:
Expand Down Expand Up @@ -106,7 +159,7 @@ jobs:
# even if they are skipped due to no changes in the relevant files.
required-checks:
name: Required checks 🐍
needs: [changes, check, serialization-schema]
needs: [changes, check, test, serialization-schema]
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
steps:
Expand All @@ -128,7 +181,7 @@ jobs:
echo "All required checks passed"
coverage:
needs: [changes, check]
needs: [changes, test]
# Run only if there are changes in the relevant files and the check job passed or was skipped
if: always() && !failure() && !cancelled() && needs.changes.outputs.python == 'true' && github.event_name != 'merge_group'
runs-on: ubuntu-latest
Expand All @@ -146,9 +199,17 @@ jobs:

- name: Install the project libraries
run: poetry install
- name: Download the hugr binary
uses: actions/download-artifact@v4
with:
name: hugr_binary
path: ${{env.HUGR_BIN_DIR}}


- name: Run python tests with coverage instrumentation
run: poetry run pytest --cov=./ --cov-report=xml
run: |
chmod +x $HUGR_BIN
poetry run pytest --cov=./ --cov-report=xml
- name: Upload python coverage to codecov.io
uses: codecov/codecov-action@v4
Expand Down
Loading

0 comments on commit 23408b5

Please sign in to comment.