qsvaps 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
qsvaps-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 QSVAPS Research Team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
qsvaps-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,343 @@
1
+ Metadata-Version: 2.4
2
+ Name: qsvaps
3
+ Version: 0.1.0
4
+ Summary: Quantum Superposition Verification for Agent Plan Safety — Grover's search as a verification oracle for AI agent plans
5
+ Author: QSVAPS Research Team
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/vmore2/qsvaps
8
+ Project-URL: Repository, https://github.com/vmore2/qsvaps
9
+ Project-URL: Issues, https://github.com/vmore2/qsvaps/issues
10
+ Keywords: quantum,ai-agents,verification,grover,plan-safety,qiskit,agent-safety
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
15
+ Classifier: Topic :: Scientific/Engineering :: Physics
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: qiskit>=1.0.0
23
+ Requires-Dist: qiskit-aer>=0.13.0
24
+ Requires-Dist: numpy>=1.24.0
25
+ Requires-Dist: matplotlib>=3.7.0
26
+ Provides-Extra: llm
27
+ Requires-Dist: openai>=1.0.0; extra == "llm"
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=7.0; extra == "dev"
30
+ Requires-Dist: pytest-cov; extra == "dev"
31
+ Dynamic: license-file
32
+
33
+ ---
34
+ title: QSVAPS
35
+ emoji: ⚛️
36
+ colorFrom: indigo
37
+ colorTo: purple
38
+ sdk: static
39
+ license: mit
40
+ tags:
41
+ - quantum-computing
42
+ - ai-agents
43
+ - grover-algorithm
44
+ - plan-verification
45
+ - agent-safety
46
+ - qiskit
47
+ pinned: false
48
+ ---
49
+
50
+ # ⚛️ QSVAPS — Quantum Superposition Verification for Agent Plan Safety
51
+
52
+ [![PyPI](https://img.shields.io/pypi/v/qsvaps.svg)](https://pypi.org/project/qsvaps/)
53
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
54
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://python.org)
55
+ [![Tests](https://img.shields.io/badge/tests-52%20passed-brightgreen.svg)](#running-tests)
56
+ [![Qiskit](https://img.shields.io/badge/Qiskit-1.0+-6929C4.svg)](https://qiskit.org)
57
+
58
+ **The first framework to use Grover's quantum search as a verification oracle for AI agent plans.**
59
+
60
+ ```
61
+ Classical Generation → Quantum Verification → Classical Repair
62
+ (LLM agent) (Grover's algorithm) (LLM agent)
63
+ ```
64
+
65
+ ---
66
+
67
+ ## 🔴 The Problem: AI Agents Fly Blind
68
+
69
+ AI agents (LangChain, AutoGen, CrewAI) generate multi-step plans every day — chaining API calls, orchestrating tools, executing code. But here's the uncomfortable truth:
70
+
71
+ > **Nobody verifies these plans before execution.**
72
+
73
+ A plan that looks correct step-by-step can fail catastrophically due to **emergent interactions** between steps:
74
+ - 🔥 **Race conditions** — two steps hit the same rate-limited API simultaneously
75
+ - 💥 **Cascading failures** — step 3 depends on step 2, which silently failed
76
+ - 🔒 **Resource deadlocks** — competing steps lock each other out
77
+ - 🕳️ **Missing fallbacks** — a critical step fails with no recovery path
78
+
79
+ Classical verification requires checking every possible execution scenario. For a plan with 20 decision points, that's **2²⁰ = 1,048,576 scenarios.** Exhaustive checking is too slow.
80
+
81
+ ## 🟢 The Solution: Quantum Verification
82
+
83
+ QSVAPS uses **Grover's quantum search algorithm** — a provably optimal quantum algorithm — to search the space of potential failures **quadratically faster** than any classical approach:
84
+
85
+ | Scenario | Classical Brute Force | QSVAPS (Grover) |
86
+ |---|---|---|
87
+ | 20 decision points (2²⁰ states) | ~1,000,000 checks | ~1,000 iterations |
88
+ | 30 decision points (2³⁰ states) | ~1,000,000,000 checks | ~31,623 iterations |
89
+ | Speedup | O(N) | O(√N) — **provably optimal** |
90
+
91
+ This isn't quantum for the sake of quantum. Grover's speedup is **information-theoretically optimal** — no classical algorithm can do better for unstructured search.
92
+
93
+ ## 🧭 Where QSVAPS Fits
94
+
95
+ ```
96
+ ┌──────────────────────────────────────────────────────────────────────┐
97
+ │ AI Agent Architecture │
98
+ ├──────────────────────────────────────────────────────────────────────┤
99
+ │ │
100
+ │ ┌─────────────┐ ┌──────────────────┐ ┌──────────────────┐ │
101
+ │ │ │ │ │ │ │ │
102
+ │ │ LLM Agent │────▶│ QSVAPS │────▶│ Safe Execution │ │
103
+ │ │ generates │ │ verifies plan │ │ with confidence │ │
104
+ │ │ plan │ │ using quantum │ │ │ │
105
+ │ │ │ │ search │ │ │ │
106
+ │ └─────────────┘ └────────┬─────────┘ └──────────────────┘ │
107
+ │ ▲ │ │
108
+ │ │ If violations found │
109
+ │ │ │ │
110
+ │ └─────────────────────┘ │
111
+ │ LLM repairs plan │
112
+ │ │
113
+ └──────────────────────────────────────────────────────────────────────┘
114
+ ```
115
+
116
+ **QSVAPS sits between plan generation and execution.** It's the safety layer that catches failures before they happen — using quantum computing as a verification co-processor.
117
+
118
+ ### What Makes This Novel
119
+
120
+ | Existing Approach | QSVAPS Difference |
121
+ |---|---|
122
+ | Quantum Neural Networks | Uses quantum for **verification**, not model training |
123
+ | LLM generates quantum code | Quantum code enhances the **agent itself** |
124
+ | Quantum hyperparameter tuning | Quantum solves a **core agent bottleneck** |
125
+ | Classical plan verification | Provable **quadratic speedup** via Grover's algorithm |
126
+
127
+ ## ⚡ Quick Start
128
+
129
+ ### Install
130
+
131
+ ```bash
132
+ pip install qsvaps
133
+ ```
134
+
135
+ ### Run the Demo
136
+
137
+ ```bash
138
+ python -m qsvaps.demo
139
+ ```
140
+
141
+ No API keys needed — uses the Qiskit Aer simulator and a built-in mock LLM.
142
+
143
+ ### Use in Your Code
144
+
145
+ ```python
146
+ from qsvaps import Plan, PlanAction, ResourceConstraint, PlanVerifier
147
+
148
+ # Define your agent's plan
149
+ plan = Plan(
150
+ name="Data Pipeline",
151
+ actions=[
152
+ PlanAction(name="fetch_data", description="Fetch from API", resources=["api_quota"]),
153
+ PlanAction(name="transform", description="Transform dataset"),
154
+ PlanAction(name="save", description="Write to database", can_fail=False),
155
+ ],
156
+ dependencies=[("fetch_data", "transform"), ("transform", "save")],
157
+ resource_constraints=[ResourceConstraint("api_quota", max_concurrent=1)],
158
+ )
159
+
160
+ # Quantum verification
161
+ verifier = PlanVerifier(shots=2048)
162
+ result = verifier.verify(plan, verbose=True)
163
+
164
+ if not result.is_safe:
165
+ print(f"Found {result.num_violations} failure modes!")
166
+ for witness in result.witnesses:
167
+ print(witness.explanation)
168
+ ```
169
+
170
+ ### Verify & Auto-Repair with LLM
171
+
172
+ ```python
173
+ from qsvaps import PlanVerifier, LLMInterface
174
+
175
+ # Connect to any OpenAI-compatible API
176
+ llm = LLMInterface(api_key="sk-...", model="gpt-4")
177
+
178
+ # Or use the built-in mock for testing
179
+ # llm = LLMInterface(mock=True)
180
+
181
+ verifier = PlanVerifier(llm=llm, max_repair_iterations=3)
182
+ results = verifier.verify_and_repair(plan, verbose=True)
183
+
184
+ # The repaired plan is in results[-1].plan
185
+ ```
186
+
187
+ ## 🔬 How It Works
188
+
189
+ ### Step 1: Constraint Extraction
190
+
191
+ Your plan's structure is automatically analyzed to extract boolean constraints:
192
+
193
+ ```
194
+ Plan: fetch_data → transform → save
195
+
196
+ Constraints extracted:
197
+ C1 [DEPENDENCY]: 'transform' requires 'fetch_data' to succeed first
198
+ Formula: (¬x₁) ∨ x₀
199
+ C2 [DEPENDENCY]: 'save' requires 'transform' to succeed first
200
+ Formula: (¬x₂) ∨ x₁
201
+ C3 [COMPLETION]: 'save' must succeed
202
+ Formula: x₂
203
+ ```
204
+
205
+ Supported constraint types:
206
+ - **Dependency** — if B depends on A, B succeeding implies A succeeded
207
+ - **Resource** — actions sharing rate-limited resources can't both run in parallel
208
+ - **Completion** — actions marked `can_fail=False` must succeed
209
+ - **Fallback** — if an action has a fallback, at least one must succeed
210
+ - **Custom** — any boolean expression you define
211
+
212
+ ### Step 2: Quantum Oracle Construction
213
+
214
+ Constraints are encoded as a **quantum phase oracle** — a circuit that flips the phase of states where any constraint is violated:
215
+
216
+ ```
217
+ |valid⟩ → |valid⟩ (no phase change)
218
+ |violation⟩ → -|violation⟩ (phase flipped)
219
+ ```
220
+
221
+ ### Step 3: Grover's Search
222
+
223
+ Grover's algorithm amplifies the probability of measuring violation states:
224
+
225
+ ```
226
+ ┌──────────┐ ┌──────────┐
227
+ |0⟩⊗ⁿ ── H⊗ⁿ ──┤ Oracle ├──┤ Diffuser ├── × k iterations ── Measure
228
+ └──────────┘ └──────────┘
229
+
230
+ k = ⌊π/4 × √(N/M)⌋ where N = total states, M = violations
231
+ ```
232
+
233
+ ### Step 4: Witness Decoding
234
+
235
+ Measured bitstrings are decoded into human-readable **failure witnesses**:
236
+
237
+ ```
238
+ Witness #1 (measured 272 times):
239
+ ✅ Action 'fetch_data' succeeds
240
+ ✅ Action 'transform' succeeds
241
+ ❌ Action 'save' FAILS
242
+
243
+ Violated: 'save' must succeed
244
+
245
+ → This scenario means the pipeline completes processing
246
+ but fails to persist results — silent data loss.
247
+ ```
248
+
249
+ ### Step 5: LLM Repair Loop
250
+
251
+ Witnesses are fed to an LLM that revises the plan:
252
+
253
+ ```
254
+ Agent: "Your plan fails when 'save' fails with no fallback.
255
+ Add a retry mechanism or fallback storage."
256
+
257
+ → Repaired plan adds: save_fallback (write to local disk)
258
+ → Re-verification confirms the fix
259
+ ```
260
+
261
+ ## 📦 Project Structure
262
+
263
+ ```
264
+ qsvaps/
265
+ ├── models.py # Plan, Action, Constraint, Witness dataclasses
266
+ ├── constraint_engine.py # Boolean constraint extraction from plans
267
+ ├── oracle_builder.py # Quantum phase oracle + Grover diffuser
268
+ ├── grover_search.py # Grover's algorithm execution engine
269
+ ├── verifier.py # Main verification pipeline
270
+ ├── llm_interface.py # LLM integration (OpenAI + mock mode)
271
+ └── visualization.py # ASCII diagrams + matplotlib plots
272
+ ```
273
+
274
+ ## 📊 Verified Results
275
+
276
+ Demo verification of a 6-action API orchestration pipeline:
277
+
278
+ | Metric | Value |
279
+ |---|---|
280
+ | Qubits | 7 |
281
+ | State space | 128 |
282
+ | Violations found | 127 / 128 |
283
+ | Grover iterations | 1 |
284
+ | Circuit depth | 516 |
285
+ | Circuit gates | 1,320 |
286
+ | Theoretical speedup | 128× |
287
+
288
+ ## 🧪 Running Tests
289
+
290
+ ```bash
291
+ pip install pytest
292
+ python -m pytest tests/ -v
293
+ ```
294
+
295
+ 52 tests covering: models, constraint extraction, oracle correctness (statevector verified), Grover amplification, end-to-end verification, and repair loops.
296
+
297
+ ## 🛣️ Roadmap
298
+
299
+ - [ ] **IBM Quantum integration** — run on real 127-qubit Eagle processors
300
+ - [ ] **LangChain plugin** — drop-in verification for LangChain agents
301
+ - [ ] **AutoGen middleware** — intercept plans before execution
302
+ - [ ] **Scalable oracles** — CNF-based oracle construction for 20+ qubit plans
303
+ - [ ] **Benchmark suite** — standardized plan verification benchmarks
304
+
305
+ ## 📖 Research Background
306
+
307
+ QSVAPS introduces a new architectural pattern: **"Generate classically, verify quantumly."** While quantum computing research typically focuses on replacing classical components (QNNs, VQCs), QSVAPS uses quantum algorithms in a fundamentally different role — as a verification oracle that checks classical output.
308
+
309
+ This builds on:
310
+ - **Grover's algorithm** (1996) — optimal O(√N) unstructured search
311
+ - **PDDL-based planning** — formal plan representation with preconditions/effects
312
+ - **Agent safety research** — the growing need to verify autonomous AI behavior
313
+
314
+ The novelty lies in the bridge: encoding agent plan constraints as quantum oracles, enabling quantum speedup for a real-world AI safety problem.
315
+
316
+ ## 📦 Dependencies
317
+
318
+ | Package | Version | Purpose |
319
+ |---|---|---|
320
+ | `qiskit` | ≥ 1.0.0 | Quantum circuit construction |
321
+ | `qiskit-aer` | ≥ 0.13.0 | Local quantum simulation |
322
+ | `numpy` | ≥ 1.24.0 | Numerical operations |
323
+ | `matplotlib` | ≥ 3.7.0 | Result visualization |
324
+ | `openai` | ≥ 1.0.0 | *Optional* — LLM integration |
325
+
326
+ ## 📄 Citation
327
+
328
+ ```bibtex
329
+ @software{qsvaps2025,
330
+ title={QSVAPS: Quantum Superposition Verification for Agent Plan Safety},
331
+ year={2025},
332
+ license={MIT},
333
+ url={https://github.com/vmore2/qsvaps}
334
+ }
335
+ ```
336
+
337
+ ## 🤝 Contributing
338
+
339
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
340
+
341
+ ## 📜 License
342
+
343
+ [MIT](LICENSE)
qsvaps-0.1.0/README.md ADDED
@@ -0,0 +1,311 @@
1
+ ---
2
+ title: QSVAPS
3
+ emoji: ⚛️
4
+ colorFrom: indigo
5
+ colorTo: purple
6
+ sdk: static
7
+ license: mit
8
+ tags:
9
+ - quantum-computing
10
+ - ai-agents
11
+ - grover-algorithm
12
+ - plan-verification
13
+ - agent-safety
14
+ - qiskit
15
+ pinned: false
16
+ ---
17
+
18
+ # ⚛️ QSVAPS — Quantum Superposition Verification for Agent Plan Safety
19
+
20
+ [![PyPI](https://img.shields.io/pypi/v/qsvaps.svg)](https://pypi.org/project/qsvaps/)
21
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
22
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://python.org)
23
+ [![Tests](https://img.shields.io/badge/tests-52%20passed-brightgreen.svg)](#running-tests)
24
+ [![Qiskit](https://img.shields.io/badge/Qiskit-1.0+-6929C4.svg)](https://qiskit.org)
25
+
26
+ **The first framework to use Grover's quantum search as a verification oracle for AI agent plans.**
27
+
28
+ ```
29
+ Classical Generation → Quantum Verification → Classical Repair
30
+ (LLM agent) (Grover's algorithm) (LLM agent)
31
+ ```
32
+
33
+ ---
34
+
35
+ ## 🔴 The Problem: AI Agents Fly Blind
36
+
37
+ AI agents (LangChain, AutoGen, CrewAI) generate multi-step plans every day — chaining API calls, orchestrating tools, executing code. But here's the uncomfortable truth:
38
+
39
+ > **Nobody verifies these plans before execution.**
40
+
41
+ A plan that looks correct step-by-step can fail catastrophically due to **emergent interactions** between steps:
42
+ - 🔥 **Race conditions** — two steps hit the same rate-limited API simultaneously
43
+ - 💥 **Cascading failures** — step 3 depends on step 2, which silently failed
44
+ - 🔒 **Resource deadlocks** — competing steps lock each other out
45
+ - 🕳️ **Missing fallbacks** — a critical step fails with no recovery path
46
+
47
+ Classical verification requires checking every possible execution scenario. For a plan with 20 decision points, that's **2²⁰ = 1,048,576 scenarios.** Exhaustive checking is too slow.
48
+
49
+ ## 🟢 The Solution: Quantum Verification
50
+
51
+ QSVAPS uses **Grover's quantum search algorithm** — a provably optimal quantum algorithm — to search the space of potential failures **quadratically faster** than any classical approach:
52
+
53
+ | Scenario | Classical Brute Force | QSVAPS (Grover) |
54
+ |---|---|---|
55
+ | 20 decision points (2²⁰ states) | ~1,000,000 checks | ~1,000 iterations |
56
+ | 30 decision points (2³⁰ states) | ~1,000,000,000 checks | ~31,623 iterations |
57
+ | Speedup | O(N) | O(√N) — **provably optimal** |
58
+
59
+ This isn't quantum for the sake of quantum. Grover's speedup is **information-theoretically optimal** — no classical algorithm can do better for unstructured search.
60
+
61
+ ## 🧭 Where QSVAPS Fits
62
+
63
+ ```
64
+ ┌──────────────────────────────────────────────────────────────────────┐
65
+ │ AI Agent Architecture │
66
+ ├──────────────────────────────────────────────────────────────────────┤
67
+ │ │
68
+ │ ┌─────────────┐ ┌──────────────────┐ ┌──────────────────┐ │
69
+ │ │ │ │ │ │ │ │
70
+ │ │ LLM Agent │────▶│ QSVAPS │────▶│ Safe Execution │ │
71
+ │ │ generates │ │ verifies plan │ │ with confidence │ │
72
+ │ │ plan │ │ using quantum │ │ │ │
73
+ │ │ │ │ search │ │ │ │
74
+ │ └─────────────┘ └────────┬─────────┘ └──────────────────┘ │
75
+ │ ▲ │ │
76
+ │ │ If violations found │
77
+ │ │ │ │
78
+ │ └─────────────────────┘ │
79
+ │ LLM repairs plan │
80
+ │ │
81
+ └──────────────────────────────────────────────────────────────────────┘
82
+ ```
83
+
84
+ **QSVAPS sits between plan generation and execution.** It's the safety layer that catches failures before they happen — using quantum computing as a verification co-processor.
85
+
86
+ ### What Makes This Novel
87
+
88
+ | Existing Approach | QSVAPS Difference |
89
+ |---|---|
90
+ | Quantum Neural Networks | Uses quantum for **verification**, not model training |
91
+ | LLM generates quantum code | Quantum code enhances the **agent itself** |
92
+ | Quantum hyperparameter tuning | Quantum solves a **core agent bottleneck** |
93
+ | Classical plan verification | Provable **quadratic speedup** via Grover's algorithm |
94
+
95
+ ## ⚡ Quick Start
96
+
97
+ ### Install
98
+
99
+ ```bash
100
+ pip install qsvaps
101
+ ```
102
+
103
+ ### Run the Demo
104
+
105
+ ```bash
106
+ python -m qsvaps.demo
107
+ ```
108
+
109
+ No API keys needed — uses the Qiskit Aer simulator and a built-in mock LLM.
110
+
111
+ ### Use in Your Code
112
+
113
+ ```python
114
+ from qsvaps import Plan, PlanAction, ResourceConstraint, PlanVerifier
115
+
116
+ # Define your agent's plan
117
+ plan = Plan(
118
+ name="Data Pipeline",
119
+ actions=[
120
+ PlanAction(name="fetch_data", description="Fetch from API", resources=["api_quota"]),
121
+ PlanAction(name="transform", description="Transform dataset"),
122
+ PlanAction(name="save", description="Write to database", can_fail=False),
123
+ ],
124
+ dependencies=[("fetch_data", "transform"), ("transform", "save")],
125
+ resource_constraints=[ResourceConstraint("api_quota", max_concurrent=1)],
126
+ )
127
+
128
+ # Quantum verification
129
+ verifier = PlanVerifier(shots=2048)
130
+ result = verifier.verify(plan, verbose=True)
131
+
132
+ if not result.is_safe:
133
+ print(f"Found {result.num_violations} failure modes!")
134
+ for witness in result.witnesses:
135
+ print(witness.explanation)
136
+ ```
137
+
138
+ ### Verify & Auto-Repair with LLM
139
+
140
+ ```python
141
+ from qsvaps import PlanVerifier, LLMInterface
142
+
143
+ # Connect to any OpenAI-compatible API
144
+ llm = LLMInterface(api_key="sk-...", model="gpt-4")
145
+
146
+ # Or use the built-in mock for testing
147
+ # llm = LLMInterface(mock=True)
148
+
149
+ verifier = PlanVerifier(llm=llm, max_repair_iterations=3)
150
+ results = verifier.verify_and_repair(plan, verbose=True)
151
+
152
+ # The repaired plan is in results[-1].plan
153
+ ```
154
+
155
+ ## 🔬 How It Works
156
+
157
+ ### Step 1: Constraint Extraction
158
+
159
+ Your plan's structure is automatically analyzed to extract boolean constraints:
160
+
161
+ ```
162
+ Plan: fetch_data → transform → save
163
+
164
+ Constraints extracted:
165
+ C1 [DEPENDENCY]: 'transform' requires 'fetch_data' to succeed first
166
+ Formula: (¬x₁) ∨ x₀
167
+ C2 [DEPENDENCY]: 'save' requires 'transform' to succeed first
168
+ Formula: (¬x₂) ∨ x₁
169
+ C3 [COMPLETION]: 'save' must succeed
170
+ Formula: x₂
171
+ ```
172
+
173
+ Supported constraint types:
174
+ - **Dependency** — if B depends on A, B succeeding implies A succeeded
175
+ - **Resource** — actions sharing rate-limited resources can't both run in parallel
176
+ - **Completion** — actions marked `can_fail=False` must succeed
177
+ - **Fallback** — if an action has a fallback, at least one must succeed
178
+ - **Custom** — any boolean expression you define
179
+
180
+ ### Step 2: Quantum Oracle Construction
181
+
182
+ Constraints are encoded as a **quantum phase oracle** — a circuit that flips the phase of states where any constraint is violated:
183
+
184
+ ```
185
+ |valid⟩ → |valid⟩ (no phase change)
186
+ |violation⟩ → -|violation⟩ (phase flipped)
187
+ ```
188
+
189
+ ### Step 3: Grover's Search
190
+
191
+ Grover's algorithm amplifies the probability of measuring violation states:
192
+
193
+ ```
194
+ ┌──────────┐ ┌──────────┐
195
+ |0⟩⊗ⁿ ── H⊗ⁿ ──┤ Oracle ├──┤ Diffuser ├── × k iterations ── Measure
196
+ └──────────┘ └──────────┘
197
+
198
+ k = ⌊π/4 × √(N/M)⌋ where N = total states, M = violations
199
+ ```
200
+
201
+ ### Step 4: Witness Decoding
202
+
203
+ Measured bitstrings are decoded into human-readable **failure witnesses**:
204
+
205
+ ```
206
+ Witness #1 (measured 272 times):
207
+ ✅ Action 'fetch_data' succeeds
208
+ ✅ Action 'transform' succeeds
209
+ ❌ Action 'save' FAILS
210
+
211
+ Violated: 'save' must succeed
212
+
213
+ → This scenario means the pipeline completes processing
214
+ but fails to persist results — silent data loss.
215
+ ```
216
+
217
+ ### Step 5: LLM Repair Loop
218
+
219
+ Witnesses are fed to an LLM that revises the plan:
220
+
221
+ ```
222
+ Agent: "Your plan fails when 'save' fails with no fallback.
223
+ Add a retry mechanism or fallback storage."
224
+
225
+ → Repaired plan adds: save_fallback (write to local disk)
226
+ → Re-verification confirms the fix
227
+ ```
228
+
229
+ ## 📦 Project Structure
230
+
231
+ ```
232
+ qsvaps/
233
+ ├── models.py # Plan, Action, Constraint, Witness dataclasses
234
+ ├── constraint_engine.py # Boolean constraint extraction from plans
235
+ ├── oracle_builder.py # Quantum phase oracle + Grover diffuser
236
+ ├── grover_search.py # Grover's algorithm execution engine
237
+ ├── verifier.py # Main verification pipeline
238
+ ├── llm_interface.py # LLM integration (OpenAI + mock mode)
239
+ └── visualization.py # ASCII diagrams + matplotlib plots
240
+ ```
241
+
242
+ ## 📊 Verified Results
243
+
244
+ Demo verification of a 6-action API orchestration pipeline:
245
+
246
+ | Metric | Value |
247
+ |---|---|
248
+ | Qubits | 7 |
249
+ | State space | 128 |
250
+ | Violations found | 127 / 128 |
251
+ | Grover iterations | 1 |
252
+ | Circuit depth | 516 |
253
+ | Circuit gates | 1,320 |
254
+ | Theoretical speedup | 128× |
255
+
256
+ ## 🧪 Running Tests
257
+
258
+ ```bash
259
+ pip install pytest
260
+ python -m pytest tests/ -v
261
+ ```
262
+
263
+ 52 tests covering: models, constraint extraction, oracle correctness (statevector verified), Grover amplification, end-to-end verification, and repair loops.
264
+
265
+ ## 🛣️ Roadmap
266
+
267
+ - [ ] **IBM Quantum integration** — run on real 127-qubit Eagle processors
268
+ - [ ] **LangChain plugin** — drop-in verification for LangChain agents
269
+ - [ ] **AutoGen middleware** — intercept plans before execution
270
+ - [ ] **Scalable oracles** — CNF-based oracle construction for 20+ qubit plans
271
+ - [ ] **Benchmark suite** — standardized plan verification benchmarks
272
+
273
+ ## 📖 Research Background
274
+
275
+ QSVAPS introduces a new architectural pattern: **"Generate classically, verify quantumly."** While quantum computing research typically focuses on replacing classical components (QNNs, VQCs), QSVAPS uses quantum algorithms in a fundamentally different role — as a verification oracle that checks classical output.
276
+
277
+ This builds on:
278
+ - **Grover's algorithm** (1996) — optimal O(√N) unstructured search
279
+ - **PDDL-based planning** — formal plan representation with preconditions/effects
280
+ - **Agent safety research** — the growing need to verify autonomous AI behavior
281
+
282
+ The novelty lies in the bridge: encoding agent plan constraints as quantum oracles, enabling quantum speedup for a real-world AI safety problem.
283
+
284
+ ## 📦 Dependencies
285
+
286
+ | Package | Version | Purpose |
287
+ |---|---|---|
288
+ | `qiskit` | ≥ 1.0.0 | Quantum circuit construction |
289
+ | `qiskit-aer` | ≥ 0.13.0 | Local quantum simulation |
290
+ | `numpy` | ≥ 1.24.0 | Numerical operations |
291
+ | `matplotlib` | ≥ 3.7.0 | Result visualization |
292
+ | `openai` | ≥ 1.0.0 | *Optional* — LLM integration |
293
+
294
+ ## 📄 Citation
295
+
296
+ ```bibtex
297
+ @software{qsvaps2025,
298
+ title={QSVAPS: Quantum Superposition Verification for Agent Plan Safety},
299
+ year={2025},
300
+ license={MIT},
301
+ url={https://github.com/vmore2/qsvaps}
302
+ }
303
+ ```
304
+
305
+ ## 🤝 Contributing
306
+
307
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
308
+
309
+ ## 📜 License
310
+
311
+ [MIT](LICENSE)