Collections and Metadata
Keys
True-Q™ uses Key
s to store attributes of some objects like
Circuit
s and Estimate
s. This is
done to enable efficient filtering and grouping of similar or dissimilar objects.
Key
s are lightweight hashable dictionaries; their keys and values
must both be hashable. One main feature of keys is their ability to match against
patterns:
import trueq as tq
key = tq.Key(fruit="banana", color="yellow", quantity=1)
print(key.match(fruit="apple"))
print(key.match(fruit="banana"))
print(key.match(fruit="banana", color="brown"))
print(key.match(fruit={"apple", "pear"}))
print(key.match(fruit={"apple", "banana"}))
False
True
False
False
True
Various other conveniences are supported:
import trueq as tq
key = tq.Key(fruit="banana", color="yellow", quantity=1)
print("shape in key: \t", "shape" in key)
print("quantity in key:\t", "quantity" in key)
print("key.quantity: \t", key.quantity)
print("key['quantity']:\t", key["quantity"])
print("key.names: \t", key.names)
shape in key: False
quantity in key: True
key.quantity: 1
key['quantity']: 1
key.names: ('fruit', 'color', 'quantity')
Special Keywords
True-Q™ uses the following keywords for Key
s internally. There are
no restrictions on using these keywords for your own purposes, or manually overriding
them, but doing so may cause fitting and other features to break.
Keyword |
Description |
---|---|
|
Stores CB decays to measure. |
|
Used by RCAL to index experiment batches. |
|
Which Pauli was compiled into the circuit prior to measurement. |
|
The cycle of interest, see e.g. CB. |
|
A tuple of qubit labels. |
|
Which basis change was compiled into the circuit. |
|
Used by KNR to store the gate-body size to probe. |
|
The number of independent random cycles in a circuit. |
|
Sometimes used to order by key. |
|
The protocol. |
|
Used to distinguish otherwise identical circuits. |
|
Non-identity errors targeted by CB. |
|
Stores the twirling group. |
Usually, fit()
produces a separate set of estimates
for every unique combination of custom keywords (i.e. not in the list above). The
exceptions to this rule are the following custom keywords, which will be ignored and
deleted in the returned fit object:
Keyword |
Description |
---|---|
|
E.g. store a job execution identifier. |
|
E.g. store a recommended number of shots for a circuit. |
KeySets
KeySet
s are special set-like containers for
Key
s. They exist (instead of using the built-in set
)
mainly to easily create subsets using the match()
functionality of
Key
s. When we call the subset()
of a KeySet, a new KeySet
is returned that contains all Key
s that match the arguments. KeySets
are also useful for getting all unique values of a particular parameter:
import trueq as tq
keys = tq.KeySet(
tq.Key(fruit="banana", color="yellow"),
tq.Key(fruit="apple", color="red"),
tq.Key(fruit="apple", color="yellow"),
tq.Key(size=1),
)
print(keys.subset(color="yellow"))
print(keys.subset(size=1))
print(keys.subset(shape="triangle"))
print(keys.fruit)
KeySet(
Key(fruit='banana', color='yellow'),
Key(fruit='apple', color='yellow'))
KeySet(
Key(size=1))
KeySet()
ItemSet({'banana', 'apple'})
Circuit Collections
Collections of circuits are stored in instances of
CircuitCollection
, and this is the type that will be returned by the
functions that create circuits for diagnostic tools. Circuit
collections are iterable and maintain insertion order. Multiple protocols can (and
usually should) put their circuits into the same collection, so that their results can
be analyzed together if applicable. Different types of circuit are differentiated within
the collection by their key
attribute, and collections of
circuits are designed so that accessing subsets of circuits by properties of these keys
is convenient.
For example, circuits created with make_srb()
have keys with the
property protocol="SRB"
, while circuits created with make_xrb()
have
keys with the property protocol="XRB"
. We may access only those circuits with keys
having the property protocol="SRB"
as follows.
import trueq as tq
circuits = tq.make_srb([0], [4, 100])
circuits += tq.make_xrb([0], [4, 100])
# see all the values of protocol inside keys in the circuit collection
print(circuits.keys().protocol)
print(circuits.subset(protocol="SRB").keys().protocol)
ItemSet({'XRB', 'SRB'})
ItemSet({'SRB'})
See the API documentation for CircuitCollection
for other key-related
convenience functions.
Perhaps most importantly, circuit collections implement the method
fit()
, which takes all of the available data in the
collection and analyzes it, returning an EstimateCollection
(see below). Similarly, plot()
contains methods to
visualize the results of any analysis.
Accessing Estimates and Circuits
Both CircuitCollection
s and
EstimateCollection
s use flat structures to enable a simple
interface between different protocols performed on various subsets of the same quantum
device. For example, the parameters estimated by the XRB protocol depend on
whether the SRB protocol was also performed, and the
make_crosstalk_diagnostics()
macro generates SRB
circuits in both simultaneous and isolated modes.
This guide supplements the API documentation for methods in the
CircuitCollection
and
EstimateCollection
classes. Skip ahead to
Circuit Collection Internals or EstimateCollection Internals if you want
to skip to useful examples immediately. Throughout this page, we will use the
following objects in our examples:
import trueq as tq
# make some varied circuits in a single CircuitCollection
circuits = tq.CircuitCollection()
circuits += tq.make_srb([4, 5], [4, 12, 64])
circuits += tq.make_xrb([4, 5], [4, 12, 64])
circuits += tq.make_cb({(4, 5): tq.Gate.cnot}, [4, 12, 64], n_decays=5)
# simulate them and put their results in an EstimateCollection
tq.Simulator().add_stochastic_pauli(px=0.02).run(circuits)
fit = circuits.fit()
Circuit Collection Internals
CircuitCollection
s are effectively lists of circuits with
convenience functions, where each circuit contains its own Key
. The
protocols built in to True-Q™ typically assign keys such that each key only appears
once per generated circuit collection.
If you happen to know the key of the list of circuits you are interested in, you can access it directly.
key = tq.Key(
n_random_cycles=4, protocol="SRB", twirl=(("C", 4),), compiled_pauli="I"
)
len(circuits[key])
0
However, it is typically inconvenient to manually construct keys in this way. There are four convenience functions for accessing circuits:
trueq.CircuitCollection.keys()
:Returns a KeySet of all keys in the collection that match a given filter.
For example, let’s get all of the keys in the collection that came from the SRB protocol:
circuits.keys(protocol="SRB")
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".KeySetList of all the keys in the KeySetprotocol The characterization protocol used to generate a circuit.twirl The twirling group used to generate a circuit.n_random_cycles The number of independent random cycles in the circuit.compiled_pauli The n-qubit Pauli operator that was compiled into the circuit immediately before measurement.measurement_basis An n-qubit Pauli operator describing the change-of-basis gates added prior to measurement.Key- Key:
-
- compiled_pauli: YX
- measurement_basis: ZZ
- n_random_cycles: 4
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 4 YX ZZ Key- Key:
-
- compiled_pauli: ZI
- measurement_basis: ZZ
- n_random_cycles: 4
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 4 ZI ZZ Key- Key:
-
- compiled_pauli: XY
- measurement_basis: ZZ
- n_random_cycles: 4
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 4 XY ZZ Key- Key:
-
- compiled_pauli: YI
- measurement_basis: ZZ
- n_random_cycles: 4
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 4 YI ZZ Key- Key:
-
- compiled_pauli: ZX
- measurement_basis: ZZ
- n_random_cycles: 4
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 4 ZX ZZ Key- Key:
-
- compiled_pauli: XZ
- measurement_basis: ZZ
- n_random_cycles: 4
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 4 XZ ZZ Key- Key:
-
- compiled_pauli: YZ
- measurement_basis: ZZ
- n_random_cycles: 4
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 4 YZ ZZ Key- Key:
-
- compiled_pauli: IX
- measurement_basis: ZZ
- n_random_cycles: 4
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 4 IX ZZ Key- Key:
-
- compiled_pauli: XX
- measurement_basis: ZZ
- n_random_cycles: 4
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 4 XX ZZ Key- Key:
-
- compiled_pauli: ZY
- measurement_basis: ZZ
- n_random_cycles: 4
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 4 ZY ZZ Key- Key:
-
- compiled_pauli: IY
- measurement_basis: ZZ
- n_random_cycles: 4
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 4 IY ZZ Key- Key:
-
- compiled_pauli: II
- measurement_basis: ZZ
- n_random_cycles: 4
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 4 II ZZ Key- Key:
-
- compiled_pauli: IY
- measurement_basis: ZZ
- n_random_cycles: 12
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 12 IY ZZ Key- Key:
-
- compiled_pauli: ZI
- measurement_basis: ZZ
- n_random_cycles: 12
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 12 ZI ZZ Key- Key:
-
- compiled_pauli: XY
- measurement_basis: ZZ
- n_random_cycles: 12
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 12 XY ZZ Key- Key:
-
- compiled_pauli: ZZ
- measurement_basis: ZZ
- n_random_cycles: 12
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 12 ZZ ZZ Key- Key:
-
- compiled_pauli: XX
- measurement_basis: ZZ
- n_random_cycles: 12
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 12 XX ZZ Key- Key:
-
- compiled_pauli: YI
- measurement_basis: ZZ
- n_random_cycles: 12
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 12 YI ZZ Key- Key:
-
- compiled_pauli: ZY
- measurement_basis: ZZ
- n_random_cycles: 12
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 12 ZY ZZ Key- Key:
-
- compiled_pauli: YX
- measurement_basis: ZZ
- n_random_cycles: 12
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 12 YX ZZ Key- Key:
-
- compiled_pauli: IZ
- measurement_basis: ZZ
- n_random_cycles: 12
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 12 IZ ZZ Key- Key:
-
- compiled_pauli: II
- measurement_basis: ZZ
- n_random_cycles: 12
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 12 II ZZ Key- Key:
-
- compiled_pauli: YY
- measurement_basis: ZZ
- n_random_cycles: 12
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 12 YY ZZ Key- Key:
-
- compiled_pauli: IX
- measurement_basis: ZZ
- n_random_cycles: 12
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 12 IX ZZ Key- Key:
-
- compiled_pauli: YZ
- measurement_basis: ZZ
- n_random_cycles: 12
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 12 YZ ZZ Key- Key:
-
- compiled_pauli: XI
- measurement_basis: ZZ
- n_random_cycles: 12
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 12 XI ZZ Key- Key:
-
- compiled_pauli: XZ
- measurement_basis: ZZ
- n_random_cycles: 64
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 64 XZ ZZ Key- Key:
-
- compiled_pauli: YI
- measurement_basis: ZZ
- n_random_cycles: 64
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 64 YI ZZ Key- Key:
-
- compiled_pauli: YX
- measurement_basis: ZZ
- n_random_cycles: 64
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 64 YX ZZ Key- Key:
-
- compiled_pauli: IZ
- measurement_basis: ZZ
- n_random_cycles: 64
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 64 IZ ZZ Key- Key:
-
- compiled_pauli: IY
- measurement_basis: ZZ
- n_random_cycles: 64
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 64 IY ZZ Key- Key:
-
- compiled_pauli: ZX
- measurement_basis: ZZ
- n_random_cycles: 64
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 64 ZX ZZ Key- Key:
-
- compiled_pauli: ZZ
- measurement_basis: ZZ
- n_random_cycles: 64
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 64 ZZ ZZ Key- Key:
-
- compiled_pauli: IX
- measurement_basis: ZZ
- n_random_cycles: 64
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 64 IX ZZ Key- Key:
-
- compiled_pauli: II
- measurement_basis: ZZ
- n_random_cycles: 64
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 64 II ZZ Key- Key:
-
- compiled_pauli: ZY
- measurement_basis: ZZ
- n_random_cycles: 64
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 64 ZY ZZ Key- Key:
-
- compiled_pauli: XX
- measurement_basis: ZZ
- n_random_cycles: 64
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 64 XX ZZ Key- Key:
-
- compiled_pauli: ZI
- measurement_basis: ZZ
- n_random_cycles: 64
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 64 ZI ZZ Key- Key:
-
- compiled_pauli: XY
- measurement_basis: ZZ
- n_random_cycles: 64
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 64 XY ZZ Key- Key:
-
- compiled_pauli: YZ
- measurement_basis: ZZ
- n_random_cycles: 64
- protocol: SRB
- twirl: Cliffords on [4, 5]
SRB Cliffords on [4, 5] 64 YZ ZZ Since the
keys()
method returns a newKeySet
, we have access to all of its methods. For example, this is the easiest way to get all sequence lengths present in the SRB protocol:circuits.keys(protocol="SRB").n_random_cycles
{4, 12, 64}
This enables convenient looping such as the following:
for m in circuits.keys(protocol="SRB").n_random_cycles: for key in circuits.keys(protocol="SRB", n_random_cycles=m): pass
Note that in this case
circuits.similar_keys("n_random_cycles", protocol="SRB")
(see below) would be even more convenient:
trueq.CircuitCollection.subset()
:Returns an iterable over all circuits whose key attribute matches a given filter. This may seamlessly join together circuits in different circuit lists.
For example, we can put all
XRB
circuits of this protocol into a newCircuitCollection
like this:circuits.subset(protocol="XRB")
CircuitCollection(<270 circuits>) * = has data Key(measurement_basis=Weyls('XX'), n_random_cycles=4, protocol='XRB', seq_label=1287, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff19, (5,): Gate.cliff17, marker=1),Cycle((4,): Gate.cli...) * Key(measurement_basis=Weyls('ZZ'), n_random_cycles=4, protocol='XRB', seq_label=1287, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff19, (5,): Gate.cliff17, marker=1),Cycle((4,): Gate.cli...) * Key(measurement_basis=Weyls('YY'), n_random_cycles=4, protocol='XRB', seq_label=1287, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff19, (5,): Gate.cliff17, marker=1),Cycle((4,): Gate.cli...) * Key(measurement_basis=Weyls('XZ'), n_random_cycles=4, protocol='XRB', seq_label=1288, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff11, (5,): Gate.cliff22, marker=1),Cycle((4,): Gate.cli...) * Key(measurement_basis=Weyls('ZY'), n_random_cycles=4, protocol='XRB', seq_label=1288, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff11, (5,): Gate.cliff22, marker=1),Cycle((4,): Gate.cli...) * Key(measurement_basis=Weyls('YX'), n_random_cycles=4, protocol='XRB', seq_label=1288, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff11, (5,): Gate.cliff22, marker=1),Cycle((4,): Gate.cli...) * Key(measurement_basis=Weyls('XX'), n_random_cycles=4, protocol='XRB', seq_label=1289, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff11, (5,): Gate.cliff8, marker=1),Cycle((4,): Gate.h, (...) * Key(measurement_basis=Weyls('YZ'), n_random_cycles=4, protocol='XRB', seq_label=1289, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff11, (5,): Gate.cliff8, marker=1),Cycle((4,): Gate.h, (...) * Key(measurement_basis=Weyls('ZY'), n_random_cycles=4, protocol='XRB', seq_label=1289, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff11, (5,): Gate.cliff8, marker=1),Cycle((4,): Gate.h, (...) * Key(measurement_basis=Weyls('XX'), n_random_cycles=4, protocol='XRB', seq_label=1290, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.y, (5,): Gate.cliff13, marker=1),Cycle((4,): Gate.cliff16, ...) * Key(measurement_basis=Weyls('YZ'), n_random_cycles=4, protocol='XRB', seq_label=1290, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.y, (5,): Gate.cliff13, marker=1),Cycle((4,): Gate.cliff16, ...) * Key(measurement_basis=Weyls('ZY'), n_random_cycles=4, protocol='XRB', seq_label=1290, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.y, (5,): Gate.cliff13, marker=1),Cycle((4,): Gate.cliff16, ...) * Key(measurement_basis=Weyls('XZ'), n_random_cycles=4, protocol='XRB', seq_label=1291, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff6, (5,): Gate.sx, marker=1),Cycle((4,): Gate.sy, (5,):...) * Key(measurement_basis=Weyls('ZX'), n_random_cycles=4, protocol='XRB', seq_label=1291, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff6, (5,): Gate.sx, marker=1),Cycle((4,): Gate.sy, (5,):...) * Key(measurement_basis=Weyls('YY'), n_random_cycles=4, protocol='XRB', seq_label=1291, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff6, (5,): Gate.sx, marker=1),Cycle((4,): Gate.sy, (5,):...) * Key(measurement_basis=Weyls('YX'), n_random_cycles=4, protocol='XRB', seq_label=1292, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff6, (5,): Gate.cliff11, marker=1),Cycle((4,): Gate.clif...) * Key(measurement_basis=Weyls('XZ'), n_random_cycles=4, protocol='XRB', seq_label=1292, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff6, (5,): Gate.cliff11, marker=1),Cycle((4,): Gate.clif...) * Key(measurement_basis=Weyls('ZY'), n_random_cycles=4, protocol='XRB', seq_label=1292, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff6, (5,): Gate.cliff11, marker=1),Cycle((4,): Gate.clif...) * Key(measurement_basis=Weyls('ZZ'), n_random_cycles=4, protocol='XRB', seq_label=1293, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.h, (5,): Gate.cliff13, marker=1),Cycle((4,): Gate.x, (5,): ...) * Key(measurement_basis=Weyls('XY'), n_random_cycles=4, protocol='XRB', seq_label=1293, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.h, (5,): Gate.cliff13, marker=1),Cycle((4,): Gate.x, (5,): ...) * Key(measurement_basis=Weyls('YX'), n_random_cycles=4, protocol='XRB', seq_label=1293, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.h, (5,): Gate.cliff13, marker=1),Cycle((4,): Gate.x, (5,): ...) * Key(measurement_basis=Weyls('XZ'), n_random_cycles=4, protocol='XRB', seq_label=1294, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff19, (5,): Gate.cliff18, marker=1),Cycle((4,): Gate.x, ...) * Key(measurement_basis=Weyls('ZX'), n_random_cycles=4, protocol='XRB', seq_label=1294, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff19, (5,): Gate.cliff18, marker=1),Cycle((4,): Gate.x, ...) * Key(measurement_basis=Weyls('YY'), n_random_cycles=4, protocol='XRB', seq_label=1294, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff19, (5,): Gate.cliff18, marker=1),Cycle((4,): Gate.x, ...) * Key(measurement_basis=Weyls('ZZ'), n_random_cycles=4, protocol='XRB', seq_label=1295, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff15, (5,): Gate.cliff6, marker=1),Cycle((4,): Gate.clif...) * Key(measurement_basis=Weyls('YY'), n_random_cycles=4, protocol='XRB', seq_label=1295, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff15, (5,): Gate.cliff6, marker=1),Cycle((4,): Gate.clif...) * Key(measurement_basis=Weyls('XX'), n_random_cycles=4, protocol='XRB', seq_label=1295, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff15, (5,): Gate.cliff6, marker=1),Cycle((4,): Gate.clif...) * Key(measurement_basis=Weyls('ZZ'), n_random_cycles=4, protocol='XRB', seq_label=1296, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff19, (5,): Gate.cliff14, marker=1),Cycle((4,): Gate.cli...) * Key(measurement_basis=Weyls('YY'), n_random_cycles=4, protocol='XRB', seq_label=1296, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff19, (5,): Gate.cliff14, marker=1),Cycle((4,): Gate.cli...) * Key(measurement_basis=Weyls('XX'), n_random_cycles=4, protocol='XRB', seq_label=1296, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff19, (5,): Gate.cliff14, marker=1),Cycle((4,): Gate.cli...) * Key(measurement_basis=Weyls('XZ'), n_random_cycles=4, protocol='XRB', seq_label=1297, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.z, (5,): Gate.cliff23, marker=1),Cycle((4,): Gate.cliff20, ...) * Key(measurement_basis=Weyls('ZY'), n_random_cycles=4, protocol='XRB', seq_label=1297, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.z, (5,): Gate.cliff23, marker=1),Cycle((4,): Gate.cliff20, ...) * Key(measurement_basis=Weyls('YX'), n_random_cycles=4, protocol='XRB', seq_label=1297, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.z, (5,): Gate.cliff23, marker=1),Cycle((4,): Gate.cliff20, ...) * Key(measurement_basis=Weyls('XZ'), n_random_cycles=4, protocol='XRB', seq_label=1298, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.z, (5,): Gate.cliff19, marker=1),Cycle((4,): Gate.cliff17, ...) * Key(measurement_basis=Weyls('YX'), n_random_cycles=4, protocol='XRB', seq_label=1298, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.z, (5,): Gate.cliff19, marker=1),Cycle((4,): Gate.cliff17, ...) * Key(measurement_basis=Weyls('ZY'), n_random_cycles=4, protocol='XRB', seq_label=1298, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.z, (5,): Gate.cliff19, marker=1),Cycle((4,): Gate.cliff17, ...) * Key(measurement_basis=Weyls('ZZ'), n_random_cycles=4, protocol='XRB', seq_label=1299, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff10, (5,): Gate.cliff21, marker=1),Cycle((4,): Gate.cli...) * Key(measurement_basis=Weyls('XY'), n_random_cycles=4, protocol='XRB', seq_label=1299, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff10, (5,): Gate.cliff21, marker=1),Cycle((4,): Gate.cli...) * Key(measurement_basis=Weyls('YX'), n_random_cycles=4, protocol='XRB', seq_label=1299, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff10, (5,): Gate.cliff21, marker=1),Cycle((4,): Gate.cli...) * Key(measurement_basis=Weyls('XY'), n_random_cycles=4, protocol='XRB', seq_label=1300, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff8, (5,): Gate.y, marker=1),Cycle((4,): Gate.s, (5,): G...) * Key(measurement_basis=Weyls('YX'), n_random_cycles=4, protocol='XRB', seq_label=1300, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff8, (5,): Gate.y, marker=1),Cycle((4,): Gate.s, (5,): G...) * Key(measurement_basis=Weyls('ZZ'), n_random_cycles=4, protocol='XRB', seq_label=1300, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff8, (5,): Gate.y, marker=1),Cycle((4,): Gate.s, (5,): G...) * Key(measurement_basis=Weyls('XZ'), n_random_cycles=4, protocol='XRB', seq_label=1301, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff8, (5,): Gate.cliff4, marker=1),Cycle((4,): Gate.cliff...) * Key(measurement_basis=Weyls('ZY'), n_random_cycles=4, protocol='XRB', seq_label=1301, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff8, (5,): Gate.cliff4, marker=1),Cycle((4,): Gate.cliff...) * Key(measurement_basis=Weyls('YX'), n_random_cycles=4, protocol='XRB', seq_label=1301, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff8, (5,): Gate.cliff4, marker=1),Cycle((4,): Gate.cliff...) * Key(measurement_basis=Weyls('YX'), n_random_cycles=4, protocol='XRB', seq_label=1302, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.sy, (5,): Gate.sy, marker=1),Cycle((4,): Gate.s, (5,): Gate...) * Key(measurement_basis=Weyls('XZ'), n_random_cycles=4, protocol='XRB', seq_label=1302, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.sy, (5,): Gate.sy, marker=1),Cycle((4,): Gate.s, (5,): Gate...) * Key(measurement_basis=Weyls('ZY'), n_random_cycles=4, protocol='XRB', seq_label=1302, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.sy, (5,): Gate.sy, marker=1),Cycle((4,): Gate.s, (5,): Gate...) * Key(measurement_basis=Weyls('XX'), n_random_cycles=4, protocol='XRB', seq_label=1303, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.sy, (5,): Gate.sy, marker=1),Cycle((4,): Gate.cliff22, (5,)...) * Key(measurement_basis=Weyls('ZZ'), n_random_cycles=4, protocol='XRB', seq_label=1303, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.sy, (5,): Gate.sy, marker=1),Cycle((4,): Gate.cliff22, (5,)...) * Key(measurement_basis=Weyls('YY'), n_random_cycles=4, protocol='XRB', seq_label=1303, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.sy, (5,): Gate.sy, marker=1),Cycle((4,): Gate.cliff22, (5,)...) * Key(measurement_basis=Weyls('XZ'), n_random_cycles=4, protocol='XRB', seq_label=1304, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff14, (5,): Gate.cliff22, marker=1),Cycle((4,): Gate.cli...) * Key(measurement_basis=Weyls('ZX'), n_random_cycles=4, protocol='XRB', seq_label=1304, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff14, (5,): Gate.cliff22, marker=1),Cycle((4,): Gate.cli...) * Key(measurement_basis=Weyls('YY'), n_random_cycles=4, protocol='XRB', seq_label=1304, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff14, (5,): Gate.cliff22, marker=1),Cycle((4,): Gate.cli...) * Key(measurement_basis=Weyls('XX'), n_random_cycles=4, protocol='XRB', seq_label=1305, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.id, (5,): Gate.cliff10, marker=1),Cycle((4,): Gate.sy, (5,)...) * Key(measurement_basis=Weyls('YZ'), n_random_cycles=4, protocol='XRB', seq_label=1305, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.id, (5,): Gate.cliff10, marker=1),Cycle((4,): Gate.sy, (5,)...) * Key(measurement_basis=Weyls('ZY'), n_random_cycles=4, protocol='XRB', seq_label=1305, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.id, (5,): Gate.cliff10, marker=1),Cycle((4,): Gate.sy, (5,)...) * Key(measurement_basis=Weyls('ZX'), n_random_cycles=4, protocol='XRB', seq_label=1306, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff11, (5,): Gate.sx, marker=1),Cycle((4,): Gate.cliff18,...) * Key(measurement_basis=Weyls('YZ'), n_random_cycles=4, protocol='XRB', seq_label=1306, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff11, (5,): Gate.sx, marker=1),Cycle((4,): Gate.cliff18,...) * Key(measurement_basis=Weyls('XY'), n_random_cycles=4, protocol='XRB', seq_label=1306, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff11, (5,): Gate.sx, marker=1),Cycle((4,): Gate.cliff18,...) * Key(measurement_basis=Weyls('YY'), n_random_cycles=4, protocol='XRB', seq_label=1307, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff10, (5,): Gate.cliff13, marker=1),Cycle((4,): Gate.cli...) * Key(measurement_basis=Weyls('XX'), n_random_cycles=4, protocol='XRB', seq_label=1307, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff10, (5,): Gate.cliff13, marker=1),Cycle((4,): Gate.cli...) * Key(measurement_basis=Weyls('ZZ'), n_random_cycles=4, protocol='XRB', seq_label=1307, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.cliff10, (5,): Gate.cliff13, marker=1),Cycle((4,): Gate.cli...) * Key(measurement_basis=Weyls('ZZ'), n_random_cycles=4, protocol='XRB', seq_label=1308, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.s, (5,): Gate.cliff23, marker=1),Cycle((4,): Gate.cliff8, (...) * Key(measurement_basis=Weyls('XX'), n_random_cycles=4, protocol='XRB', seq_label=1308, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.s, (5,): Gate.cliff23, marker=1),Cycle((4,): Gate.cliff8, (...) * Key(measurement_basis=Weyls('YY'), n_random_cycles=4, protocol='XRB', seq_label=1308, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.s, (5,): Gate.cliff23, marker=1),Cycle((4,): Gate.cliff8, (...) * Key(measurement_basis=Weyls('XZ'), n_random_cycles=4, protocol='XRB', seq_label=1309, twirl=Twirl({(4,): 'C', (5,): 'C'}, dim=2)) Circuit(Cycle((4,): Gate.sx, (5,): Gate.cliff8, marker=1),Cycle((4,): Gate.cliff13, ...) * ...
We can match on multiple values:
len(circuits.subset(protocol="XRB", n_random_cycles={4, 5}))
90
trueq.CircuitCollection.similar_keys()
:Returns an iterable over KeySets. Each KeySet contains keys that match the filter, but are additionally grouped by some equal (or unequal) estimate value.
It is often useful to both group and filter at the same time. Suppose we want all
XRB
circuits, and that we want to group them by theirn_random_cycles
value.for keys in circuits.similar_keys("n_random_cycles", protocol="XRB"): # keys is a KeySet where protocol=XRB, and where every n_random_cycles is equal for key in keys: pass
As a convenience for more concise code, we can also group where everything except
n_random_cycles
is equal. This is done with theinvert=True
flag. This is particularly useful forseq_label
in XRB.for keys in circuits.similar_keys("seq_label", invert=True, protocol="XRB"): # keys is a KeySet where protocol=XRB, and all other key fields except # seq_label are equal for key in keys: pass
EstimateCollection Internals
EstimateCollection
s are containers of
Estimate
s with fancy pattern matching functionality.
The most convenient way to view the output of a
EstimateCollection
is its fancy HTML representation in an
IPython Notebook. If you want to access specific values then the
relevant methods are listed below, followed by some illustrative examples.
trueq.estimate.EstimateCollection.keys()
Calling syntax:
fit.keys(**filter)
trueq.estimate.EstimateCollection.subset()
Calling syntax:
fit.subset(pattern="*", **filter)
Suppose we are after the SRB
infidelity of the qubit with label 4. Our first step
might be to list all of the keys just to see what sorts of estimates they have:
fit.keys()
KeySet
List of all the keys in the KeySet
|
protocol
The characterization protocol used to generate a circuit.
|
cycles | labels |
twirl
The twirling group used to generate a circuit.
|
Key
|
CB | (Cycle((4, 5): Gate.cx),) | (4, 5) | Paulis on [4, 5] |
Key
|
SRB | (4,) | Cliffords on [4, 5] | |
Key
|
SRB | (5,) | Cliffords on [4, 5] | |
Key
|
XRB | (4,) | Cliffords on [4, 5] | |
Key
|
XRB | (5,) | Cliffords on [4, 5] |
Looking at these keys we can choose a filter to pass to
keys()
and then extract the corresponding
estimates:
[estimate.e_F for estimate in fit.subset(protocol="SRB", labels=(4,))]
[EstimateTuple(name='e_F', val=0.023950211197939747, std=0.0022873409398693327)]
You will notice that there are two entries returned in the list. This is because we
added SRB to the circuit collection in two different ways; we are seeing the estimates
of \(e_F\) when SRB is isolated on qubit 4
, and when SRB is run simultaneously
on qubits (4, 5)
. If this behaviour were undesired, we would have to filter
further. For example, we could filter by the twirling group of the Cliffords on qubit
4
:
[estimate.e_F for estimate in fit.subset(protocol="SRB", twirl=(("C", 4),))]
[]