IQMServerClient#

Module: iqm.iqm_server_client.iqm_server_client

class iqm.iqm_server_client.iqm_server_client.IQMServerClient(iqm_server_url: str | None = None, *, quantum_computer: str | None = None, token: str | None = None, tokens_file: str | None = None, client_signature: str | None = None, enable_opentelemetry: bool = False, timeout: float = 120.0)#

Bases: Serializable

Shared functionality for clients communicating with the same IQM server.

Parameters:
  • iqm_server_url (str | None) – Remote IQM Server URL to connect to.

  • quantum_computer (str | None) – ID or alias of the quantum computer to connect to, if the IQM Server instance controls more than one.

  • token (str | None) – Long-lived IQM token in plain text format.

  • tokens_file (str | None) – Path to a tokens file used for authentication.

  • client_signature (str | None) – String that is added to the User-Agent header of requests sent to the server.

  • enable_opentelemetry (bool) – Iff True, enable Jaeger/OpenTelemetry tracing.

  • timeout (float) – Timeout for the request in seconds.

Attributes

api_version

API version of the IQM Server API this client is using.

proxy_path

Resolved URL path prefix for station-proxied requests to this quantum computer.

quantum_computer

Human-readable alias of the quantum computer this client connects to.

Methods

clean_query_parameters

Sanitize query parameters, defaulting 'invalid' to False if supported by the model.

deserialize

Reconstruct an instance from a dictionary payload.

deserialize_response

Parse HTTP response text directly into Pydantic models.

get_about

Get information about IQM Server.

get_health

Get the status of the IQM Server.

prepare_request_kwargs

Return the keyword arguments for a requests HTTP method.

send_request

Send an HTTP request.

serialize

Serialize the object instance into a dictionary payload.

serialize_model

Serialize a Pydantic model into a JSON string.

serialize_query_params

Serialize query parameters, skipping None values and empty dictionaries.

serialize() → dict[str, Any]#

Serialize the object instance into a dictionary payload.

Return type:

dict[str, Any]

classmethod deserialize(data: dict[str, Any]) → IQMServerClient#

Reconstruct an instance from a dictionary payload.

Parameters:

data (dict[str, Any])

Return type:

IQMServerClient

property api_version: str#

API version of the IQM Server API this client is using.

property quantum_computer: str#

Human-readable alias of the quantum computer this client connects to.

property proxy_path: str#

Resolved URL path prefix for station-proxied requests to this quantum computer.

Raises:

ClientConfigurationError – Station-proxied requests are not available for this quantum computer, e.g. due to missing permissions, or the station proxy feature not being enabled on the server.

get_about() → dict#

Get information about IQM Server.

Return type:

dict

get_health() → dict[str, Any]#

Get the status of the IQM Server.

Return type:

dict[str, Any]

static serialize_model(model: BaseModel) → str#

Serialize a Pydantic model into a JSON string.

All Pydantic models should be serialized using this method, to keep the client behavior uniform.

Parameters:

model (BaseModel) – Pydantic model to JSON-serialize.

Returns:

Corresponding JSON string, may contain arbitrary Unicode characters.

Return type:

str

send_request(http_method: Callable[[...], Response], url_path: str, *, headers: dict[str, str] | None = None, params: dict[str, Any] | None = None, json_data: str | None = None, protobuf_data: bytes | None = None) → Response#

Send an HTTP request.

Parameters json_str and octets are mutually exclusive. The first non-None argument (in this order) will be used to construct the body of the request.

Parameters:
  • http_method (Callable[[...], Response]) – HTTP method to use for the request, any of requests.[post|get|put|head|delete|patch|options].

  • url_path (str) – URL for the request.

  • headers (dict[str, str] | None) – Additional HTTP headers for the request. Some may be overridden.

  • params (dict[str, Any] | None) – HTTP query parameters to store in the query string of the request URL.

  • json_data (str | None) – JSON string to store in the body, may contain arbitrary Unicode characters.

  • protobuf_data (bytes | None) – Pre-serialized protobuf binary data to store in the body.

Returns:

Response to the request.

Raises:

IQMError – Request was not successful.

Return type:

Response

static clean_query_parameters(model: Any, **kwargs) → dict[str, Any]#

Sanitize query parameters, defaulting ‘invalid’ to False if supported by the model.

Parameters:

model (Any)

Return type:

dict[str, Any]

prepare_request_kwargs(*, is_mutating: bool, headers: dict[str, str], params: dict[str, Any], json_data: str | None = None, protobuf_data: bytes | None = None, timeout: float) → dict[str, Any]#

Return the keyword arguments for a requests HTTP method.

Parameters:
Return type:

dict[str, Any]

static deserialize_response(response: Response, model_class: type[TypePydanticBase | ListModel], *, list_with_meta: bool = False) → TypePydanticBase | ListWithMeta#

Parse HTTP response text directly into Pydantic models.

Logs metadata errors as warnings if list_with_meta is enabled.

Parameters:
  • response (Response)

  • model_class (type[TypePydanticBase | ListModel])

  • list_with_meta (bool)

Return type:

TypePydanticBase | ListWithMeta

serialize_query_params(params: dict[str, Any]) → dict[str, Any]#

Serialize query parameters, skipping None values and empty dictionaries.

Parameters:

params (dict[str, Any])

Return type:

dict[str, Any]

Inheritance

Inheritance diagram of iqm.iqm_server_client.iqm_server_client.IQMServerClient