-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stage_Selector.py
99 lines (82 loc) · 3.42 KB
/
Stage_Selector.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from Qflow_Level_Builder import stage
from Graph_Constructor import Graph_Wrapper
from qiskit import QuantumCircuit
#This module is currently designed to hold the circuit data needed to constuct each stage. The stage selection is currently made
#using the input function but this could be changed to used a tkinter GUI
class Stage_Holder:
def __init__(self):
self.stage_1 = QuantumCircuit(2)
self.stage_1.h(0)
self.stage_1.h(1)
self.stage_2 = QuantumCircuit(3)
self.stage_2.h((0,1))
self.stage_2.cx(1,0)
self.stage_2.z(2)
if __name__== '__main__':
seq= 1
w= 500
h=500
node_size=1
Stages = Stage_Holder()
stagenumber = input('Pick Stage:') #takes user input
print('Stage',stagenumber,'loaded')
if stagenumber == '1': #if stage 1 is selected all the level graphs are created a json strings and stored in an array
Stage_Selected = Stages.stage_1
stage = stage(Stages.stage_1)
graphs = []
for levels in range(1,stage.num_levels+1):
G_wrapper = Graph_Wrapper(stage.levelOperator(levels),stage.levelState(levels))
temp = G_wrapper.data
del temp["directed"]
del temp["multigraph"]
del temp["graph"]
graphs.append(temp)
print(graphs[0])
print('Level files generated')
elif stagenumber == '2':
Stage_Selected = Stages.stage_2
stage = stage(Stages.stage_2)
graphs = []
for levels in range(1,stage.num_levels+1):
G_wrapper = Graph_Wrapper(stage.levelOperator(levels),stage.levelState(levels))
temp = G_wrapper.data
del temp["directed"]
del temp["multigraph"]
del temp["graph"]
graphs.append(temp)
print('Level files generated')
else:
print('Invalid Selection')
#############################################################################################
# This sections creates a HTML webpage for each levels of the stage.
#This can the code can be modified to open the first level automatically
for levels in range(0,stage.num_levels):
html1 = """<!DOCTYPE html>
<html lang = "en">
<head>
<meta charset="utf-8">
<title>Qflow - A Quantum Game</title>
<style type="text/css">
canvas {
border: 1px solid black;
}
body {
margin: 0;
overflow:hidden;
}
div1 {
display: none
}
</style>
</head>
<body id = "body">"""
html2= """<div class = "div1" data-graph = "{}"></div>""".format(graphs[levels])
html3= """<canvas></canvas>
<script src="Qflow.js"></script>
</body>
</html>"""
html = html1+html2+html3
#This writes the generated HTML version of the graph to a html file which can be viewed in browser
f = open(r"C:\Users\User\Documents\Cohort_Project\qflow\Qflow_Level{}.html".format(levels+1), "w")
f.write(html)
f.close()