Skip to content

Commit

Permalink
feat!: created/discarded_qubits circuit attribute (#87)
Browse files Browse the repository at this point in the history
[pytket
`1.7.3`](https://tket.quantinuum.com/api-docs/changelog.html#october-2022)
added `created`/`discarded_qubits` fields to the circuit serialization,
but we never added them here.

BREAKING CHANGE: Made `SerialCircuit` non exhaustive.
  • Loading branch information
aborgna-q authored Nov 5, 2024
1 parent 8e84a00 commit bd5fcc4
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 @@ -206,6 +206,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 @@ -223,6 +224,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 @@ -241,6 +248,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 @@ -289,6 +312,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 @@ -308,6 +346,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 bd5fcc4

Please sign in to comment.