Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: created/discarded_qubits circuit attribute #87

Merged
merged 2 commits into from
Nov 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>>,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a vector of qubits, not a vector of qubit registers. But it seems Register is used in this file to refer to qubits (or bits). The name and description ("A register of locations sharing the same name") perhaps arise from a misunderstanding: qubits can be multi-indexed, so e.g. ["q", [0]] and ["q", [0, 1]] are both serializations of single qubits.

Copy link
Collaborator Author

@aborgna-q aborgna-q Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the naming there is terrible. I'll open the issue.

Edit: #88

/// 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,
}
}
}
Loading