Skip to content

Commit

Permalink
feat: add CZ op (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
ss2165 authored Sep 20, 2023
1 parent a5071a7 commit 1d436e6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/json/op.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ impl From<&JsonOp> for OpType {
JsonOpType::PhasedX => T2Op::PhasedX.into(),
JsonOpType::ZZMax => T2Op::ZZMax.into(),
JsonOpType::ZZPhase => T2Op::ZZPhase.into(),
JsonOpType::CZ => T2Op::CZ.into(),
JsonOpType::noop => LeafOp::Noop { ty: QB_T }.into(),
_ => LeafOp::CustomOp(Box::new(json_op.as_opaque_op())).into(),
}
Expand Down Expand Up @@ -228,6 +229,7 @@ impl TryFrom<&OpType> for JsonOp {
T2Op::TK1 => JsonOpType::TK1,
T2Op::PhasedX => JsonOpType::PhasedX,
T2Op::ZZPhase => JsonOpType::ZZPhase,
T2Op::CZ => JsonOpType::CZ,
}
} else if let LeafOp::CustomOp(b) = leaf {
let ext = (*b).as_ref();
Expand Down
6 changes: 4 additions & 2 deletions src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ pub const EXTENSION_ID: ExtensionId = ExtensionId::new_unchecked("quantum.tket2"
)]
#[cfg_attr(feature = "pyo3", pyclass)]
#[allow(missing_docs)]
#[non_exhaustive]
/// Simple enum of tket 2 quantum operations.
pub enum T2Op {
H,
Expand All @@ -64,6 +65,7 @@ pub enum T2Op {
PhasedX,
ZZPhase,
AngleAdd,
CZ,
TK1,
}

Expand Down Expand Up @@ -129,7 +131,7 @@ impl SimpleOpEnum for T2Op {
let two_qb_row = type_row![QB_T, QB_T];
match self {
H | T | S | X | Y | Z | Tdg | Sdg => FunctionType::new(one_qb_row.clone(), one_qb_row),
CX | ZZMax => FunctionType::new(two_qb_row.clone(), two_qb_row),
CX | ZZMax | CZ => FunctionType::new(two_qb_row.clone(), two_qb_row),
ZZPhase => FunctionType::new(type_row![QB_T, QB_T, FLOAT64_TYPE], two_qb_row),
Measure => FunctionType::new(one_qb_row, type_row![QB_T, BOOL_T]),
RzF64 | RxF64 => FunctionType::new(type_row![QB_T, FLOAT64_TYPE], one_qb_row),
Expand Down Expand Up @@ -183,7 +185,7 @@ impl T2Op {
X | RxF64 => vec![(0, Pauli::X)],
T | Z | S | Tdg | Sdg | RzF64 | Measure => vec![(0, Pauli::Z)],
CX => vec![(0, Pauli::Z), (1, Pauli::X)],
ZZMax | ZZPhase => vec![(0, Pauli::Z), (1, Pauli::Z)],
ZZMax | ZZPhase | CZ => vec![(0, Pauli::Z), (1, Pauli::Z)],
// by default, no commutation
_ => vec![],
}
Expand Down

0 comments on commit 1d436e6

Please sign in to comment.