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.
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:
qubit_mapping (dict[str, str] | None) – Mapping of logical qubit names to physical qubit names. Can be set to
None
if allcircuits
already use physical qubit names. Note that thequbit_mapping
is used for allcircuits
.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 oneshots (int) – number of times
circuits
are executed, value must be greater than zeromax_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 valueNone
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:
- get_run(job_id, *, timeout_secs=60.0)#
Query the status and results of a submitted job.
- Parameters:
- Returns:
result of the job (can be pending)
- Raises:
CircuitExecutionError – IQM server specific exceptions
HTTPException – HTTP exceptions
- Return type:
- get_run_status(job_id, *, timeout_secs=60.0)#
Query the status of a submitted job.
- Parameters:
- Returns:
status of the job
- Raises:
CircuitExecutionError – IQM server specific exceptions
HTTPException – HTTP exceptions
- Return type:
- wait_for_compilation(job_id, timeout_secs=900)#
Poll results until a job is either pending execution, ready, failed, aborted, or timed out.
- Parameters:
- Returns:
job result
- Raises:
APITimeoutError – time exceeded the set timeout
- Return type:
- 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:
- Returns:
job result
- Raises:
APITimeoutError – time exceeded the set timeout
- Return type:
- abort_job(job_id, *, timeout_secs=60.0)#
Abort a job that was submitted for execution.
- Parameters:
- 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:
APITimeoutError – time exceeded the set timeout
ClientConfigurationError – if no valid authentication is provided
HTTPException – HTTP exceptions
- Return type:
- close_auth_session()#
Terminate session with authentication server if there was one created.
- Returns:
True iff session was successfully closed
- Raises:
ClientAuthenticationError – if logout failed
ClientAuthenticationError – if asked to close externally managed authentication session
- Return type: