ibrahim321123 commited on
Commit
921b5d4
·
verified ·
1 Parent(s): 3863a5b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -27
app.py CHANGED
@@ -1,39 +1,36 @@
1
- # app.py
2
- from qiskit_aer import Aer
3
- from qiskit import QuantumInstance
4
- from qiskit.algorithms import Shor
5
  import gradio as gr
6
 
7
- # Function to run Shor's algorithm
8
- def run_shor(N):
9
  try:
10
  N = int(N)
11
- if N % 2 == 0 or N <= 1:
12
- return f"Please enter an odd integer > 1."
13
- if N > 21:
14
- return f"Too big! Factor small numbers like 15 or 21 for simulation."
15
-
16
- # Use Aer simulator backend
17
- backend = Aer.get_backend('aer_simulator')
18
- quantum_instance = QuantumInstance(backend, shots=1024)
19
-
20
- shor = Shor(quantum_instance=quantum_instance)
21
- result = shor.factor(N)
22
-
23
- if result.factors:
24
- return f"Factors of {N} are: {result.factors}"
25
- else:
26
- return f"Failed to find factors. Try again!"
27
  except Exception as e:
28
  return str(e)
29
 
30
- # Gradio interface
31
  iface = gr.Interface(
32
- fn=run_shor,
33
- inputs=gr.Number(label="Enter an integer to factor"),
34
  outputs=gr.Textbox(label="Result"),
35
- title="Shor's Algorithm Demo",
36
- description="A simple Qiskit + Gradio demo to factor integers using Shor's Algorithm. Runs on simulator, so keep N small (e.g., 15, 21)."
37
  )
38
 
39
  if __name__ == "__main__":
 
1
+ from qiskit import QuantumCircuit, transpile, assemble, Aer, execute
2
+ from qiskit.visualization import plot_histogram
 
 
3
  import gradio as gr
4
 
5
+ # This is just a placeholder for a basic quantum circuit that shows QFT
6
+ def run_basic_qft_demo(N):
7
  try:
8
  N = int(N)
9
+ if N <= 0 or N > 8:
10
+ return "Please enter a small integer (1–8) for demo."
11
+
12
+ qc = QuantumCircuit(N)
13
+ # Apply Hadamards to all qubits as a trivial QFT placeholder
14
+ for i in range(N):
15
+ qc.h(i)
16
+
17
+ backend = Aer.get_backend("aer_simulator")
18
+ qc.measure_all()
19
+
20
+ result = execute(qc, backend, shots=1024).result()
21
+ counts = result.get_counts()
22
+
23
+ return f"Simulated simple QFT-like circuit for {N} qubits.\nResult: {counts}"
24
+
25
  except Exception as e:
26
  return str(e)
27
 
 
28
  iface = gr.Interface(
29
+ fn=run_basic_qft_demo,
30
+ inputs=gr.Number(label="Enter number of qubits (1–8)"),
31
  outputs=gr.Textbox(label="Result"),
32
+ title="Modern Qiskit Demo — QFT placeholder",
33
+ description="Modern Qiskit 1.x example: runs a trivial circuit to show basic QFT structure. For real Shor, you’d build modular exponentiation + QFT manually."
34
  )
35
 
36
  if __name__ == "__main__":