iqm.iqm_client.iqm_client.IQMClient#

class iqm.iqm_client.iqm_client.IQMClient(url, *, client_signature=None, tokens_file=None, token=None, **credentials)#

Bases: object

Provides access to IQM quantum computers.

Parameters:
  • url (str) – Endpoint for accessing the server. Has to start with http or https.

  • client_signature (Optional[str]) – String that IQMClient adds to User-Agent header of requests it sends to the server. The signature is appended to IQMClients own version information and is intended to carry additional version information, for example the version information of the caller.

  • tokens_file (Optional[str]) – Optional path to a tokens file used for authentication. This can also be set in the IQM_TOKENS_FILE environment variable. If tokens_file is set, auth_server_url, username and password must not be set.

  • token (Optional[str]) – If an IQM token is long-lived and the server provides it in plain text format, it can be passed in this argument. It can also be provided in the IQM_TOKEN environment variable. If tokens_file (or IQM_TOKENS_FILE) is set, it will override the value of this token.

Keyword Arguments:
  • auth_server_url (str) – Optional base URL of the authentication server. This can also be set in the IQM_AUTH_SERVER environment variable. If unset, requests will be sent unauthenticated.

  • username (str) – Optional username to log in to authentication server. This can also be set in the IQM_AUTH_USERNAME environment variable. Username must be set if auth_server_url is set.

  • password (str) – Optional password to log in to authentication server. This can also be set in the IQM_AUTH_PASSWORD environment variable. Password must be set if auth_server_url is set.

Methods

__del__()

_default_headers()

_get_bearer_token([retries])

Make a bearer token for Authorization header.

_retry_request_on_error(request)

This is a temporary workaround for 502 errors.

_update_tokens()

Update access token and refresh token.

_validate_circuit_instructions(architecture, ...)

Validates that the instructions target correct qubits in the given circuits.

_validate_instruction(architecture, instruction)

Validates that the instruction targets correct qubits in the given architecture.

_validate_qubit_mapping(architecture, circuits)

Validates the given qubit mapping, if defined.

abort_job(job_id, *[, timeout_secs])

Abort a job that was submitted for execution.

close_auth_session()

Terminate session with authentication server if there was one created.

get_quantum_architecture(*[, timeout_secs])

Retrieve quantum architecture from server.

get_run(job_id, *[, timeout_secs])

Query the status and results of a submitted job.

get_run_status(job_id, *[, timeout_secs])

Query the status of a submitted job.

submit_circuits(circuits, *[, ...])

Submits a batch of quantum circuits for execution on a quantum computer.

wait_for_compilation(job_id[, timeout_secs])

Poll results until a job is either pending execution, ready, failed, aborted, or timed out.

wait_for_results(job_id[, timeout_secs])

Poll results until a job is either ready, failed, aborted, or timed out.

submit_circuits(circuits, *, qubit_mapping=None, custom_settings=None, calibration_set_id=None, shots=1, max_circuit_duration_over_t2=None, heralding_mode=HeraldingMode.NONE)#

Submits a batch of quantum circuits for execution on a quantum computer.

Parameters:
  • circuits (list[Circuit]) – list of circuits to be executed

  • qubit_mapping (dict[str, str] | None) – Mapping of logical qubit names to physical qubit names. Can be set to None if all circuits already use physical qubit names. Note that the qubit_mapping is used for all circuits.

  • custom_settings (dict[str, Any] | None) – Custom settings to override default settings and calibration data. Note: This field should always be None in normal use.

  • calibration_set_id (UUID | None) – ID of the calibration set to use, or None to use the latest one

  • shots (int) – number of times circuits are executed, value must be greater than zero

  • max_circuit_duration_over_t2 (float | None) – Circuits are disqualified on the server if they are longer than this ratio of the T2 time of the qubits. Setting this value to 0.0 turns off circuit duration checking. The default value None instructs server to use server’s default value in the checking.

  • heralding_mode (HeraldingMode) – Heralding mode to use during the execution.

Returns:

ID for the created job. This ID is needed to query the job status and the execution results.

Return type:

UUID

get_run(job_id, *, timeout_secs=60.0)#

Query the status and results of a submitted job.

Parameters:
  • job_id (UUID) – id of the job to query

  • timeout_secs (float) – network request timeout

Returns:

result of the job (can be pending)

Raises:
Return type:

RunResult

get_run_status(job_id, *, timeout_secs=60.0)#

Query the status of a submitted job.

Parameters:
  • job_id (UUID) – id of the job to query

  • timeout_secs (float) – network request timeout

Returns:

status of the job

Raises:
Return type:

RunStatus

wait_for_compilation(job_id, timeout_secs=900)#

Poll results until a job is either pending execution, ready, failed, aborted, or timed out.

Parameters:
  • job_id (UUID) – id of the job to wait for

  • timeout_secs (float) – how long to wait for a response before raising an APITimeoutError

Returns:

job result

Raises:

APITimeoutError – time exceeded the set timeout

Return type:

RunResult

wait_for_results(job_id, timeout_secs=900)#
Poll results until a job is either ready, failed, aborted, or timed out.

Note, that jobs handling on the server side is async and if we try to request the results right after submitting the job (which is usually the case) we will find the job is still pending at least for the first query.

Parameters:
  • job_id (UUID) – id of the job to wait for

  • timeout_secs (float) – how long to wait for a response before raising an APITimeoutError

Returns:

job result

Raises:

APITimeoutError – time exceeded the set timeout

Return type:

RunResult

abort_job(job_id, *, timeout_secs=60.0)#

Abort a job that was submitted for execution.

Parameters:
  • job_id (UUID) – id of the job to be aborted

  • timeout_secs (float) – network request timeout

Raises:
  • HTTPException – HTTP exceptions

  • JobAbortionError – if aborting the job failed

Return type:

None

get_quantum_architecture(*, timeout_secs=60.0)#

Retrieve quantum architecture from server. Caches the result and returns the same result on later invocations.

Parameters:

timeout_secs (float) – network request timeout

Returns:

quantum architecture

Raises:
Return type:

QuantumArchitectureSpecification

close_auth_session()#

Terminate session with authentication server if there was one created.

Returns:

True iff session was successfully closed

Raises:
Return type:

bool