-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_test.py
More file actions
43 lines (34 loc) · 1.25 KB
/
api_test.py
File metadata and controls
43 lines (34 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from qiskit.circuit.random.utils import random_circuit
import requests
import json
import time
'''
Python script that sends requests to the api, starts them and retrieves the results
'''
url_creation = "http://localhost:5000/tasks"
url_task = "http://localhost:5000/tasks/"
headers = {'Content-Type': 'application/json'}
tasks = []
circuits = []
for i in range(100):
circuits.append({"qasm":random_circuit(5, 5, 2, measure=True).qasm(), "config":{ "quantum_resource_mapper": {"backend_chooser":{"allow_simulator":True}, "execution_types":{"raw":False}}}})
print("Send request")
response = requests.request("POST", url_creation, json={"circuits":circuits}, headers=headers)
print(response.text)
results = json.loads(response.text)
for res in results["results"]:
tasks.append(res["id"])
for task in tasks:
response = requests.request("PUT", url_task+task)
print(f"Started {task}")
while len(tasks)>0:
task = tasks[0]
response = requests.request("GET", url_task+task+"/status")
res_json = json.loads(response.text)
if res_json["status"] == "running":
print(f"{task} is still running")
time.sleep(10)
continue
response = requests.request("GET", url_task+task+"/result")
print(response.text)
tasks.pop(0)