Exemple #1
0
    def calibration_results(self):
        """Returns the results of a run_calibration() call.

        This function will fail if any other type of results were returned
        by the Engine.
        """
        import cirq.google.engine.engine as engine_base

        if not self._calibration_results:
            result = self._wait_for_result()
            result_type = result.type_url[len(engine_base.TYPE_PREFIX):]
            if result_type != 'cirq.google.api.v2.FocusedCalibrationResult':
                raise ValueError(
                    f'Did not find calibration results, instead found: {result_type}'
                )
            parsed_val = v2.calibration_pb2.FocusedCalibrationResult.FromString(
                result.value)
            cal_results = []
            for layer in parsed_val.results:
                metrics = calibration.Calibration(layer.metrics)
                message = layer.error_message or None
                token = layer.token or None
                if layer.valid_until_ms > 0:
                    ts = datetime.datetime.fromtimestamp(layer.valid_until_ms /
                                                         1000)
                else:
                    ts = None
                cal_results.append(
                    CalibrationResult(layer.code, message, token, ts, metrics))
            self._calibration_results = cal_results
        return self._calibration_results
Exemple #2
0
 def get_calibration(self) -> Optional[calibration.Calibration]:
     """Returns the recorded calibration at the time when the job was run, if
     one was captured, else None."""
     status = self._inner_job().execution_status
     if not status.calibration_name:
         return None
     ids = self.context.client._ids_from_calibration_name(
         status.calibration_name)
     response = self.context.client.get_calibration(*ids)
     metrics = v2.metrics_pb2.MetricsSnapshot.FromString(response.data.value)
     return calibration.Calibration(metrics)
Exemple #3
0
    def get_calibration(self, calibration_name: str) -> calibration.Calibration:
        """Retrieve metadata about a specific calibration run.

        Params:
            calibration_name: A string of the form
                `<processor name>/calibrations/<ms since epoch>`

        Returns:
            A dictionary containing the metadata.
        """
        response = self.service.projects().processors().calibrations().get(
            name=calibration_name).execute()
        return calibration.Calibration(response['data']['data'])
Exemple #4
0
    def get_calibration(self, calibration_name: str) -> calibration.Calibration:
        """Retrieve metadata about a specific calibration run.

        Params:
            calibration_name: A string of the form
                `projects/<project_id>/processors/<processor id>`
                `/calibrations/<timestamp in seconds since epoch>`

        Returns:
            A dictionary containing the metadata.
        """
        response = self._make_request(
            self.service.projects().processors().calibrations().get(
                name=calibration_name))
        return calibration.Calibration(response['data'])
Exemple #5
0
    def get_calibration(self, calibration_name: str) -> calibration.Calibration:
        """Retrieve metadata about a specific calibration run.

        Params:
            calibration_name: A string of the form
                `projects/<project_id>/processors/<processor id>`
                `/calibrations/<timestamp in seconds since epoch>`

        Returns:
            A dictionary containing the metadata.
        """
        response = self._make_request(lambda: self.client.
                                      get_quantum_calibration(calibration_name))
        metrics = v2.metrics_pb2.MetricsSnapshot()
        metrics.ParseFromString(response.data.value)
        return calibration.Calibration(metrics)
Exemple #6
0
    def get_latest_calibration(
            self, processor_id: str) -> Optional[calibration.Calibration]:
        """Returns metadata about the latest known calibration for a processor.

        Params:
            processor_id: The processor identifier within the resource name,
                where name has the format:
                `projects/<project_id>/processors/<processor_id>`.

        Returns:
            A dictionary containing the calibration data or None if there are
            no calibrations.
        """
        processor_name = 'projects/{}/processors/{}'.format(
            self.project_id, processor_id)
        response = self.service.projects().processors().calibrations().list(
            parent=processor_name).execute()
        if (not 'calibrations' in response
                or len(response['calibrations']) < 1):
            return None
        return calibration.Calibration(response['calibrations'][0]['data'])
Exemple #7
0
 def _to_calibration(
         calibration_any: qtypes.any_pb2.Any) -> calibration.Calibration:
     metrics = v2.metrics_pb2.MetricsSnapshot()
     metrics.ParseFromString(calibration_any.value)
     return calibration.Calibration(metrics)