Shortcuts

qiskit.providers.ibmq.job.IBMQJob

class IBMQJob(backend, api_client, job_id, creation_date, status, kind=None, name=None, time_per_step=None, result=None, qobj=None, error=None, tags=None, run_mode=None, share_level=None, client_info=None, **kwargs)[소스]

Representation of a job that executes on an IBM Quantum Experience backend.

The job may be executed on a simulator or a real device. A new IBMQJob instance is returned when you call IBMQBackend.run() to submit a job to a particular backend.

If the job is successfully submitted, you can inspect the job’s status by calling status(). Job status can be one of the JobStatus members. For example:

from qiskit.providers.jobstatus import JobStatus

job = backend.run(...)

try:
    job_status = job.status()  # Query the backend server for job status.
    if job_status is JobStatus.RUNNING:
        print("The job is still running")
except IBMQJobApiError as ex:
    print("Something wrong happened!: {}".format(ex))

참고

An error may occur when querying the remote server to get job information. The most common errors are temporary network failures and server errors, in which case an IBMQJobApiError is raised. These errors usually clear quickly, so retrying the operation is likely to succeed.

Some of the methods in this class are blocking, which means control may not be returned immediately. result() is an example of a blocking method:

job = backend.run(...)

try:
    job_result = job.result()  # It will block until the job finishes.
    print("The job finished with result {}".format(job_result))
except JobError as ex:
    print("Something wrong happened!: {}".format(ex))

Job information retrieved from the server is attached to the IBMQJob instance as attributes. Given that Qiskit and the server can be updated independently, some of these attributes might be deprecated or experimental. Supported attributes can be retrieved via methods. For example, you can use creation_date() to retrieve the job creation date, which is a supported attribute.

IBMQJob constructor.

매개변수
  • backend (IBMQBackend) – The backend instance used to run this job.

  • api_client (AccountClient) – Object for connecting to the server.

  • job_id (str) – Job ID.

  • creation_date (str) – Job creation date.

  • status (str) – Job status returned by the server.

  • kind (Optional[str]) – Job type.

  • name (Optional[str]) – Job name.

  • time_per_step (Optional[dict]) – Time spent for each processing step.

  • result (Optional[dict]) – Job result.

  • qobj (Union[dict, QasmQobj, PulseQobj, None]) – Qobj for this job.

  • error (Optional[dict]) – Job error.

  • tags (Optional[List[str]]) – Job tags.

  • run_mode (Optional[str]) – Scheduling mode the job runs in.

  • share_level (Optional[str]) – Level the job can be shared with.

  • client_info (Optional[Dict[str, str]]) – Client version.

  • kwargs (Any) – Additional job attributes.

__init__(backend, api_client, job_id, creation_date, status, kind=None, name=None, time_per_step=None, result=None, qobj=None, error=None, tags=None, run_mode=None, share_level=None, client_info=None, **kwargs)[소스]

IBMQJob constructor.

매개변수
  • backend (IBMQBackend) – The backend instance used to run this job.

  • api_client (AccountClient) – Object for connecting to the server.

  • job_id (str) – Job ID.

  • creation_date (str) – Job creation date.

  • status (str) – Job status returned by the server.

  • kind (Optional[str]) – Job type.

  • name (Optional[str]) – Job name.

  • time_per_step (Optional[dict]) – Time spent for each processing step.

  • result (Optional[dict]) – Job result.

  • qobj (Union[dict, QasmQobj, PulseQobj, None]) – Qobj for this job.

  • error (Optional[dict]) – Job error.

  • tags (Optional[List[str]]) – Job tags.

  • run_mode (Optional[str]) – Scheduling mode the job runs in.

  • share_level (Optional[str]) – Level the job can be shared with.

  • client_info (Optional[Dict[str, str]]) – Client version.

  • kwargs (Any) – Additional job attributes.

Methods

__init__(backend, api_client, job_id, …[, …])

IBMQJob constructor.

backend()

Return the backend where this job was executed.

cancel()

Attempt to cancel the job.

cancelled()

Return whether the job has been cancelled.

creation_date()

Return job creation date, in local time.

done()

Return whether the job has successfully run.

error_message()

Provide details about the reason of failure.

from_dict(data)

Deserialize a dictionary of simple types into an instance of this class.

in_final_state()

Return whether the job is in a final job state.

job_id()

Return the job ID assigned by the server.

name()

Return the name assigned to this job.

properties()

Return the backend properties for this job.

qobj()

Return the Qobj for this job.

queue_info()

Return queue information for this job.

queue_position([refresh])

Return the position of the job in the server queue.

refresh()

Obtain the latest job information from the server.

result([timeout, wait, partial, refresh])

Return the result of the job.

running()

Return whether the job is actively running.

scheduling_mode()

