Skip to content

Commit

Permalink
chore: use MonomorphizationPass
Browse files Browse the repository at this point in the history
  • Loading branch information
ss2165 committed Dec 18, 2024
1 parent aafd73c commit 962b9ff
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
19 changes: 9 additions & 10 deletions Cargo.lock

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

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ 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]

Expand Down
19 changes: 9 additions & 10 deletions tket2-hseries/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! 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,
validation::{ValidatePassError, ValidationLevel},
MonomorphizePass,
},
hugr::HugrError,
Hugr, HugrView,
Expand Down Expand Up @@ -61,21 +61,16 @@ pub enum QSystemPassError {
LowerTk2Error(LowerTk2Error),
/// An error from the component [ConstantFoldPass] pass.
ConstantFoldError(ConstFoldError),
/// An error from the component [MoomorphizePass] pass.
MonomorphizeError(hugr::algorithms::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.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));
mem::swap(&mut owned_hugr, hugr);

Ok::<_, QSystemPassError>(())
})?;
self.monomorphization().run(hugr)?;
}

if self.constant_fold {
Expand Down Expand Up @@ -113,6 +108,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 962b9ff

Please sign in to comment.