quantum-study-utils 0.2.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.
Files changed (23) hide show
  1. quantum_study_utils-0.2.0/LICENSE +21 -0
  2. quantum_study_utils-0.2.0/PKG-INFO +513 -0
  3. quantum_study_utils-0.2.0/README.md +461 -0
  4. quantum_study_utils-0.2.0/pyproject.toml +105 -0
  5. quantum_study_utils-0.2.0/setup.cfg +4 -0
  6. quantum_study_utils-0.2.0/src/quantum_study_utils.egg-info/PKG-INFO +513 -0
  7. quantum_study_utils-0.2.0/src/quantum_study_utils.egg-info/SOURCES.txt +21 -0
  8. quantum_study_utils-0.2.0/src/quantum_study_utils.egg-info/dependency_links.txt +1 -0
  9. quantum_study_utils-0.2.0/src/quantum_study_utils.egg-info/requires.txt +36 -0
  10. quantum_study_utils-0.2.0/src/quantum_study_utils.egg-info/top_level.txt +1 -0
  11. quantum_study_utils-0.2.0/src/quantum_utils/__init__.py +42 -0
  12. quantum_study_utils-0.2.0/src/quantum_utils/display/__init__.py +48 -0
  13. quantum_study_utils-0.2.0/src/quantum_utils/display/_utils.py +137 -0
  14. quantum_study_utils-0.2.0/src/quantum_utils/display/display.py +388 -0
  15. quantum_study_utils-0.2.0/src/quantum_utils/display/formatters.py +197 -0
  16. quantum_study_utils-0.2.0/src/quantum_utils/display/templates.py +225 -0
  17. quantum_study_utils-0.2.0/src/quantum_utils/formatting.py +136 -0
  18. quantum_study_utils-0.2.0/src/quantum_utils/measurements.py +268 -0
  19. quantum_study_utils-0.2.0/src/quantum_utils/visualization.py +371 -0
  20. quantum_study_utils-0.2.0/tests/test_display.py +151 -0
  21. quantum_study_utils-0.2.0/tests/test_formatting.py +100 -0
  22. quantum_study_utils-0.2.0/tests/test_measurements.py +111 -0
  23. quantum_study_utils-0.2.0/tests/test_visualization.py +78 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Quantum Study Utils 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,513 @@
