Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
"""

import gradio as gr
import numpy as np

from quantumpytho.engine import QuantumEngine
from quantumpytho.modules.bloch_ascii import one_qubit_from_angles
from quantumpytho.modules.circuit_explorer import bell_pair

# Initialize quantum engine
engine = QuantumEngine()


def bloch_sphere_demo(theta, phi):
"""Generate Bloch sphere ASCII visualization."""
try:
Expand All @@ -20,40 +21,48 @@ def bloch_sphere_demo(theta, phi):
except Exception as e:
return f"Error: {str(e)}"


def create_bell_pair():
"""Create a Bell pair and return circuit diagram."""
try:
circuit = bell_pair()
return circuit.draw(output='text')
return circuit.draw(output="text")
except Exception as e:
return f"Error: {str(e)}"


def run_quantum_teleport():
"""Run quantum teleportation demo."""
try:
from quantumpytho.modules.teleport_bridge import build_teleport_circuit

circuit = build_teleport_circuit()
result = engine.run(circuit)
return f"Teleportation circuit executed successfully!\n\nCounts: {result}"
except Exception as e:
return f"Error: {str(e)}"


def run_qec_demo(code_type="Shor"):
"""Run Quantum Error Correction demo."""
try:
if code_type == "Shor":
from quantumpytho.modules.qec_shor import run_shor_qec_demo

return run_shor_qec_demo()
else:
from quantumpytho.modules.qec_steane import run_steane_qec_demo

return run_steane_qec_demo()
except Exception as e:
return f"Error: {str(e)}"


def generate_qrng(count, phi_scale=False):
"""Generate quantum random numbers."""
try:
from quantumpytho.modules.qrng_sacred import qrng_phi_sequence

if phi_scale:
result = qrng_phi_sequence(count)
return f"QRNG with phi-scaling:\n{result}"
Expand All @@ -67,6 +76,7 @@ def generate_qrng(count, phi_scale=False):
except Exception as e:
return f"Error: {str(e)}"


# Create Gradio interface
def create_interface():
with gr.Blocks(title="QPyth - Quantum Computing") as demo:
Expand All @@ -75,54 +85,59 @@ def create_interface():

A professionally engineered quantum computing library built on Qiskit.
""")

with gr.Tab("Bloch Sphere"):
gr.Markdown("Visualize quantum states on the Bloch sphere")
with gr.Row():
theta = gr.Slider(0, 180, value=45, label="Theta (degrees)")
phi = gr.Slider(0, 360, value=45, label="Phi (degrees)")
bloch_output = gr.Textbox(label="Bloch Sphere Visualization", lines=20)
bloch_btn = gr.Button("Generate")
bloch_btn.click(bloch_sphere_demo, inputs=[theta, phi], outputs=bloch_output)

bloch_btn.click(
bloch_sphere_demo, inputs=[theta, phi], outputs=bloch_output
)

with gr.Tab("Bell Pair"):
gr.Markdown("Create an entangled Bell pair")
bell_output = gr.Textbox(label="Circuit", lines=15)
bell_btn = gr.Button("Create Bell Pair")
bell_btn.click(create_bell_pair, outputs=bell_output)

with gr.Tab("Quantum Teleportation"):
gr.Markdown("Run the quantum teleportation protocol")
teleport_output = gr.Textbox(label="Result", lines=10)
teleport_btn = gr.Button("Run Teleportation")
teleport_btn.click(run_quantum_teleport, outputs=teleport_output)

with gr.Tab("Quantum Error Correction"):
gr.Markdown("Demonstrate quantum error correction codes")
code_type = gr.Radio(["Shor", "Steane"], label="Code Type", value="Shor")
qec_output = gr.Textbox(label="Result", lines=15)
qec_btn = gr.Button("Run QEC Demo")
qec_btn.click(run_qec_demo, inputs=code_type, outputs=qec_output)

with gr.Tab("Quantum RNG"):
gr.Markdown("Generate quantum random numbers")
with gr.Row():
count = gr.Slider(1, 100, value=10, step=1, label="Number of values")
phi_scale = gr.Checkbox(label="Use phi-scaling")
qrng_output = gr.Textbox(label="Random Numbers", lines=10)
qrng_btn = gr.Button("Generate")
qrng_btn.click(generate_qrng, inputs=[count, phi_scale], outputs=qrng_output)

qrng_btn.click(
generate_qrng, inputs=[count, phi_scale], outputs=qrng_output
)

gr.Markdown("""
---

**Note**: This is a demo interface. For full functionality including VQE,
IBM Quantum hardware access, and the complete web UI, please use the CLI or
deploy the full application.
""")

return demo


# Launch the app
if __name__ == "__main__":
demo = create_interface()
Expand Down
Loading