From 8c69cb286ad00b37732805767df229c69a07a8d2 Mon Sep 17 00:00:00 2001 From: Agustin Borgna Date: Fri, 23 Feb 2024 19:08:22 +0000 Subject: [PATCH 1/2] feat: ToffoliBox encoding --- src/circuit_json.rs | 21 +++++++++++++++++++++ src/optype.rs | 3 +++ 2 files changed, 24 insertions(+) diff --git a/src/circuit_json.rs b/src/circuit_json.rs index 32d10ae..6047ce4 100644 --- a/src/circuit_json.rs +++ b/src/circuit_json.rs @@ -192,6 +192,17 @@ pub enum OpBox { #[serde(default = "default_impl_diag")] impl_diag: bool, }, + /// An operation that constructs a circuit to implement the specified + /// permutation of classical basis states. + ToffoliBox { + id: BoxID, + /// The classical basis state permutation. + permutation: Permutation, + strat: ToffoliBoxSynthStrat, + #[serde(skip_serializing_if = "Option::is_none")] + #[serde(default)] + rotation_axis: Option, + }, } fn default_impl_diag() -> bool { @@ -280,3 +291,13 @@ impl

Operation

{ } } } + +/// Strategies for synthesising ToffoliBoxes. +#[derive(Deserialize, Serialize, Clone, Debug, PartialEq)] +#[non_exhaustive] +pub enum ToffoliBoxSynthStrat { + /// Use multiplexors to perform parallel swaps on hypercubes. + Matching, + /// Use CnX gates to perform transpositions. + Cycle, +} diff --git a/src/optype.rs b/src/optype.rs index eeef5d2..4ae591e 100644 --- a/src/optype.rs +++ b/src/optype.rs @@ -418,6 +418,9 @@ pub enum OpType { /// See \ref MultiplexedU2Box MultiplexedU2Box, + + /// See \ref ToffoliBox + ToffoliBox, } #[cfg(feature = "pyo3")] From 4b0334f95c6064b356f3f797e6271c5f588896ca Mon Sep 17 00:00:00 2001 From: Agustin Borgna Date: Mon, 26 Feb 2024 11:57:58 +0000 Subject: [PATCH 2/2] Add docs --- src/circuit_json.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/circuit_json.rs b/src/circuit_json.rs index 6047ce4..77da8b0 100644 --- a/src/circuit_json.rs +++ b/src/circuit_json.rs @@ -198,7 +198,11 @@ pub enum OpBox { id: BoxID, /// The classical basis state permutation. permutation: Permutation, + // Synthesis strategy. See [`ToffoliBoxSynthStrat`]. strat: ToffoliBoxSynthStrat, + // The rotation axis of the multiplexors used in the decomposition. Can + // be either `Rx` or `Ry`. Only applicable to the + // [`ToffoliBoxSynthStrat::Matching`] strategy. Default to `Ry`. #[serde(skip_serializing_if = "Option::is_none")] #[serde(default)] rotation_axis: Option,