import os
import time
import requests
API_KEY = os.environ["QCOS_API_KEY"]
BASE_URL = "https://api.softquantus.com"
HEADERS = {"Authorization": f"Bearer {API_KEY}", "Content-Type": "application/json"}
# Find the best vendor for the workload
best = requests.post(
f"{BASE_URL}/api/v1/marketplace/find",
headers=HEADERS,
json={"num_qubits": 12, "shots": 2048, "objective": "fidelity"}
)
best.raise_for_status()
print("Best match:", best.json())
# Submit the circuit through the marketplace
run_resp = requests.post(
f"{BASE_URL}/api/v1/marketplace/submit",
headers=HEADERS,
json={
"circuit_qasm": "OPENQASM 2.0; ...",
"num_qubits": 12,
"shots": 2048
}
)
run_resp.raise_for_status()
order_id = run_resp.json()["order_id"]
print(f"Order submitted: {order_id}")
# Poll the order
while True:
r = requests.get(f"{BASE_URL}/api/v1/marketplace/orders/{order_id}", headers=HEADERS).json()
if r["status"] in ("completed", "failed"):
break
time.sleep(5)
print("Result:", r)