Return the scheduling mode the job is in.

share_level()

Return the share level of the job.

status()

Query the server for the latest job status.

submit()

Submit this job to an IBM Quantum Experience backend.

tags()

Return the tags assigned to this job.

time_per_step()

Return the date and time information on each step of the job processing.

to_dict()

Serialize the model into a Python dict of simple types.

update_name(name)

Update the name associated with this job.

update_tags([replacement_tags, …])

Update the tags associated with this job.

wait_for_final_state([timeout, wait, callback])

Wait until the job progresses to a final state such as DONE or ERROR.

Attributes

client_version

Return version of the client used for this job.

backend()

Return the backend where this job was executed.

반환 형식

BaseBackend

cancel()[소스]

Attempt to cancel the job.

참고

Depending on the state the job is in, it might be impossible to cancel the job.

반환 형식

bool

반환값

True if the job is cancelled, else False.

예외

IBMQJobApiError – If an unexpected error occurred when communicating with the server.

cancelled()

Return whether the job has been cancelled.

반환 형식

bool

property client_version

Return version of the client used for this job.

반환 형식

Dict[str, str]

반환값

Client version in dictionary format, where the key is the name

of the client and the value is the version.

creation_date()[소스]

Return job creation date, in local time.

반환 형식

datetime

반환값

The job creation date as a datetime object, in local time.

done()

Return whether the job has successfully run.

반환 형식

bool

error_message()[소스]

Provide details about the reason of failure.

반환 형식

Optional[str]

반환값

An error report if the job failed or None otherwise.

classmethod from_dict(data)[소스]

Deserialize a dictionary of simple types into an instance of this class.

매개변수

data (Any) – Data to be deserialized.

반환 형식

IBMQJob

반환값

An instance of this class.

in_final_state()

Return whether the job is in a final job state.

반환 형식

bool

job_id()[소스]

Return the job ID assigned by the server.

반환 형식

str

반환값

Job ID.

name()[소스]

Return the name assigned to this job.

반환 형식

Optional[str]

반환값

Job name or None if no name was assigned to this job.

properties()[소스]

Return the backend properties for this job.

반환 형식

Optional[BackendProperties]

반환값

The backend properties used for this job, or None if properties are not available.

예외

IBMQJobApiError – If an unexpected error occurred when communicating with the server.

qobj()[소스]

Return the Qobj for this job.

반환 형식

Union[QasmQobj, PulseQobj, None]

반환값

The Qobj for this job, or None if the job does not have a Qobj.

예외

IBMQJobApiError – If an unexpected error occurred when retrieving job information from the server.

queue_info()[소스]

Return queue information for this job.

The queue information may include queue position, estimated start and end time, and dynamic priorities for the hub, group, and project. See QueueInfo for more information.

참고

The queue information is calculated after the job enters the queue. Therefore, some or all of the information may not be immediately available, and this method may return None.

반환 형식

Optional[QueueInfo]

반환값

A QueueInfo instance that contains queue information for this job, or None if queue information is unknown or not applicable.

queue_position(refresh=False)[소스]

Return the position of the job in the server queue.

참고

The position returned is within the scope of the provider and may differ from the global queue position.

매개변수

refresh (bool) – If True, re-query the server to get the latest value. Otherwise return the cached value.

반환 형식

Optional[int]

반환값

Position in the queue or None if position is unknown or not applicable.

refresh()[소스]

Obtain the latest job information from the server.

This method may add additional attributes to this job instance, if new information becomes available.

예외

IBMQJobApiError – If an unexpected error occurred when communicating with the server.

반환 형식

None

result(timeout=None, wait=5, partial=False, refresh=False)[소스]

Return the result of the job.

참고

Some IBM Quantum Experience job results can only be read once. A second attempt to query the server for the same job will fail, since the job has already been 《consumed》.

The first call to this method in an IBMQJob instance will query the server and consume any available job results. Subsequent calls to that instance’s result() will also return the results, since they are cached. However, attempting to retrieve the results again in another instance or session might fail due to the job results having been consumed.

참고

When partial=True, this method will attempt to retrieve partial results of failed jobs. In this case, precaution should be taken when accessing individual experiments, as doing so might cause an exception. The success attribute of the returned Result instance can be used to verify whether it contains partial results.

For example, if one of the experiments in the job failed, trying to get the counts of the unsuccessful experiment would raise an exception since there are no counts to return:

try:
    counts = result.get_counts("failed_experiment")
except QiskitError:
    print("Experiment failed!")

If the job failed, you can use error_message() to get more information.

매개변수
  • timeout (Optional[float]) – Number of seconds to wait for job.

  • wait (float) – Time in seconds between queries.

  • partial (bool) – If True, return partial results if possible.

  • refresh (bool) – If True, re-query the server for the result. Otherwise return the cached value.

