Skip to content

Commit

Permalink
feat!: move angle types + and ops to new "tket2.angle" extension (#591)
Browse files Browse the repository at this point in the history
Closes #589

BREAKING CHANGE: "tket2.quantum" ops no longer contains angle type/ops.
Use "tket2.angle".
  • Loading branch information
ss2165 authored Sep 5, 2024
1 parent e3f9da1 commit f0884cc
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
Binary file modified test_files/eccs/nam_4_2.rwr
Binary file not shown.
Binary file modified test_files/eccs/nam_6_3.rwr
Binary file not shown.
Binary file modified test_files/eccs/small_eccs.rwr
Binary file not shown.
Binary file modified tket2-eccs/src/tket2_eccs/data/nam_6_3.rwr
Binary file not shown.
1 change: 1 addition & 0 deletions tket2/src/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub static ref REGISTRY: ExtensionRegistry = ExtensionRegistry::try_new([
PRELUDE.to_owned(),
TKET2_EXTENSION.to_owned(),
FLOAT_TYPES.to_owned(),
angle::ANGLE_EXTENSION.to_owned()
]).unwrap();


Expand Down
29 changes: 22 additions & 7 deletions tket2/src/extension/angle.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use hugr::extension::prelude::{sum_with_error, BOOL_T, USIZE_T};
use hugr::extension::simple_op::{MakeOpDef, MakeRegisteredOp};
use hugr::extension::ExtensionSet;
use hugr::extension::{ExtensionId, ExtensionSet, Version};
use hugr::ops::constant::{downcast_equal_consts, CustomConst};
use hugr::std_extensions::arithmetic::float_types::FLOAT64_TYPE;
use hugr::type_row;
Expand All @@ -12,13 +12,28 @@ use smol_str::SmolStr;
use std::f64::consts::TAU;
use strum::{EnumIter, EnumString, IntoStaticStr};

use super::TKET2_EXTENSION_ID;
use lazy_static::lazy_static;

/// Name of tket 2 angle extension.
pub const ANGLE_EXTENSION_ID: ExtensionId = ExtensionId::new_unchecked("tket2.angle");

/// Current version of the TKET 2 angle extension
pub const ANGLE_EXTENSION_VERSION: Version = Version::new(0, 1, 0);

lazy_static! {
/// The extension definition for TKET2 angle type and ops.
pub static ref ANGLE_EXTENSION: Extension = {
let mut e = Extension::new(ANGLE_EXTENSION_ID, ANGLE_EXTENSION_VERSION);
add_to_extension(&mut e);
e
};
}

/// Identifier for the angle type.
const ANGLE_TYPE_ID: SmolStr = SmolStr::new_inline("angle");
/// Dyadic rational angle type (as [CustomType])
pub const ANGLE_CUSTOM_TYPE: CustomType =
CustomType::new_simple(ANGLE_TYPE_ID, TKET2_EXTENSION_ID, TypeBound::Copyable);
CustomType::new_simple(ANGLE_TYPE_ID, ANGLE_EXTENSION_ID, TypeBound::Copyable);

/// Type representing an angle that is a dyadic rational multiple of π (as [Type])
pub const ANGLE_TYPE: Type = Type::new_extension(ANGLE_CUSTOM_TYPE);
Expand Down Expand Up @@ -130,7 +145,7 @@ impl CustomConst for ConstAngle {
downcast_equal_consts(self, other)
}
fn extension_reqs(&self) -> ExtensionSet {
ExtensionSet::singleton(&TKET2_EXTENSION_ID)
ExtensionSet::singleton(&ANGLE_EXTENSION_ID)
}
}

Expand Down Expand Up @@ -170,7 +185,7 @@ impl MakeOpDef for AngleOp {
where
Self: Sized,
{
hugr::extension::simple_op::try_from_name(op_def.name(), &TKET2_EXTENSION_ID)
hugr::extension::simple_op::try_from_name(op_def.name(), &ANGLE_EXTENSION_ID)
}

fn signature(&self) -> hugr::extension::SignatureFunc {
Expand Down Expand Up @@ -216,7 +231,7 @@ impl MakeOpDef for AngleOp {
}

fn extension(&self) -> hugr::extension::ExtensionId {
TKET2_EXTENSION_ID
ANGLE_EXTENSION_ID
}

// TODO constant folding
Expand All @@ -225,7 +240,7 @@ impl MakeOpDef for AngleOp {

impl MakeRegisteredOp for AngleOp {
fn extension_id(&self) -> hugr::extension::ExtensionId {
TKET2_EXTENSION_ID
ANGLE_EXTENSION_ID
}

fn registry<'s, 'r: 's>(&'s self) -> &'r hugr::extension::ExtensionRegistry {
Expand Down

0 comments on commit f0884cc

Please sign in to comment.