Skip to content
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

chore: use MonomorphizationPass #732

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// An error from the component [MoomorphizePass] pass.
/// An error from the component [MonomorphizePass] pass.

MonomorphizeError(hugr::algorithms::MonomorphizeError),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's inconsistent with the above to qualify this here. It's Ok if you prefer it.

}

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
Loading