-
Notifications
You must be signed in to change notification settings - Fork 3
/
main_dumper.py
82 lines (66 loc) · 2.07 KB
/
main_dumper.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
from IBMQuantumExperience import IBMQuantumExperience
from slackclient import SlackClient
import json
import time
import pickle
import logging
import requests
import os
import utils
# Enable logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - \
%(message)s', level=logging.INFO)
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
with open('res/token_q.json') as jsn:
qx_config = json.load(jsn)
api = IBMQuantumExperience(token=qx_config['APItoken'], config={'url': qx_config['url']})
def dumper(delay):
if os.path.exists(utils.PKL1) is False:
data = list()
with open(utils.PKL1, 'wb') as f:
pickle.dump(data, f)
if os.path.exists(utils.PKL2) is False:
data = list()
with open(utils.PKL2, 'wb') as f:
pickle.dump(data, f)
step = 0
logger.info("Dumper is running!")
while True:
# Load.
data = utils.load_data()
if len(data) > 0:
# Store data for 24 hours only.
day_back = max([x[0] for x in data]) - 86400
data = list(filter(lambda x: x[0] >= day_back, data))
# Append.
# remote_backends = discover_remote_backends(api)
remote_backends = utils.backends
try:
device_status = [api.backend_status(backend) for backend in remote_backends]
data.append((time.time(), device_status))
except requests.exceptions.ConnectionError as e:
print(e)
except Exception as e:
pass
# Store.
if step == 0:
with open(utils.PKL1, 'wb') as f:
pickle.dump(data, f)
elif step == 1:
with open(utils.PKL2, 'wb') as f:
pickle.dump(data, f)
step += 1
step %= 2
#############
# Make Plots.
for backend in utils.backends:
utils.plot_full(backend, api)
###
# Sleep.
time.sleep(delay)
def main():
delay = 30 # Seconds.
dumper(delay)
if __name__ == "__main__":
main()