Skip to content

Commit

Permalink
Add CHGate, CPhaseGate, CSGate, CSdgGate, CSXGate, CSwapGate
Browse files Browse the repository at this point in the history
  • Loading branch information
ElePT committed Jun 24, 2024
1 parent 306bd54 commit f894c14
Show file tree
Hide file tree
Showing 9 changed files with 513 additions and 80 deletions.
133 changes: 133 additions & 0 deletions crates/circuit/src/gate_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,127 @@ pub static TDG_GATE: [[Complex64; 2]; 2] = [
[c64(0., 0.), c64(FRAC_1_SQRT_2, -FRAC_1_SQRT_2)],
];

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

pub static CS_GATE: [[Complex64; 4]; 4] = [
[c64(1., 0.), c64(0., 0.), c64(0., 0.), c64(0., 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.)],
[c64(0., 0.), c64(0., 0.), c64(0., 0.), c64(0., 1.)],
];

pub static CSDG_GATE: [[Complex64; 4]; 4] = [
[c64(1., 0.), c64(0., 0.), c64(0., 0.), c64(0., 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.)],
[c64(0., 0.), c64(0., 0.), c64(0., 0.), c64(0., -1.)],
];

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

pub static CSWAP_GATE: [[Complex64; 8]; 8] = [
[
c64(1., 0.),
c64(0., 0.),
c64(0., 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(0., 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(0., 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(0., 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(0., 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(0., 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(0., 0.),
c64(0., 0.),
c64(0., 0.),
c64(0., 0.),
c64(0., 0.),
c64(0., 0.),
c64(0., 0.),
c64(1., 0.),
],
];

#[inline]
pub fn global_phase_gate(theta: f64) -> [[Complex64; 1]; 1] {
[[c64(0., theta).exp()]]
Expand Down Expand Up @@ -324,3 +445,15 @@ pub fn xx_plus_yy_gate(theta: f64, beta: f64) -> [[Complex64; 4]; 4] {
[c64(0., 0.), c64(0., 0.), c64(0., 0.), c64(1., 0.)],
]
}

#[inline]
pub fn cphase_gate(lam: f64) -> [[Complex64; 4]; 4] {
let cos = (1. / lam).cos();
let sin = (1. / lam).sin();
[
[c64(1., 0.), c64(0., 0.), c64(0., 0.), c64(0., 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.)],
[c64(0., 0.), c64(0., 0.), c64(0., 0.), c64(cos, sin)],
]
}
53 changes: 51 additions & 2 deletions crates/circuit/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ pub static SINGLETON_CONTROLLED_GATE: ImportOnceCell =
///
/// NOTE: the order here is significant, the StandardGate variant's number must match
/// index of it's entry in this table. This is all done statically for performance
// TODO: replace placeholders with actual implementation
static STDGATE_IMPORT_PATHS: [[&str; 2]; STANDARD_GATE_SIZE] = [
// ZGate = 0
["qiskit.circuit.library.standard_gates.z", "ZGate"],
Expand Down Expand Up @@ -131,12 +132,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"],
//XXMinusYYGate = 24
// XXMinusYYGate = 24
[
"qiskit.circuit.library.standard_gates.xx_minus_yy",
"XXMinusYYGate",
],
//XXPlusYYGate = 25
// XXPlusYYGate = 25
[
"qiskit.circuit.library.standard_gates.xx_plus_yy",
"XXPlusYYGate",
Expand All @@ -147,6 +148,54 @@ static STDGATE_IMPORT_PATHS: [[&str; 2]; STANDARD_GATE_SIZE] = [
["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 = 34
["qiskit.circuit.library.standard_gates.p", "CPhaseGate"],
// CSGate = 35
["qiskit.circuit.library.standard_gates.s", "CSGate"],
// CSdgGate = 36
["qiskit.circuit.library.standard_gates.s", "CSdgGate"],
// CSXGate = 37
["qiskit.circuit.library.standard_gates.sx", "CSXGate"],
// CSwapGate = 38
["qiskit.circuit.library.standard_gates.swap", "CSwapGate"],
// CUGate = 39
["qiskit.circuit.library.standard_gates.u", "CUGate"],
// CU1Gate = 40
["qiskit.circuit.library.standard_gates.u1", "CU1Gate"],
// 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
Loading

0 comments on commit f894c14

Please sign in to comment.