From a193bcf3615c6d9e69d2e7df4e89bc10fc18eb78 Mon Sep 17 00:00:00 2001 From: Julien Gacon Date: Wed, 19 Jun 2024 16:36:57 +0200 Subject: [PATCH 1/5] v0 of CR-Pauli gates --- crates/circuit/src/gate_matrix.rs | 37 ++++++ crates/circuit/src/imports.rs | 6 + crates/circuit/src/operations.rs | 118 +++++++++++++++++++- qiskit/circuit/library/standard_gates/rx.py | 2 + qiskit/circuit/library/standard_gates/ry.py | 2 + qiskit/circuit/library/standard_gates/rz.py | 2 + 6 files changed, 164 insertions(+), 3 deletions(-) diff --git a/crates/circuit/src/gate_matrix.rs b/crates/circuit/src/gate_matrix.rs index ad8c918e73bc..1b51489dea57 100644 --- a/crates/circuit/src/gate_matrix.rs +++ b/crates/circuit/src/gate_matrix.rs @@ -46,6 +46,43 @@ pub fn rz_gate(theta: f64) -> [[Complex64; 2]; 2] { [[(-ilam2).exp(), c64(0., 0.)], [c64(0., 0.), ilam2.exp()]] } +#[inline] +pub fn crx_gate(theta: f64) -> [[Complex64; 4]; 4] { + let half_theta = theta / 2.; + let cos = c64(half_theta.cos(), 0.); + let isin = c64(0., -half_theta.sin()); + [ + [c64(1., 0.), c64(0., 0.), c64(0., 0.), c64(0., 0.)], + [c64(0., 0.), cos, c64(0., 0.), -isin], + [c64(0., 0.), c64(0., 0.), c64(1., 0.), c64(0., 0.)], + [c64(0., 0.), -isin, c64(0., 0.), cos], + ] +} + +#[inline] +pub fn cry_gate(theta: f64) -> [[Complex64; 4]; 4] { + let half_theta = theta / 2.; + let cos = c64(half_theta.cos(), 0.); + let sin = c64(half_theta.sin(), 0.); + [ + [c64(1., 0.), c64(0., 0.), c64(0., 0.), c64(0., 0.)], + [c64(0., 0.), cos, c64(0., 0.), -sin], + [c64(0., 0.), c64(0., 0.), c64(0., 1.), c64(0., 0.)], + [c64(0., 0.), sin, c64(0., 0.), cos], + ] +} + +#[inline] +pub fn crz_gate(theta: f64) -> [[Complex64; 4]; 4] { + let i_half_theta = c64(0., theta / 2.); + [ + [c64(1., 0.), c64(0., 0.), c64(0., 0.), c64(0., 0.)], + [c64(0., 0.), (-i_half_theta).exp(), c64(0., 0.), c64(0., 0.)], + [c64(0., 0.), c64(0., 0.), c64(-1., 0.), c64(0., 0.)], + [c64(0., 0.), c64(0., 0.), i_half_theta.exp(), c64(0., 0.)], + ] +} + pub static H_GATE: [[Complex64; 2]; 2] = [ [c64(FRAC_1_SQRT_2, 0.), c64(FRAC_1_SQRT_2, 0.)], [c64(FRAC_1_SQRT_2, 0.), c64(-FRAC_1_SQRT_2, 0.)], diff --git a/crates/circuit/src/imports.rs b/crates/circuit/src/imports.rs index 8db3b88fd7d2..82f51bf3c04a 100644 --- a/crates/circuit/src/imports.rs +++ b/crates/circuit/src/imports.rs @@ -131,6 +131,12 @@ static STDGATE_IMPORT_PATHS: [[&str; 2]; STANDARD_GATE_SIZE] = [ ["qiskit.circuit.library.standard_gates.sx", "SXdgGate"], // iSWAPGate = 23 ["qiskit.circuit.library.standard_gates.iswap", "iSwapGate"], + // CRXGate = 24 + ["qiskit.circuit.library.standard_gates.crx", "CRXGate"], + // CRYGate = 25 + ["qiskit.circuit.library.standard_gates.cry", "CRYGate"], + // CRZGate = 26 + ["qiskit.circuit.library.standard_gates.crz", "CRZGate"], ]; /// A mapping from the enum variant in crate::operations::StandardGate to the python object for the diff --git a/crates/circuit/src/operations.rs b/crates/circuit/src/operations.rs index 9048c55d9d48..e1c462ea49ae 100644 --- a/crates/circuit/src/operations.rs +++ b/crates/circuit/src/operations.rs @@ -203,14 +203,17 @@ pub enum StandardGate { TdgGate = 21, SXdgGate = 22, ISwapGate = 23, + CRXGate = 24, + CRYGate = 25, + CRZGate = 26, } static STANDARD_GATE_NUM_QUBITS: [u32; STANDARD_GATE_SIZE] = [ - 1, 1, 1, 2, 2, 2, 3, 1, 1, 1, 2, 2, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, + 1, 1, 1, 2, 2, 2, 3, 1, 1, 1, 2, 2, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, ]; static STANDARD_GATE_NUM_PARAMS: [u32; STANDARD_GATE_SIZE] = [ - 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 3, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 3, 0, 0, 0, 0, 0, 0, 1, 1, 1, ]; static STANDARD_GATE_NAME: [&str; STANDARD_GATE_SIZE] = [ @@ -238,6 +241,9 @@ static STANDARD_GATE_NAME: [&str; STANDARD_GATE_SIZE] = [ "tdg", "sxdg", "iswap", + "crx", + "cry", + "crz", ]; #[pymethods] @@ -287,7 +293,7 @@ impl StandardGate { // Remove this when std::mem::variant_count() is stabilized (see // https://github.com/rust-lang/rust/issues/73662 ) -pub const STANDARD_GATE_SIZE: usize = 24; +pub const STANDARD_GATE_SIZE: usize = 27; impl Operation for StandardGate { fn name(&self) -> &str { @@ -356,6 +362,18 @@ impl Operation for StandardGate { [Param::Float(theta)] => Some(aview2(&gate_matrix::rz_gate(*theta)).to_owned()), _ => None, }, + Self::CRXGate => match params { + [Param::Float(theta)] => Some(aview2(&gate_matrix::crx_gate(*theta)).to_owned()), + _ => None, + }, + Self::CRYGate => match params { + [Param::Float(theta)] => Some(aview2(&gate_matrix::cry_gate(*theta)).to_owned()), + _ => None, + }, + Self::CRZGate => match params { + [Param::Float(theta)] => Some(aview2(&gate_matrix::crz_gate(*theta)).to_owned()), + _ => None, + }, Self::ECRGate => match params { [] => Some(aview2(&gate_matrix::ECR_GATE).to_owned()), _ => None, @@ -570,6 +588,100 @@ impl Operation for StandardGate { Param::Obj(_) => unreachable!(), } }), + Self::CRXGate => Python::with_gil(|py| -> Option { + match ¶ms[0] { + Param::Float(theta) => Some( + CircuitData::from_standard_gates( + py, + 2, + [ + ( + Self::PhaseGate, + smallvec![Param::Float(PI2)], + smallvec![Qubit(1)], + ), + (Self::CXGate, smallvec![], smallvec![Qubit(0), Qubit(1)]), + ( + Self::UGate, + smallvec![ + Param::Float(0.5 * theta), + Param::Float(0.0), + Param::Float(0.0) + ], + smallvec![Qubit(1)], + ), + (Self::CXGate, smallvec![], smallvec![Qubit(0), Qubit(1)]), + ( + Self::UGate, + smallvec![ + Param::Float(-0.5 * theta), + Param::Float(-PI2), + Param::Float(0.0) + ], + smallvec![Qubit(1)], + ), + ], + Param::Float(0.0), + ) + .expect("Unexpected Qiskit Python bug!"), + ), + _ => None, // only Param::Float supported for now + } + }), + Self::CRYGate => Python::with_gil(|py| -> Option { + match ¶ms[0] { + Param::Float(theta) => Some( + CircuitData::from_standard_gates( + py, + 2, + [ + ( + Self::RYGate, + smallvec![Param::Float(theta / 2.)], + smallvec![Qubit(1)], + ), + (Self::CXGate, smallvec![], smallvec![Qubit(0), Qubit(1)]), + ( + Self::RYGate, + smallvec![Param::Float(-theta / 2.)], + smallvec![Qubit(1)], + ), + (Self::CXGate, smallvec![], smallvec![Qubit(0), Qubit(1)]), + ], + Param::Float(0.0), + ) + .expect("Unexpected Qiskit Python bug!"), + ), + _ => None, // only Param::Float supported for now + } + }), + Self::CRZGate => Python::with_gil(|py| -> Option { + match ¶ms[0] { + Param::Float(theta) => Some( + CircuitData::from_standard_gates( + py, + 2, + [ + ( + Self::RZGate, + smallvec![Param::Float(theta / 2.)], + smallvec![Qubit(1)], + ), + (Self::CXGate, smallvec![], smallvec![Qubit(0), Qubit(1)]), + ( + Self::RZGate, + smallvec![Param::Float(-theta / 2.)], + smallvec![Qubit(1)], + ), + (Self::CXGate, smallvec![], smallvec![Qubit(0), Qubit(1)]), + ], + Param::Float(0.0), + ) + .expect("Unexpected Qiskit Python bug!"), + ), + _ => None, // only Param::Float supported for now + } + }), Self::ECRGate => todo!("Add when we have RZX"), Self::SwapGate => Python::with_gil(|py| -> Option { Some( diff --git a/qiskit/circuit/library/standard_gates/rx.py b/qiskit/circuit/library/standard_gates/rx.py index 5579f9d3707d..cb851a740d28 100644 --- a/qiskit/circuit/library/standard_gates/rx.py +++ b/qiskit/circuit/library/standard_gates/rx.py @@ -199,6 +199,8 @@ class CRXGate(ControlledGate): \end{pmatrix} """ + _standard_gate = StandardGate.CRXGate + def __init__( self, theta: ParameterValueType, diff --git a/qiskit/circuit/library/standard_gates/ry.py b/qiskit/circuit/library/standard_gates/ry.py index e27398cc2960..b60b34ffde6f 100644 --- a/qiskit/circuit/library/standard_gates/ry.py +++ b/qiskit/circuit/library/standard_gates/ry.py @@ -198,6 +198,8 @@ class CRYGate(ControlledGate): \end{pmatrix} """ + _standard_gate = StandardGate.CRYGate + def __init__( self, theta: ParameterValueType, diff --git a/qiskit/circuit/library/standard_gates/rz.py b/qiskit/circuit/library/standard_gates/rz.py index e8ee0f976036..78cf20efa5c6 100644 --- a/qiskit/circuit/library/standard_gates/rz.py +++ b/qiskit/circuit/library/standard_gates/rz.py @@ -216,6 +216,8 @@ class CRZGate(ControlledGate): phase difference. """ + _standard_gate = StandardGate.CRZGate + def __init__( self, theta: ParameterValueType, From 50869a0a748156f1ac181592350320f0aa442e77 Mon Sep 17 00:00:00 2001 From: Julien Gacon Date: Thu, 20 Jun 2024 08:38:30 +0200 Subject: [PATCH 2/5] fix inevitable matrix typos --- crates/circuit/src/gate_matrix.rs | 8 ++++---- crates/circuit/src/operations.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/circuit/src/gate_matrix.rs b/crates/circuit/src/gate_matrix.rs index 1b51489dea57..319101f566d9 100644 --- a/crates/circuit/src/gate_matrix.rs +++ b/crates/circuit/src/gate_matrix.rs @@ -50,7 +50,7 @@ pub fn rz_gate(theta: f64) -> [[Complex64; 2]; 2] { pub fn crx_gate(theta: f64) -> [[Complex64; 4]; 4] { let half_theta = theta / 2.; let cos = c64(half_theta.cos(), 0.); - let isin = c64(0., -half_theta.sin()); + let isin = c64(0., half_theta.sin()); [ [c64(1., 0.), c64(0., 0.), c64(0., 0.), c64(0., 0.)], [c64(0., 0.), cos, c64(0., 0.), -isin], @@ -67,7 +67,7 @@ pub fn cry_gate(theta: f64) -> [[Complex64; 4]; 4] { [ [c64(1., 0.), c64(0., 0.), c64(0., 0.), c64(0., 0.)], [c64(0., 0.), cos, c64(0., 0.), -sin], - [c64(0., 0.), c64(0., 0.), c64(0., 1.), c64(0., 0.)], + [c64(0., 0.), c64(0., 0.), c64(1., 0.), c64(0., 0.)], [c64(0., 0.), sin, c64(0., 0.), cos], ] } @@ -78,8 +78,8 @@ pub fn crz_gate(theta: f64) -> [[Complex64; 4]; 4] { [ [c64(1., 0.), c64(0., 0.), c64(0., 0.), c64(0., 0.)], [c64(0., 0.), (-i_half_theta).exp(), c64(0., 0.), c64(0., 0.)], - [c64(0., 0.), c64(0., 0.), c64(-1., 0.), c64(0., 0.)], - [c64(0., 0.), c64(0., 0.), i_half_theta.exp(), c64(0., 0.)], + [c64(0., 0.), c64(0., 0.), c64(1., 0.), c64(0., 0.)], + [c64(0., 0.), c64(0., 0.), c64(0., 0.), i_half_theta.exp()], ] } diff --git a/crates/circuit/src/operations.rs b/crates/circuit/src/operations.rs index e1c462ea49ae..2cf723513b7d 100644 --- a/crates/circuit/src/operations.rs +++ b/crates/circuit/src/operations.rs @@ -604,7 +604,7 @@ impl Operation for StandardGate { ( Self::UGate, smallvec![ - Param::Float(0.5 * theta), + Param::Float(-0.5 * theta), Param::Float(0.0), Param::Float(0.0) ], @@ -614,7 +614,7 @@ impl Operation for StandardGate { ( Self::UGate, smallvec![ - Param::Float(-0.5 * theta), + Param::Float(0.5 * theta), Param::Float(-PI2), Param::Float(0.0) ], From c0879602998bf881ed6ac7c6e0aa8ae88ba67113 Mon Sep 17 00:00:00 2001 From: Julien Gacon Date: Mon, 24 Jun 2024 10:33:50 +0200 Subject: [PATCH 3/5] update multiply_param and prepare for U1/2/3 PR --- crates/circuit/src/imports.rs | 6 +- crates/circuit/src/operations.rs | 176 +++++++++++++++---------------- 2 files changed, 88 insertions(+), 94 deletions(-) diff --git a/crates/circuit/src/imports.rs b/crates/circuit/src/imports.rs index a03dfe5f4470..9ec3cc0cd900 100644 --- a/crates/circuit/src/imports.rs +++ b/crates/circuit/src/imports.rs @@ -141,11 +141,11 @@ static STDGATE_IMPORT_PATHS: [[&str; 2]; STANDARD_GATE_SIZE] = [ "qiskit.circuit.library.standard_gates.xx_plus_yy", "XXPlusYYGate", ], - // CRXGate = 26 + // CRXGate = 29 ["qiskit.circuit.library.standard_gates.crx", "CRXGate"], - // CRYGate = 27 + // CRYGate = 30 ["qiskit.circuit.library.standard_gates.cry", "CRYGate"], - // CRZGate = 28 + // CRZGate = 31 ["qiskit.circuit.library.standard_gates.crz", "CRZGate"], ]; diff --git a/crates/circuit/src/operations.rs b/crates/circuit/src/operations.rs index 01db559c1916..6349301be236 100644 --- a/crates/circuit/src/operations.rs +++ b/crates/circuit/src/operations.rs @@ -205,9 +205,9 @@ pub enum StandardGate { ISwapGate = 23, XXMinusYYGate = 24, XXPlusYYGate = 25, - CRXGate = 26, - CRXGate = 27, - CRXGate = 28, + CRXGate = 29, + CRYGate = 30, + CRZGate = 31, } static STANDARD_GATE_NUM_QUBITS: [u32; STANDARD_GATE_SIZE] = [ @@ -587,98 +587,92 @@ impl Operation for StandardGate { ) }), Self::CRXGate => Python::with_gil(|py| -> Option { - match ¶ms[0] { - Param::Float(theta) => Some( - CircuitData::from_standard_gates( - py, - 2, - [ - ( - Self::PhaseGate, - smallvec![Param::Float(PI2)], - smallvec![Qubit(1)], - ), - (Self::CXGate, smallvec![], smallvec![Qubit(0), Qubit(1)]), - ( - Self::UGate, - smallvec![ - Param::Float(-0.5 * theta), - Param::Float(0.0), - Param::Float(0.0) - ], - smallvec![Qubit(1)], - ), - (Self::CXGate, smallvec![], smallvec![Qubit(0), Qubit(1)]), - ( - Self::UGate, - smallvec![ - Param::Float(0.5 * theta), - Param::Float(-PI2), - Param::Float(0.0) - ], - smallvec![Qubit(1)], - ), - ], - Param::Float(0.0), - ) - .expect("Unexpected Qiskit Python bug!"), - ), - _ => None, // only Param::Float supported for now - } + let theta = ¶ms[0]; + Some( + CircuitData::from_standard_gates( + py, + 2, + [ + ( + Self::PhaseGate, + smallvec![Param::Float(PI2)], + smallvec![Qubit(1)], + ), + (Self::CXGate, smallvec![], smallvec![Qubit(0), Qubit(1)]), + ( + Self::UGate, + smallvec![ + multiply_param(theta, -0.5, py), + Param::Float(0.0), + Param::Float(0.0) + ], + smallvec![Qubit(1)], + ), + (Self::CXGate, smallvec![], smallvec![Qubit(0), Qubit(1)]), + ( + Self::UGate, + smallvec![ + multiply_param(theta, 0.5, py), + Param::Float(-PI2), + Param::Float(0.0) + ], + smallvec![Qubit(1)], + ), + ], + Param::Float(0.0), + ) + .expect("Unexpected Qiskit Python bug!"), + ) }), Self::CRYGate => Python::with_gil(|py| -> Option { - match ¶ms[0] { - Param::Float(theta) => Some( - CircuitData::from_standard_gates( - py, - 2, - [ - ( - Self::RYGate, - smallvec![Param::Float(theta / 2.)], - smallvec![Qubit(1)], - ), - (Self::CXGate, smallvec![], smallvec![Qubit(0), Qubit(1)]), - ( - Self::RYGate, - smallvec![Param::Float(-theta / 2.)], - smallvec![Qubit(1)], - ), - (Self::CXGate, smallvec![], smallvec![Qubit(0), Qubit(1)]), - ], - Param::Float(0.0), - ) - .expect("Unexpected Qiskit Python bug!"), - ), - _ => None, // only Param::Float supported for now - } + let theta = ¶ms[0]; + Some( + CircuitData::from_standard_gates( + py, + 2, + [ + ( + Self::RYGate, + smallvec![multiply_param(theta, 0.5, py)], + smallvec![Qubit(1)], + ), + (Self::CXGate, smallvec![], smallvec![Qubit(0), Qubit(1)]), + ( + Self::RYGate, + smallvec![multiply_param(theta, -0.5, py)], + smallvec![Qubit(1)], + ), + (Self::CXGate, smallvec![], smallvec![Qubit(0), Qubit(1)]), + ], + Param::Float(0.0), + ) + .expect("Unexpected Qiskit Python bug!"), + ) }), Self::CRZGate => Python::with_gil(|py| -> Option { - match ¶ms[0] { - Param::Float(theta) => Some( - CircuitData::from_standard_gates( - py, - 2, - [ - ( - Self::RZGate, - smallvec![Param::Float(theta / 2.)], - smallvec![Qubit(1)], - ), - (Self::CXGate, smallvec![], smallvec![Qubit(0), Qubit(1)]), - ( - Self::RZGate, - smallvec![Param::Float(-theta / 2.)], - smallvec![Qubit(1)], - ), - (Self::CXGate, smallvec![], smallvec![Qubit(0), Qubit(1)]), - ], - Param::Float(0.0), - ) - .expect("Unexpected Qiskit Python bug!"), - ), - _ => None, // only Param::Float supported for now - } + let theta = ¶ms[0]; + Some( + CircuitData::from_standard_gates( + py, + 2, + [ + ( + Self::RZGate, + smallvec![multiply_param(theta, 0.5, py)], + smallvec![Qubit(1)], + ), + (Self::CXGate, smallvec![], smallvec![Qubit(0), Qubit(1)]), + ( + Self::RZGate, + smallvec![multiply_param(theta, -0.5, py)], + smallvec![Qubit(1)], + ), + (Self::CXGate, smallvec![], smallvec![Qubit(0), Qubit(1)]), + ], + Param::Float(0.0), + ) + .expect("Unexpected Qiskit Python bug!"), + ) }), Self::ECRGate => todo!("Add when we have RZX"), Self::SwapGate => Python::with_gil(|py| -> Option { From c15b9056e164c884887435f946d3c5ef8796a39a Mon Sep 17 00:00:00 2001 From: Julien Gacon Date: Tue, 25 Jun 2024 11:27:16 +0200 Subject: [PATCH 4/5] fix num params/qubits --- crates/circuit/src/operations.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/circuit/src/operations.rs b/crates/circuit/src/operations.rs index 496f91077749..a778555db652 100644 --- a/crates/circuit/src/operations.rs +++ b/crates/circuit/src/operations.rs @@ -238,8 +238,8 @@ pub enum StandardGate { static STANDARD_GATE_NUM_QUBITS: [u32; STANDARD_GATE_SIZE] = [ 1, 1, 1, 2, 2, 2, 3, 1, 1, 1, // 0-9 2, 2, 1, 0, 1, 1, 1, 1, 1, 1, // 10-19 - 1, 1, 1, 2, 2, 2, 1, 1, 1, 34, // 20-29 - 34, 34, 34, 2, 2, 2, 2, 2, 3, 2, // 30-39 + 1, 1, 1, 2, 2, 2, 1, 1, 1, 2, // 20-29 + 2, 2, 34, 2, 2, 2, 2, 2, 3, 2, // 30-39 2, 2, 34, 34, 34, 34, 34, 34, 34, 34, // 40-49 34, 34, 34, // 50-52 ]; @@ -248,8 +248,8 @@ static STANDARD_GATE_NUM_QUBITS: [u32; STANDARD_GATE_SIZE] = [ static STANDARD_GATE_NUM_PARAMS: [u32; STANDARD_GATE_SIZE] = [ 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, // 0-9 0, 0, 0, 1, 0, 0, 1, 3, 0, 0, // 10-19 - 0, 0, 0, 0, 2, 2, 1, 2, 3, 34, // 20-29 - 34, 34, 34, 0, 1, 0, 0, 0, 0, 3, // 30-39 + 0, 0, 0, 0, 2, 2, 1, 2, 3, 1, // 20-29 + 1, 1, 34, 0, 1, 0, 0, 0, 0, 3, // 30-39 1, 3, 34, 34, 34, 34, 34, 34, 34, 34, // 40-49 34, 34, 34, // 50-52 ]; From ed7ebe6aef43ba87b0c5087bc2cb6aaf5c569d7e Mon Sep 17 00:00:00 2001 From: Julien Gacon Date: Tue, 25 Jun 2024 17:38:52 +0200 Subject: [PATCH 5/5] cct methods to append rust gates --- crates/circuit/src/imports.rs | 6 +++--- qiskit/circuit/quantumcircuit.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/crates/circuit/src/imports.rs b/crates/circuit/src/imports.rs index 564eec326ee9..c4faeb6fd7ee 100644 --- a/crates/circuit/src/imports.rs +++ b/crates/circuit/src/imports.rs @@ -151,11 +151,11 @@ static STDGATE_IMPORT_PATHS: [[&str; 2]; STANDARD_GATE_SIZE] = [ // U3Gate = 28 ["qiskit.circuit.library.standard_gates.u3", "U3Gate"], // CRXGate = 29 - ["qiskit.circuit.library.standard_gates.crx", "CRXGate"], + ["qiskit.circuit.library.standard_gates.rx", "CRXGate"], // CRYGate = 30 - ["qiskit.circuit.library.standard_gates.cry", "CRYGate"], + ["qiskit.circuit.library.standard_gates.ry", "CRYGate"], // CRZGate = 31 - ["qiskit.circuit.library.standard_gates.crz", "CRZGate"], + ["qiskit.circuit.library.standard_gates.rz", "CRZGate"], // RGate 32 ["placeholder", "placeholder"], // CHGate = 33 diff --git a/qiskit/circuit/quantumcircuit.py b/qiskit/circuit/quantumcircuit.py index ee52e3308a94..ccaa0703166c 100644 --- a/qiskit/circuit/quantumcircuit.py +++ b/qiskit/circuit/quantumcircuit.py @@ -4776,6 +4776,12 @@ def crx( """ from .library.standard_gates.rx import CRXGate + # if the control state is |1> use the fast Rust version of the gate + if ctrl_state is None or ctrl_state in ["1", 1]: + return self._append_standard_gate( + StandardGate.CRXGate, [theta], [control_qubit, target_qubit], None, label=label + ) + return self.append( CRXGate(theta, label=label, ctrl_state=ctrl_state), [control_qubit, target_qubit], @@ -4845,6 +4851,12 @@ def cry( """ from .library.standard_gates.ry import CRYGate + # if the control state is |1> use the fast Rust version of the gate + if ctrl_state is None or ctrl_state in ["1", 1]: + return self._append_standard_gate( + StandardGate.CRYGate, [theta], [control_qubit, target_qubit], None, label=label + ) + return self.append( CRYGate(theta, label=label, ctrl_state=ctrl_state), [control_qubit, target_qubit], @@ -4911,6 +4923,12 @@ def crz( """ from .library.standard_gates.rz import CRZGate + # if the control state is |1> use the fast Rust version of the gate + if ctrl_state is None or ctrl_state in ["1", 1]: + return self._append_standard_gate( + StandardGate.CRZGate, [theta], [control_qubit, target_qubit], None, label=label + ) + return self.append( CRZGate(theta, label=label, ctrl_state=ctrl_state), [control_qubit, target_qubit],