Skip to content

Commit

Permalink
Add placeholders for all gates
Browse files Browse the repository at this point in the history
  • Loading branch information
ElePT committed Jun 24, 2024
1 parent c76f107 commit 86de861
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 61 deletions.
56 changes: 46 additions & 10 deletions crates/circuit/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,24 +141,60 @@ static STDGATE_IMPORT_PATHS: [[&str; 2]; STANDARD_GATE_SIZE] = [
"qiskit.circuit.library.standard_gates.xx_plus_yy",
"XXPlusYYGate",
],
// CHGate = 26
// U1Gate = 26
["qiskit.circuit.library.standard_gates.u1", "U1Gate"],
// U2Gate = 27
["qiskit.circuit.library.standard_gates.u2", "U2Gate"],
// U3Gate = 28
["qiskit.circuit.library.standard_gates.u3", "U3Gate"],
// CRXGate = 29
["placeholder", "placeholder"],
// CRYGate = 30
["placeholder", "placeholder"],
// CRZGate = 31
["placeholder", "placeholder"],
// RGate 32
["placeholder", "placeholder"],
// CHGate = 33
["qiskit.circuit.library.standard_gates.h", "CHGate"],
// CPhaseGate = 27
// CPhaseGate = 34
["qiskit.circuit.library.standard_gates.p", "CPhaseGate"],
// CSGate = 28
// CSGate = 35
["qiskit.circuit.library.standard_gates.s", "CSGate"],
// CSdgGate = 29
// CSdgGate = 36
["qiskit.circuit.library.standard_gates.s", "CSdgGate"],
// CSXGate = 30
// CSXGate = 37
["qiskit.circuit.library.standard_gates.sx", "CSXGate"],
// CSwapGate = 31
// CSwapGate = 38
["qiskit.circuit.library.standard_gates.swap", "CSwapGate"],
// CU1Gate = 32
// CUGate = 39
["qiskit.circuit.library.standard_gates.u", "CUGate"],
// CU1Gate = 40
["qiskit.circuit.library.standard_gates.u1", "CU1Gate"],
// CU2Gate = 33
["qiskit.circuit.library.standard_gates.u2", "CU2Gate"],
// CU3Gate = 34
// CU3Gate = 41
["qiskit.circuit.library.standard_gates.u3", "CU3Gate"],
// C3XGate = 42
["placeholder", "placeholder"],
// C3SXGate = 43
["placeholder", "placeholder"],
// C4XGate = 44
["placeholder", "placeholder"],
// DCXGate = 45
["placeholder", "placeholder"],
// CCZGate = 46
["placeholder", "placeholder"],
// RCCXGate = 47
["placeholder", "placeholder"],
// RC3XGate = 48
["placeholder", "placeholder"],
// RXXGate = 49
["placeholder", "placeholder"],
// RYYGate = 50
["placeholder", "placeholder"],
// RZZGate = 51
["placeholder", "placeholder"],
// RZXGate = 52
["placeholder", "placeholder"],
];

/// A mapping from the enum variant in crate::operations::StandardGate to the python object for the
Expand Down
164 changes: 113 additions & 51 deletions crates/circuit/src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,63 +205,107 @@ pub enum StandardGate {
ISwapGate = 23,
XXMinusYYGate = 24,
XXPlusYYGate = 25,
CHGate = 26,
CPhaseGate = 27,
CSGate = 28,
CSdgGate = 29,
CSXGate = 30,
CSwapGate = 31,
CU1Gate = 32,
CU2Gate = 33,
CU3Gate = 34,
U1Gate = 26,
U2Gate = 27,
U3Gate = 28,
CRXGate = 29,
CRYGate = 30,
CRZGate = 31,
RGate = 32,
CHGate = 33,
CPhaseGate = 34,
CSGate = 35,
CSdgGate = 36,
CSXGate = 37,
CSwapGate = 38,
CUGate = 39,
CU1Gate = 40,
CU3Gate = 41,
C3XGate = 42,
C3SXGate = 43,
C4XGate = 44,
DCXGate = 45,
CCZGate = 46,
RCCXGate = 47,
RC3XGate = 48,
RXXGate = 49,
RYYGate = 50,
RZZGate = 51,
RZXGate = 52,
}

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, 2, 2, 2, 2, 2, 2, 2, 3,
2, 2, 2,
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
2, 2, 34, 34, 34, 34, 34, 34, 34, 34, // 40-49
34, 34, 34, // 50-52
];

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, 2, 2, 0, 1, 0, 0, 0, 0,
1, 2, 3,
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
1, 3, 34, 34, 34, 34, 34, 34, 34, 34, // 40-49
34, 34, 34, // 50-52
];