반환 형식

Result

반환값

Job result.

예외
running()

Return whether the job is actively running.

반환 형식

bool

scheduling_mode()[소스]

Return the scheduling mode the job is in.

The scheduling mode indicates how the job is scheduled to run. For example, fairshare indicates the job is scheduled using a fairshare algorithm.

This information is only available if the job status is RUNNING or DONE.

반환 형식

Optional[str]

반환값

The scheduling mode the job is in or None if the information is not available.

share_level()[소스]

Return the share level of the job.

The share level is one of global, hub, group, project, and none.

반환 형식

str

반환값

The share level of the job.

status()[소스]

Query the server for the latest job status.

참고

This method is not designed to be invoked repeatedly in a loop for an extended period of time. Doing so may cause the server to reject your request. Use wait_for_final_state() if you want to wait for the job to finish.

참고

If the job failed, you can use error_message() to get more information.

반환 형식

JobStatus

반환값

The status of the job.

예외

IBMQJobApiError – If an unexpected error occurred when communicating with the server.

submit()[소스]

Submit this job to an IBM Quantum Experience backend.

참고

This function is deprecated, please use IBMQBackend.run() to submit a job.

예외

IBMQJobInvalidStateError – If the job has already been submitted.

반환 형식

None

tags()[소스]

Return the tags assigned to this job.

반환 형식

List[str]

반환값

Tags assigned to this job.

time_per_step()[소스]

Return the date and time information on each step of the job processing.

The output dictionary contains the date and time information on each step of the job processing, in local time. The keys of the dictionary are the names of the steps, and the values are the date and time data, as a datetime object with local timezone info. For example:

{'CREATING': datetime(2020, 2, 13, 15, 19, 25, 717000, tzinfo=tzlocal(),
 'CREATED': datetime(2020, 2, 13, 15, 19, 26, 467000, tzinfo=tzlocal(),
 'VALIDATING': datetime(2020, 2, 13, 15, 19, 26, 527000, tzinfo=tzlocal()}
반환 형식

Optional[Dict]

반환값

Date and time information on job processing steps, in local time, or None if the information is not yet available.

to_dict()[소스]

Serialize the model into a Python dict of simple types.

참고

This is a unsupported method and will be removed in the next release.

반환 형식

Dict

반환값

An empty dictionary.

update_name(name)[소스]

Update the name associated with this job.

매개변수

name (str) – The new name for this job.

반환 형식

str

반환값

The new name associated with this job.

예외
update_tags(replacement_tags=None, additional_tags=None, removal_tags=None)[소스]

Update the tags associated with this job.

When multiple parameters are specified, the parameters are processed in the following order:

  1. replacement_tags

  2. additional_tags

  3. removal_tags

For example, if 〈new_tag〉 is specified for both additional_tags and removal_tags, then it is added and subsequently removed from the tags list, making it a 《do nothing》 operation.

참고

  • Some tags, such as those starting with ibmq_jobset, are used internally by ibmq-provider and therefore cannot be modified.

  • When removing tags, if the job does not have a specified tag, it will be ignored.

매개변수
  • replacement_tags (Optional[List[str]]) – The tags that should replace the current tags associated with this job.

  • additional_tags (Optional[List[str]]) – The new tags that should be added to the current tags associated with this job.

  • removal_tags (Optional[List[str]]) – The tags that should be removed from the current tags associated with this job.

반환 형식

List[str]

반환값

The new tags associated with this job.

예외
  • IBMQJobApiError – If an unexpected error occurred when communicating with the server or updating the job tags.

  • IBMQJobInvalidStateError – If none of the input parameters are specified or if any of the input parameters are invalid.

wait_for_final_state(timeout=None, wait=None, callback=None)[소스]

Wait until the job progresses to a final state such as DONE or ERROR.

매개변수
  • timeout (Optional[float]) – Seconds to wait for the job. If None, wait indefinitely.

  • wait (Optional[float]) – Seconds to wait between invoking the callback function. If None, the callback function is invoked only if job status or queue position has changed.

  • callback (Optional[Callable]) –

    Callback function invoked after each querying iteration. The following positional arguments are provided to the callback function:

    • job_id: Job ID

    • job_status: Status of the job from the last query.

    • job: This IBMQJob instance.

    In addition, the following keyword arguments are also provided:

    • queue_info: A QueueInfo instance with job queue information, or None if queue information is unknown or not applicable. You can use the to_dict() method to convert the QueueInfo instance to a dictionary, if desired.

예외

IBMQJobTimeoutError – if the job does not reach a final state before the specified timeout.

반환 형식

None

당신은 다음 언어로 문서를 보고 있다 lang: Korean
언어
English
Japanese
German
Korean