Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: TKET2 compatibility requirements #450

Merged
merged 2 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/extension/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions src/ops/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExtensionOp> for OpaqueOp {
Expand Down
8 changes: 8 additions & 0 deletions src/std_extensions/arithmetic/float_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 15 additions & 0 deletions src/std_extensions/quantum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down