Cycle¶
-
class
trueq.
Cycle
(content=None, marker=0)¶ Represents a “clock cycle” of a
Circuit
; a set ofGate
s that happen in parallel to a disjoint set of systems. The storage format is adict
that mapstuple
s of system labels toGate
objects. Any given system can only be addressed once in aCycle
.This class is iterable, yielding tuples of the form
(labels, gate)
.import trueq as tq # Single system operations can be applied to multiple systems at once cycle = tq.Cycle({(0, 1): tq.Gate.cnot, (2, 3, 4): tq.Gate.t}) for labels, operation in cycle: print(f'Labels: {str(labels): <8}\tOperation: {operation}')
Labels: (0, 1) Operation: Gate.cx Labels: (2,) Operation: Gate.t Labels: (3,) Operation: Gate.t Labels: (4,) Operation: Gate.t
Compilation tools will only perform actions on lists of contiguous cycles with equal markers; markers serve as a compiler directive describing which portions of a circuit can be recompiled as a block.
- Parameters
content (
dict
) – Adict
whose keys aretuple
s and whose values areOperation
s; the methodadd()
is called on each pair.marker (
int
) – An identifier used to label related cycles for compiler and benchmarking tools.
-
property
dim
¶ The dimension of each subsystem, e.g.
2
if this cycle acts on qubits. However, if no gates have been added to this cycle, then the dimension is unknown and this value is equal toNone
.import trueq as tq cycle = tq.Cycle({(0, 1): tq.Gate.cnot, (2, 3, 4): tq.Gate.t}) cycle.dim
2
- Type
int
|None
-
property
labels
¶ The sorted union of all system labels acted on by
Operation
s in thisCycle
.import trueq as tq cycle = tq.Cycle({(0, 1): tq.Gate.cnot, (2, 3, 4): tq.Gate.t, 5: tq.Meas(), 6: tq.Prep(), 7: tq.Block()}) cycle.labels
(0, 1, 2, 3, 4, 5, 6, 7)
- Type
tuple
-
property
n_gates
¶ The number of gates in this
Cycle
.import trueq as tq cycle = tq.Cycle({(0, 1): tq.Gate.cnot, (2, 3, 4): tq.Gate.t, 5: tq.Meas(), 6: tq.Prep(), 7: tq.Block()}) cycle.n_gates
4
- Type
int
-
property
n_meas
¶ The number of measurements (
Meas
) in thisCycle
.import trueq as tq cycle = tq.Cycle({(0, 1): tq.Gate.cnot, (2, 3, 4): tq.Gate.t, 5: tq.Meas(), 6: tq.Prep(), 7: tq.Block()}) cycle.n_meas
1
- Type
int
-
property
n_prep
¶ The number of preparations (
Prep
) in thisCycle
.import trueq as tq cycle = tq.Cycle({(0, 1): tq.Gate.cnot, (2, 3, 4): tq.Gate.t, 5: tq.Meas(), 6: tq.Prep(), 7: tq.Block()}) cycle.n_prep
1
- Type
int
-
property
n_block
¶ The number of preparations (
Prep
) in thisCycle
.import trueq as tq cycle = tq.Cycle({(0, 1): tq.Gate.cnot, (2, 3, 4): tq.Gate.t, 5: tq.Meas(), 6: tq.Prep(), 7: tq.Block()}) cycle.n_block
1
- Type
int
-
property
n_operations
¶ The total number of operations in this
Cycle
, equal to the sum ofn_gates
,n_meas
, andn_prep
.import trueq as tq cycle = tq.Cycle({(0, 1): tq.Gate.cnot, (2, 3, 4): tq.Gate.t, 5: tq.Meas(), 6: tq.Prep(), 7: tq.Block()}) cycle.n_operations
7
- Type
int
-
property
n_sys
¶ The number of distinct systems participating in this
Cycle
.import trueq as tq cycle = tq.Cycle({(0, 1): tq.Gate.cnot, (2, 3, 4): tq.Gate.t, 5: tq.Meas(), 6: tq.Prep(), 7: tq.Block()}) cycle.n_sys
8
- Type
int
-
property
gates
¶ The
dict
ofGate
s in thisCycle
.import trueq as tq cycle = tq.Cycle({(0, 1): tq.Gate.cnot, (2, 3, 4): tq.Gate.t, 5: tq.Meas(), 6: tq.Prep(), 7: tq.Block()}) cycle.gates
{(0, 1): Gate.cx, (2,): Gate.t, (3,): Gate.t, (4,): Gate.t}
- Type
dict
-
property
gates_single
¶ The single-qubit gates of this cycle; a
dict
ofGate
s in thisCycle
that act on one subsystem.import trueq as tq cycle = tq.Cycle({(0, 1): tq.Gate.cnot, (2, 3, 4): tq.Gate.t, 5: tq.Meas(), 6: tq.Prep(), 7: tq.Block()}) cycle.gates_single
{(2,): Gate.t, (3,): Gate.t, (4,): Gate.t}
- Type
dict
-
property
gates_multi
¶ The multi-qubit gates of this cycle; a
dict
ofGate
s in thisCycle
that act on at least two subsystems.import trueq as tq cycle = tq.Cycle({(0, 1): tq.Gate.cnot, (2, 3, 4): tq.Gate.t, 5: tq.Meas(), 6: tq.Prep(), 7: tq.Block()}) cycle.gates_multi
{(0, 1): Gate.cx}
- Type
dict
-
property
gate_labels
¶ A sorted tuple of all labels in the cycle that have gates (i.e. labels that point to a
Gate
operation).import trueq as tq cycle = tq.Cycle({(0, 1): tq.Gate.cnot, (2, 3, 4): tq.Gate.t, 5: tq.Meas(), 6: tq.Prep(), 7: tq.Block()}) cycle.gate_labels
(0, 1, 2, 3, 4)
- Type
list
-
property
prep
¶ The
dict
ofPrep
s in thisCycle
.import trueq as tq cycle = tq.Cycle({(0, 1): tq.Gate.cnot, (2, 3, 4): tq.Gate.t, 5: tq.Meas(), 6: tq.Prep(), 7: tq.Block()}) cycle.prep
{(6,): Prep()}
- Type
dict
-
property
prep_labels
¶ A sorted tuple of all labels in the cycle that are a preparation (i.e. labels that point to a
Prep
operation).import trueq as tq cycle = tq.Cycle({(0, 1): tq.Gate.cnot, (2, 3, 4): tq.Gate.t, 5: tq.Meas(), 6: tq.Prep(), 7: tq.Block()}) cycle.prep_labels
(6,)
- Type
list
-
property
meas
¶ The
dict
ofMeas
s in thisCycle
.import trueq as tq cycle = tq.Cycle({(0, 1): tq.Gate.cnot, (2, 3, 4): tq.Gate.t, 5: tq.Meas(), 6: tq.Prep(), 7: tq.Block()}) cycle.meas
{(5,): Meas()}
- Type
dict
-
property
meas_labels
¶ A sorted tuple of all labels in the cycle that are a preparation (i.e. labels that point to a
Meas
operation).import trueq as tq cycle = tq.Cycle({(0, 1): tq.Gate.cnot, (2, 3, 4): tq.Gate.t, 5: tq.Meas(), 6: tq.Prep(), 7: tq.Block()}) cycle.meas_labels
(5,)
- Type
list
-
property
block
¶ The
dict
ofBlock
s in thisCycle
.import trueq as tq cycle = tq.Cycle({(0, 1): tq.Gate.cnot, (2, 3, 4): tq.Gate.t, 5: tq.Meas(), 6: tq.Prep(), 7: tq.Block()}) cycle.block
{(7,): Block()}
- Type
dict
-
property
block_labels
¶ A sorted tuple of all labels in the cycle that are blocked (i.e. labels that point to a
Block
operation).import trueq as tq cycle = tq.Cycle({(0, 1): tq.Gate.cnot, (2, 3, 4): tq.Gate.t, 5: tq.Meas(), 6: tq.Prep(), 7: tq.Block()}) cycle.block_labels
(7,)
- Type
list
-
property
operations
¶ The total
dict
ofOperation
s in thisCycle
.import trueq as tq cycle = tq.Cycle({(0, 1): tq.Gate.cnot, (2, 3, 4): tq.Gate.t, 5: tq.Meas(), 6: tq.Prep(), 7: tq.Block()}) cycle.operations
{(0, 1): Gate.cx, (2,): Gate.t, (3,): Gate.t, (4,): Gate.t, (6,): Prep(), (5,): Meas(), (7,): Block()}
- Type
dict
-
tensor
(labels=None)¶ Returns a
Tensor
representation of theGate
s in thisCycle
.The matrix representation (which will be exponentially sized in the number of systems!) of this cycle can be obtained with:
import trueq as tq cycle = tq.Cycle({(0, 1): tq.Gate.cx, 2: tq.Gate.i}) matrix = cycle.tensor().mat() tq.visualization.plot_mat(matrix)
- Parameters
labels (
list
) – An optional list of labels to force into the tensor in case they are not already present as labels in this cycle.- Return type
-
is_equivalent
(other, ignore_marker=True, ignore_id=True)¶ Checks if this cycle is equivalent to another cycle.
import trueq as tq cycle1 = tq.Cycle({(0, 1): tq.Gate.cx}) cycle2 = tq.Cycle({(0, 1): tq.Gate.cx}) cycle1.is_equivalent(cycle2)
True
- Parameters
other (
Cycle
) – Another cycle to compare this one to.ignore_marker (
bool
) – Whether to ignore the marker values. Default isTrue
.ignore_id (
bool
) – Whether to treat all identity gates as though they are not present. Default isTrue
.
- Return type
bool
-
to_dict
()¶ Returns a dictionary representation of a
Cycle
object. This dictionary representation contains only base Python classes.import trueq as tq cycle = tq.Cycle({(0, 1): tq.Gate.cx}) cycle.to_dict()
{'content': {(0, 1): ('Gate', {'u': (((1+0j), 0j, 0j, 0j), (0j, (1+0j), 0j, 0j), (0j, 0j, 0j, (1+0j)), (0j, 0j, (1+0j), 0j))})}, 'marker': 0}
- Return type
dict
-
static
from_dict
(dic)¶ Returns a
Cycle
constructed from a dictionary representation.import trueq as tq cycle = tq.Cycle({(0, 1): tq.Gate.cx}) cycle.from_dict(cycle.to_dict())
True-Q formatting will not be loaded without trusting this notebook or rerunning the affected cells. Notebooks can be marked as trusted by clicking "File -> Trust Notebook".- Marker 0
Compilation tools may only recompile cycles with equal markers.(0, 1): Gate.cx- Name:
-
- Gate.cx
- Aliases:
-
- Gate.cx
- Gate.cnot
- Likeness:
-
- CNOT
- Generators:
-
- 'IX': 90.0
- 'ZI': 90.0
- 'ZX': -90.0
- Matrix:
-
-
property
marker
¶ An identifier used to label related cycles for compiler and benchmarking tools.
This defaults to
0
but can be optionally set to any positiveint
.- Type
int