Skip to content

Commit

Permalink
from turns returns an option_type. fix hseries extension depending … (
Browse files Browse the repository at this point in the history
#613)

…on rotation
  • Loading branch information
doug-q authored Sep 16, 2024
1 parent 99dd2c5 commit 65a372c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
2 changes: 0 additions & 2 deletions tket2-hseries/src/extension/hseries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ lazy_static! {
futures::EXTENSION.name(),
PRELUDE.name(),
FLOAT_TYPES.name(),
tket2::extension::rotation::ROTATION_EXTENSION.name(),
].into_iter().cloned()));
HSeriesOp::load_all_ops(&mut ext).unwrap();
ext
Expand All @@ -57,7 +56,6 @@ lazy_static! {
futures::EXTENSION.to_owned(),
PRELUDE.to_owned(),
FLOAT_TYPES.to_owned(),
tket2::extension::rotation::ROTATION_EXTENSION.to_owned(),
]).unwrap();
}

Expand Down
19 changes: 15 additions & 4 deletions tket2-hseries/src/extension/hseries/lower.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
use std::collections::HashMap;

use hugr::{
algorithms::validation::{ValidatePassError, ValidationLevel},
builder::{BuildError, DFGBuilder, Dataflow, DataflowHugr},
extension::ExtensionRegistry,
hugr::{hugrmut::HugrMut, HugrError},
ops::{self, DataflowOpTrait},
std_extensions::arithmetic::{float_ops::FloatOps, float_types::ConstF64},
std_extensions::arithmetic::{
float_ops::FloatOps,
float_types::ConstF64,
},
types::Signature,
Hugr, HugrView, Node, Wire,
};
use lazy_static::lazy_static;
use std::collections::HashMap;
use strum::IntoEnumIterator;
use thiserror::Error;
use tket2::{extension::rotation::RotationOpBuilder, Tk2Op};

use crate::extension::hseries::{HSeriesOp, HSeriesOpBuilder};

use super::REGISTRY;
lazy_static! {
/// Extension registry including [crate::extension::hseries::REGISTRY] and
/// [tket2::extension::rotation::ROTATION_EXTENSION].
pub static ref REGISTRY: ExtensionRegistry = {
let mut registry = super::REGISTRY.to_owned();
registry.register(tket2::extension::rotation::ROTATION_EXTENSION.to_owned()).unwrap();
registry
};
}

pub(super) fn pi_mul_f64<T: Dataflow + ?Sized>(builder: &mut T, multiplier: f64) -> Wire {
const_f64(builder, multiplier * std::f64::consts::PI)
Expand Down
20 changes: 12 additions & 8 deletions tket2/src/extension/rotation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use hugr::builder::{BuildError, Dataflow};
use hugr::extension::simple_op::{MakeOpDef, MakeRegisteredOp};
use hugr::extension::{ExtensionId, ExtensionSet, Version};
use hugr::extension::{prelude::option_type, ExtensionId, ExtensionSet, Version};
use hugr::ops::constant::{downcast_equal_consts, CustomConst};
use hugr::std_extensions::arithmetic::float_types::FLOAT64_TYPE;
use hugr::{type_row, Wire};
Expand Down Expand Up @@ -131,9 +131,10 @@ impl MakeOpDef for RotationOp {

fn signature(&self) -> hugr::extension::SignatureFunc {
match self {
RotationOp::fromturns => {
Signature::new(type_row![FLOAT64_TYPE], type_row![ROTATION_TYPE])
}
RotationOp::fromturns => Signature::new(
type_row![FLOAT64_TYPE],
Type::from(option_type(type_row![ROTATION_TYPE])),
),
RotationOp::toturns => {
Signature::new(type_row![ROTATION_TYPE], type_row![FLOAT64_TYPE])
}
Expand Down Expand Up @@ -259,14 +260,17 @@ mod test {

#[test]
fn test_builder() {
let mut builder = DFGBuilder::new(Signature::new_endo(vec![ROTATION_TYPE])).unwrap();
let mut builder = DFGBuilder::new(Signature::new(
ROTATION_TYPE,
Type::from(option_type(ROTATION_TYPE)),
))
.unwrap();

let [rotation] = builder.input_wires_arr();
let turns = builder.add_toturns(rotation).unwrap();
let rotation = builder.add_fromturns(turns).unwrap();

let mb_rotation = builder.add_fromturns(turns).unwrap();
let _hugr = builder
.finish_hugr_with_outputs([rotation], &REGISTRY)
.finish_hugr_with_outputs([mb_rotation], &REGISTRY)
.unwrap();
}

Expand Down

0 comments on commit 65a372c

Please sign in to comment.