Skip to content

Commit

Permalink
chore: use MonomorphizationPass (#732)
Browse files Browse the repository at this point in the history
  • Loading branch information
ss2165 authored Dec 18, 2024
1 parent aafd73c commit d581a8c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
18 changes: 8 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,18 @@ missing_docs = "warn"
[patch.crates-io]

# Uncomment to use unreleased versions of hugr
#hugr = { git = "https://github.com/CQCL/hugr", ref = "b517dc3530c3f01d854579e210da51d7a63e3036" }
#hugr-core = { git = "https://github.com/CQCL/hugr", ref = "b517dc3530c3f01d854579e210da51d7a63e3036" }
#hugr-passes = { git = "https://github.com/CQCL/hugr", ref = "b517dc3530c3f01d854579e210da51d7a63e3036" }
#hugr-cli = { git = "https://github.com/CQCL/hugr", ref = "b517dc3530c3f01d854579e210da51d7a63e3036" }
#hugr-model = { git = "https://github.com/CQCL/hugr", ref = "b517dc3530c3f01d854579e210da51d7a63e3036" }
# hugr = { git = "https://github.com/CQCL/hugr", ref = "1e9eee2" }
# hugr-core = { git = "https://github.com/CQCL/hugr", ref = "1e9eee2" }
# hugr-passes = { git = "https://github.com/CQCL/hugr", ref = "1e9eee2" }
# hugr-cli = { git = "https://github.com/CQCL/hugr", ref = "1e9eee2" }
# hugr-model = { git = "https://github.com/CQCL/hugr", ref = "1e9eee2" }

[workspace.dependencies]

# Make sure to run `just recompile-eccs` if the hugr serialisation format changes.
hugr = "0.14.0"
hugr-core = "0.14.0"
hugr-cli = "0.14.0"
hugr = "0.14.1"
hugr-core = "0.14.1"
hugr-cli = "0.14.1"
portgraph = "0.12"
pyo3 = "0.23.3"
itertools = "0.13.0"
Expand Down
14 changes: 11 additions & 3 deletions tket2-hseries/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
//! Provides a preparation and validation workflow for Hugrs targeting
//! Quantinuum H-series quantum computers.
use std::mem;

use derive_more::{Display, Error, From};
use hugr::{
algorithms::{
const_fold::{ConstFoldError, ConstantFoldPass},
force_order, monomorphize, remove_polyfuncs,
force_order, remove_polyfuncs,
validation::{ValidatePassError, ValidationLevel},
MonomorphizeError, MonomorphizePass,
},
hugr::HugrError,
Hugr, HugrView,
Expand Down Expand Up @@ -61,19 +63,21 @@ pub enum QSystemPassError {
LowerTk2Error(LowerTk2Error),
/// An error from the component [ConstantFoldPass] pass.
ConstantFoldError(ConstFoldError),
/// An error from the component [MonomorphizePass] pass.
MonomorphizeError(MonomorphizeError),
}

impl QSystemPass {
/// Run `QSystemPass` on the given [Hugr]. `registry` is used for
/// validation, if enabled.
pub fn run(&self, hugr: &mut Hugr) -> Result<(), QSystemPassError> {
if self.monomorphize {
self.monomorphization().run(hugr)?;
self.validation_level.run_validated_pass(hugr, |hugr, _| {
let mut owned_hugr = Hugr::default();
mem::swap(&mut owned_hugr, hugr);
owned_hugr = remove_polyfuncs(monomorphize(owned_hugr));
owned_hugr = remove_polyfuncs(owned_hugr);
mem::swap(&mut owned_hugr, hugr);

Ok::<_, QSystemPassError>(())
})?;
}
Expand Down Expand Up @@ -113,6 +117,10 @@ impl QSystemPass {
ConstantFoldPass::default().validation_level(self.validation_level)
}

fn monomorphization(&self) -> MonomorphizePass {
MonomorphizePass::default().validation_level(self.validation_level)
}

/// Returns a new `QSystemPass` with the given [ValidationLevel].
pub fn with_validation_level(mut self, level: ValidationLevel) -> Self {
self.validation_level = level;
Expand Down

0 comments on commit d581a8c

Please sign in to comment.