-
Notifications
You must be signed in to change notification settings - Fork 4
chore: move to justfile for test hugr generation #308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
25cbb85
a947ba3
6c79a36
a5d877d
a631ea3
6ea6a7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # List the available commands | ||
| help: | ||
| @just --list --justfile {{justfile()}} | ||
|
|
||
| # Run basic formatting, linting and typechecking | ||
| qfmt: | ||
| echo -e "Running formatting, linting and typechecking 🧹 🔧 \n" | ||
|
|
||
| uv run ruff check --select I --fix | ||
| uv run ruff check | ||
| uv run ruff format | ||
| uv run mypy qnexus/ tests/ integration/ | ||
|
|
||
| # Re-compile test hugr files. | ||
| recompile-test-files: | ||
| @echo "---- Recompiling example guppy programs ----" | ||
| just tests/data/recompile |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Test programs | ||
|
|
||
| This directory contains simple quantum programs used for testing. | ||
|
|
||
| The compiled HUGR is stored (alongside the guppy python program) with a `.hugr` extension. | ||
|
|
||
| Run `just recompile` in this directory (or `just recompile-test-hugrs` on | ||
| the root) to recompile the `.hugr` files. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| """Simple guppylang program from https://docs.quantinuum.com/guppy""" | ||
|
|
||
| from pathlib import Path | ||
| from sys import argv | ||
|
|
||
| from guppylang import guppy | ||
| from guppylang.std.builtins import result | ||
| from guppylang.std.quantum import cx, h, measure, qubit, x, z | ||
|
|
||
|
|
||
| @guppy | ||
| def bell() -> tuple[qubit, qubit]: | ||
| """Constructs a bell state.""" | ||
| q1, q2 = qubit(), qubit() | ||
| h(q1) | ||
| cx(q1, q2) | ||
| return q1, q2 | ||
|
|
||
|
|
||
| @guppy | ||
| def main() -> None: | ||
| src = qubit() | ||
| x(src) | ||
| alice, bob = bell() | ||
|
|
||
| cx(src, alice) | ||
| h(src) | ||
| if measure(alice): | ||
| x(bob) | ||
| if measure(src): | ||
| z(bob) | ||
|
|
||
| result("teleported", measure(bob)) | ||
|
|
||
|
|
||
| main.check() | ||
| program = main.compile_function() | ||
| Path(argv[0]).with_suffix(".hugr").write_bytes(program.to_bytes()) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # List the available commands | ||
| help: | ||
| @just --list --justfile {{justfile()}} | ||
|
|
||
| # Re-generate all test hugr files. | ||
| recompile: recompile-hugrs | ||
|
|
||
| # Re-generate all hugr files. | ||
| recompile-hugrs: | ||
| #!/usr/bin/env sh | ||
| for example in $(find . -type f -name "*.py"); do | ||
|
||
| echo "Re-generating $example" | ||
| uv run --no-project "$example" | ||
| done | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small typo, the justfile command in the root is
recompile-test-files.