|
1 | 1 | //! Provides a preparation and validation workflow for Hugrs targeting
|
2 | 2 | //! Quantinuum H-series quantum computers.
|
| 3 | +
|
3 | 4 | use std::mem;
|
4 | 5 |
|
5 | 6 | use derive_more::{Display, Error, From};
|
6 | 7 | use hugr::{
|
7 | 8 | algorithms::{
|
8 | 9 | const_fold::{ConstFoldError, ConstantFoldPass},
|
9 |
| - force_order, monomorphize, remove_polyfuncs, |
| 10 | + force_order, remove_polyfuncs, |
10 | 11 | validation::{ValidatePassError, ValidationLevel},
|
| 12 | + MonomorphizeError, MonomorphizePass, |
11 | 13 | },
|
12 | 14 | hugr::HugrError,
|
13 | 15 | Hugr, HugrView,
|
@@ -61,19 +63,21 @@ pub enum QSystemPassError {
|
61 | 63 | LowerTk2Error(LowerTk2Error),
|
62 | 64 | /// An error from the component [ConstantFoldPass] pass.
|
63 | 65 | ConstantFoldError(ConstFoldError),
|
| 66 | + /// An error from the component [MonomorphizePass] pass. |
| 67 | + MonomorphizeError(MonomorphizeError), |
64 | 68 | }
|
65 | 69 |
|
66 | 70 | impl QSystemPass {
|
67 | 71 | /// Run `QSystemPass` on the given [Hugr]. `registry` is used for
|
68 | 72 | /// validation, if enabled.
|
69 | 73 | pub fn run(&self, hugr: &mut Hugr) -> Result<(), QSystemPassError> {
|
70 | 74 | if self.monomorphize {
|
| 75 | + self.monomorphization().run(hugr)?; |
71 | 76 | self.validation_level.run_validated_pass(hugr, |hugr, _| {
|
72 | 77 | let mut owned_hugr = Hugr::default();
|
73 | 78 | mem::swap(&mut owned_hugr, hugr);
|
74 |
| - owned_hugr = remove_polyfuncs(monomorphize(owned_hugr)); |
| 79 | + owned_hugr = remove_polyfuncs(owned_hugr); |
75 | 80 | mem::swap(&mut owned_hugr, hugr);
|
76 |
| - |
77 | 81 | Ok::<_, QSystemPassError>(())
|
78 | 82 | })?;
|
79 | 83 | }
|
@@ -113,6 +117,10 @@ impl QSystemPass {
|
113 | 117 | ConstantFoldPass::default().validation_level(self.validation_level)
|
114 | 118 | }
|
115 | 119 |
|
| 120 | + fn monomorphization(&self) -> MonomorphizePass { |
| 121 | + MonomorphizePass::default().validation_level(self.validation_level) |
| 122 | + } |
| 123 | + |
116 | 124 | /// Returns a new `QSystemPass` with the given [ValidationLevel].
|
117 | 125 | pub fn with_validation_level(mut self, level: ValidationLevel) -> Self {
|
118 | 126 | self.validation_level = level;
|
|
0 commit comments