55
66import gradio as gr
77import numpy as np
8- import json
9- from qiskit import QuantumCircuit
108from quantumpytho .engine import QuantumEngine
119from quantumpytho .modules .bloch_ascii import one_qubit_from_angles
1210from quantumpytho .modules .circuit_explorer import bell_pair
1311
1412# Initialize quantum engine
1513engine = QuantumEngine ()
1614
15+
1716def bloch_sphere_demo (theta , phi ):
1817 """Generate Bloch sphere ASCII visualization."""
1918 try :
@@ -22,43 +21,51 @@ def bloch_sphere_demo(theta, phi):
2221 except Exception as e :
2322 return f"Error: { str (e )} "
2423
24+
2525def create_bell_pair ():
2626 """Create a Bell pair and return circuit diagram."""
2727 try :
28- result = bell_pair (engine )
29- return f"Bell pair created successfully! \n \n Measurement counts: { result . counts } "
28+ circuit = bell_pair ()
29+ return circuit . draw ( output = 'text' )
3030 except Exception as e :
3131 return f"Error: { str (e )} "
3232
33+
3334def run_quantum_teleport ():
3435 """Run quantum teleportation demo."""
3536 try :
3637 from quantumpytho .modules .teleport_bridge import build_teleport_circuit
38+
3739 circuit = build_teleport_circuit ()
3840 result = engine .run (circuit )
3941 return f"Teleportation circuit executed successfully!\n \n Counts: { result .counts } "
4042 except Exception as e :
4143 return f"Error: { str (e )} "
4244
45+
4346def run_qec_demo (code_type = "Shor" ):
4447 """Run Quantum Error Correction demo."""
4548 try :
4649 if code_type == "Shor" :
4750 from quantumpytho .modules .qec_shor import run_shor_qec_demo
51+
4852 return run_shor_qec_demo ()
4953 elif code_type == "Steane" :
5054 from quantumpytho .modules .qec_steane import run_steane_qec_demo
55+
5156 return run_steane_qec_demo ()
5257 else : # Surface
5358 from quantumpytho .modules .qec_surface import run_surface_code_demo
5459 return run_surface_code_demo ()
5560 except Exception as e :
5661 return f"Error: { str (e )} "
5762
63+
5864def generate_qrng (count , phi_scale = False ):
5965 """Generate quantum random numbers."""
6066 try :
6167 from quantumpytho .modules .qrng_sacred import qrng_phi_sequence
68+
6269 if phi_scale :
6370 result = qrng_phi_sequence (count )
6471 return f"QRNG with phi-scaling:\n { result } "
@@ -215,42 +222,6 @@ def run_benchmark():
215222 except Exception as e :
216223 return f"Error: { str (e )} "
217224
218- def check_ibm_status ():
219- """Check IBM Quantum hardware status."""
220- try :
221- from quantumpytho .modules .hardware_ibm import get_ibm_backends
222-
223- backends = get_ibm_backends ()
224-
225- output = f"""IBM Quantum Hardware Status:
226-
227- Available Backends:
228- { json .dumps (backends , indent = 2 )}
229-
230- Note: To run on actual hardware, configure IBM Quantum credentials
231- and set execution mode to HARDWARE.
232- """
233- return output
234- except Exception as e :
235- return f"IBM Hardware check unavailable: { str (e )} \n \n Note: IBM Quantum credentials not configured."
236-
237- def view_ibm_archive ():
238- """View archived IBM Quantum jobs."""
239- try :
240- from quantumpytho .modules .ibm_archive import get_available_ibm_archive_jobs
241-
242- jobs = get_available_ibm_archive_jobs ()
243-
244- output = f"""IBM Quantum Archive:
245-
246- Available Jobs: { len (jobs )}
247-
248- { json .dumps (jobs [:10 ], indent = 2 )}
249- """
250- return output
251- except Exception as e :
252- return f"Archive unavailable: { str (e )} "
253-
254225# Create Gradio interface
255226def create_interface ():
256227 with gr .Blocks (title = "QPyth - Quantum Computing" , theme = gr .themes .Soft ()) as demo :
@@ -261,64 +232,7 @@ def create_interface():
261232 Featuring VQE, IBM Quantum integration, QEC, noisy simulation, and more.
262233 """ )
263234
264- with gr .Tab ("🔬 VQE - H₂ Molecule" ):
265- gr .Markdown ("Variational Quantum Eigensolver for Hydrogen molecule" )
266- with gr .Row ():
267- bond_length = gr .Slider (0.5 , 2.0 , value = 0.74 , step = 0.01 , label = "Bond Length (Å)" )
268- vqe_shots = gr .Slider (100 , 8192 , value = 1024 , step = 100 , label = "Shots" )
269- vqe_output = gr .Textbox (label = "VQE Results" , lines = 20 )
270- vqe_btn = gr .Button ("Run VQE" )
271- vqe_btn .click (run_vqe_h2 , inputs = [bond_length , vqe_shots ], outputs = vqe_output )
272-
273- with gr .Tab ("🔊 Noisy Simulation" ):
274- gr .Markdown ("Hardware-calibrated noisy simulation with backend profiles" )
275- with gr .Row ():
276- backend_profile = gr .Dropdown (
277- ["IBM" , "IonQ" , "Rigetti" , "Quantinuum" , "Pasqal" ],
278- value = "IBM" ,
279- label = "Backend Profile"
280- )
281- noise_level = gr .Slider (0.0 , 0.1 , value = 0.01 , step = 0.001 , label = "Noise Level" )
282- noisy_output = gr .Textbox (label = "Simulation Results" , lines = 20 )
283- noisy_btn = gr .Button ("Run Noisy Simulation" )
284- noisy_btn .click (run_noisy_simulation , inputs = [backend_profile , noise_level ], outputs = noisy_output )
285-
286- with gr .Tab ("🧬 DNA Circuits" ):
287- gr .Markdown ("DNA-inspired quantum circuit exploration" )
288- sequence_name = gr .Textbox (value = "ATCG" , label = "DNA Sequence" )
289- dna_output = gr .Textbox (label = "Circuit Analysis" , lines = 20 )
290- dna_btn = gr .Button ("Explore DNA Circuit" )
291- dna_btn .click (explore_dna_circuits , inputs = sequence_name , outputs = dna_output )
292-
293- with gr .Tab ("🔷 Sacred Geometry" ):
294- gr .Markdown ("TMT Sierpinski 21-qubit sacred geometry circuit" )
295- tmt_output = gr .Textbox (label = "Sierpinski Results" , lines = 20 )
296- tmt_btn = gr .Button ("Run TMT Circuit" )
297- tmt_btn .click (run_tmt_sierpinski , outputs = tmt_output )
298-
299- with gr .Tab ("🛡️ Quantum Error Correction" ):
300- gr .Markdown ("Quantum error correction codes" )
301- code_type = gr .Radio (["Shor" , "Steane" , "Surface" ], label = "Code Type" , value = "Shor" )
302- qec_output = gr .Textbox (label = "QEC Results" , lines = 20 )
303- qec_btn = gr .Button ("Run QEC Demo" )
304- qec_btn .click (run_qec_demo , inputs = code_type , outputs = qec_output )
305-
306- with gr .Tab ("🌐 IBM Quantum" ):
307- gr .Markdown ("IBM Quantum hardware integration" )
308- with gr .Row ():
309- ibm_status_btn = gr .Button ("Check IBM Status" )
310- ibm_archive_btn = gr .Button ("View Archive" )
311- ibm_output = gr .Textbox (label = "IBM Quantum Info" , lines = 25 )
312- ibm_status_btn .click (check_ibm_status , outputs = ibm_output )
313- ibm_archive_btn .click (view_ibm_archive , outputs = ibm_output )
314-
315- with gr .Tab ("📊 Benchmark" ):
316- gr .Markdown ("Performance benchmark dashboard" )
317- bench_output = gr .Textbox (label = "Benchmark Results" , lines = 25 )
318- bench_btn = gr .Button ("Run Benchmarks" )
319- bench_btn .click (run_benchmark , outputs = bench_output )
320-
321- with gr .Tab ("🔮 Bloch Sphere" ):
235+ with gr .Tab ("Bloch Sphere" ):
322236 gr .Markdown ("Visualize quantum states on the Bloch sphere" )
323237 with gr .Row ():
324238 theta = gr .Slider (0 , 180 , value = 45 , label = "Theta (degrees)" )
@@ -327,37 +241,47 @@ def create_interface():
327241 bloch_btn = gr .Button ("Generate" )
328242 bloch_btn .click (bloch_sphere_demo , inputs = [theta , phi ], outputs = bloch_output )
329243
330- with gr .Tab ("🔗 Bell Pair" ):
244+ with gr .Tab ("Bell Pair" ):
331245 gr .Markdown ("Create an entangled Bell pair" )
332246 bell_output = gr .Textbox (label = "Bell Pair Results" , lines = 15 )
333247 bell_btn = gr .Button ("Create Bell Pair" )
334248 bell_btn .click (create_bell_pair , outputs = bell_output )
335249
336- with gr .Tab ("📡 Quantum Teleportation" ):
250+ with gr .Tab ("Quantum Teleportation" ):
337251 gr .Markdown ("Run the quantum teleportation protocol" )
338252 teleport_output = gr .Textbox (label = "Teleportation Results" , lines = 15 )
339253 teleport_btn = gr .Button ("Run Teleportation" )
340254 teleport_btn .click (run_quantum_teleport , outputs = teleport_output )
341255
342- with gr .Tab ("🎲 Quantum RNG" ):
256+ with gr .Tab ("Quantum Error Correction" ):
257+ gr .Markdown ("Demonstrate quantum error correction codes" )
258+ code_type = gr .Radio (["Shor" , "Steane" ], label = "Code Type" , value = "Shor" )
259+ qec_output = gr .Textbox (label = "Result" , lines = 15 )
260+ qec_btn = gr .Button ("Run QEC Demo" )
261+ qec_btn .click (run_qec_demo , inputs = code_type , outputs = qec_output )
262+
263+ with gr .Tab ("Quantum RNG" ):
343264 gr .Markdown ("Generate quantum random numbers" )
344265 with gr .Row ():
345266 count = gr .Slider (1 , 100 , value = 10 , step = 1 , label = "Number of values" )
346267 phi_scale = gr .Checkbox (label = "Use phi-scaling" )
347268 qrng_output = gr .Textbox (label = "Random Numbers" , lines = 15 )
348269 qrng_btn = gr .Button ("Generate" )
349- qrng_btn .click (generate_qrng , inputs = [count , phi_scale ], outputs = qrng_output )
350-
270+ qrng_btn .click (
271+ generate_qrng , inputs = [count , phi_scale ], outputs = qrng_output
272+ )
273+
351274 gr .Markdown ("""
352275 ---
353276
354277 **QPyth v0.4.0** | Built with Qiskit | Apache 2.0 License
355278
356279 For CLI access and advanced features, install with: `pip install QPyth`
357280 """ )
358-
281+
359282 return demo
360283
284+
361285# Launch the app
362286if __name__ == "__main__" :
363287 demo = create_interface ()
0 commit comments