cirq_google.engine.Calibration

A convenience wrapper for calibrations that acts like a dictionary.

Calibrations act as dictionaries whose keys are the names of the metric, and whose values are the metric values. The metric values themselves are represented as a dictionary. These metric value dictionaries have keys that are tuples of cirq.GridQubits and values that are lists of the metric values for those qubits. If a metric acts globally and is attached to no specified number of qubits, the map will be from the empty tuple to the metrics values.

Calibrations act just like a python dictionary. For example you can get a list of all of the metric names using

`calibration.keys()`

and query a single value by looking up the name by index:

`calibration['t1']`

This class can be instantiated either from a MetricsSnapshot proto or from a dictionary of metric values.

timestamp The time that this calibration was run, in milliseconds since the epoch.

Methods

get

D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.

heatmap

View source

Return a heatmap for metrics that target single qubits.

Args
key The metric key to return a heatmap for.

Returns
A cirq.Heatmap for the metric.

Raises
ValueError If the heatmap is not for one/two qubits or the metric values are not single floats.

items

D.items() -> a set-like object providing a view on D's items

key_to_qubit

View source

Returns a single qubit from a metric key.

Raises
ValueError If the metric key is a tuple of strings.

key_to_qubits

View source

Returns a tuple of qubits from a metric key.

Raises
ValueError If the metric key is a tuple of strings.

keys

D.keys() -> a set-like object providing a view on D's keys

plot

View source

Plots a heatmap and an integrated histogram for the given key.

Args
key The metric key to plot a heatmap and integrated histogram for.
fig The figure to plot on. If none, we generate one.

Returns
The figure and list of axis that was plotted on.

Raises
ValueError if the key is not for one/two qubits metric or the metric values are not single floats.

plot_histograms

View source

Plots integrated histograms of metric values corresponding to keys

Args
keys List of metric keys for which an integrated histogram should be plot
ax The axis to plot on. If None, we generate one.
labels Optional label that will be used in the legend.

Returns
The axis that was plotted on.

Raises
ValueError If the metric values are not single floats.

str_to_key

View source

Turns a string into a calibration key.

Attempts to parse it as a GridQubit. If this fails, returns the string itself.

timestamp_str

View source

Return a string for the calibration timestamp.

Args
tz The timezone for the string. If None, the method uses the platform's local timezone.
timespec See datetime.isoformat for valid values.

Returns
The string in ISO 8601 format YYYY-MM-DDTHH:MM:SS.ffffff.

to_proto

View source

Reconstruct the protobuf message represented by this class.

value_to_float

View source

Returns a single float from a metric value.

Metric values can be a list of strings, ints, or floats. However, the typical case is that they are a single float. This converts the metric value to a single float.

If the metric value has multiple values, only the first will be returned. If the value is empty or a string that cannot be converted, this function will raise a ValueError.

values

D.values() -> an object providing a view on D's values

__contains__

__eq__

Return self==value.

__getitem__

View source

Supports getting calibrations by index.

Calibration may be accessed by key:

`calibration['t1']`.

This returns a map from tuples of cirq.GridQubits to a list of the values of the metric. If there are no targets, the only key will only be an empty tuple.

__iter__

View source

__len__

View source