Download

Download this file as Jupyter notebook: circuit_collections.ipynb.

Circuit Collections

A CircuitCollection is a list-like object containing Circuits. This is a natural type in True-Q™ because the core strategy of many built-in diagnostic and suppression protocols is to produce a collection of many circuits. After the circuits have been run, their results can be jointly fit to estimate certain parameters of interest. It is also a natural type for quantum experiments more generally; one is often interested in executing a family of related circuits and a circuit collection is a convenient container to encapsulate them, their results, and their metadata.

Creating and Appending to Circuit Collections

Circuit collections are created by many of the tools built in to True-Q™. For example, the most basic protocol, SRB, has an associated function make_srb() that instantiates a new collection of random circuits:

[2]:
import trueq as tq

# create circuits for simultaneous randomized benchmarking on qubits labeled 0 through 4
srb_circuits = tq.make_srb(range(5), [4, 12, 24])

Circuit collections can also be created manually from zero or more existing circuits:

[3]:
# create an empty circuit collection
circuits = tq.CircuitCollection()

In either case, we can append single circuits or iterables of circuits (including other circuit collections) to existing circuit collections. The appended circuits are not copied, so that the same circuit instance can exist in multiple collections. The += operator is equivalent to the append() method.

[4]:
# append a single circuit to the empty collection created above
circuits += tq.Circuit({range(5): tq.Gate.h})

# append randomized benchmarking circuits that were generated above
circuits += srb_circuits

# append new cycle benchmarking circuits to the collection
circuits += tq.make_cb({range(5): tq.Gate.h}, [4, 12, 24])

# append new readout calibration circuits
circuits += tq.make_rcal(range(5))

Standard list-like conveniences are available on the collection:

[5]:
# get the 5th (0-indexed) circuit
circuits[5]
[5]:
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".
Circuit
Key:
  • compiled_pauli: IYIZZ
  • measurement_basis: ZZZZZ
  • n_random_cycles: 4
  • protocol: SRB
  • twirl: Cliffords on [0, 1, 2, 3, 4]
1
Marker 1
Compilation tools may only recompile cycles with equal markers.
(0): Gate.x
Name:
  • Gate.x
Aliases:
  • Gate.x
  • Gate.cliff1
Generators:
  • 'X': -180.0
Matrix:
  • 1.00j 1.00j
(1): Gate.cliff10
Name:
  • Gate.cliff10
Aliases:
  • Gate.cliff10
Generators:
  • 'Y': -127.279
  • 'X': -127.279
Matrix:
  • 1.00 1.00j
(2): Gate.cliff18
Name:
  • Gate.cliff18
Aliases:
  • Gate.cliff18
Generators:
  • 'Y': 69.282
  • 'X': -69.282
  • 'Z': -69.282
Matrix:
  • 0.50 -0.50j 0.50 0.50j 0.50 -0.50j -0.50 -0.50j
(3): Gate.cliff17
Name:
  • Gate.cliff17
Aliases:
  • Gate.cliff17
Generators:
  • 'Y': -69.282
  • 'X': -69.282
  • 'Z': 69.282
Matrix:
  • 0.50 0.50j -0.50 0.50j -0.50 -0.50j -0.50 0.50j
(4): Gate.s
Name:
  • Gate.s
Aliases:
  • Gate.s
  • Gate.sz
  • Gate.cliff9
Generators:
  • 'Z': 90.0
Matrix:
  • 1.00 1.00j
2
Marker 2
Compilation tools may only recompile cycles with equal markers.
(0): Gate.cliff8
Name:
  • Gate.cliff8
Aliases:
  • Gate.cliff8
Generators:
  • 'Z': -90.0
Matrix:
  • 1.00 -1.00j
(1): Gate.y
Name:
  • Gate.y
Aliases:
  • Gate.y
  • Gate.cliff2
Generators:
  • 'Y': 180.0
Matrix:
  • -1.00 1.00
(2): Gate.cliff16
Name:
  • Gate.cliff16
Aliases:
  • Gate.cliff16
Generators:
  • 'Y': -69.282
  • 'X': -69.282
  • 'Z': -69.282
Matrix:
  • 0.71 0.71 0.71j -0.71j
(3): Gate.cliff4
Name:
  • Gate.cliff4
Aliases:
  • Gate.cliff4
Generators:
  • 'X': -90.0
Matrix:
  • 0.71 0.71j 0.71j 0.71
(4): Gate.cliff4
Name:
  • Gate.cliff4
Aliases:
  • Gate.cliff4
Generators:
  • 'X': -90.0
Matrix:
  • 0.71 0.71j 0.71j 0.71
3
Marker 3
Compilation tools may only recompile cycles with equal markers.
(0): Gate.sy
Name:
  • Gate.sy
Aliases:
  • Gate.sy
  • Gate.cliff7
Generators:
  • 'Y': -270.0
Matrix:
  • -0.71 0.71 -0.71 -0.71
(1): Gate.cliff21
Name:
  • Gate.cliff21
Aliases:
  • Gate.cliff21
Generators:
  • 'Y': 138.564
  • 'X': -138.564
  • 'Z': -138.564
Matrix:
  • -0.71 -0.71 0.71j -0.71j
(2): Gate.sy
Name:
  • Gate.sy
Aliases:
  • Gate.sy
  • Gate.cliff7
Generators:
  • 'Y': -270.0
