Skip to content

Commit d581a8c

Browse files
authored
chore: use MonomorphizationPass (#732)
1 parent aafd73c commit d581a8c

File tree

3 files changed

+27
-21
lines changed

3 files changed

+27
-21
lines changed

Cargo.lock

Lines changed: 8 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ missing_docs = "warn"
2626
[patch.crates-io]
2727

2828
# Uncomment to use unreleased versions of hugr
29-
#hugr = { git = "https://github.com/CQCL/hugr", ref = "b517dc3530c3f01d854579e210da51d7a63e3036" }
30-
#hugr-core = { git = "https://github.com/CQCL/hugr", ref = "b517dc3530c3f01d854579e210da51d7a63e3036" }
31-
#hugr-passes = { git = "https://github.com/CQCL/hugr", ref = "b517dc3530c3f01d854579e210da51d7a63e3036" }
32-
#hugr-cli = { git = "https://github.com/CQCL/hugr", ref = "b517dc3530c3f01d854579e210da51d7a63e3036" }
33-
#hugr-model = { git = "https://github.com/CQCL/hugr", ref = "b517dc3530c3f01d854579e210da51d7a63e3036" }
29+
# hugr = { git = "https://github.com/CQCL/hugr", ref = "1e9eee2" }
30+
# hugr-core = { git = "https://github.com/CQCL/hugr", ref = "1e9eee2" }
31+
# hugr-passes = { git = "https://github.com/CQCL/hugr", ref = "1e9eee2" }
32+
# hugr-cli = { git = "https://github.com/CQCL/hugr", ref = "1e9eee2" }
33+
# hugr-model = { git = "https://github.com/CQCL/hugr", ref = "1e9eee2" }
3434

3535
[workspace.dependencies]
3636

3737
# Make sure to run `just recompile-eccs` if the hugr serialisation format changes.
38-
hugr = "0.14.0"
39-
hugr-core = "0.14.0"
40-
hugr-cli = "0.14.0"
38+
hugr = "0.14.1"
39+
hugr-core = "0.14.1"
40+
hugr-cli = "0.14.1"
4141
portgraph = "0.12"
4242
pyo3 = "0.23.3"
4343
itertools = "0.13.0"

tket2-hseries/src/lib.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
//! Provides a preparation and validation workflow for Hugrs targeting
22
//! Quantinuum H-series quantum computers.
3+
34
use std::mem;
45

56
use derive_more::{Display, Error, From};
67
use hugr::{
78
algorithms::{
89
const_fold::{ConstFoldError, ConstantFoldPass},
9-
force_order, monomorphize, remove_polyfuncs,
10+
force_order, remove_polyfuncs,
1011
validation::{ValidatePassError, ValidationLevel},
12+
MonomorphizeError, MonomorphizePass,
1113
},
1214
hugr::HugrError,
1315
Hugr, HugrView,
@@ -61,19 +63,21 @@ pub enum QSystemPassError {
6163
LowerTk2Error(LowerTk2Error),
6264
/// An error from the component [ConstantFoldPass] pass.
6365
ConstantFoldError(ConstFoldError),
66+
/// An error from the component [MonomorphizePass] pass.
67+
MonomorphizeError(MonomorphizeError),
6468
}
6569

6670
impl QSystemPass {
6771
/// Run `QSystemPass` on the given [Hugr]. `registry` is used for
6872
/// validation, if enabled.
6973
pub fn run(&self, hugr: &mut Hugr) -> Result<(), QSystemPassError> {
7074
if self.monomorphize {
75+
self.monomorphization().run(hugr)?;
7176
self.validation_level.run_validated_pass(hugr, |hugr, _| {
7277
let mut owned_hugr = Hugr::default();
7378
mem::swap(&mut owned_hugr, hugr);
74-
owned_hugr = remove_polyfuncs(monomorphize(owned_hugr));
79+
owned_hugr = remove_polyfuncs(owned_hugr);
7580
mem::swap(&mut owned_hugr, hugr);
76-
7781
Ok::<_, QSystemPassError>(())
7882
})?;
7983
}
@@ -113,6 +117,10 @@ impl QSystemPass {
113117
ConstantFoldPass::default().validation_level(self.validation_level)
114118
}
115119

120+
fn monomorphization(&self) -> MonomorphizePass {
121+
MonomorphizePass::default().validation_level(self.validation_level)
122+
}
123+
116124
/// Returns a new `QSystemPass` with the given [ValidationLevel].
117125
pub fn with_validation_level(mut self, level: ValidationLevel) -> Self {
118126
self.validation_level = level;

0 commit comments

Comments
 (0)