quantum-debugger 0.1.1__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.
- quantum_debugger-0.1.1/CHANGELOG.md +40 -0
- quantum_debugger-0.1.1/LICENSE +21 -0
- quantum_debugger-0.1.1/MANIFEST.in +6 -0
- quantum_debugger-0.1.1/PKG-INFO +176 -0
- quantum_debugger-0.1.1/README.md +124 -0
- quantum_debugger-0.1.1/examples/bell_state_debug.py +85 -0
- quantum_debugger-0.1.1/examples/grover_profiling.py +136 -0
- quantum_debugger-0.1.1/examples/interactive_demo.py +250 -0
- quantum_debugger-0.1.1/quantum_debugger/__init__.py +22 -0
- quantum_debugger-0.1.1/quantum_debugger/core/__init__.py +7 -0
- quantum_debugger-0.1.1/quantum_debugger/core/circuit.py +269 -0
- quantum_debugger-0.1.1/quantum_debugger/core/gates.py +153 -0
- quantum_debugger-0.1.1/quantum_debugger/core/quantum_state.py +293 -0
- quantum_debugger-0.1.1/quantum_debugger/debugger/__init__.py +7 -0
- quantum_debugger-0.1.1/quantum_debugger/debugger/breakpoints.py +132 -0
- quantum_debugger-0.1.1/quantum_debugger/debugger/debugger.py +222 -0
- quantum_debugger-0.1.1/quantum_debugger/debugger/inspector.py +219 -0
- quantum_debugger-0.1.1/quantum_debugger/profiler/__init__.py +6 -0
- quantum_debugger-0.1.1/quantum_debugger/profiler/metrics.py +129 -0
- quantum_debugger-0.1.1/quantum_debugger/profiler/profiler.py +174 -0
- quantum_debugger-0.1.1/quantum_debugger/visualization/__init__.py +6 -0
- quantum_debugger-0.1.1/quantum_debugger/visualization/bloch_sphere.py +152 -0
- quantum_debugger-0.1.1/quantum_debugger/visualization/state_viz.py +205 -0
- quantum_debugger-0.1.1/quantum_debugger.egg-info/PKG-INFO +176 -0
- quantum_debugger-0.1.1/quantum_debugger.egg-info/SOURCES.txt +29 -0
- quantum_debugger-0.1.1/quantum_debugger.egg-info/dependency_links.txt +1 -0
- quantum_debugger-0.1.1/quantum_debugger.egg-info/requires.txt +16 -0
- quantum_debugger-0.1.1/quantum_debugger.egg-info/top_level.txt +1 -0
- quantum_debugger-0.1.1/requirements.txt +14 -0
- quantum_debugger-0.1.1/setup.cfg +4 -0
- quantum_debugger-0.1.1/setup.py +52 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to QuantumDebugger will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.1.1] - 2025-12-03
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
- Fixed SWAP gate matrix for little-endian qubit ordering
|
|
12
|
+
- Fixed CNOT gate matrix for little-endian qubit ordering
|
|
13
|
+
- Fixed Toffoli gate matrix for little-endian qubit ordering
|
|
14
|
+
- Fixed entanglement detection for Bell states
|
|
15
|
+
- Rewrote multi-qubit gate expansion algorithm using tensor products
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
- 69 comprehensive tests (100% pass rate)
|
|
19
|
+
- Test suites: quickstart, advanced, comprehensive, extreme, validation, production, edge cases
|
|
20
|
+
- Numerical stability tests (100+ consecutive operations)
|
|
21
|
+
- Quantum mechanics validation tests
|
|
22
|
+
- Production readiness tests
|
|
23
|
+
|
|
24
|
+
### Changed
|
|
25
|
+
- Improved gate expansion algorithm for better accuracy
|
|
26
|
+
- Enhanced test coverage to 69 tests across 7 test suites
|
|
27
|
+
|
|
28
|
+
## [0.1.0] - 2025-11-30
|
|
29
|
+
|
|
30
|
+
### Added
|
|
31
|
+
- Initial release
|
|
32
|
+
- Core quantum state representation
|
|
33
|
+
- 15+ quantum gates (H, X, Y, Z, S, T, RX, RY, RZ, PHASE, CNOT, CZ, SWAP, Toffoli)
|
|
34
|
+
- Step-through debugger with breakpoints
|
|
35
|
+
- Circuit profiler with optimization suggestions
|
|
36
|
+
- State visualization tools
|
|
37
|
+
- Bloch sphere representation
|
|
38
|
+
- Support for up to 15 qubits
|
|
39
|
+
- Example circuits and demos
|
|
40
|
+
- Comprehensive documentation
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 QuantumDebugger Contributors
|
|
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.
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: quantum-debugger
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Interactive debugger and profiler for quantum circuits
|
|
5
|
+
Home-page: https://github.com/yourusername/quantum-debugger
|
|
6
|
+
Author: warlord9004
|
|
7
|
+
Author-email: your.email@example.com
|
|
8
|
+
Project-URL: Bug Reports, https://github.com/yourusername/quantum-debugger/issues
|
|
9
|
+
Project-URL: Source, https://github.com/yourusername/quantum-debugger
|
|
10
|
+
Project-URL: Documentation, https://quantum-debugger.readthedocs.io
|
|
11
|
+
Keywords: quantum computing debugging profiling quantum-circuit visualization
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
16
|
+
Classifier: Topic :: Software Development :: Debuggers
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Requires-Python: >=3.8
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: numpy>=1.21.0
|
|
27
|
+
Requires-Dist: matplotlib>=3.5.0
|
|
28
|
+
Requires-Dist: scipy>=1.7.0
|
|
29
|
+
Provides-Extra: qiskit
|
|
30
|
+
Requires-Dist: qiskit>=0.39.0; extra == "qiskit"
|
|
31
|
+
Provides-Extra: cirq
|
|
32
|
+
Requires-Dist: cirq>=1.0.0; extra == "cirq"
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest-cov>=3.0.0; extra == "dev"
|
|
36
|
+
Requires-Dist: black>=22.0.0; extra == "dev"
|
|
37
|
+
Requires-Dist: flake8>=4.0.0; extra == "dev"
|
|
38
|
+
Requires-Dist: sphinx>=4.5.0; extra == "dev"
|
|
39
|
+
Dynamic: author
|
|
40
|
+
Dynamic: author-email
|
|
41
|
+
Dynamic: classifier
|
|
42
|
+
Dynamic: description
|
|
43
|
+
Dynamic: description-content-type
|
|
44
|
+
Dynamic: home-page
|
|
45
|
+
Dynamic: keywords
|
|
46
|
+
Dynamic: license-file
|
|
47
|
+
Dynamic: project-url
|
|
48
|
+
Dynamic: provides-extra
|
|
49
|
+
Dynamic: requires-dist
|
|
50
|
+
Dynamic: requires-python
|
|
51
|
+
Dynamic: summary
|
|
52
|
+
|
|
53
|
+
# QuantumDebugger 🔬
|
|
54
|
+
|
|
55
|
+
A powerful Python library for **interactive debugging and profiling of quantum circuits** with step-through execution, state visualization, and performance analysis.
|
|
56
|
+
|
|
57
|
+
## 🌟 Features
|
|
58
|
+
|
|
59
|
+
### 🐛 Interactive Debugging
|
|
60
|
+
- **Step-through execution**: Execute quantum circuits gate-by-gate
|
|
61
|
+
- **Breakpoints**: Set breakpoints at specific gates or conditions
|
|
62
|
+
- **State inspection**: Examine quantum state at any point in execution
|
|
63
|
+
- **Execution history**: Track and replay circuit execution
|
|
64
|
+
- **Rewind capability**: Step backwards through circuit execution
|
|
65
|
+
|
|
66
|
+
### 📊 Visualization
|
|
67
|
+
- **State vector plots**: Visualize quantum state amplitudes and phases
|
|
68
|
+
- **Probability distributions**: See measurement probabilities
|
|
69
|
+
- **Bloch sphere**: 3D visualization for single qubit states
|
|
70
|
+
- **Circuit diagrams**: ASCII and graphical circuit representations
|
|
71
|
+
|
|
72
|
+
### 📈 Performance Profiling
|
|
73
|
+
- **Gate depth analysis**: Measure circuit depth and critical paths
|
|
74
|
+
- **Complexity metrics**: Gate counts, T-count, CNOT count
|
|
75
|
+
- **Performance estimation**: Predict execution time on quantum hardware
|
|
76
|
+
- **Optimization suggestions**: Get recommendations for circuit improvements
|
|
77
|
+
|
|
78
|
+
## 🚀 Quick Start
|
|
79
|
+
|
|
80
|
+
### Installation
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
pip install quantum-debugger
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Basic Usage
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from quantum_debugger import QuantumCircuit, QuantumDebugger
|
|
90
|
+
|
|
91
|
+
# Create a Bell state circuit
|
|
92
|
+
qc = QuantumCircuit(2)
|
|
93
|
+
qc.h(0)
|
|
94
|
+
qc.cnot(0, 1)
|
|
95
|
+
|
|
96
|
+
# Debug the circuit
|
|
97
|
+
debugger = QuantumDebugger(qc)
|
|
98
|
+
|
|
99
|
+
# Step through execution
|
|
100
|
+
debugger.step() # Apply H gate
|
|
101
|
+
debugger.inspect_state() # Examine current state
|
|
102
|
+
debugger.visualize() # Show state visualization
|
|
103
|
+
|
|
104
|
+
debugger.step() # Apply CNOT
|
|
105
|
+
debugger.inspect_state() # See entangled state
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Setting Breakpoints
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
# Set breakpoint at gate 5
|
|
112
|
+
debugger.set_breakpoint(gate=5)
|
|
113
|
+
|
|
114
|
+
# Run until breakpoint
|
|
115
|
+
debugger.run_until_breakpoint()
|
|
116
|
+
|
|
117
|
+
# Conditional breakpoint
|
|
118
|
+
debugger.set_breakpoint(condition=lambda state: state.is_entangled())
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Profiling
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
from quantum_debugger import CircuitProfiler
|
|
125
|
+
|
|
126
|
+
profiler = CircuitProfiler(qc)
|
|
127
|
+
report = profiler.analyze()
|
|
128
|
+
|
|
129
|
+
print(f"Gate depth: {report.depth}")
|
|
130
|
+
print(f"Total gates: {report.gate_count}")
|
|
131
|
+
print(f"CNOT count: {report.cnot_count}")
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## 📚 Examples
|
|
135
|
+
|
|
136
|
+
Check out the `examples/` directory for:
|
|
137
|
+
- **Bell State Debugging**: Step-by-step entanglement creation
|
|
138
|
+
- **Grover's Algorithm**: Profiling and optimization
|
|
139
|
+
- **Interactive Demo**: Full feature showcase
|
|
140
|
+
|
|
141
|
+
## 🛠️ Requirements
|
|
142
|
+
|
|
143
|
+
- Python 3.8+
|
|
144
|
+
- NumPy
|
|
145
|
+
- Matplotlib
|
|
146
|
+
- (Optional) Qiskit/Cirq for integration
|
|
147
|
+
|
|
148
|
+
## 🤝 Contributing
|
|
149
|
+
|
|
150
|
+
Contributions welcome! Please feel free to submit a Pull Request.
|
|
151
|
+
|
|
152
|
+
## 📄 License
|
|
153
|
+
|
|
154
|
+
MIT License - feel free to use in your quantum computing projects!
|
|
155
|
+
|
|
156
|
+
## 🎯 Why QuantumDebugger?
|
|
157
|
+
|
|
158
|
+
Unlike existing quantum libraries that focus on circuit creation and execution, **QuantumDebugger** is specifically designed for:
|
|
159
|
+
- **Learning**: Understand how quantum algorithms work step-by-step
|
|
160
|
+
- **Development**: Debug complex quantum circuits efficiently
|
|
161
|
+
- **Research**: Analyze and optimize quantum algorithms
|
|
162
|
+
- **Teaching**: Demonstrate quantum concepts interactively
|
|
163
|
+
|
|
164
|
+
## 📖 Documentation
|
|
165
|
+
|
|
166
|
+
Full documentation available at: [quantum-debugger.readthedocs.io](https://quantum-debugger.readthedocs.io)
|
|
167
|
+
|
|
168
|
+
## 🌐 Links
|
|
169
|
+
|
|
170
|
+
- **GitHub**: [github.com/yourusername/quantum-debugger](https://github.com/yourusername/quantum-debugger)
|
|
171
|
+
- **PyPI**: [pypi.org/project/quantum-debugger](https://pypi.org/project/quantum-debugger)
|
|
172
|
+
- **Issues**: [Report bugs](https://github.com/yourusername/quantum-debugger/issues)
|
|
173
|
+
|
|
174
|
+
---
|
|
175
|
+
|
|
176
|
+
Made with ❤️ for the quantum computing community
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# QuantumDebugger 🔬
|
|
2
|
+
|
|
3
|
+
A powerful Python library for **interactive debugging and profiling of quantum circuits** with step-through execution, state visualization, and performance analysis.
|
|
4
|
+
|
|
5
|
+
## 🌟 Features
|
|
6
|
+
|
|
7
|
+
### 🐛 Interactive Debugging
|
|
8
|
+
- **Step-through execution**: Execute quantum circuits gate-by-gate
|
|
9
|
+
- **Breakpoints**: Set breakpoints at specific gates or conditions
|
|
10
|
+
- **State inspection**: Examine quantum state at any point in execution
|
|
11
|
+
- **Execution history**: Track and replay circuit execution
|
|
12
|
+
- **Rewind capability**: Step backwards through circuit execution
|
|
13
|
+
|
|
14
|
+
### 📊 Visualization
|
|
15
|
+
- **State vector plots**: Visualize quantum state amplitudes and phases
|
|
16
|
+
- **Probability distributions**: See measurement probabilities
|
|
17
|
+
- **Bloch sphere**: 3D visualization for single qubit states
|
|
18
|
+
- **Circuit diagrams**: ASCII and graphical circuit representations
|
|
19
|
+
|
|
20
|
+
### 📈 Performance Profiling
|
|
21
|
+
- **Gate depth analysis**: Measure circuit depth and critical paths
|
|
22
|
+
- **Complexity metrics**: Gate counts, T-count, CNOT count
|
|
23
|
+
- **Performance estimation**: Predict execution time on quantum hardware
|
|
24
|
+
- **Optimization suggestions**: Get recommendations for circuit improvements
|
|
25
|
+
|
|
26
|
+
## 🚀 Quick Start
|
|
27
|
+
|
|
28
|
+
### Installation
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install quantum-debugger
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Basic Usage
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from quantum_debugger import QuantumCircuit, QuantumDebugger
|
|
38
|
+
|
|
39
|
+
# Create a Bell state circuit
|
|
40
|
+
qc = QuantumCircuit(2)
|
|
41
|
+
qc.h(0)
|
|
42
|
+
qc.cnot(0, 1)
|
|
43
|
+
|
|
44
|
+
# Debug the circuit
|
|
45
|
+
debugger = QuantumDebugger(qc)
|
|
46
|
+
|
|
47
|
+
# Step through execution
|
|
48
|
+
debugger.step() # Apply H gate
|
|
49
|
+
debugger.inspect_state() # Examine current state
|
|
50
|
+
debugger.visualize() # Show state visualization
|
|
51
|
+
|
|
52
|
+
debugger.step() # Apply CNOT
|
|
53
|
+
debugger.inspect_state() # See entangled state
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Setting Breakpoints
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
# Set breakpoint at gate 5
|
|
60
|
+
debugger.set_breakpoint(gate=5)
|
|
61
|
+
|
|
62
|
+
# Run until breakpoint
|
|
63
|
+
debugger.run_until_breakpoint()
|
|
64
|
+
|
|
65
|
+
# Conditional breakpoint
|
|
66
|
+
debugger.set_breakpoint(condition=lambda state: state.is_entangled())
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Profiling
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
from quantum_debugger import CircuitProfiler
|
|
73
|
+
|
|
74
|
+
profiler = CircuitProfiler(qc)
|
|
75
|
+
report = profiler.analyze()
|
|
76
|
+
|
|
77
|
+
print(f"Gate depth: {report.depth}")
|
|
78
|
+
print(f"Total gates: {report.gate_count}")
|
|
79
|
+
print(f"CNOT count: {report.cnot_count}")
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## 📚 Examples
|
|
83
|
+
|
|
84
|
+
Check out the `examples/` directory for:
|
|
85
|
+
- **Bell State Debugging**: Step-by-step entanglement creation
|
|
86
|
+
- **Grover's Algorithm**: Profiling and optimization
|
|
87
|
+
- **Interactive Demo**: Full feature showcase
|
|
88
|
+
|
|
89
|
+
## 🛠️ Requirements
|
|
90
|
+
|
|
91
|
+
- Python 3.8+
|
|
92
|
+
- NumPy
|
|
93
|
+
- Matplotlib
|
|
94
|
+
- (Optional) Qiskit/Cirq for integration
|
|
95
|
+
|
|
96
|
+
## 🤝 Contributing
|
|
97
|
+
|
|
98
|
+
Contributions welcome! Please feel free to submit a Pull Request.
|
|
99
|
+
|
|
100
|
+
## 📄 License
|
|
101
|
+
|
|
102
|
+
MIT License - feel free to use in your quantum computing projects!
|
|
103
|
+
|
|
104
|
+
## 🎯 Why QuantumDebugger?
|
|
105
|
+
|
|
106
|
+
Unlike existing quantum libraries that focus on circuit creation and execution, **QuantumDebugger** is specifically designed for:
|
|
107
|
+
- **Learning**: Understand how quantum algorithms work step-by-step
|
|
108
|
+
- **Development**: Debug complex quantum circuits efficiently
|
|
109
|
+
- **Research**: Analyze and optimize quantum algorithms
|
|
110
|
+
- **Teaching**: Demonstrate quantum concepts interactively
|
|
111
|
+
|
|
112
|
+
## 📖 Documentation
|
|
113
|
+
|
|
114
|
+
Full documentation available at: [quantum-debugger.readthedocs.io](https://quantum-debugger.readthedocs.io)
|
|
115
|
+
|
|
116
|
+
## 🌐 Links
|
|
117
|
+
|
|
118
|
+
- **GitHub**: [github.com/yourusername/quantum-debugger](https://github.com/yourusername/quantum-debugger)
|
|
119
|
+
- **PyPI**: [pypi.org/project/quantum-debugger](https://pypi.org/project/quantum-debugger)
|
|
120
|
+
- **Issues**: [Report bugs](https://github.com/yourusername/quantum-debugger/issues)
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
Made with ❤️ for the quantum computing community
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Bell State Creation and Debugging Demo
|
|
3
|
+
|
|
4
|
+
This example demonstrates step-by-step debugging of Bell state creation.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from quantum_debugger import QuantumCircuit, QuantumDebugger
|
|
8
|
+
from quantum_debugger.visualization import StateVisualizer, BlochSphere
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def main():
|
|
12
|
+
print("=" * 70)
|
|
13
|
+
print(" " * 15 + "BELL STATE DEBUGGING DEMO")
|
|
14
|
+
print("=" * 70)
|
|
15
|
+
|
|
16
|
+
# Create a Bell state circuit
|
|
17
|
+
print("\n1️⃣ Creating Bell state circuit...")
|
|
18
|
+
qc = QuantumCircuit(2)
|
|
19
|
+
qc.h(0) # Hadamard on qubit 0
|
|
20
|
+
qc.cnot(0, 1) # CNOT with control=0, target=1
|
|
21
|
+
|
|
22
|
+
print(f" Circuit created: {qc.size()} gates, depth {qc.depth()}")
|
|
23
|
+
print(qc.draw())
|
|
24
|
+
|
|
25
|
+
# Initialize debugger
|
|
26
|
+
print("\n2️⃣ Initializing debugger...")
|
|
27
|
+
debugger = QuantumDebugger(qc)
|
|
28
|
+
|
|
29
|
+
# Inspect initial state
|
|
30
|
+
print("\n3️⃣ Initial state |00⟩:")
|
|
31
|
+
debugger.visualize()
|
|
32
|
+
|
|
33
|
+
# Step 1: Apply Hadamard
|
|
34
|
+
print("\n4️⃣ Stepping through: Applying H gate to qubit 0...")
|
|
35
|
+
debugger.step()
|
|
36
|
+
debugger.visualize()
|
|
37
|
+
|
|
38
|
+
print("\n 🔍 Analysis after Hadamard:")
|
|
39
|
+
print(f" - Qubit 0 is in superposition")
|
|
40
|
+
prob_0, prob_1 = debugger.inspector.get_qubit_probabilities(debugger.current_state, 0)
|
|
41
|
+
print(f" - Qubit 0 probabilities: |0⟩={prob_0:.3f}, |1⟩={prob_1:.3f}")
|
|
42
|
+
print(f" - Qubit 1 is still |0⟩")
|
|
43
|
+
|
|
44
|
+
# Step 2: Apply CNOT
|
|
45
|
+
print("\n5️⃣ Stepping through: Applying CNOT gate...")
|
|
46
|
+
debugger.step()
|
|
47
|
+
debugger.visualize()
|
|
48
|
+
|
|
49
|
+
print("\n 🔍 Analysis after CNOT:")
|
|
50
|
+
state_info = debugger.inspect_state()
|
|
51
|
+
print(f" - State is entangled: {state_info['is_entangled']}")
|
|
52
|
+
print(f" - Entropy: {state_info['entropy']:.3f}")
|
|
53
|
+
|
|
54
|
+
# Show measurement statistics
|
|
55
|
+
print("\n6️⃣ Measurement statistics:")
|
|
56
|
+
stats = debugger.inspector.get_measurement_stats(debugger.current_state)
|
|
57
|
+
for basis, prob in stats.items():
|
|
58
|
+
print(f" |{basis}⟩: {prob:.4f} ({prob*100:.1f}%)")
|
|
59
|
+
|
|
60
|
+
# Run actual measurements
|
|
61
|
+
print("\n7️⃣ Running 1000 measurements...")
|
|
62
|
+
results = qc.run(shots=1000)
|
|
63
|
+
print(f" Measurement counts:")
|
|
64
|
+
for outcome, count in sorted(results['counts'].items()):
|
|
65
|
+
print(f" |{outcome}⟩: {count} times ({count/10:.1f}%)")
|
|
66
|
+
|
|
67
|
+
# Visualizations
|
|
68
|
+
print("\n8️⃣ Creating visualizations...")
|
|
69
|
+
try:
|
|
70
|
+
# Plot state probabilities
|
|
71
|
+
StateVisualizer.plot_probabilities(debugger.current_state)
|
|
72
|
+
|
|
73
|
+
# Plot Bloch sphere for each qubit
|
|
74
|
+
BlochSphere.plot(debugger.current_state, qubit=0)
|
|
75
|
+
BlochSphere.plot(debugger.current_state, qubit=1)
|
|
76
|
+
|
|
77
|
+
except Exception as e:
|
|
78
|
+
print(f" Visualization requires display: {e}")
|
|
79
|
+
|
|
80
|
+
print("\n✅ Demo complete!")
|
|
81
|
+
print("=" * 70 + "\n")
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
if __name__ == "__main__":
|
|
85
|
+
main()
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Grover's Algorithm Profiling Demo
|
|
3
|
+
|
|
4
|
+
This example demonstrates circuit profiling and optimization analysis.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
from quantum_debugger import QuantumCircuit, CircuitProfiler
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def create_grover_circuit(n_qubits: int = 3, target: int = 5):
|
|
12
|
+
"""
|
|
13
|
+
Create a simple Grover's algorithm circuit
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
n_qubits: Number of qubits
|
|
17
|
+
target: Target state to search for
|
|
18
|
+
"""
|
|
19
|
+
qc = QuantumCircuit(n_qubits)
|
|
20
|
+
|
|
21
|
+
# Initialize: Create superposition
|
|
22
|
+
for q in range(n_qubits):
|
|
23
|
+
qc.h(q)
|
|
24
|
+
|
|
25
|
+
# Oracle: Mark target state
|
|
26
|
+
# (Simplified oracle using phase flip)
|
|
27
|
+
for i, bit in enumerate(format(target, f'0{n_qubits}b')):
|
|
28
|
+
if bit == '0':
|
|
29
|
+
qc.x(i)
|
|
30
|
+
|
|
31
|
+
# Multi-controlled Z gate (simplified with Toffoli decomposition)
|
|
32
|
+
if n_qubits == 3:
|
|
33
|
+
qc.toffoli(0, 1, 2)
|
|
34
|
+
|
|
35
|
+
for i, bit in enumerate(format(target, f'0{n_qubits}b')):
|
|
36
|
+
if bit == '0':
|
|
37
|
+
qc.x(i)
|
|
38
|
+
|
|
39
|
+
# Diffusion operator
|
|
40
|
+
for q in range(n_qubits):
|
|
41
|
+
qc.h(q)
|
|
42
|
+
for q in range(n_qubits):
|
|
43
|
+
qc.x(q)
|
|
44
|
+
|
|
45
|
+
if n_qubits == 3:
|
|
46
|
+
qc.toffoli(0, 1, 2)
|
|
47
|
+
|
|
48
|
+
for q in range(n_qubits):
|
|
49
|
+
qc.x(q)
|
|
50
|
+
for q in range(n_qubits):
|
|
51
|
+
qc.h(q)
|
|
52
|
+
|
|
53
|
+
return qc
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def main():
|
|
57
|
+
print("=" * 70)
|
|
58
|
+
print(" " * 15 + "GROVER'S ALGORITHM PROFILING DEMO")
|
|
59
|
+
print("=" * 70)
|
|
60
|
+
|
|
61
|
+
# Create Grover circuit
|
|
62
|
+
print("\n1️⃣ Creating Grover's search circuit...")
|
|
63
|
+
target_state = 5 # Searching for |101⟩
|
|
64
|
+
qc = create_grover_circuit(n_qubits=3, target=target_state)
|
|
65
|
+
|
|
66
|
+
print(f" Circuit created: {qc.size()} gates, {qc.num_qubits} qubits")
|
|
67
|
+
print(f" Searching for state: |{format(target_state, '03b')}⟩")
|
|
68
|
+
|
|
69
|
+
# Display circuit
|
|
70
|
+
print("\n2️⃣ Circuit diagram:")
|
|
71
|
+
print(qc.draw())
|
|
72
|
+
|
|
73
|
+
# Initialize profiler
|
|
74
|
+
print("\n3️⃣ Running profiler analysis...")
|
|
75
|
+
profiler = CircuitProfiler(qc)
|
|
76
|
+
|
|
77
|
+
# Print comprehensive report
|
|
78
|
+
profiler.print_report()
|
|
79
|
+
|
|
80
|
+
# Get specific metrics
|
|
81
|
+
print("\n4️⃣ Detailed metrics:")
|
|
82
|
+
metrics = profiler.metrics
|
|
83
|
+
|
|
84
|
+
print(f"\n Gate Distribution:")
|
|
85
|
+
total = metrics.total_gates
|
|
86
|
+
for gate_name, count in sorted(metrics.gate_counts.items(),
|
|
87
|
+
key=lambda x: x[1], reverse=True):
|
|
88
|
+
percentage = (count / total) * 100
|
|
89
|
+
print(f" - {gate_name}: {count} ({percentage:.1f}%)")
|
|
90
|
+
|
|
91
|
+
print(f"\n Critical Path Analysis:")
|
|
92
|
+
print(f" - Critical path length: {len(metrics.critical_path)} gates")
|
|
93
|
+
print(f" - Total gates: {metrics.total_gates}")
|
|
94
|
+
print(f" - Parallelism achieved: {metrics.parallelism:.2f}x")
|
|
95
|
+
|
|
96
|
+
# Run circuit and analyze results
|
|
97
|
+
print("\n5️⃣ Running circuit simulation...")
|
|
98
|
+
results = qc.run(shots=1000)
|
|
99
|
+
|
|
100
|
+
print(f"\n Measurement results (top 5):")
|
|
101
|
+
sorted_counts = sorted(results['counts'].items(),
|
|
102
|
+
key=lambda x: x[1], reverse=True)
|
|
103
|
+
for outcome, count in sorted_counts[:5]:
|
|
104
|
+
print(f" |{outcome}⟩: {count} times ({count/10:.1f}%)")
|
|
105
|
+
|
|
106
|
+
# Check if target was found
|
|
107
|
+
target_binary = format(target_state, '03b')
|
|
108
|
+
if target_binary in results['counts']:
|
|
109
|
+
target_count = results['counts'][target_binary]
|
|
110
|
+
print(f"\n ✅ Target state |{target_binary}⟩ found {target_count} times!")
|
|
111
|
+
print(f" Success probability: {target_count/10:.1f}%")
|
|
112
|
+
|
|
113
|
+
# Compare different circuit sizes
|
|
114
|
+
print("\n6️⃣ Scaling analysis:")
|
|
115
|
+
print(f"\n {'Qubits':<10} {'Gates':<10} {'Depth':<10} {'CNOT':<10} {'Exec Time (μs)':<15}")
|
|
116
|
+
print(f" {'-'*60}")
|
|
117
|
+
|
|
118
|
+
for n in [2, 3, 4, 5]:
|
|
119
|
+
try:
|
|
120
|
+
temp_qc = create_grover_circuit(n_qubits=n, target=1)
|
|
121
|
+
temp_profiler = CircuitProfiler(temp_qc)
|
|
122
|
+
temp_metrics = temp_profiler.metrics
|
|
123
|
+
exec_time = temp_metrics.estimate_execution_time()
|
|
124
|
+
|
|
125
|
+
print(f" {n:<10} {temp_metrics.total_gates:<10} "
|
|
126
|
+
f"{temp_metrics.depth:<10} {temp_metrics.cnot_count:<10} "
|
|
127
|
+
f"{exec_time:<15.2f}")
|
|
128
|
+
except:
|
|
129
|
+
pass
|
|
130
|
+
|
|
131
|
+
print("\n✅ Profiling demo complete!")
|
|
132
|
+
print("=" * 70 + "\n")
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
if __name__ == "__main__":
|
|
136
|
+
main()
|