Exemple #1
0
    def get_value_by_result_type(self, result_type: ResultType) -> Any:
        """
        Get value by result type. The result type must have already been
        requested in the circuit sent to the device for this task result.

        Args:
            result_type (ResultType): result type requested

        Returns:
            Any: value of the result corresponding to the result type

        Raises:
            ValueError: If result type is not found in result.
                Result types must be added to the circuit before the circuit is run on a device.
        """
        rt_ir = result_type.to_ir()
        try:
            rt_hash = GateModelQuantumTaskResult._result_type_hash(rt_ir)
            result_type_index = self._result_types_indices[rt_hash]
            return self.values[result_type_index]
        except KeyError:
            raise ValueError(
                "Result type not found in result. "
                + "Result types must be added to circuit before circuit is run on device."
            )
Exemple #2
0
    def get_value_by_result_type(self, result_type: ResultType) -> Any:
        """
        Get value by result type. The result type must have already been
        requested in the circuit sent to the device for this task result.

        Args:
            result_type (ResultType): result type requested

        Returns:
            Any: value of the result corresponding to the result type

        Raises:
            ValueError: If result type is not found in result.
                Result types must be added to the circuit before the circuit is run on a device.
        """
        rt_ir = result_type.to_ir()
        for rt in self.result_types:
            if rt_ir == rt.type:
                return rt.value
        raise ValueError(
            "Result type not found in result. "
            + "Result types must be added to circuit before circuit is run on device."
        )