-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: Test missing op definitions against
pytket
(#36)
Adds an integration tests that checks whether all elements of `pytket.OpType.__members__` are present in the `OpType` enum. Adds a CI check for this that runs on pull requests / merges as well as on a cron job every day to ensure that new pytket releases are always tested. This test currently fails with the following message: ``` Missing optypes in `tket_json_rs`: - Phase - CS - CSdg - TermSequenceBox - ConjugationBox - DummyBox - CnY - CnZ - WASM - MultiplexedTensoredU2Box - StatePreparationBox - DiagonalBox Please add them to the `OpType` enum in `tket_json_rs/src/optype.rs`. ``` I'll open another PR with those implementations. Ideally the cron job would also create an issue when the test fails, but I'll look into that another time. Closes #31 .
- Loading branch information
Showing
9 changed files
with
595 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Detect missing operation definitions | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
workflow_dispatch: {} | ||
schedule: | ||
# 04:00 daily | ||
- cron: '0 4 * * *' | ||
|
||
env: | ||
CARGO_TERM_COLOR: always | ||
SCCACHE_GHA_ENABLED: "true" | ||
RUSTC_WRAPPER: "sccache" | ||
|
||
jobs: | ||
missing-optypes: | ||
name: Check for missing op type definitions | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: mozilla-actions/[email protected] | ||
- name: Install stable toolchain | ||
uses: dtolnay/rust-toolchain@stable | ||
with: | ||
components: rustfmt, clippy | ||
- name: Install poetry | ||
run: pipx install poetry | ||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.12' | ||
cache: "poetry" | ||
- name: Update the project dependencies | ||
run: poetry -C tests update | ||
- name: Run the missing op types test | ||
run: poetry -C tests run -- cargo test --test integration -- --ignored missing_optypes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
/target | ||
Cargo.lock | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# List the available commands | ||
help: | ||
@just --list --justfile {{justfile()}} | ||
|
||
# Run all the rust tests | ||
test: | ||
cargo test --all-features | ||
|
||
# Auto-fix all clippy warnings | ||
fix: | ||
cargo clippy --all-targets --all-features --workspace --fix --allow-staged | ||
|
||
# Check for missing optypes | ||
check-optypes: | ||
poetry -C tests update | ||
poetry -C tests run -- cargo test -- --ignored missing_optypes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
//! Integration tests. | ||
pub mod missing_optypes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//! Integration test to detect missing optypes in the optype module. | ||
//! | ||
//! Requires the `pyo3` feature to be enabled. | ||
use std::str::FromStr; | ||
|
||
use pyo3::prelude::*; | ||
use pyo3::types::PyDict; | ||
use tket_json_rs::OpType; | ||
|
||
#[test] | ||
#[ignore = "Requires a python environment with `pytket` installed."] | ||
fn missing_optypes() -> PyResult<()> { | ||
println!("Checking missing optypes"); | ||
|
||
pyo3::prepare_freethreaded_python(); | ||
Python::with_gil(|py| { | ||
let Ok(pytket) = PyModule::import_bound(py, "pytket") else { | ||
panic!("Failed to import `pytket`. Make sure the python library is installed."); | ||
}; | ||
let py_enum = pytket.getattr("OpType")?; | ||
let py_members = py_enum.getattr("__members__")?; | ||
let py_members = py_members.downcast::<PyDict>()?; | ||
|
||
let missing: Vec<String> = py_members | ||
.into_iter() | ||
.filter_map(|(name, _class)| { | ||
let name = name.extract::<String>().unwrap(); | ||
match OpType::from_str(&name) { | ||
Err(_) => Some(name), | ||
Ok(_) => None, | ||
} | ||
}) | ||
.collect(); | ||
|
||
if !missing.is_empty() { | ||
let msg = "\nMissing optypes in `tket_json_rs`:\n".to_string(); | ||
let msg = missing | ||
.into_iter() | ||
.fold(msg, |msg, s| msg + " - " + &s + "\n"); | ||
let msg = | ||
msg + "Please add them to the `OpType` enum in `tket_json_rs/src/optype.rs`.\n"; | ||
panic!("{msg}"); | ||
} | ||
|
||
Ok(()) | ||
}) | ||
} |
Oops, something went wrong.