pub struct PauliGraph { /* private fields */ }Expand description
A tk-pg-core program consisting of a qubit count and an ordered list of operations.
The following structural validity checks are performed at Op insertion time:
- All
Op::Gateoperations have valid parameter counts for their gate type. - All
Op::Gateoperations have valid arguments for their gate type, within the valid range. - All Pauli graph native operations have Pauli strings with length matching the graph’s qubit count.
- Conditional bits/values lengths match.
Op::BlackBoxoperations have all argument qubits within the valid range.GateType::BlackBoxgates have no conditions, and they must have data.
Implementations§
Source§impl PauliGraph
impl PauliGraph
Sourcepub fn with_ops(self, ops: Vec<Op>) -> Self
pub fn with_ops(self, ops: Vec<Op>) -> Self
Returns the graph with its operation list replaced by ops.
§Arguments
mut self(Self) - The current graph instance.ops(Vec<Op>) - The new list ofOps to replace the current list.
§Returns
Self- The updated graph instance with the newOplist.
§Panics
Panics if any operation in ops fails the structural validity checks.
Sourcepub fn extend(&mut self, other: PauliGraph)
pub fn extend(&mut self, other: PauliGraph)
Sourcepub fn add_conditional_op(
&mut self,
op: Op,
conditional_bits: Vec<usize>,
conditional_values: Vec<bool>,
)
pub fn add_conditional_op( &mut self, op: Op, conditional_bits: Vec<usize>, conditional_values: Vec<bool>, )
Appends conditional op.
If the last operation is a
Op::ConditionalBox with matching conditions, op is appended into it instead of
creating a new box. If conditional_bits is empty, op is added unconditionally
via Self::add_op.
§Panics
Panics if op fails the structural validity checks, or if conditional_bits and
conditional_values have different lengths.
Sourcepub fn insert_conditional_op(
&mut self,
index: usize,
op: Op,
conditional_bits: Vec<usize>,
conditional_values: Vec<bool>,
)
pub fn insert_conditional_op( &mut self, index: usize, op: Op, conditional_bits: Vec<usize>, conditional_values: Vec<bool>, )
Inserts conditional op at position index.
If the adjacent operation at index - 1 or index is a Op::ConditionalBox with matching conditions, op is merged into
it instead of creating a new box. If conditional_bits is empty, op is inserted
unconditionally via Self::insert_op.
§Panics
Panics if op fails the structural validity checks, or if conditional_bits and
conditional_values have different lengths.
Sourcepub fn swap_ops(&mut self, index1: usize, index2: usize)
pub fn swap_ops(&mut self, index1: usize, index2: usize)
Swaps the operations at positions index1 and index2.
§Panics
Panics if index1 or index2 is out of bounds.
Sourcepub fn replace_slice(&mut self, range: Range<usize>, new_ops: Vec<Op>)
pub fn replace_slice(&mut self, range: Range<usize>, new_ops: Vec<Op>)
Replaces the operations in the index range range with new_ops.
§Panics
Panics if any operation in new_ops fails the structural validity checks or if range is out of bounds.
Sourcepub fn add_qubit(&mut self)
pub fn add_qubit(&mut self)
Increases the qubit count by one, extending all Pauli strings with an identity on the new qubit.
Sourcepub fn get_n_qubits(&self) -> usize
pub fn get_n_qubits(&self) -> usize
Returns the number of qubits.
Sourcepub fn try_validate(&self) -> Result<(), PauliGraphError>
pub fn try_validate(&self) -> Result<(), PauliGraphError>
Validates all operations against the structural validity checks.
§Panics
Panics if any operation fails the structural validity checks.