Skip to content

Commit d1d077b

Browse files
committed
animate_bloch returns html not funcanimation
1 parent 10a41d6 commit d1d077b

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

quantum_app_backend/app.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,18 +174,18 @@ def Qtrace(gate, init_state, mag, t2):
174174
@app.route('/receive_data/qft', methods=['GET'])
175175
def Qfouriertransform():
176176
logger.debug("Startting QFT generator")
177-
anim = None
177+
anim_js = None
178178
try:
179179
qft_ode = QFTStepByStepODE(initial_state_str='011')
180180
qft_ode.run(n_step=6)
181-
anim = qft_ode.animate_bloch()
181+
anim_js = qft_ode.animate_bloch()
182182

183-
if not anim:
183+
if not anim_js:
184184
raise Exception("Error generating QFT model")
185185
except Exception as e:
186186
logger.error(f"Error generating QFT model: {str(e)}", exc_info=True)
187187
raise
188-
return anim
188+
return anim_js
189189

190190
@socketio.on('connect')
191191
def handle_connect():

quantum_app_backend/model_generators/QuantumFourierTransform.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,19 +396,24 @@ def animate(frame_idx):
396396
blit=False
397397
)
398398

399+
anim_js = anim.to_jshtml(fps=30)
399400
# plt.show()
400401
# or, to save:
401-
402-
anim_js = anim.to_jshtml(fps=30)
403-
with open(f"qft_with_bloch_and_probs_{self.n_step}.html", "w") as f:
404-
f.write(anim_js)
405-
402+
403+
## Uncomment to save file locally
404+
# path = os.path.abspath(os.path.join(f"quantum_app_backend/cache/qft/qft_with_bloch_and_probs_{self.n_step}.html"))
405+
406+
# if not Path(path).exists():
407+
# with open(path, "w", encoding="utf-8") as f:
408+
# portalocker.lock(f, portalocker.LOCK_EX)
409+
# f.write(anim_js)
410+
406411
# html_writer = HTMLWriter()
407412
# anim.save(f"qft_with_bloch_and_probs_{self.n_step}.html", writer=html_writer)
408413

409414
# print(f"Animation saved as qft_with_bloch_and_probs_{self.n_step}.html")
410415
#
411-
return anim
416+
return anim_js
412417

413418

414419
##############################################################################

0 commit comments

Comments
 (0)