From ab86010bbbe65203447abe27498dc08118310e7c Mon Sep 17 00:00:00 2001 From: John Children Date: Fri, 8 Sep 2023 16:53:06 +0100 Subject: [PATCH 1/3] feat: expand box types and match order - Expand box types to support more (but not all) of the current possible pytket box types. - Re-order the OpType variants to match those of the boxes. --- src/circuit_json.rs | 56 +++++++++++++++++++++++++++++++++++++++++++-- src/optype.rs | 39 +++++++++++++++++++++---------- 2 files changed, 81 insertions(+), 14 deletions(-) diff --git a/src/circuit_json.rs b/src/circuit_json.rs index 011beae..5a7f669 100644 --- a/src/circuit_json.rs +++ b/src/circuit_json.rs @@ -102,8 +102,31 @@ pub enum OpBox { id: BoxID, /// List of Pauli operators. paulis: Vec, - /// Symengine expression + /// Symengine expression. phase: String, + /// Config param for decomposition of Pauli exponentials. + #[serde(default)] + cx_config: String, + }, + /// Operation defined as a pair of exponential of a tensor of Pauli operators. + PauliExpPairBox { + id: BoxID, + /// List of List of Pauli operators. + paulis: Vec>, + /// List of Symengine expressions. + phase: Vec, + /// Config param for decomposition of Pauli exponentials. + cx_config: String, + }, + /// Operation defined as a set of commuting exponentials of a tensor of Pauli operators. + PauliExpCommutingSetBox { + id: BoxID, + /// List of List of Pauli operators. + paulis: Vec<(Vec, String)>, + /// List of Symengine expressions. + pauli_gadgets: Vec<(Vec, String)>, + /// Config param for decomposition of Pauli exponentials. + cx_config: String, }, /// An operation capable of representing arbitrary Circuits made up of CNOT /// and RZ, as a PhasePolynomial plus a boolean matrix representing an @@ -112,16 +135,19 @@ pub enum OpBox { id: BoxID, /// Number of qubits. n_qubits: u32, - qubit_indices: Vec<(u32, u32)>, + qubit_indices: Vec<(u32, u32)>, // TODO: come back to this one. }, + /// A user-defined assertion specified by a list of Pauli stabilisers. StabiliserAssertionBox { id: BoxID, stabilisers: Vec, }, + /// A user-defined assertion specified by a 2x2, 4x4, or 8x8 projector matrix. ProjectorAssertionBox { id: BoxID, matrix: Vec>, }, + /// A user-defined gate defined by a parametrized Circuit. Composite { id: BoxID, gate: CompositeGate, @@ -135,6 +161,9 @@ pub enum OpBox { n_controls: u32, /// The operation to be controlled. op: Box, + /// The state of the control. + #[serde(default)] + control_state: u32, }, /// Holding box for abstract expressions on Bits. ClassicalExpBox { @@ -144,6 +173,29 @@ pub enum OpBox { n_o: u32, exp: ClassicalExp, }, + /// A user-defined multiplexor specified by a map from bitstrings to Operations. + MultiplexorBox { + id: BoxID, + op_map: Vec<(Vec, Operation)>, + }, + /// A user-defined multiplexed rotation gate specified by a map from + /// bitstrings to Operations. + MultiplexedRotationBox { + id: BoxID, + op_map: Vec<(Vec, Operation)>, + }, + /// A user-defined multiplexed rotation gate specified by a map from + /// bitstrings to Operations. + MultiplexedU2Box { + id: BoxID, + op_map: Vec<(Vec, Operation)>, + #[serde(default = "default_impl_diag")] + impl_diag: bool, + }, +} + +fn default_impl_diag() -> bool { + true } /// Decorates another op, adding a QASM-style classical condition. diff --git a/src/optype.rs b/src/optype.rs index 2569b1d..b939b52 100644 --- a/src/optype.rs +++ b/src/optype.rs @@ -373,32 +373,47 @@ pub enum OpType { /// See \ref PauliExpBox PauliExpBox, + /// See \ref PauliExpPairBox + PauliExpPairBox, + + /// See \ref PauliExpCommutingSetBox + PauliExpCommutingSetBox, + /// NYI CliffBox, - /// See \ref CustomGate - CustomGate, - /// See \ref PhasePolyBox PhasePolyBox, + /// NYI + Conditional, + + /// See \ref StabiliserAssertionBox + StabiliserAssertionBox, + + /// See \ref ProjectorAssertionBox + ProjectorAssertionBox, + + /// See \ref Composite + Composite, + /// See \ref QControlBox QControlBox, + /// NYI + UnitaryTableauBox, + /// See \ref ClassicalExpBox ClassicalExpBox, - /// See \ref Conditional - Conditional, + /// See \ref MultiplexorBox + MultiplexorBox, - /// See \ref ProjectorAssertionBox - ProjectorAssertionBox, + /// See \ref MultiplexedRotationBox + MultiplexedRotationBox, - /// See \ref StabiliserAssertionBox - StabiliserAssertionBox, - - /// See \ref UnitaryTableauBox - UnitaryTableauBox, + /// See \ref MultiplexedU2Box + MultiplexedU2Box, } #[cfg(feature = "pyo3")] From fecef0c908e32d62bea10b8f63cda21ba7de347e Mon Sep 17 00:00:00 2001 From: John Children Date: Thu, 14 Sep 2023 17:21:49 +0100 Subject: [PATCH 2/3] fix: correct type of qubit_indices The left member of the tuple should be a Register. --- src/circuit_json.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/circuit_json.rs b/src/circuit_json.rs index 5a7f669..32d10ae 100644 --- a/src/circuit_json.rs +++ b/src/circuit_json.rs @@ -135,7 +135,7 @@ pub enum OpBox { id: BoxID, /// Number of qubits. n_qubits: u32, - qubit_indices: Vec<(u32, u32)>, // TODO: come back to this one. + qubit_indices: Vec<(Register, u32)>, }, /// A user-defined assertion specified by a list of Pauli stabilisers. StabiliserAssertionBox { From 50788aba0bffd72d7f14fc8159bf4a0b941b932b Mon Sep 17 00:00:00 2001 From: John Children Date: Tue, 19 Sep 2023 18:02:22 +0100 Subject: [PATCH 3/3] fix: correct CustomGate OpType name. --- src/optype.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/optype.rs b/src/optype.rs index b939b52..5298bf8 100644 --- a/src/optype.rs +++ b/src/optype.rs @@ -394,8 +394,8 @@ pub enum OpType { /// See \ref ProjectorAssertionBox ProjectorAssertionBox, - /// See \ref Composite - Composite, + /// See \ref CustomGate + CustomGate, /// See \ref QControlBox QControlBox,