Skip to content

Commit

Permalink
feat: ToffoliBox encoding (#28)
Browse files Browse the repository at this point in the history
Closes #27
  • Loading branch information
aborgna-q authored Feb 26, 2024
1 parent c1f6767 commit 9121f65
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/circuit_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,21 @@ 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,
// 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<OpType>,
},
}

fn default_impl_diag() -> bool {
Expand Down Expand Up @@ -280,3 +295,13 @@ impl<P> Operation<P> {
}
}
}

/// 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,
}
3 changes: 3 additions & 0 deletions src/optype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,9 @@ pub enum OpType {

/// See \ref MultiplexedU2Box
MultiplexedU2Box,

/// See \ref ToffoliBox
ToffoliBox,
}

#[cfg(feature = "pyo3")]
Expand Down

0 comments on commit 9121f65

Please sign in to comment.