Example #1
0
    def heatmap(self, key: str) -> vis.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:
            AssertionError if the heatmap is not for single qubits or the metric
            values are not single floats.
        """
        metrics = self[key]
        assert all(
            len(k) == 1 for k in metrics.keys()
        ), 'Heatmaps are only supported if all the targets in a metric are single qubits.'
        assert all(
            len(k) == 1 for k in metrics.values()
        ), 'Heatmaps are only supported if all the values in a metric are single metric values.'
        value_map: Dict['cirq.GridQubit', SupportsFloat] = {
            self.key_to_qubit(target): float(value)
            for target, (value, ) in metrics.items()
        }
        return vis.Heatmap(value_map)
Example #2
0
    def heatmap(self, key: str) -> vis.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 vis.Heatmap(value_map)
        elif all(len(k) == 2 for k in value_map.keys()):
            return vis.TwoQubitInteractionHeatmap(value_map)
        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()}')
Example #3
0
 def heatmap(self, key: str) -> vis.Heatmap:
     metrics = self[key]
     assert all(len(k) == 1 for k in metrics.keys()), (
         'Heatmaps are only supported if all the targets in a metric'
         ' are single qubits.')
     assert all(len(k) == 1 for k in metrics.values()), (
         'Heatmaps are only supported if all the values in a metric'
         ' are single metric values.')
     value_map = {qubit: value for (qubit, ), (value, ) in metrics.items()}
     return vis.Heatmap(value_map)
Example #4
0
    def heatmap(self, key: str) -> vis.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:
            AssertionError if the heatmap is not for single qubits or the metric
            values are not single floats.
        """
        metrics = self[key]
        assert all(len(k) == 1 for k in metrics.keys()), (
            'Heatmaps are only supported if all the targets in a metric'
            ' are single qubits.')
        assert all(len(k) == 1 for k in metrics.values()), (
            'Heatmaps are only supported if all the values in a metric'
            ' are single metric values.')
        value_map = {qubit: value for (qubit, ), (value, ) in metrics.items()}
        return vis.Heatmap(value_map)