poseidon666 commited on
Commit
a71591d
·
verified ·
1 Parent(s): 82013db

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +192 -26
  2. TODO_inference.md +21 -0
  3. server/app.py +1 -1
README.md CHANGED
@@ -1,53 +1,219 @@
1
  ---
2
- title: Quantum Circuit Optimization Environment
3
- emoji: ""
4
  colorFrom: indigo
5
  colorTo: blue
6
  sdk: docker
7
  pinned: false
8
  app_port: 7860
9
  tags:
10
- - openenv
11
  - quantum
12
  - reinforcement-learning
 
 
 
13
  base_path: /web
14
  ---
15
 
16
- # Quantum Circuit Optimization Environment
17
 
18
- > **🚀 Deployment Status: READY** | All OpenEnv compliance requirements verified
19
- >
20
- > See [DEPLOYMENT_READY.md](DEPLOYMENT_READY.md) for full checklist
21
 
22
- A **noise-aware, hardware-constrained** reinforcement learning environment for quantum circuit design and optimisation, built on the [OpenEnv](https://github.com/meta-pytorch/OpenEnv) framework.
23
 
24
- ## Real-World Relevance
 
 
 
 
25
 
26
- Quantum hardware is fragile and expensive. Current NISQ (Noisy Intermediate-Scale Quantum) devices have limited qubit counts, noisy gates, and restricted connectivity. Efficiently compiling and optimising quantum circuits is a **real bottleneck** in quantum computing today. This environment directly maps to:
27
 
28
- - **Quantum compiler optimisation** -- replacing heuristic compilers with learned agents
29
- - **Hardware-aware circuit design** -- respecting physical qubit topology
30
- - **NISQ-era algorithm engineering** -- maximising fidelity under noise
31
 
32
- ## Problem
 
 
 
 
33
 
34
- The agent must construct quantum circuits step-by-step to:
35
-
36
- 1. **Maximise fidelity** -- match a target quantum state
37
- 2. **Minimise depth** -- shorter circuits run faster
38
- 3. **Minimise gate count** -- fewer operations = less noise
39
- 4. **Respect connectivity** -- multi-qubit gates only on connected qubits
40
- 5. **Resist noise** -- circuits must survive decoherence
41
-
42
- ## Action Space
43
 
44
  | Action | Description | Parameters |
45
  |--------|-------------|------------|
46
  | `ADD` | Add a quantum gate | `gate` (H, X, CNOT, RX, RZ), `qubits`, `parameter` |
47
- | `REMOVE` | Remove the last gate | -- |
48
  | `SWAP` | Swap two qubits | `qubits` [q1, q2] |
49
- | `PARAM` | Tune last parametric gate | `parameter` (angle) |
50
- | `STOP` | End the episode | -- |
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
  **Gates available:** Hadamard (H), Pauli-X (X), CNOT, RX(theta), RZ(theta)
53
 
 
1
  ---
2
+ title: Quantum Circuit Optimizer
3
+ emoji: "⚛️"
4
  colorFrom: indigo
5
  colorTo: blue
6
  sdk: docker
7
  pinned: false
8
  app_port: 7860
9
  tags:
 
10
  - quantum
11
  - reinforcement-learning
12
+ - circuit-optimization
13
+ - gradio
14
+ - qiskit
15
  base_path: /web
16
  ---
17
 
18
+ # ⚛️ Quantum Circuit Optimizer
19
 
20
+ A web-based reinforcement learning environment for optimizing quantum circuits. Build and optimize quantum circuits step-by-step to maximize fidelity with target quantum states while respecting hardware constraints and noise.
 
 
21
 
22
+ ## 🌟 Features
23
 
24
+ - **Interactive Web UI**: Built with Gradio for easy circuit construction
25
+ - **Reinforcement Learning Ready**: Compatible with RL algorithms for automated optimization
26
+ - **Hardware-Aware**: Respects qubit connectivity and gate constraints
27
+ - **Noise Simulation**: Includes noise models for realistic NISQ-era circuits
28
+ - **Multiple Tasks**: From simple Bell states to complex unitary approximations
29
 
30
+ ## 🎯 Problem Statement
31
 
32
+ The agent must construct quantum circuits to:
 
 
33
 
34
+ 1. **Maximize Fidelity** - Match target quantum states
35
+ 2. **Minimize Depth** - Shorter circuits run faster
36
+ 3. **Minimize Gate Count** - Fewer operations reduce noise
37
+ 4. **Respect Connectivity** - Multi-qubit gates only on connected qubits
38
+ 5. **Resist Noise** - Circuits must survive decoherence
39
 
40
+ ## 🚀 Action Space
 
 
 
 
 
 
 
 
41
 
42
  | Action | Description | Parameters |
43
  |--------|-------------|------------|
44
  | `ADD` | Add a quantum gate | `gate` (H, X, CNOT, RX, RZ), `qubits`, `parameter` |
45
+ | `REMOVE` | Remove last gate | -- |
46
  | `SWAP` | Swap two qubits | `qubits` [q1, q2] |
47
+ | `PARAM` | Tune parametric gate | `parameter` (angle in radians) |
48
+ | `STOP` | End episode | -- |
49
+
50
+ **Available Gates:**
51
+ - **H** - Hadamard (single qubit)
52
+ - **X** - Pauli-X / NOT (single qubit)
53
+ - **CNOT** - Controlled-NOT (two qubits)
54
+ - **RX(θ)** - Rotation around X-axis (parameterized)
55
+ - **RZ(θ)** - Rotation around Z-axis (parameterized)
56
+
57
+ ## 🏗️ Architecture
58
+
59
+ - **Backend**: Qiskit for quantum state simulation
60
+ - **Frontend**: Gradio web interface
61
+ - **Server**: FastAPI with WebSocket support
62
+ - **Environment**: Custom Gym-compatible RL environment
63
+
64
+ ## 🚀 Quick Start
65
+
66
+ ### Local Development
67
+
68
+ 1. **Clone and setup:**
69
+ ```bash
70
+ git clone https://github.com/viditkaushik/quantum_circuit_optimizer.git
71
+ cd quantum_circuit_optimizer
72
+ pip install -r requirements.txt
73
+ ```
74
+
75
+ 2. **Run locally:**
76
+ ```bash
77
+ python server/app.py
78
+ # Or with uvicorn:
79
+ uvicorn server.app:app --host 0.0.0.0 --port 7860
80
+ ```
81
+
82
+ 3. **Open browser:** http://localhost:7860
83
+
84
+ ### Docker Deployment
85
+
86
+ ```bash
87
+ # Build image
88
+ docker build -t quantum-circuit-optimizer .
89
+
90
+ # Run container
91
+ docker run -p 7860:7860 quantum-circuit-optimizer
92
+ ```
93
+
94
+ ## 📊 Tasks
95
+
96
+ - **Easy**: Bell State (2 qubits, no noise)
97
+ - **Medium**: GHZ State (3 qubits, depolarizing noise)
98
+ - **Hard**: Unitary Approximation (2 qubits, thermal noise)
99
+ - **Efficient**: Imperfect but Efficient (budget constraints)
100
+ - **Noisy**: Noise-Dominant (high decoherence)
101
+ - **Budget**: Budgeted Optimization (resource limits)
102
+ - **Approx**: Approximate Target (tolerance-based)
103
+
104
+ ## 🔧 API Endpoints
105
+
106
+ - `POST /reset` - Reset environment with task
107
+ - `POST /step` - Execute action
108
+ - `GET /state` - Get current state
109
+ - `GET /health` - Health check
110
+
111
+ ## 📈 Metrics
112
+
113
+ - **Fidelity**: How close circuit output is to target state
114
+ - **Efficiency**: Circuit depth and gate count
115
+ - **Noise Score**: Resilience to decoherence
116
+ - **Constraints Score**: Hardware constraint satisfaction
117
+ - **Aggregate Score**: Weighted combination of above
118
+
119
+ ## 🤝 Contributing
120
+
121
+ 1. Fork the repository
122
+ 2. Create feature branch
123
+ 3. Make changes
124
+ 4. Add tests
125
+ 5. Submit pull request
126
+
127
+ ## 📄 License
128
+
129
+ This project is licensed under the BSD-style license.
130
+
131
+ ## 🙏 Acknowledgments
132
+
133
+ Built using Qiskit, Gradio, FastAPI, and OpenEnv framework.
134
+ - **H** - Hadamard (single qubit)
135
+ - **X** - Pauli-X / NOT (single qubit)
136
+ - **CNOT** - Controlled-NOT (two qubits)
137
+ - **RX(θ)** - Rotation around X-axis (parameterized)
138
+ - **RZ(θ)** - Rotation around Z-axis (parameterized)
139
+
140
+ ## 🏗️ Architecture
141
+
142
+ - **Backend**: Qiskit for quantum state simulation
143
+ - **Frontend**: Gradio web interface
144
+ - **Server**: FastAPI with WebSocket support
145
+ - **Environment**: Custom Gym-compatible RL environment
146
+
147
+ ## 🚀 Quick Start
148
+
149
+ ### Local Development
150
+
151
+ 1. **Clone and setup:**
152
+ ```bash
153
+ git clone https://github.com/viditkaushik/quantum_circuit_optimizer.git
154
+ cd quantum_circuit_optimizer
155
+ pip install -r requirements.txt
156
+ ```
157
+
158
+ 2. **Run locally:**
159
+ ```bash
160
+ python server/app.py
161
+ # Or with uvicorn:
162
+ uvicorn server.app:app --host 0.0.0.0 --port 7860
163
+ ```
164
+
165
+ 3. **Open browser:** http://localhost:7860
166
+
167
+ ### Docker Deployment
168
+
169
+ ```bash
170
+ # Build image
171
+ docker build -t quantum-circuit-optimizer .
172
+
173
+ # Run container
174
+ docker run -p 7860:7860 quantum-circuit-optimizer
175
+ ```
176
+
177
+ ## 📊 Tasks
178
+
179
+ - **Easy**: Bell State (2 qubits, no noise)
180
+ - **Medium**: GHZ State (3 qubits, depolarizing noise)
181
+ - **Hard**: Unitary Approximation (2 qubits, thermal noise)
182
+ - **Efficient**: Imperfect but Efficient (budget constraints)
183
+ - **Noisy**: Noise-Dominant (high decoherence)
184
+ - **Budget**: Budgeted Optimization (resource limits)
185
+ - **Approx**: Approximate Target (tolerance-based)
186
+
187
+ ## 🔧 API Endpoints
188
+
189
+ - `POST /reset` - Reset environment with task
190
+ - `POST /step` - Execute action
191
+ - `GET /state` - Get current state
192
+ - `GET /health` - Health check
193
+
194
+ ## 📈 Metrics
195
+
196
+ - **Fidelity**: How close circuit output is to target state
197
+ - **Efficiency**: Circuit depth and gate count
198
+ - **Noise Score**: Resilience to decoherence
199
+ - **Constraints Score**: Hardware constraint satisfaction
200
+ - **Aggregate Score**: Weighted combination of above
201
+
202
+ ## 🤝 Contributing
203
+
204
+ 1. Fork the repository
205
+ 2. Create feature branch
206
+ 3. Make changes
207
+ 4. Add tests
208
+ 5. Submit pull request
209
+
210
+ ## 📄 License
211
+
212
+ This project is licensed under the BSD-style license.
213
+
214
+ ## 🙏 Acknowledgments
215
+
216
+ Built using Qiskit, Gradio, FastAPI, and OpenEnv framework.
217
 
218
  **Gates available:** Hadamard (H), Pauli-X (X), CNOT, RX(theta), RZ(theta)
219
 
TODO_inference.md ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Fix inference.py Crash
2
+
3
+ ## Info Gathered
4
+ - Crash at asyncio.run(main()): env = await QuantumCircuitEnv.from_docker_image(None)
5
+ - Wrong import: from my_env (missing) → models & server.my_env_environment
6
+ - Docker image init fails for local → use HTTP client "http://localhost:7860"
7
+ - No error handling
8
+
9
+ ## Plan
10
+ 1. Fix imports in inference.py
11
+ 2. Change env init to QuantumCircuitEnv("http://localhost:7860")
12
+ 3. Add try/except around async calls
13
+ 4. Align TASKS with server tasks
14
+ 5. Test: python inference.py
15
+
16
+ ## Pending
17
+ - [ ] Edit inference.py
18
+ - [ ] Test run
19
+ - [ ] Complete
20
+
21
+ Ready - confirm?
server/app.py CHANGED
@@ -32,7 +32,7 @@ from pydantic import BaseModel
32
  from openenv.core.env_server import create_fastapi_app
33
 
34
  from models import ActionType, GateType, QuantumAction, QuantumObservation
35
- from server.my_env_environment import QuantumCircuitEnvironment
36
 
37
  logging.basicConfig(level=logging.INFO)
38
  logger = logging.getLogger(__name__)
 
32
  from openenv.core.env_server import create_fastapi_app
33
 
34
  from models import ActionType, GateType, QuantumAction, QuantumObservation
35
+ from .my_env_environment import QuantumCircuitEnvironment
36
 
37
  logging.basicConfig(level=logging.INFO)
38
  logger = logging.getLogger(__name__)