|  View source on GitHub | 
A convenience wrapper for calibrations that acts like a dictionary.
cirq_google.engine.Calibration(
    calibration: v2.metrics_pb2.MetricsSnapshot = v2.metrics_pb2.MetricsSnapshot(),
    metrics: (ALL_METRICS | None) = None
) -> None
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.
| Attributes | |
|---|---|
| timestamp | The time that this calibration was run, in milliseconds since the epoch. | 
Methods
get
get(
    key, default=None
)
D.get(k[,d]) -> D[k] if k in D, else d. d defaults to None.
heatmap
heatmap(
    key: str
) -> cirq.Heatmap
Return a heatmap for metrics that target single qubits.
| Args | |
|---|---|
| key | The metric key to return a heatmap for. | 
| Returns | |
|---|---|
| A cirq.Heatmapfor the metric. | 
| Raises | |
|---|---|
| ValueError | If the heatmap is not for one/two qubits or the metric values are not single floats. | 
items
items()
D.items() -> a set-like object providing a view on D's items
key_to_qubit
@staticmethodkey_to_qubit( target: METRIC_KEY ) -> cirq.GridQubit
Returns a single qubit from a metric key.
| Raises | |
|---|---|
| ValueError | If the metric key is a tuple of strings. | 
key_to_qubits
@staticmethodkey_to_qubits( target: METRIC_KEY ) -> tuple[cirq.GridQubit, ...]
Returns a tuple of qubits from a metric key.
| Raises | |
|---|---|
| ValueError | If the metric key is a tuple of strings. | 
keys
keys()
D.keys() -> a set-like object providing a view on D's keys
plot
plot(
    key: str, fig: (mpl.figure.Figure | None) = None
) -> tuple[mpl.figure.Figure, list[plt.Axes]]
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
plot_histograms(
    keys: Sequence[str],
    ax: (plt.Axes | None) = None,
    *,
    labels: (Sequence[str] | None) = None
) -> plt.Axes
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
str_to_key(
    target: str
) -> (cirq.GridQubit | str)
Turns a string into a calibration key.
Attempts to parse it as a GridQubit. If this fails, returns the string itself.
timestamp_str
timestamp_str(
    tz: (datetime.tzinfo | None) = None, timespec: str = 'auto'
) -> str
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
to_proto() -> v2.metrics_pb2.MetricsSnapshot
Reconstruct the protobuf message represented by this class.
value_to_float
@staticmethodvalue_to_float( value: METRIC_VALUE ) -> float
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
values()
D.values() -> an object providing a view on D's values
__contains__
__contains__(
    key
)
__eq__
__eq__(
    other
)
Return self==value.
__getitem__
__getitem__(
    key: str
) -> METRIC_DICT
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__
__iter__() -> Iterator
__len__
__len__() -> int