Skip to content

Commit

Permalink
Merge 203cec4 into 4d3821b
Browse files Browse the repository at this point in the history
  • Loading branch information
eliarbel committed Jun 26, 2024
2 parents 4d3821b + 203cec4 commit 2e60175
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
7 changes: 7 additions & 0 deletions crates/circuit/src/gate_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ pub static TDG_GATE: [[Complex64; 2]; 2] = [
[c64(0., 0.), c64(FRAC_1_SQRT_2, -FRAC_1_SQRT_2)],
];

pub static DCX_GATE: [[Complex64; 4]; 4] = [
[c64(1., 0.), c64(0., 0.), c64(0., 0.), c64(0., 0.)],
[c64(0., 0.), c64(0., 0.), c64(0., 0.), c64(1., 0.)],
[c64(0., 0.), c64(1., 0.), c64(0., 0.), c64(0., 0.)],
[c64(0., 0.), c64(0., 0.), c64(1., 0.), c64(0., 0.)],
];

#[inline]
pub fn global_phase_gate(theta: f64) -> [[Complex64; 1]; 1] {
[[c64(0., theta).exp()]]
Expand Down
2 changes: 1 addition & 1 deletion crates/circuit/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ static STDGATE_IMPORT_PATHS: [[&str; 2]; STANDARD_GATE_SIZE] = [
// C4XGate = 44
["placeholder", "placeholder"],
// DCXGate = 45
["placeholder", "placeholder"],
["qiskit.circuit.library.standard_gates.dcx", "DCXGate"],
// CCZGate = 46
["placeholder", "placeholder"],
// RCCXGate = 47
Expand Down
25 changes: 21 additions & 4 deletions crates/circuit/src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ static STANDARD_GATE_NUM_QUBITS: [u32; STANDARD_GATE_SIZE] = [
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
2, 2, 34, 34, 34, 34, 34, 34, 34, 34, // 40-49
2, 2, 34, 34, 34, 2, 34, 34, 34, 34, // 40-49
34, 34, 34, // 50-52
];

Expand All @@ -250,7 +250,7 @@ static STANDARD_GATE_NUM_PARAMS: [u32; STANDARD_GATE_SIZE] = [
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
1, 3, 34, 34, 34, 34, 34, 34, 34, 34, // 40-49
1, 3, 34, 34, 34, 0, 34, 34, 34, 34, // 40-49
34, 34, 34, // 50-52
];

Expand Down Expand Up @@ -523,7 +523,10 @@ impl Operation for StandardGate {
Self::CSwapGate => todo!(),
Self::CUGate | Self::CU1Gate | Self::CU3Gate => todo!(),
Self::C3XGate | Self::C3SXGate | Self::C4XGate => todo!(),
Self::DCXGate => todo!(),
Self::DCXGate => match params {
[] => Some(aview2(&gate_matrix::DCX_GATE).to_owned()),
_ => None,
},
Self::CCZGate => todo!(),
Self::RCCXGate | Self::RC3XGate => todo!(),
Self::RXXGate | Self::RYYGate | Self::RZZGate => todo!(),
Expand Down Expand Up @@ -965,7 +968,21 @@ impl Operation for StandardGate {
Self::CU1Gate => todo!(),
Self::CU3Gate => todo!(),
Self::C3XGate | Self::C3SXGate | Self::C4XGate => todo!(),
Self::DCXGate => todo!(),
Self::DCXGate => Python::with_gil(|py| -> Option<CircuitData> {
Some(
CircuitData::from_standard_gates(
py,
2,
[
(Self::CXGate, smallvec![], smallvec![Qubit(0), Qubit(1)]),
(Self::CXGate, smallvec![], smallvec![Qubit(1), Qubit(0)]),
],
FLOAT_ZERO,
)
.expect("Unexpected Qiskit python bug"),
)
}),

Self::CCZGate => todo!(),
Self::RCCXGate | Self::RC3XGate => todo!(),
Self::RXXGate | Self::RYYGate | Self::RZZGate => todo!(),
Expand Down
3 changes: 3 additions & 0 deletions qiskit/circuit/library/standard_gates/dcx.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from qiskit.circuit.singleton import SingletonGate, stdlib_singleton_key
from qiskit.circuit.quantumregister import QuantumRegister
from qiskit.circuit._utils import with_gate_array
from qiskit._accelerate.circuit import StandardGate


@with_gate_array([[1, 0, 0, 0], [0, 0, 0, 1], [0, 1, 0, 0], [0, 0, 1, 0]])
Expand Down Expand Up @@ -48,6 +49,8 @@ class DCXGate(SingletonGate):
\end{pmatrix}
"""

_standard_gate = StandardGate.DCXGate

def __init__(self, label=None, *, duration=None, unit="dt"):
"""Create new DCX gate."""
super().__init__("dcx", 2, [], label=label, duration=duration, unit=unit)
Expand Down
4 changes: 1 addition & 3 deletions qiskit/circuit/quantumcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -5328,9 +5328,7 @@ def dcx(self, qubit1: QubitSpecifier, qubit2: QubitSpecifier) -> InstructionSet:
Returns:
A handle to the instructions created.
"""
from .library.standard_gates.dcx import DCXGate

return self.append(DCXGate(), [qubit1, qubit2], [], copy=False)
return self._append_standard_gate(op=StandardGate.DCXGate, qargs=[qubit1, qubit2])

def ccx(
self,
Expand Down

0 comments on commit 2e60175

Please sign in to comment.