static STANDARD_GATE_NAME: [&str; STANDARD_GATE_SIZE] = [
"z",
"y",
"x",
"cz",
"cy",
"cx",
"ccx",
"rx",
"ry",
"rz",
"ecr",
"swap",
"sx",
"global_phase",
"id",
"h",
"p",
"u",
"s",
"sdg",
"t",
"tdg",
"sxdg",
"iswap",
"xx_minus_yy",
"xx_plus_yy",
"ch",
"cphase",
"cs",
"csdg",
"csx",
"cswap",
"cu1",
"cu2",
"cu3",
"z", // 0
"y", // 1
"x", // 2
"cz", // 3
"cy", // 4
"cx", // 5
"ccx", // 6
"rx", // 7
"ry", // 8
"rz", // 9
"ecr", // 10
"swap", // 11
"sx", // 12
"global_phase", // 13
"id", // 14
"h", // 15
"p", // 16
"u", // 17
"s", // 18
"sdg", // 19
"t", // 20
"tdg", // 21
"sxdg", // 22
"iswap", // 23
"xx_minus_yy", // 24
"xx_plus_yy", // 25
"u1", // 26
"u2", // 27
"u3", // 28
"crx", // 29
"cry", // 30
"crz", // 31
"r", // 32
"ch", // 33
"cphase", // 34
"cs", // 35
"csdg", // 36
"csx", // 37
"cswap", // 38
"cu", // 39
"cu1", // 40
"cu3", // 41
"c3x", // 42
"c3sx", // 43
"c4x", // 44
"dcx", // 45
"ccz", // 46
"rccx", // 47
"rc3x", // 48
"rxx", // 49
"ryy", // 50
"rzz", // 51
"rzx", // 52
];

#[pymethods]
Expand Down Expand Up @@ -311,7 +355,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 = 35;
pub const STANDARD_GATE_SIZE: usize = 53;

impl Operation for StandardGate {
fn name(&self) -> &str {
Expand Down Expand Up @@ -452,6 +496,9 @@ impl Operation for StandardGate {
}
_ => None,
},
Self::U1Gate | Self::U2Gate | Self::U3Gate => todo!(),
Self::CRXGate | Self::CRYGate | Self::CRZGate => todo!(),
Self::RGate => todo!(),
Self::CHGate => match params {
[] => Some(aview2(&gate_matrix::CH_GATE).to_owned()),
_ => None,
Expand All @@ -476,7 +523,13 @@ impl Operation for StandardGate {
[] => Some(aview2(&gate_matrix::CSWAP_GATE).to_owned()),
_ => None,
},
Self::CU1Gate | Self::CU2Gate | Self::CU3Gate => todo!(),
Self::CUGate | Self::CU1Gate | Self::CU3Gate => todo!(),
Self::C3XGate | Self::C3SXGate | Self::C4XGate => todo!(),
Self::DCXGate => todo!(),
Self::CCZGate => todo!(),
Self::RCCXGate | Self::RC3XGate => todo!(),
Self::RXXGate | Self::RYYGate | Self::RZZGate => todo!(),
Self::RZXGate => todo!(),
}
}

Expand Down Expand Up @@ -857,6 +910,9 @@ impl Operation for StandardGate {
.expect("Unexpected Qiskit python bug"),
)
}),
Self::U1Gate | Self::U2Gate | Self::U3Gate => todo!(),
Self::CRXGate | Self::CRYGate | Self::CRZGate => todo!(),
Self::RGate => todo!(),
Self::CHGate => Python::with_gil(|py| -> Option<CircuitData> {
let q1 = smallvec![Qubit(1)];
let q0_1 = smallvec![Qubit(0), Qubit(1)];
Expand Down Expand Up @@ -970,9 +1026,15 @@ impl Operation for StandardGate {
.expect("Unexpected Qiskit python bug"),
)
}),
Self::CUGate => None,
Self::CU1Gate => None,
Self::CU2Gate => None,
Self::CU3Gate => None,
Self::C3XGate | Self::C3SXGate | Self::C4XGate => todo!(),
Self::DCXGate => todo!(),
Self::CCZGate => todo!(),
Self::RCCXGate | Self::RC3XGate => todo!(),
Self::RXXGate | Self::RYYGate | Self::RZZGate => todo!(),
Self::RZXGate => todo!(),
}
}

Expand Down

0 comments on commit 86de861

Please sign in to comment.