Skip to content

Commit

Permalink
rename more things
Browse files Browse the repository at this point in the history
  • Loading branch information
ss2165 committed Nov 28, 2024
1 parent 43eb396 commit 409b826
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion tket2-hseries/src/extension/qsystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use super::futures::future_type;

mod lower;
use lower::pi_mul_f64;
pub use lower::{check_lowered, lower_tk2_op, LowerTk2Error, LowerTket2ToHSeriesPass};
pub use lower::{check_lowered, lower_tk2_op, LowerTk2Error, LowerTket2ToQSystemPass};

/// The "tket2.qsystem" extension id.
pub const EXTENSION_ID: ExtensionId = ExtensionId::new_unchecked("tket2.qsystem");
Expand Down
14 changes: 7 additions & 7 deletions tket2-hseries/src/extension/qsystem/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ pub fn check_lowered(hugr: &impl HugrView) -> Result<(), Vec<Node>> {
/// Invokes [lower_tk2_op]. If validation is enabled the resulting HUGR is
/// checked with [check_lowered].
#[derive(Default, Debug, Clone)]
pub struct LowerTket2ToHSeriesPass(ValidationLevel);
pub struct LowerTket2ToQSystemPass(ValidationLevel);

impl LowerTket2ToHSeriesPass {
/// Run `LowerTket2ToHSeriesPass` on the given [HugrMut]. `registry` is used
impl LowerTket2ToQSystemPass {
/// Run `LowerTket2ToQSystemPass` on the given [HugrMut]. `registry` is used
/// for validation, if enabled.
pub fn run(
&self,
Expand All @@ -196,7 +196,7 @@ impl LowerTket2ToHSeriesPass {
})
}

/// Returns a new `LowerTket2ToHSeriesPass` with the given [ValidationLevel].
/// Returns a new `LowerTket2ToQSystemPass` with the given [ValidationLevel].
pub fn with_validation_level(&self, level: ValidationLevel) -> Self {
Self(level)
}
Expand Down Expand Up @@ -283,7 +283,7 @@ mod test {
// conditional doesn't fit in to commands
#[case(Tk2Op::Measure, None)]
#[case(Tk2Op::QAlloc, None)]
fn test_lower(#[case] t2op: Tk2Op, #[case] hseries_ops: Option<Vec<QSystemOp>>) {
fn test_lower(#[case] t2op: Tk2Op, #[case] qsystem_ops: Option<Vec<QSystemOp>>) {
// build dfg with just the op

let h = op_to_hugr(t2op).unwrap();
Expand All @@ -292,8 +292,8 @@ mod test {
.commands()
.filter_map(|com| com.optype().cast())
.collect();
if let Some(hseries_ops) = hseries_ops {
assert_eq!(ops, hseries_ops);
if let Some(qsystem_ops) = qsystem_ops {
assert_eq!(ops, qsystem_ops);
}

assert_eq!(check_lowered(&h), Ok(()));
Expand Down
34 changes: 17 additions & 17 deletions tket2-hseries/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use tket2::Tk2Op;

use extension::{
futures::FutureOpDef,
qsystem::{LowerTk2Error, LowerTket2ToHSeriesPass, QSystemOp},
qsystem::{LowerTk2Error, LowerTket2ToQSystemPass, QSystemOp},
};
use lazify_measure::{LazifyMeasurePass, LazifyMeasurePassError};

Expand All @@ -23,37 +23,37 @@ pub mod extension;

pub mod lazify_measure;

/// Modify a [hugr::Hugr] into a form that is acceptable for ingress into an H-series.
/// Modify a [hugr::Hugr] into a form that is acceptable for ingress into a Q-System.
/// Returns an error if this cannot be done.
///
/// To construct a `HSeriesPass` use [Default::default].
/// To construct a `QSystemPass` use [Default::default].
#[derive(Debug, Clone, Copy, Default)]
pub struct HSeriesPass {
pub struct QSystemPass {
validation_level: ValidationLevel,
}

#[derive(Error, Debug, Display, From)]
#[non_exhaustive]
/// An error reported from [HSeriesPass].
pub enum HSeriesPassError {
/// An error reported from [QSystemPass].
pub enum QSystemPassError {
/// The [hugr::Hugr] was invalid either before or after a pass ran.
ValidationError(ValidatePassError),
/// An error from the component [LazifyMeasurePass].
LazyMeasureError(LazifyMeasurePassError),
/// An error from the component [force_order()] pass.
ForceOrderError(HugrError),
/// An error from the component [LowerTket2ToHSeriesPass] pass.
/// An error from the component [LowerTket2ToQSystemPass] pass.
LowerTk2Error(LowerTk2Error),
}

impl HSeriesPass {
/// Run `HSeriesPass` on the given [HugrMut]. `registry` is used for
impl QSystemPass {
/// Run `QSystemPass` on the given [HugrMut]. `registry` is used for
/// validation, if enabled.
pub fn run(
&self,
hugr: &mut impl HugrMut,
registry: &ExtensionRegistry,
) -> Result<(), HSeriesPassError> {
) -> Result<(), QSystemPassError> {
self.lower_tk2().run(hugr, registry)?;
self.lazify_measure().run(hugr, registry)?;
self.validation_level
Expand All @@ -70,20 +70,20 @@ impl HSeriesPass {
0
}
})?;
Ok::<_, HSeriesPassError>(())
Ok::<_, QSystemPassError>(())
})?;
Ok(())
}

fn lower_tk2(&self) -> LowerTket2ToHSeriesPass {
LowerTket2ToHSeriesPass::default().with_validation_level(self.validation_level)
fn lower_tk2(&self) -> LowerTket2ToQSystemPass {
LowerTket2ToQSystemPass::default().with_validation_level(self.validation_level)
}

fn lazify_measure(&self) -> LazifyMeasurePass {
LazifyMeasurePass::default().with_validation_level(self.validation_level)
}

/// Returns a new `HSeriesPass` with the given [ValidationLevel].
/// Returns a new `QSystemPass` with the given [ValidationLevel].
pub fn with_validation_level(mut self, level: ValidationLevel) -> Self {
self.validation_level = level;
self
Expand All @@ -106,11 +106,11 @@ mod test {

use crate::{
extension::{futures::FutureOpDef, qsystem::QSystemOp},
HSeriesPass,
QSystemPass,
};

#[test]
fn hseries_pass() {
fn qsystem_pass() {
let registry = &tket2::extension::REGISTRY;
let (mut hugr, [call_node, h_node, f_node, rx_node]) = {
let mut builder = DFGBuilder::new(Signature::new(QB_T, vec![BOOL_T, BOOL_T])).unwrap();
Expand Down Expand Up @@ -160,7 +160,7 @@ mod test {
(hugr, [call_node, h_node, f_node, rx_node])
};

HSeriesPass::default().run(&mut hugr, registry).unwrap();
QSystemPass::default().run(&mut hugr, registry).unwrap();

let topo_sorted = Topo::new(&hugr.as_petgraph())
.iter(&hugr.as_petgraph())
Expand Down

0 comments on commit 409b826

Please sign in to comment.