def __init__( self, backend: 'ibmqbackend.IBMQBackend', api: AccountClient, job_id: str, creation_date: str, status: str, kind: Optional[str] = None, name: Optional[str] = None, time_per_step: Optional[dict] = None, result: Optional[dict] = None, qobj: Optional[Union[dict, QasmQobj, PulseQobj]] = None, error: Optional[dict] = None, tags: Optional[List[str]] = None, run_mode: Optional[str] = None, **kwargs: Any ) -> None: """IBMQJob constructor. Args: backend: The backend instance used to run this job. api: Object for connecting to the server. job_id: Job ID. creation_date: Job creation date. status: Job status returned by the server. kind: Job type. name: Job name. time_per_step: Time spent for each processing step. result: Job result. qobj: Qobj for this job. error: Job error. tags: Job tags. run_mode: Scheduling mode the job runs in. kwargs: Additional job attributes. """ self._backend = backend self._api = api self._job_id = job_id self._creation_date = dateutil.parser.isoparse(creation_date) self._api_status = status self._kind = ApiJobKind(kind) if kind else None self._name = name self._time_per_step = time_per_step self._result = Result.from_dict(result) if result else None if isinstance(qobj, dict): qobj = dict_to_qobj(qobj) self._qobj = qobj self._error = error self._tags = tags or [] self._run_mode = run_mode self._status, self._queue_info = \ self._get_status_position(status, kwargs.pop('info_queue', None)) self._use_object_storage = (self._kind == ApiJobKind.QOBJECT_STORAGE) SimpleNamespace.__init__(self, **kwargs) BaseJob.__init__(self, self.backend(), self.job_id()) # Properties used for caching. self._cancelled = False self._job_error_msg = None # type: Optional[str]
def __init__(self, _backend: BaseBackend, api: AccountClient, _job_id: str, _creation_date: datetime, _api_status: ApiJobStatus, **kwargs: Any) -> None: """IBMQJob init function. Args: _backend: the backend instance used to run this job. api: object for connecting to the API. _job_id: job ID of this job. _creation_date: job creation date. _api_status: API job status. kwargs: additional job attributes, that will be added as instance members. """ # pylint: disable=redefined-builtin BaseModel.__init__(self, _backend=_backend, _job_id=_job_id, _creation_date=_creation_date, _api_status=_api_status, **kwargs) BaseJob.__init__(self, self.backend(), self.job_id()) # Model attributes. self._api = api self._use_object_storage = (self.kind == ApiJobKind.QOBJECT_STORAGE) self._queue_info = None # type: Optional[QueueInfo] self._update_status_position(_api_status, kwargs.pop('infoQueue', None)) # Properties used for caching. self._cancelled = False self._job_error_msg = None # type: Optional[str]
def __init__(self, _backend: BaseBackend, api: AccountClient, _job_id: str, _creation_date: str, kind: ApiJobKind, _status: ApiJobStatus, **kwargs: Any) -> None: """IBMQJob init function. Args: _backend (BaseBackend): the backend instance used to run this job. api (AccountClient): object for connecting to the API. _job_id (str or None): job ID of this job. _creation_date (str): job creation date. kind (ApiJobKind): job kind. _status (ApiJobStatus): job status. kwargs (dict): additional job attributes, that will be added as instance members. """ # pylint: disable=redefined-builtin BaseModel.__init__(self, _backend=_backend, _job_id=_job_id, _creation_date=_creation_date, kind=kind, _status=_status, **kwargs) BaseJob.__init__(self, self.backend(), self.job_id()) # Model attributes. self._api = api self._use_object_storage = (self.kind == ApiJobKind.QOBJECT_STORAGE) self._queue_position = None self._update_status_position(_status, kwargs.pop('infoQueue', None)) # Properties used for caching. self._cancelled = False self._job_error_msg = self._error.message if self._error else None
def print_real(cls, job: BaseJob, algorithm: str): results = job.result() answer = results.get_counts() print("\nTotal counts are:", answer) elapsed = results.time_taken print( f"The time it took for the experiment to complete after validation was {elapsed} seconds" ) plot_histogram(data=answer, title=f"{constants.algorithms[int(algorithm)]}") plt.show() return
def __init__(self, _backend: BaseBackend, api: AccountClient, _job_id: str, _creation_date: datetime, _api_status: ApiJobStatus, **kwargs: Any) -> None: """IBMQJob constructor. Args: _backend: The backend instance used to run this job. api: Object for connecting to the server. _job_id: Job ID. _creation_date: Job creation date. _api_status: Job status returned by the server. kwargs: Additional job attributes. """ # pylint: disable=redefined-builtin # Convert qobj from dictionary to Qobj. if isinstance(kwargs.get('_qobj', None), dict): self._qobj = Qobj.from_dict(kwargs.pop('_qobj')) BaseModel.__init__(self, _backend=_backend, _job_id=_job_id, _creation_date=_creation_date, _api_status=_api_status, **kwargs) BaseJob.__init__(self, self.backend(), self.job_id()) # Model attributes. self._api = api self._use_object_storage = (self.kind == ApiJobKind.QOBJECT_STORAGE) self._queue_info = None # type: Optional[QueueInfo] self._status, self._queue_info = self._get_status_position( _api_status, kwargs.pop('info_queue', None)) # Properties used for caching. self._cancelled = False self._job_error_msg = None # type: Optional[str]
def _safe_get_job_status(job: BaseJob, job_id: str) -> JobStatus: while True: try: job_status = job.status() break except JobError as ex: logger.warning("FAILURE: job id: %s, " "status: 'FAIL_TO_GET_STATUS' " "Terra job error: %s", job_id, ex) time.sleep(5) except Exception as ex: raise QiskitError("FAILURE: job id: {}, " "status: 'FAIL_TO_GET_STATUS' " "Unknown error: ({})".format(job_id, ex)) from ex return job_status
def _safe_get_job_status(job: BaseJob, job_id: str, max_job_retries: int, wait: float) -> JobStatus: for _ in range(max_job_retries): try: job_status = job.status() break except JobError as ex: logger.warning( "FAILURE: job id: %s, status: 'FAIL_TO_GET_STATUS' Terra job error: %s", job_id, ex, ) time.sleep(wait) except Exception as ex: raise QiskitError( f"job id: {job_id}, status: 'FAIL_TO_GET_STATUS' Unknown error: ({ex})" ) from ex else: raise QiskitError( f"Max retry limit reached. Failed to get status for job with id {job_id}" ) return job_status