schrodinger.application.matsci.qb_sdk.client module

This module implements a class for interacting with the QUBEC REST API using the requests module. Some of the requests are wrapped using the backoff decorator to deal with potential API failures or disconnections

class schrodinger.application.matsci.qb_sdk.client.QubecTokenData(username: Optional[str] = None, password: Optional[str] = None, api_token: Optional[str] = None, last_update: Optional[datetime.datetime] = None)

Bases: object

JWT token information

username: Optional[str] = None
password: Optional[str] = None
api_token: Optional[str] = None
last_update: Optional[datetime.datetime] = None
__init__(username: Optional[str] = None, password: Optional[str] = None, api_token: Optional[str] = None, last_update: Optional[datetime.datetime] = None) None
class schrodinger.application.matsci.qb_sdk.client.QubecClient(http_protocol: str, endpoint: str, port: int, verbose: bool = True)

Bases: object

__init__(http_protocol: str, endpoint: str, port: int, verbose: bool = True) None

Initialize a new instance of a QUBEC REST API client

Args:

http_protocol (str): the HTTP protocol to use for interacting with QUBEC, can be either ‘http’ or ‘https’ endpoint (str): the QUBEC remote endpoint to query port (int): The port to use when building the request verbose (bool): Whether to print debugging information or not

login(username: str, password: str)

Login to a QUBEC session using valid user credentials

Args:

username (str): the username as registered on the Qu&Co website password (str): the password chosen by the user at registration time

logout()
Reset all token information thus initiating a new, non authenticated

QUBEC session

current_user(token: str = None) dict

Get current user information from a valid QUBEC token either stored or given as input

Args:

token (str): A valid, i.e. not expired, JWT token of the QUBEC platform

Returns:

A dictionary with the current logged in user

refresh_session() None

Regenerate token information in the case that it has expired

submit_job(data: dict) dict

Submit a new QUBEC job. If an error occurs in performing the requests due to a temporary disconnection, the request will be retried up to 3 times

Sample output:

``` {

“status”: “success”, “application”: “qubec”, “version”: “1.0”, “data” {

“job_id”: “14eefd92-5aaf-43e6-9e0f-1f4784021155”

}, “message”: “Job successfully submitted”

Args:

data (dict): Dictionary with all job specification parameters

Returns:

A dictionary with API response JSON

progress_job(job_id: str) dict

Query a given job ID for progresses. If an error occurs in performing the requests due to a temporary disconnection, the request will be retried up to 3 times

Sample output:

``` {

“status”: “success”, “application”: “qubec”, “version”: “1.0”, “data”: {

“job_id”: , “algorithm_type”: “vqa”, “status”: “completed”, “result”: {

“optimal_value”: 1.2345 “optimal_theta”: 1.2345 “history_values”: [1.2345, 1.2345], “history_values_std”: [1.2345, 1.2345], “history_theta”: [ [1.2345, 1.2345], [1.2345, 1.2345] ],

} “error_msg”: null, “details”: {

“start_date”: 2020-10-10T00:00:00, “wall_clock”: 12345

}

}

Args:

job_id (str): the job identifier

Returns:

A dictionary with API response JSON

cancel_job(job_id: str) dict

Request a remote cancellation of a supposedly running job. If an error occurs in performing the requests due to a temporary disconnection, the request will be retried up to 3 times

Sample output:

``` {

“status”: “success”, “application”: “qubec”, “version”: “1.0”, “data” {

“job_id”: “14eefd92-5aaf-43e6-9e0f-1f4784021155”

}, “message”: “Job successfully cancelled”

Args:

job_id (str): A string containing the unique job identifier

Returns:

A dictionary with API response JSON

Raises:

QubecSdk error if the response did not succeeded

schrodinger.application.matsci.qb_sdk.client.memoize(fn)
schrodinger.application.matsci.qb_sdk.client.get_client(http_protocol: str = 'https', endpoint: str = 'cloud-quandco.com', port: int = 443)

Get a client for performing QUBEC REST API requests

Args:

http_protocol (str): the HTTP protocol to use for interacting with QUBEC, can be either ‘http’ or ‘https’ endpoint (str): the QUBEC remote endpoint to query port (int): The port to use when building the request use_cached (bool): Whether to use or not a memoized instance of the QUBEC client previously initialized

Returns:
An instance of a QUBEC client either new and not authenticated or previously initialized

and potentially already authenticated