def heatmap(self, 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.Heatmap` for the metric. Raises: ValueError: If the heatmap is not for one/two qubits or the metric values are not single floats. """ metrics = self[key] if not all(len(k) == 1 for k in metrics.values()): raise ValueError( 'Heatmaps are only supported if all values in a metric are single metric values.' + f'{key} has metric values {metrics.values()}') value_map = { self.key_to_qubits(k): self.value_to_float(v) for k, v in metrics.items() } if all(len(k) == 1 for k in value_map.keys()): return cirq.Heatmap(value_map, title=key.replace('_', ' ').title()) elif all(len(k) == 2 for k in value_map.keys()): return cirq.TwoQubitInteractionHeatmap(value_map, title=key.replace( '_', ' ').title()) raise ValueError( 'Heatmaps are only supported if all the targets in a metric are one or two qubits.' + f'{key} has target qubits {value_map.keys()}')
def two_qubit_interaction_heatmap(): """Demo of cirq.InteractionHeatmap. Demonstrates how cirq.Heatmap can be used to generate a two qubit interaction heatmap. """ # normally one would get these from cirq_google.engine s = np.random.RandomState(1234) random_characterization_data = { tuple(qubit_pair): s.rand() for qubit_pair in cirq_google.Sycamore.metadata.qubit_pairs } heatmap = cirq.TwoQubitInteractionHeatmap( value_map=random_characterization_data, title='Two Qubit Sycamore Gate XEB Cycle Total Error', ) # this is going to plot something similar to examples/two_qubit_interaction_heatmap_example.png heatmap.plot()
def two_qubit_interaction_heatmap(): """Demo of cirq.InteractionHeatmap. Demonstrates how cirq.Heatmap can be used to generate a two qubit interaction heatmap. """ # normally one would get these from cirq.google.engine s = np.random.RandomState(1234) random_characterization_data = { qubit_pair: s.random() for qubit_pair in _sycamore_qubit_pairs() } heatmap = cirq.TwoQubitInteractionHeatmap( value_map=random_characterization_data, title='Two Qubit Sycamore Gate XEB Cycle Total Error', ) file_path = "examples/two_qubit_interaction_heatmap_example.png" fig, _ = heatmap.plot() fig.figure.savefig(file_path)