Update app.py
Browse files
app.py
CHANGED
@@ -38,15 +38,21 @@ pipeline = load_pipeline()
|
|
38 |
is_gpu_busy = False
|
39 |
def get_qcs(srv, num_of_qubits, max_gates, g):
|
40 |
global is_gpu_busy
|
41 |
-
|
42 |
-
out_tensor = generate_srv_tensors(pipeline, f"Generate SRV: {srv}", samples=6, system_size=num_of_qubits, num_of_qubits=num_of_qubits, max_gates=max_gates, g=g)
|
43 |
-
qc_list, _, svr_list = convert_tensors_to_srvs(out_tensor, pipeline.gate_pool)
|
44 |
-
|
45 |
-
fig, axs = plt.subplots(3, 2, figsize=(7,10), constrained_layout=True, dpi=120)
|
46 |
-
for qc,is_svr,ax in zip(qc_list, svr_list, axs.flatten()):
|
47 |
-
qc.draw("mpl", plot_barriers=False, ax=ax)
|
48 |
-
ax.set_title(f"{'Correct' if is_svr==srv else 'NOT correct'}, is SRV = {is_svr}")
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
# buf = io.BytesIO()
|
51 |
# fig.savefig(buf)
|
52 |
# buf.seek(0)
|
@@ -60,6 +66,7 @@ st.title("genQC · Generative Quantum Circuits")
|
|
60 |
st.write("""
|
61 |
Generating quantum circuits with diffusion models. Official demo of [[paper-arxiv]](https://arxiv.org/abs/2311.02041) [[code-repo]](https://github.com/FlorianFuerrutter/genQC).
|
62 |
""")
|
|
|
63 |
|
64 |
col1, col2 = st.columns(2)
|
65 |
|
@@ -68,7 +75,12 @@ num_of_qubits = col1.radio('Number of qubits (should match SRV)', [3,4,5,6,7,8],
|
|
68 |
max_gates = col1.select_slider('Max gates', options=[4,8,12,16,20,24,28], value=16)
|
69 |
g = col1.slider('Guidance scale', min_value=0.0, max_value=15.0, value=7.5)
|
70 |
|
|
|
|
|
|
|
|
|
|
|
71 |
if col1.button('Generate circuits'):
|
72 |
-
fig = get_qcs(
|
73 |
# col2.image(image, use_column_width=True)
|
74 |
col2.pyplot(fig)
|
|
|
38 |
is_gpu_busy = False
|
39 |
def get_qcs(srv, num_of_qubits, max_gates, g):
|
40 |
global is_gpu_busy
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
+
with st.status("Generation started", expanded=True) as status:
|
43 |
+
st.write("Generating tensors...")
|
44 |
+
out_tensor = generate_srv_tensors(pipeline, f"Generate SRV: {srv}", samples=6, system_size=num_of_qubits, num_of_qubits=num_of_qubits, max_gates=max_gates, g=g)
|
45 |
+
|
46 |
+
st.write("Converting to circuits...")
|
47 |
+
qc_list, _, svr_list = convert_tensors_to_srvs(out_tensor, pipeline.gate_pool)
|
48 |
+
|
49 |
+
st.write("Plotting...")
|
50 |
+
fig, axs = plt.subplots(3, 2, figsize=(7,10), constrained_layout=True, dpi=120)
|
51 |
+
for qc,is_svr,ax in zip(qc_list, svr_list, axs.flatten()):
|
52 |
+
qc.draw("mpl", plot_barriers=False, ax=ax)
|
53 |
+
ax.set_title(f"{'Correct' if is_svr==srv else 'NOT correct'}, is SRV = {is_svr}")
|
54 |
+
status.update(label="Generation complete!", state="complete", expanded=False)
|
55 |
+
|
56 |
# buf = io.BytesIO()
|
57 |
# fig.savefig(buf)
|
58 |
# buf.seek(0)
|
|
|
66 |
st.write("""
|
67 |
Generating quantum circuits with diffusion models. Official demo of [[paper-arxiv]](https://arxiv.org/abs/2311.02041) [[code-repo]](https://github.com/FlorianFuerrutter/genQC).
|
68 |
""")
|
69 |
+
st.divider()
|
70 |
|
71 |
col1, col2 = st.columns(2)
|
72 |
|
|
|
75 |
max_gates = col1.select_slider('Max gates', options=[4,8,12,16,20,24,28], value=16)
|
76 |
g = col1.slider('Guidance scale', min_value=0.0, max_value=15.0, value=7.5)
|
77 |
|
78 |
+
srv_list = ast.literal_eval(srv)
|
79 |
+
|
80 |
+
if len(srv_list)!=num_of_qubits:
|
81 |
+
st.warning('Number of qubits does not match with given SRV. This will result in error-circuits!', icon="⚠️")
|
82 |
+
|
83 |
if col1.button('Generate circuits'):
|
84 |
+
fig = get_qcs(srv_list, num_of_qubits, max_gates, g)
|
85 |
# col2.image(image, use_column_width=True)
|
86 |
col2.pyplot(fig)
|