def _get_experiment_results(self, jobs: List[Dict[str, Any]]) -> List[ExperimentResult]: """ Get results from experiments from the Quantum Inspire platform for one or more jobs. :param jobs: A list of jobs :raises QiskitBackendError: If an error occurred while executing the job on the Quantum Inspire backend. :return: A list of experiment results; containing the data, execution time, status, etc. for the list of jobs. """ results = [self.__api.get_result_from_job(job['id']) for job in jobs] experiment_results = [] for result, job in zip(results, jobs): if not result.get('histogram', {}): raise QiskitBackendError( 'Result from backend contains no histogram data!\n{}'.format(result.get('raw_text'))) user_data = json.loads(str(job.get('user_data'))) measurements = user_data.pop('measurements') histogram_obj, memory_data = self.__convert_result_data(result, measurements) full_state_histogram_obj = self.__convert_histogram(result, measurements) calibration = self.__api.get_calibration_from_result(result['id']) experiment_result_data = ExperimentResultData(counts=histogram_obj, memory=memory_data, probabilities=full_state_histogram_obj, calibration=calibration) header = QobjExperimentHeader.from_dict(user_data) experiment_result_dictionary = {'name': job.get('name'), 'seed': 42, 'shots': job.get('number_of_shots'), 'data': experiment_result_data, 'status': 'DONE', 'success': True, 'time_taken': result.get('execution_time_in_seconds'), 'header': header} experiment_results.append(ExperimentResult(**experiment_result_dictionary)) return experiment_results
def get_experiment_results(self, qi_job: QIJob) -> List[ExperimentResult]: """ Get results from experiments from the Quantum-inspire platform. Args: qi_job: A job that has already been submitted and which execution is completed. Raises: QisKitBackendError: If an error occurred during execution by the backend. Returns: A list of experiment results; containing the data, execution time, status, etc. """ jobs = self.__api.get_jobs_from_project(int(qi_job.job_id())) results = [self.__api.get_result_from_job(job['id']) for job in jobs] experiment_results = [] for result, job in zip(results, jobs): if not result.get('histogram', {}): raise QisKitBackendError( 'Result from backend contains no histogram data!\n{}'. format(result.get('raw_text'))) user_data = json.loads(str(job.get('user_data'))) measurements = user_data.pop('measurements') histogram_obj, memory_data = self.__convert_result_data( result, measurements) full_state_histogram_obj = self.__convert_histogram( result, measurements) experiment_result_data = ExperimentResultData(counts=histogram_obj, memory=memory_data) experiment_result_data.probabilities = full_state_histogram_obj header = QobjExperimentHeader.from_dict(user_data) experiment_result_dictionary = { 'name': job.get('name'), 'seed': 42, 'shots': job.get('number_of_shots'), 'data': experiment_result_data, 'status': 'DONE', 'success': True, 'time_taken': result.get('execution_time_in_seconds'), 'header': header } experiment_results.append( ExperimentResult(**experiment_result_dictionary)) return experiment_results
def from_dict(cls, data): """Create a new ExperimentResult object from a dictionary. Args: data (dict): A dictionary representing the ExperimentResult to create. It will be in the same format as output by :meth:`to_dict` Returns: ExperimentResult: The ``ExperimentResult`` object from the input dictionary. """ in_data = copy.copy(data) data_obj = ExperimentResultData.from_dict(in_data.pop("data")) if "header" in in_data: in_data["header"] = QobjExperimentHeader.from_dict( in_data.pop("header")) shots = in_data.pop("shots") success = in_data.pop("success") return cls(shots, success, data_obj, **in_data)