diff --git a/src/extension/prelude.rs b/src/extension/prelude.rs index a79497a61..15a20930e 100644 --- a/src/extension/prelude.rs +++ b/src/extension/prelude.rs @@ -60,9 +60,12 @@ pub(crate) const QB_CUSTOM_T: CustomType = CustomType::new_simple( TypeBound::Any, ); -pub(crate) const QB_T: Type = Type::new_extension(QB_CUSTOM_T); -pub(crate) const USIZE_T: Type = Type::new_extension(USIZE_CUSTOM_T); -pub(crate) const BOOL_T: Type = Type::new_simple_predicate(2); +/// Qubit type. +pub const QB_T: Type = Type::new_extension(QB_CUSTOM_T); +/// Unsigned size type. +pub const USIZE_T: Type = Type::new_extension(USIZE_CUSTOM_T); +/// Boolean type - Sum of two units. +pub const BOOL_T: Type = Type::new_simple_predicate(2); /// Initialize a new array of type `typ` of length `size` pub fn new_array(typ: Type, size: u64) -> Type { diff --git a/src/ops/custom.rs b/src/ops/custom.rs index 368d986c1..9302ee110 100644 --- a/src/ops/custom.rs +++ b/src/ops/custom.rs @@ -118,6 +118,11 @@ impl ExtensionOp { pub fn args(&self) -> &[TypeArg] { &self.args } + + /// Returns a reference to the [`OpDef`] of this [`ExtensionOp`]. + pub fn def(&self) -> &OpDef { + self.def.as_ref() + } } impl From for OpaqueOp { diff --git a/src/std_extensions/arithmetic/float_types.rs b/src/std_extensions/arithmetic/float_types.rs index 8c56e2ad9..69ad19876 100644 --- a/src/std_extensions/arithmetic/float_types.rs +++ b/src/std_extensions/arithmetic/float_types.rs @@ -24,6 +24,14 @@ pub const FLOAT64_TYPE: Type = Type::new_extension(FLOAT64_CUSTOM_TYPE); /// A floating-point value. pub struct ConstF64(f64); +impl std::ops::Deref for ConstF64 { + type Target = f64; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + impl ConstF64 { /// Create a new [`ConstF64`] pub fn new(value: f64) -> Self { diff --git a/src/std_extensions/quantum.rs b/src/std_extensions/quantum.rs index 4f110b94f..d97ecc62f 100644 --- a/src/std_extensions/quantum.rs +++ b/src/std_extensions/quantum.rs @@ -4,6 +4,7 @@ use smol_str::SmolStr; use crate::extension::prelude::{BOOL_T, QB_T}; use crate::extension::{ExtensionSet, SignatureError}; +use crate::std_extensions::arithmetic::float_types::FLOAT64_TYPE; use crate::type_row; use crate::types::type_param::TypeArg; use crate::types::TypeRow; @@ -36,6 +37,20 @@ fn extension() -> Extension { one_qb_func, ) .unwrap(); + extension + .add_op_custom_sig_simple( + SmolStr::new_inline("RzF64"), + "Rotation specified by float".into(), + vec![], + |_: &[_]| { + Ok(( + type_row![QB_T, FLOAT64_TYPE], + type_row![QB_T], + ExtensionSet::new(), + )) + }, + ) + .unwrap(); extension .add_op_custom_sig_simple(SmolStr::new_inline("CX"), "CX".into(), vec![], two_qb_func)