From 4ab59f09877bcd3c037a624b9d1b8324a7cc0081 Mon Sep 17 00:00:00 2001 From: Marina Walt Date: Thu, 8 Jul 2021 11:40:55 +0000 Subject: [PATCH 1/3] added KaK decomposition for PhaseShiftedControlledZ gate --- .../operations/two_qubit_gate_operations.rs | 2 +- .../operations/_auto_generated_operations.rs | 3 ++ .../operations/two_qubit_gate_operations.rs | 30 +++++++++++++++++++ .../operations/two_qubit_gate_operations.rs | 3 ++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/qoqo/src/operations/two_qubit_gate_operations.rs b/qoqo/src/operations/two_qubit_gate_operations.rs index 3a2e8b35..359a69b4 100644 --- a/qoqo/src/operations/two_qubit_gate_operations.rs +++ b/qoqo/src/operations/two_qubit_gate_operations.rs @@ -493,7 +493,7 @@ pub struct ComplexPMInteraction { } #[allow(clippy::upper_case_acronyms)] -#[wrap(Operate, OperateTwoQubit, OperateGate)] //+ OperateTwoQubitGate (tbd) +#[wrap(Operate, OperateTwoQubit, OperateGate, OperateTwoQubitGate)] /// The phased-shifted controlled-Z gate. /// /// Modified, i.e. phase-shifted ControlledPauliZ two-qubit gate (https://arxiv.org/pdf/1908.06101.pdf eq.(1)). diff --git a/roqoqo/src/operations/_auto_generated_operations.rs b/roqoqo/src/operations/_auto_generated_operations.rs index 18d7dbe8..6b2f62f2 100644 --- a/roqoqo/src/operations/_auto_generated_operations.rs +++ b/roqoqo/src/operations/_auto_generated_operations.rs @@ -708,6 +708,9 @@ pub enum TwoQubitGateOperation { #[allow(clippy::upper_case_acronyms)] #[doc = "Variant for ComplexPMInteraction"] ComplexPMInteraction(ComplexPMInteraction), + #[allow(clippy::upper_case_acronyms)] + #[doc = "Variant for PhaseShiftedControlledZ"] + PhaseShiftedControlledZ(PhaseShiftedControlledZ), } #[doc = r" Enum of all Operations implementing [OperateMultiQubitGate]"] #[derive( diff --git a/roqoqo/src/operations/two_qubit_gate_operations.rs b/roqoqo/src/operations/two_qubit_gate_operations.rs index cb73896b..660b68f0 100644 --- a/roqoqo/src/operations/two_qubit_gate_operations.rs +++ b/roqoqo/src/operations/two_qubit_gate_operations.rs @@ -2237,3 +2237,33 @@ impl OperateGate for PhaseShiftedControlledZ { ]) } } + +/// Trait for all gate operations acting on exactly two qubits. +impl OperateTwoQubitGate for PhaseShiftedControlledZ { + /// Returns [KakDecomposition] of the gate. + /// + /// # Returns + /// + /// * struct `KakDecomposition { global_phase, k_vector, circuit_before, circuit_after }` + fn kak_decomposition(&self) -> KakDecomposition { + let mut circuit_b = Circuit::new(); + circuit_b += RotateZ::new(self.control, CalculatorFloat::FRAC_PI_2); + circuit_b += RotateZ::new(self.target, CalculatorFloat::FRAC_PI_2); + + let mut circuit_a = Circuit::new(); + circuit_a += RotateZ::new(self.control, self.phi.clone()); + circuit_a += RotateZ::new(self.target, self.phi.clone()); + + let g: CalculatorFloat = CalculatorFloat::FRAC_PI_4 + self.phi.clone(); + KakDecomposition { + global_phase: g, + k_vector: [ + CalculatorFloat::ZERO, + CalculatorFloat::ZERO, + CalculatorFloat::FRAC_PI_4, + ], + circuit_before: Some(circuit_b), + circuit_after: Some(circuit_a), + } + } +} diff --git a/roqoqo/tests/integration/operations/two_qubit_gate_operations.rs b/roqoqo/tests/integration/operations/two_qubit_gate_operations.rs index c44077b6..9341df2c 100644 --- a/roqoqo/tests/integration/operations/two_qubit_gate_operations.rs +++ b/roqoqo/tests/integration/operations/two_qubit_gate_operations.rs @@ -157,6 +157,9 @@ fn kak_sigma_matrix( #[test_case(TwoQubitGateOperation::from(ComplexPMInteraction::new(0, 1, CalculatorFloat::from(1.0), CalculatorFloat::from(-1.0))); "ComplexPMInteraction")] #[test_case(TwoQubitGateOperation::from(ControlledPauliY::new(0, 1)); "ControlledPauliY")] #[test_case(TwoQubitGateOperation::from(Bogoliubov::new(0, 1, CalculatorFloat::from(1.0), CalculatorFloat::from(-1.0))); "Bogoliubov")] +#[test_case(TwoQubitGateOperation::from(PhaseShiftedControlledZ::new(0, 1, CalculatorFloat::PI)); "PhaseShiftedControlledZ_pi")] +#[test_case(TwoQubitGateOperation::from(PhaseShiftedControlledZ::new(0, 1, CalculatorFloat::ZERO)); "PhaseShiftedControlledZ_zero")] +#[test_case(TwoQubitGateOperation::from(PhaseShiftedControlledZ::new(0, 1, CalculatorFloat::from(PI/(-3.0)))); "PhaseShiftedControlledZ")] fn test_kakdecomposition(gate: TwoQubitGateOperation) { // k vector let k = gate.kak_decomposition().k_vector; From 9e9bf9e0ea9db8391650dd560c6e470a7e36e82e Mon Sep 17 00:00:00 2001 From: Marina Walt Date: Thu, 8 Jul 2021 11:46:33 +0000 Subject: [PATCH 2/3] roqoqo unit tests extended for PhaseShiftedControlledZ gate --- roqoqo/tests/integration/operations/two_qubit_gate_operations.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/roqoqo/tests/integration/operations/two_qubit_gate_operations.rs b/roqoqo/tests/integration/operations/two_qubit_gate_operations.rs index 9341df2c..f52d2a29 100644 --- a/roqoqo/tests/integration/operations/two_qubit_gate_operations.rs +++ b/roqoqo/tests/integration/operations/two_qubit_gate_operations.rs @@ -363,6 +363,7 @@ fn test_twoqubitgates_clone(gate1: Operation) { #[test_case(TwoQubitGateOperation::from(Bogoliubov::new(0, 1, CalculatorFloat::from(1.0), CalculatorFloat::from(-1.0))); "Bogoliubov")] #[test_case(TwoQubitGateOperation::from(PMInteraction::new(0, 1, CalculatorFloat::PI)); "PMInteraction")] #[test_case(TwoQubitGateOperation::from(ComplexPMInteraction::new(0, 1, CalculatorFloat::from(1.0), CalculatorFloat::from(-1.0))); "ComplexPMInteraction")] +#[test_case(TwoQubitGateOperation::from(PhaseShiftedControlledZ::new(0, 1, CalculatorFloat::FRAC_PI_4)); "PhaseShiftedControlledZ")] fn test_qubits_twoqubitgates(gate: TwoQubitGateOperation) { let control: &usize = &gate.control(); assert_eq!(control, &0); From 37a7e7853f45bd492836cf1e75ae10b48ffab08e Mon Sep 17 00:00:00 2001 From: Marina Walt Date: Fri, 9 Jul 2021 12:35:39 +0000 Subject: [PATCH 3/3] remove minor typos in docstrings --- qoqo/src/operations/two_qubit_gate_operations.rs | 2 +- roqoqo/src/operations/two_qubit_gate_operations.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/qoqo/src/operations/two_qubit_gate_operations.rs b/qoqo/src/operations/two_qubit_gate_operations.rs index 359a69b4..b2d33c1b 100644 --- a/qoqo/src/operations/two_qubit_gate_operations.rs +++ b/qoqo/src/operations/two_qubit_gate_operations.rs @@ -505,7 +505,7 @@ pub struct ComplexPMInteraction { /// 1 & 0 & 0 & 0 \\\\ /// 0 & e^{i \phi} & 0 & 0 \\\\ /// 0 & 0 & e^{i \phi} & 0 \\\\ -/// 0 & 0 & 0 & e^{i (2\cdot\phi - \pi} +/// 0 & 0 & 0 & e^{i (2\cdot\phi - \pi)} /// \end{pmatrix} /// /// Args: diff --git a/roqoqo/src/operations/two_qubit_gate_operations.rs b/roqoqo/src/operations/two_qubit_gate_operations.rs index 660b68f0..65e09673 100644 --- a/roqoqo/src/operations/two_qubit_gate_operations.rs +++ b/roqoqo/src/operations/two_qubit_gate_operations.rs @@ -2162,7 +2162,7 @@ impl OperateTwoQubitGate for ComplexPMInteraction { /// 1 & 0 & 0 & 0 \\\\ /// 0 & e^{i \phi} & 0 & 0 \\\\ /// 0 & 0 & e^{i \phi} & 0 \\\\ -/// 0 & 0 & 0 & e^{i (2\cdot\phi - \pi} +/// 0 & 0 & 0 & e^{i (2\cdot\phi - \pi)} /// \end{pmatrix} /// $$ ///