Matrix:
  • -0.71 0.71 -0.71 -0.71
(3): Gate.cliff18
Name:
  • Gate.cliff18
Aliases:
  • Gate.cliff18
Generators:
  • 'Y': 69.282
  • 'X': -69.282
  • 'Z': -69.282
Matrix:
  • 0.50 -0.50j 0.50 0.50j 0.50 -0.50j -0.50 -0.50j
(4): Gate.cliff13
Name:
  • Gate.cliff13
Aliases:
  • Gate.cliff13
Generators:
  • 'X': 127.279
  • 'Z': -127.279
Matrix:
  • 0.71 -0.71 -0.71 -0.71
4
Marker 4
Compilation tools may only recompile cycles with equal markers.
(0): Gate.cliff4
Name:
  • Gate.cliff4
Aliases:
  • Gate.cliff4
Generators:
  • 'X': -90.0
Matrix:
  • 0.71 0.71j 0.71j 0.71
(1): Gate.cliff15
Name:
  • Gate.cliff15
Aliases:
  • Gate.cliff15
Generators:
  • 'Y': 127.279
  • 'Z': -127.279
Matrix:
  • 0.71j -0.71 0.71 -0.71j
(2): Gate.cliff15
Name:
  • Gate.cliff15
Aliases:
  • Gate.cliff15
Generators:
  • 'Y': 127.279
  • 'Z': -127.279
Matrix:
  • 0.71j -0.71 0.71 -0.71j
(3): Gate.id
Name:
  • Gate.id
Aliases:
  • Gate.id
  • Gate.i
  • Gate.cliff0
Likeness:
  • Identity
Generators:
  • 'I': 0
Matrix:
  • 1.00 1.00
(4): Gate.cliff16
Name:
  • Gate.cliff16
Aliases:
  • Gate.cliff16
Generators:
  • 'Y': -69.282
  • 'X': -69.282
  • 'Z': -69.282
Matrix:
  • 0.71 0.71 0.71j -0.71j
5
Marker 5
Compilation tools may only recompile cycles with equal markers.
(0): Gate.sy
Name:
  • Gate.sy
Aliases:
  • Gate.sy
  • Gate.cliff7
Generators:
  • 'Y': -270.0
Matrix:
  • -0.71 0.71 -0.71 -0.71
(1): Gate.y
Name:
  • Gate.y
Aliases:
  • Gate.y
  • Gate.cliff2
Generators:
  • 'Y': 180.0
Matrix:
  • -1.00 1.00
(2): Gate.cliff19
Name:
  • Gate.cliff19
Aliases:
  • Gate.cliff19
Generators:
  • 'Y': 69.282
  • 'X': -69.282
  • 'Z': 69.282
Matrix:
  • 0.50 -0.50j -0.50 0.50j 0.50 0.50j 0.50 0.50j
(3): Gate.sx
Name:
  • Gate.sx
Aliases:
  • Gate.sx
  • Gate.cliff5
Generators:
  • 'X': 90.0
Matrix:
  • 0.71 -0.71j -0.71j 0.71
(4): Gate.cliff13
Name:
  • Gate.cliff13
Aliases:
  • Gate.cliff13
Generators:
  • 'X': 127.279
  • 'Z': -127.279
Matrix:
  • 0.71 -0.71 -0.71 -0.71
6
Marker 6
Compilation tools may only recompile cycles with equal markers.
(0): Meas()
Name:
  • Meas()
(1): Meas()
Name:
  • Meas()
(2): Meas()
Name:
  • Meas()
(3): Meas()
Name:
  • Meas()
(4): Meas()
Name:
  • Meas()
[6]:
# find the number of circuits in the collection
len(circuits)
[6]:
1083
[7]:
# loop through circuits in the collection
for circuit in circuits:
    pass

CircuitCollection for a full list of available properties and methods, such as has_some_results, fit(), save(), sum_results(), and batch().

Filtering Circuit Collections

During data analysis, it is useful to be able to quickly filter specific subsets of circuits for processing. Rather than introspecting the gates and cycles within each circuit, or relying on their order within a collection, it is more robust and convenient to rely on circuit metadata to filter circuits. Every circuit owns a key attribute for this purpose, which is discussed in Filtering Based on Keys.

To briefly summarize, we can use the trueq.CircuitCollection.keys() method to display a table to find out which metedata is available to filter on (or circuits.keys().names to more briefly display the available keynames), and subsequently the subset() method to specify criteria we want members of the subset to satisfy. For example, again using the circuit collection defined above, we can create a new collection containing only those circuits which are either CB circuits or RCAL circuits.

[8]:
# collect only CB and RCAL circuits
cb_or_rcal_circuits = circuits.subset(protocol={"CB", "RCAL"})

# simulate these circuits with a simple over-rotation noise source
sim = tq.Simulator().add_overrotation(0.04)
sim.run(cb_or_rcal_circuits)

# we can see how many of the original circuits have been simulated
print("Total Circuits:", len(circuits), "\tSimulated Circuits:", circuits.n_results)
Total Circuits: 1083    Simulated Circuits: 992

We can also filter based on whether or not the circuits have had their results populated with bitstrings or not, in combination with keyword filtering.

[9]:
unsimulated_circuits = circuits.subset(has_results=False)
len(unsimulated_circuits)
[9]:
91

Download

Download this file as Jupyter notebook: circuit_collections.ipynb.