Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into ab/clexprop
Browse files Browse the repository at this point in the history
  • Loading branch information
aborgna-q committed Nov 5, 2024
2 parents 2722c08 + bd5fcc4 commit dc3539e
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/circuit_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ pub struct ImplicitPermutation(pub Register, pub Register);

/// Pytket canonical serialized circuit
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq)]
#[non_exhaustive]
pub struct SerialCircuit<P = String> {
/// The name of the circuit.
#[serde(skip_serializing_if = "Option::is_none")]
Expand All @@ -230,6 +231,12 @@ pub struct SerialCircuit<P = String> {
/// Number of wasm wires in the circuit.
#[serde(skip_serializing_if = "Option::is_none")]
pub number_of_ws: Option<u64>,
/// A list of qubits initialized at the start of the circuit.
#[serde(skip_serializing_if = "Option::is_none")]
pub created_qubits: Option<Vec<Register>>,
/// A list of qubits discarded at the end of the circuit.
#[serde(skip_serializing_if = "Option::is_none")]
pub discarded_qubits: Option<Vec<Register>>,
}

impl<P> Default for Operation<P> {
Expand All @@ -249,6 +256,22 @@ impl<P> Default for Operation<P> {
}
}

impl<P: Default> Default for SerialCircuit<P> {
fn default() -> Self {
Self {
name: None,
phase: Default::default(),
commands: Default::default(),
qubits: Default::default(),
bits: Default::default(),
implicit_permutation: Default::default(),
number_of_ws: None,
created_qubits: None,
discarded_qubits: None,
}
}
}

impl<P> Operation<P> {
/// Returns a default-initialized Operation with the given type.
///
Expand Down Expand Up @@ -298,6 +321,21 @@ impl<P> Command<P> {
}

impl<P> SerialCircuit<P> {
/// Initialize a new SerialCircuit with the given name and phase.
pub fn new(name: Option<String>, phase: P) -> Self {
Self {
name,
phase,
commands: Vec::new(),
qubits: Vec::new(),
bits: Vec::new(),
implicit_permutation: Vec::new(),
number_of_ws: None,
created_qubits: None,
discarded_qubits: None,
}
}

/// Applies a function over the parameters of the circuit.
///
/// Returns a new SerialCircuit with the same data, but with a new generic
Expand All @@ -317,6 +355,8 @@ impl<P> SerialCircuit<P> {
bits: self.bits,
implicit_permutation: self.implicit_permutation,
number_of_ws: self.number_of_ws,
created_qubits: self.created_qubits,
discarded_qubits: self.discarded_qubits,
}
}
}

0 comments on commit dc3539e

Please sign in to comment.