Download
Download this file as Jupyter notebook: circuit_collections.ipynb.
Circuit Collections
A CircuitCollection
is a list-like object containing
Circuit
s. 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]:
Circuit
|
|||||
1
|
(0):
Gate.x
|
(1):
Gate.cliff10
|
(2):
Gate.cliff18
|
(3):
Gate.cliff17
|
(4):
Gate.s
|
2
|
(0):
Gate.cliff8
|
(1):
Gate.y
|
(2):
Gate.cliff16
|
(3):
Gate.cliff4
|
(4):
Gate.cliff4
|
3
|
(0):
Gate.sy
|
(1):
Gate.cliff21
|
(2):
Gate.sy
|
(3):
Gate.cliff18
|
(4):
Gate.cliff13
|
4
|
(0):
Gate.cliff4
|
(1):
Gate.cliff15
|
(2):
Gate.cliff15
|
(3):
Gate.id
|
(4):
Gate.cliff16
|
5
|
(0):
Gate.sy
|
(1):
Gate.y
|
(2):
Gate.cliff19
|
(3):
Gate.sx
|
(4):
Gate.cliff13
|
6
|
(0):
Meas()
|
(1):
Meas()
|
(2):
Meas()
|
(3):
Meas()
|
(4):
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 ashas_some_results
,fit()
,save()
,sum_results()
, andbatch()
.
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.