ApiAdapter#

class pennylane_calculquebec.API.adapter.ApiAdapter#

Bases: object

A singleton wrapper around the Thunderhead REST API.

Call initialize() once with an ApiClient before making any requests. Afterwards, use instance() to access the singleton.

Cached values (machine, benchmark, qubits/couplers) are invalidated automatically after 24 hours via is_last_update_expired().

client: ApiClient#
headers: dict[str, str]#

clean_cache()

Invalidate all cached API values.

get_benchmark(*args, **kwargs)

get_connectivity_for_machine(machine_name)

Return the coupler-to-qubit connectivity map for a machine.

get_machine_by_name(*args, **kwargs)

get_project_id_by_name(*args, **kwargs)

get_qubits_and_couplers(*args, **kwargs)

initialize(client)

Create (or replace) the singleton ApiAdapter instance.

instance()

Return the current singleton instance.

is_last_update_expired()

Check whether the cached data is older than 24 hours.

job_by_id(*args, **kwargs)

list_jobs(*args, **kwargs)

list_machines(*args, **kwargs)

post_job(*args, **kwargs)

raise_exception(res)

Parse an unsuccessful HTTP response and raise an ApiException.

static clean_cache()#

Invalidate all cached API values.

Forces the next request for machine, benchmark, or qubit/coupler data to perform a fresh API call.

static get_benchmark(*args, **kwargs)#
static get_connectivity_for_machine(machine_name: str) dict#

Return the coupler-to-qubit connectivity map for a machine.

Parameters:

machine_name (str) – the name of the machine to query

Returns:

mapping of coupler identifiers to the pair of connected qubits

Return type:

dict

Raises:

ApiException – if no machine with machine_name is available

static get_machine_by_name(*args, **kwargs)#
static get_project_id_by_name(*args, **kwargs)#
static get_qubits_and_couplers(*args, **kwargs)#
classmethod initialize(client: ApiClient)#

Create (or replace) the singleton ApiAdapter instance.

Builds the authentication headers from client and, when client.project_name is set, resolves it to a project ID via get_project_id_by_name().

Parameters:

client (ApiClient) – client credentials and configuration used for every subsequent API request

classmethod instance()#

Return the current singleton instance.

Returns:

the unique adapter instance created by initialize()

Return type:

ApiAdapter

static is_last_update_expired()#

Check whether the cached data is older than 24 hours.

Returns:

True if the last successful cache update was more than 24 hours ago, False otherwise.

Return type:

bool

static job_by_id(*args, **kwargs)#
static list_jobs(*args, **kwargs)#
static list_machines(*args, **kwargs)#
static post_job(*args, **kwargs)#
static raise_exception(res)#

Parse an unsuccessful HTTP response and raise an ApiException.

Attempts to deserialize the response body as JSON and extract an "error" field; falls back to the raw text if deserialization fails.

Parameters:

res (requests.Response) – the failed HTTP response

Raises:

ApiException – always raised with the extracted status code and message