1
+ Metadata-Version: 2.4
2
+ Name: quantum-study-utils
3
+ Version: 0.2.0
4
+ Summary: Utilities for quantum computing education, visualization and research
5
+ Author-email: "Wellington F. Silva" <wellington@altrion.com.br>
6
+ License-Expression: MIT
7
+ Keywords: quantum computing,quantum mechanics,qiskit,visualization,display,education,research
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Education
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Topic :: Scientific/Engineering :: Physics
17
+ Classifier: Topic :: Scientific/Engineering :: Visualization
18
+ Requires-Python: >=3.10
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: numpy>=1.24
22
+ Requires-Dist: matplotlib>=3.7
23
+ Requires-Dist: seaborn>=0.12
24
+ Requires-Dist: ipython>=8.0
25
+ Provides-Extra: qiskit
26
+ Requires-Dist: qiskit>=2.0; extra == "qiskit"
27
+ Provides-Extra: simulator
28
+ Requires-Dist: qiskit>=2.0; extra == "simulator"
29
+ Requires-Dist: qiskit-aer>=0.17; extra == "simulator"
30
+ Provides-Extra: ibm
31
+ Requires-Dist: qiskit>=2.0; extra == "ibm"
32
+ Requires-Dist: qiskit-ibm-runtime>=0.45; extra == "ibm"
33
+ Provides-Extra: notebook
34
+ Requires-Dist: ipykernel>=6.0; extra == "notebook"
35
+ Requires-Dist: jupyterlab>=4.0; extra == "notebook"
36
+ Provides-Extra: dev
37
+ Requires-Dist: pytest>=8.0; extra == "dev"
38
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
39
+ Requires-Dist: black>=24.0; extra == "dev"
40
+ Requires-Dist: flake8>=7.0; extra == "dev"
41
+ Requires-Dist: isort>=5.13; extra == "dev"
42
+ Requires-Dist: mypy>=1.0; extra == "dev"
43
+ Requires-Dist: build>=1.0; extra == "dev"
44
+ Requires-Dist: twine>=5.0; extra == "dev"
45
+ Provides-Extra: all
46
+ Requires-Dist: qiskit>=2.0; extra == "all"
47
+ Requires-Dist: qiskit-aer>=0.17; extra == "all"
48
+ Requires-Dist: qiskit-ibm-runtime>=0.45; extra == "all"
49
+ Requires-Dist: ipykernel>=6.0; extra == "all"
50
+ Requires-Dist: jupyterlab>=4.0; extra == "all"
51
+ Dynamic: license-file
52
+
53
+ # Quantum Study Utils
54
+
55
+ [![Python 3.8+](https://img.shields.io/badge/Python-3.8%2B-blue)](https://www.python.org/)
56
+ [![License](https://img.shields.io/badge/License-MIT-green)](LICENSE)
57
+ ![Version](https://img.shields.io/badge/Version-0.2.0-brightgreen)
58
+
59
+ A robust Python library for visualization, analysis, and formatting of quantum computing data. Perfect for academic purposes, research, and education.
60
+
61
+ **Documentation in:** English | [Português](README_PT.md)
62
+
63
+ ---
64
+
65
+ ## ✨ Features
66
+
67
+ - **Quantum Data Visualization** - Interactive displays with customizable themes
68
+ - **Academic Formatting** - LaTeX notation for mathematical expressions
69
+ - **Dirac Notation** - Automatic quantum state conversion
70
+ - **Multiple Themes** - Light, dark, professional, and neon themes
71
+ - **Operator Heatmaps** - Visualization of quantum operator matrices
72
+ - ✅ **100% Compatible** - Fully backward compatible with previous version
73
+
74
+ ---
75
+
76
+ ## Installation
77
+
78
+ ### Local Installation (Development)
79
+
80
+ ```bash
81
+ # Clone the repository
82
+ git clone https://github.com/wellington/comp-quantica.git
83
+ cd quantum-study-utils
84
+
85
+ # Install in editable mode (development)
86
+ pip install -e ".[dev]"
87
+ ```
88
+
89
+ ### Installation in Jupyter Notebook
90
+
91
+ Once the module is installed correctly, import it in your notebook:
92
+
93
+ ```python
94
+ import quantum_utils
95
+ from quantum_utils import (
96
+ display_data,
97
+ display_probabilities,
98
+ display_counts,
99
+ display_operator_heatmap,
100
+ AcademicNumberFormatter,
101
+ DiracExpressionGenerator,
102
+ HTMLTheme,
103
+ )
104
+ ```
105
+
106
+ ---
107
+
108
+ ## Quick Start Guide
109
+
110
+ ### 1️⃣ Import and Configure Themes
111
+
112
+ ```python
113
+ import numpy as np
114
+ from quantum_utils import display_data, HTMLTheme
115
+
116
+ # Define themes (once, at the beginning)
117
+ DARK_THEME = HTMLTheme.DARK
118
+ LIGHT_THEME = HTMLTheme.LIGHT
119
+ PROFESSIONAL_THEME = HTMLTheme.PROFESSIONAL
120
+ NEON_THEME = HTMLTheme.NEON
121
+ ```
122
+
123
+ ### 2️⃣ Visualize Quantum States
124
+
125
+ ```python
126
+ # Bell state: |Φ+⟩ = (1/√2)(|00⟩ + |11⟩)
127
+ bell_state = np.array([1/np.sqrt(2), 0, 0, 1/np.sqrt(2)])
128
+
129
+ display_data(bell_state, label="Bell State |Φ+⟩", theme=LIGHT_THEME)
130
+ ```
131
+
132
+ ### 3️⃣ Display Probabilities
133
+
134
+ ```python
135
+ # Normalized superposition state
136
+ superposition = np.array([1/np.sqrt(2), 1/np.sqrt(2)])
137
+
138
+ display_probabilities(
139
+ superposition,
140
+ label="Superposition (50% |0⟩, 50% |1⟩)",
141
+ theme=DARK_THEME
142
+ )
143
+ ```
144
+
145
+ ### 4️⃣ Show Measurement Counts
146
+
147
+ ```python
148
+ # Measurement results (1000 shots)
149
+ counts = {
150
+ '0': 512,
151
+ '1': 488,
152
+ }
153
+
154
+ display_counts(counts, label="Results: Aer Simulator", theme=LIGHT_THEME)
155
+ ```
156
+
157
+ ### 5️⃣ Visualize Operators
158
+
159
+ ```python
160
+ # Pauli X matrix (NOT gate)
161
+ pauli_x = np.array([[0, 1], [1, 0]])
162
+
163
+ display_operator_heatmap(pauli_x, label="Pauli X Operator", theme=PROFESSIONAL_THEME)
164
+ ```
165
+
166
+ ### 6️⃣ Academic Formatting
167
+
168
+ ```python
169
+ from quantum_utils import AcademicNumberFormatter, DiracExpressionGenerator
170
+
171
+ # Number formatter
172
+ formatter = AcademicNumberFormatter()
173
+ print(formatter.format(1/np.sqrt(2), precision=3)) # → \frac{1}{\sqrt{2}}
174
+ print(formatter.format(1+2j, precision=2)) # → (1.00+2.00i)
175
+
176
+ # Dirac notation generator
177
+ generator = DiracExpressionGenerator()
178
+ bell = np.array([1/np.sqrt(2), 0, 0, 1/np.sqrt(2)])
179
+ print(generator.generate(bell)) # → (1/√2)|00⟩ + (1/√2)|11⟩
180
+ ```
181
+
182
+ ---
183
+
184
+ ## Detailed Documentation
185
+
186
+ ### Visualization Functions
187
+
188
+ #### `display_data(value, label=None, theme=None)`
189
+ Displays a vector or array as quantum data.
190
+
191
+ **Parameters:**
192
+ - `value` (array): Vector or numpy array
193
+ - `label` (str, optional): Graph title
194
+ - `theme` (HTMLTheme, optional): Visual theme
195
+
196
+ **Example:**
197
+ ```python
198
+ display_data([1, 0, 0, 0], label="State |00⟩")
199
+ ```
200
+
201
+ ---
202
+
203
+ #### `display_probabilities(statevector, label=None, theme=None)`
204
+ Displays probabilities of a normalized statevector.
205
+
206
+ **Parameters:**
207
+ - `statevector` (array): Normalized array with ⟨ψ|ψ⟩ = 1.0
208
+ - `label` (str, optional): Graph title
209
+ - `theme` (HTMLTheme, optional): Visual theme
210
+
211
+ **Important:** The statevector MUST be normalized!
212
+ ```python
213
+ # ✅ CORRECT - Normalized
214
+ superposition = np.array([1/np.sqrt(2), 1/np.sqrt(2)]) # norm = 1.0
215
+
216
+ # ❌ WRONG - Not normalized
217
+ wrong = np.array([0.5, 0.5]) # norm = 0.707
218
+ ```
219
+
220
+ ---
221
+
222
+ #### `display_counts(counts, label=None, theme=None)`
223
+ Displays measurement counts as a histogram.
224
+
225
+ **Parameters:**
226
+ - `counts` (dict): Dictionary with key (str) and values (int)
227
+ - `label` (str, optional): Graph title
228
+ - `theme` (HTMLTheme, optional): Visual theme
229
+
230
+ **Example:**
231
+ ```python
232
+ counts = {'0': 500, '1': 500}
233
+ display_counts(counts, label="Results")
234
+ ```
235
+
236
+ ---
237
+
238
+ #### `display_operator_heatmap(operator, label=None, theme=None)`
239
+ Displays an operator matrix as a heatmap.
240
+
241
+ **Parameters:**
242
+ - `operator` (array 2D): Operator matrix
243
+ - `label` (str, optional): Graph title
244
+ - `theme` (HTMLTheme, optional): Visual theme
245
+
246
+ **Example:**
247
+ ```python
248
+ hadamard = (1/np.sqrt(2)) * np.array([[1, 1], [1, -1]])
249
+ display_operator_heatmap(hadamard, label="Hadamard Gate")
250
+ ```
251
+
252
+ ---
253
+
254
+ ### Formatting Classes
255
+
256
+ #### `AcademicNumberFormatter`
257
+ Formats numbers in academic LaTeX notation.
258
+
259
+ **Methods:**
260
+ ```python
261
+ formatter = AcademicNumberFormatter()
262
+
263
+ # Format with precision
264
+ latex_str = formatter.format(number, precision=3)
265
+ ```
266
+
267
+ **Examples:**
268
+ ```python
269
+ fmt = AcademicNumberFormatter()
270
+
271
+ fmt.format(1/np.sqrt(2)) # → r"\frac{1}{\sqrt{2}}"
272
+ fmt.format(np.sqrt(2)/2) # → r"\frac{\sqrt{2}}{2}"
273
+ fmt.format(1+2j, precision=2) # → "(1.00+2.00i)"
274
+ fmt.format(0.707, precision=3) # → "0.707"
275
+ ```
276
+
277
+ ---
278
+
279
+ #### `DiracExpressionGenerator`
280
+ Converts statevectors to automatic Dirac notation.
281
+
282
+ **Methods:**
283
+ ```python
284
+ gen = DiracExpressionGenerator()
285
+ dirac_expr = gen.generate(statevector)
286
+ ```
287
+
288
+ **Examples:**
289
+ ```python
290
+ gen = DiracExpressionGenerator()
291
+
292
+ # Single qubit - superposition
293
+ superposition = np.array([1/np.sqrt(2), 1/np.sqrt(2)])
294
+ print(gen.generate(superposition))
295
+ # → "(1/√2)|0⟩ + (1/√2)|1⟩"
296
+
297
+ # Bell state - two qubits
298
+ bell = np.array([1/np.sqrt(2), 0, 0, 1/np.sqrt(2)])
299
+ print(gen.generate(bell))
300
+ # → "(1/√2)|00⟩ + (1/√2)|11⟩"
301
+
302
+ # Generic state - 3 qubits
303
+ state_3q = np.array([1/np.sqrt(2), 0, 0, 0, 0, 0, 0, 1/np.sqrt(2)])
304
+ print(gen.generate(state_3q))
305
+ # → "(1/√2)|000⟩ + (1/√2)|111⟩"
306
+ ```
307
+
308
+ ---
309
+
310
+ #### `HTMLTheme`
311
+ Defines visual themes for graphs.
312
+
313
+ **Available Themes:**
314
+ ```python
315
+ HTMLTheme.DARK # Dark theme (default)
316
+ HTMLTheme.LIGHT # Light theme
317
+ HTMLTheme.PROFESSIONAL # Professional theme
318
+ HTMLTheme.NEON # Vibrant neon theme
319
+ ```
320
+
321
+ **Usage Example:**
322
+ ```python
323
+ display_data(state, label="My State", theme=HTMLTheme.PROFESSIONAL)
324
+ ```
325
+
326
+ ---
327
+
328
+ ## Jupyter Notebook Examples
329
+
330
+ See the [examples/exemplos.ipynb](examples/exemplos.ipynb) file for 9 ready-to-copy cells:
331
+
332
+ 1. **CELL 1** - Imports and themes (REQUIRED)
333
+ 2. **CELL 2** - Simple quantum states
334
+ 3. **CELL 3** - Superpositions and distributions
335
+ 4. **CELL 4** - Measurement counts
336
+ 5. **CELL 5** - Quantum operators
337
+ 6. **CELL 6** - Academic formatting (numbers and Dirac)
338
+ 7. **CELL 7** - Custom themes
339
+ 8. **CELL 8** - Multiple visualizations
340
+ 9. **CELL 9** - Real-world use cases
341
+
342
+ ---
343
+
344
+ ## ⚠️ Common Problems and Solutions
345
+
346
+ ### ❌ `ModuleNotFoundError: No module named 'quantum_utils'`
347
+
348
+ **Solution:**
349
+ ```bash
350
+ # Navigate to project directory
351
+ cd /Users/wellington/comp-quantica/quantum-study-utils
352
+
353
+ # Install the module
354
+ pip install -e "."
355
+ ```
356
+
357
+ ---
358
+
359
+ ### ❌ `ImportError: cannot import name 'X' from 'quantum_utils'`
360
+
361
+ **Cause:** Old file conflicting with new module.
362
+
363
+ **Solution:**
364
+ ```python
365
+ # Restart Jupyter kernel:
366
+ # 1. Menu Kernel → Restart Kernel
367
+ # 2. Or in terminal: jupyter --clean-cache
368
+ ```
369
+
370
+ ---
371
+
372
+ ### ❌ `ValueError: Statevector is not normalized: ⟨ψ|ψ⟩ = 0.50`
373
+
374
+ **Cause:** Array is not normalized (norm ≠ 1.0).
375
+
376
+ **Solution:**
377
+ ```python
378
+ # ❌ WRONG
379
+ wrong = np.array([0.5, 0.5]) # norm = 0.707
380
+
381
+ # ✅ CORRECT
382
+ correct = np.array([1/np.sqrt(2), 1/np.sqrt(2)]) # norm = 1.0
383
+
384
+ # Or normalize manually
385
+ wrong_norm = wrong / np.linalg.norm(wrong) # now norm = 1.0
386
+ ```
387
+
388
+ ---
389
+
390
+ ### ❌ `TypeError: unexpected keyword argument 'use_sqrt'`
391
+
392
+ **Cause:** Wrong parameter in AcademicNumberFormatter.
393
+
394
+ **Solution:**
395
+ ```python
396
+ # ❌ WRONG
397
+ fmt.format(num, use_sqrt=True)
398
+
399
+ # ✅ CORRECT
400
+ fmt.format(num, precision=3)
401
+ ```
402
+
403
+ ---
404
+
405
+ ## Detailed Guides
406
+
407
+ - [GUIA_RÁPIDO.md](GUIA_RÁPIDO.md) - Quick cheat sheet with examples (Portuguese)
408
+ - [REFERÊNCIA_PARÂMETROS.md](REFERÊNCIA_PARÂMETROS.md) - Complete API reference (Portuguese)
409
+ - [GUIA_FORMATADORES.md](GUIA_FORMATADORES.md) - All about formatters (Portuguese)
410
+ - [examples/exemplos.ipynb](examples/exemplos.ipynb) - 9 example cells
411
+
412
+ ---
413
+
414
+ ## Tests
415
+
416
+ Run tests to check library integrity:
417
+
418
+ ```bash
419
+ # All tests
420
+ pytest tests/
421
+
422
+ # With coverage
423
+ pytest tests/ --cov=src/quantum_utils
424
+
425
+ # Specific test
426
+ pytest tests/test_measurements.py -v
427
+ ```
428
+
429
+ ---
430
+
431
+ ## Project Structure
432
+
433
+ ```
434
+ quantum-study-utils/
435
+ ├── pyproject.toml # Project configuration
436
+ ├── README.md # Documentation in English
437
+ ├── README_PT.md # Documentation in Portuguese
438
+ ├── LICENSE # MIT License
439
+ │
440
+ ├── src/quantum_utils/ # Source code
441
+ │ ├── __init__.py
442
+ │ ├── display/
443
+ │ │ ├── __init__.py
444
+ │ │ ├── display.py # Visualization functions
445
+ │ │ ├── formatters.py # Formatters (LaTeX, Dirac)
446
+ │ │ └── themes.py # Visual themes
447
+ │ ├── formatting.py # General formatting
448
+ │ ├── visualization.py # Visualization
449
+ │ └── measurements.py # Measurements
450
+ │
451
+ ├── examples/ # Examples
452
+ │ ├── bell_state.ipynb
453
+ │ └── ibm_quantum.ipynb
454
+ │
455
+ ├── tests/ # Tests
456
+ │ └── test_measurements.py
457
+ │
458
+ ├── docs/ # Extra documentation
459
+ │ ├── examples/
460
+ │ ├── GUIA_RÁPIDO.md
461
+ │ ├── REFERÊNCIA_PARÂMETROS.md
462
+ │ └── GUIA_FORMATADORES.md
463
+ │
464
+ └── venv/ # Virtual environment (ignored)
465
+ ```
466
+
467
+ ---
468
+
469
+ ## Contributing
470
+
471
+ Contributions are welcome! Please:
472
+
473
+ 1. Fork the repository
474
+ 2. Create a branch for your feature (`git checkout -b feature/new-feature`)
475
+ 3. Commit your changes (`git commit -m 'Add new feature'`)
476
+ 4. Push to the branch (`git push origin feature/new-feature`)
477
+ 5. Open a Pull Request
478
+
479
+ ---
480
+
481
+ ## License
482
+
483
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
484
+
485
+ ---
486
+
487
+ ## ‍ Author
488
+
489
+ **Wellington** - Software Developer
490
+ - GitHub: [@wellington](https://github.com/wellington)
491
+ - Project: comp-quantica
492
+
493
+ ---
494
+
495
+ ## Support
496
+
497
+ Have questions? Check out:
498
+
499
+ - [GUIA_RÁPIDO.md](GUIA_RÁPIDO.md) - Quick answers (Portuguese)
500
+ - [REFERÊNCIA_PARÂMETROS.md](REFERÊNCIA_PARÂMETROS.md) - Complete documentation (Portuguese)
501
+ - [examples/exemplos.ipynb](examples/exemplos.ipynb) - Working examples
502
+
503
+ ---
504
+
505
+ ## Next Steps
506
+
507
+ 1. ✅ Install the library
508
+ 2. ✅ See [examples/exemplos.ipynb](examples/exemplos.ipynb)
509
+ 3. ✅ Paste into your Jupyter Notebook
510
+ 4. ✅ Explore examples from cells 2-9
511
+ 5. ✅ Refer to [REFERÊNCIA_PARÂMETROS.md](REFERÊNCIA_PARÂMETROS.md) as needed
512
+
513
+ **Have fun exploring quantum computing! **