Table of Contents
Introduction #
In order to ease the use of the QCentroid Platform API, we have devolped an SDK in Python.
This SDK is a very simple class that provides a wrapper for easy access to the most used endpoint.
Description #
Imports #
Only two external librares are used by the SDK:
import requests
import json
Methods #
The following methods are defined in the SDK:
def __init__(QCENTROID_PUBLIC_API, PAYLOAD_USER)
def login()
def execute(header, problem, payload)
def get_result(header, job_name)
def get_results(header)
def get_best_result(header, job_name)
Usage examples #
This is an example of how to obtain a random number using the Quantun Random Numbers Generator (QRNG):
# Import the QCentroid SDK package and other auxiliary packages. Make sure that all packages are installed
from Qcentrod import Qcentroid_SDK
import time
from IPython.display import display, clear_output
# Set your private endpoint and credentials
QCENTROID_PUBLIC_API = "https://api.qcentroid.xyz"
PAYLOAD_USER = {"username": "your-username", "password": "your-password"}
# This problem only recieves one parameter. The size of the bitstring of randomness to receive
PAYLOAD_QRNG = {
"data": {
"size": 50
}
}
# Initialize the SDK
qcentroid_api = Qcentroid_SDK(QCENTROID_PUBLIC_API, PAYLOAD_USER)
# API login using the credentials set above
# Save the header (with your temporal access token) to be used in following requests
header = qcentroid_api.login()
# Execute the Job
response_json = qcentroid_api.execute(header=header, problem='qrng', payload=PAYLOAD_QRNG)
# Extract the Job Id from the response
job_id = response_json['job']
# Obtain the result using the Job Id
result = qcentroid_api.get_result(header=header, job_name=job_id)
# Print the result
print("Execution Result:")
print(result['job'][job_id])
GitHub Resources #
Check the SDK in Github: https://github.com/QapitanQuantum/Qapitan_Public_Tutorials/blob/main/Qcentroid_SDK.py
Check the tutorials that use the SDK: https://github.com/QapitanQuantum/Qapitan_Public_Tutorials