I currently make a QRNG(Quantum Random Number Generator) simulator apps, I build the apps using flask, and Python. What I trying to do is, from the string generated in python backend is sent to HTML text area.
For concept what I mean:
When I click Generate !
button it will show the output on given text area (I build the apps using tkinter)
Flask version:
any solution ? For the code and file structure GITHUB
from flask import *
from qiskit import *
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def main():
if request.method == 'POST':
iteration = int(request.form.get("iteration"))
shot = int(request.form.get("shots"))
qubit = int(request.form.get("qubit"))
auto_iter = int(request.form.get("auto_iter"))
option = request.form["radio_select"]
circ = QuantumCircuit(qubit,qubit)
if qubit==1:
for i in range(0,qubit):
circ.h(i)
circ.measure(i,i)
elif qubit==2:
for i in range(0,qubit):
circ.h(i)
circ.measure(i,i)
elif qubit==3:
for i in range(0,qubit):
circ.h(i)
circ.measure(i,i)
elif qubit==4:
for i in range(0,qubit):
circ.h(i)
circ.measure(i,i)
elif qubit==5:
for i in range(0,qubit):
circ.h(i)
circ.measure(i,i)
number = []
for i in range(0, iteration):
sim = Aer.get_backend('qasm_simulator')
job = execute(circ, sim, shots=shot)
result = job.result()
count = result.get_counts(circ)
max_prob = max(count, key=count.get)
number.append(max_prob)
strings = [str(number) for number in number]
bit_string = "".join(strings)
rslt = int(bit_string,2)
digit = str(len(str(rslt)))
return render_template("main.html")
@app.route('/help')
def help():
return render_template("help.html")
@app.route('/stat')
def feedback():
return render_template("stat.html")
if __name__ == "__main__":
app.debug = True
app.run(port=80)
<body>
<h1>QRNG Simulator</h1>
<div class="main">
<div class="main_core">
<form class="main_form" method="POST">
<p>
<label class="lbl_iteration">Iteration: </label>
<input type="number" name="iteration" id="iteration" min="1" max="10000" value="1">
</p>
<p>
<label class="lbl_shots">Shots: </label>
<input type="number" name="shots" id="shots" min="32" max="65536" step="1" value="32">
</p>
<p>
<label class="lbl_qubit">Qubit Count:</label>
<input type="number" name="qubit" id="qubit" min="1" max="5" value="1">
</p>
<p>
<label class="lbl_auto_iter">Auto Iteration: </label>
<input type="number" name="auto_iter" id="auto_iter" min="1" max="10000" value="1">
</p>
<p class="radio_btn">
<label for="radio_result">Result</label>
<input type="radio" class="radio" name="radio_select" id="radio_result" value="rslt" checked>
</p>
<p class="radio_btn">
<label for="radio_binary">Binary form</label>
<input type="radio" class="radio" name="radio_select" id="radio_binary" value="bin">
</p>
<p class="radio_btn">
<label for="radio_digit">Digit</label>
<input type="radio" class="radio" name="radio_select" id="radio_digit" value="digit">
</p>
<p class="radio_btn">
<label for="radio_all">All info</label>
<input type="radio" class="radio" name="radio_select" id="radio_all" value="all">
</p>
<p>
<textarea id="txt_result" class="txt_area_result" name="txt_result" rows="5" cols="50" disabled></textarea>
</p>
<input type="submit" class="btn_generate btn" value="Generate !">
<input type="button" class="btn_clear btn" value="Clear !">
<input type="button" class="btn_export btn" value="Export !">
<input type="button" class="btn_auto_gen btn" value="Auto Generate !">
<input type="button" class="btn_auto_gen_stat btn" value="Auto Generate Statistics">
</form>
</div>
</div>
</body>
Aucun commentaire:
Enregistrer un commentaire