qang 0.4.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 (120) hide show
  1. qang-0.4.0/LICENSE +21 -0
  2. qang-0.4.0/PKG-INFO +232 -0
  3. qang-0.4.0/README.md +166 -0
  4. qang-0.4.0/pyproject.toml +45 -0
  5. qang-0.4.0/qang/__init__.py +43 -0
  6. qang-0.4.0/qang/algorithms.py +310 -0
  7. qang-0.4.0/qang/ansatze.py +171 -0
  8. qang-0.4.0/qang/circuits.py +350 -0
  9. qang-0.4.0/qang/cirq_gate.py +117 -0
  10. qang-0.4.0/qang/core.py +336 -0
  11. qang-0.4.0/qang/gradients.py +489 -0
  12. qang-0.4.0/qang/knitting.py +97 -0
  13. qang-0.4.0/qang/mixed.py +185 -0
  14. qang-0.4.0/qang/multiqubit.py +418 -0
  15. qang-0.4.0/qang/pennylane_gate.py +108 -0
  16. qang-0.4.0/qang/phase.py +121 -0
  17. qang-0.4.0/qang/qec.py +150 -0
  18. qang-0.4.0/qang/qiskit_gate.py +128 -0
  19. qang-0.4.0/qang/sectors.py +114 -0
  20. qang-0.4.0/qang/statistics.py +471 -0
  21. qang-0.4.0/qang/transformations.py +40 -0
  22. qang-0.4.0/qang.egg-info/PKG-INFO +232 -0
  23. qang-0.4.0/qang.egg-info/SOURCES.txt +118 -0
  24. qang-0.4.0/qang.egg-info/dependency_links.txt +1 -0
  25. qang-0.4.0/qang.egg-info/requires.txt +66 -0
  26. qang-0.4.0/qang.egg-info/top_level.txt +1 -0
  27. qang-0.4.0/setup.cfg +4 -0
  28. qang-0.4.0/tests/test_algorithms.py +165 -0
  29. qang-0.4.0/tests/test_amplitude_estimation_chebyshev_qg.py +60 -0
  30. qang-0.4.0/tests/test_ansatze.py +139 -0
  31. qang-0.4.0/tests/test_barren_plateau_qg_local_cost.py +119 -0
  32. qang-0.4.0/tests/test_barren_plateaus_qg_vs_theta.py +130 -0
  33. qang-0.4.0/tests/test_battery_ergotropy_qg.py +67 -0
  34. qang-0.4.0/tests/test_bb84_attacks_beyond_ir_qg.py +78 -0
  35. qang-0.4.0/tests/test_bb84_finite_key_qg.py +79 -0
  36. qang-0.4.0/tests/test_bb84_qg_eve_vs_noise.py +46 -0
  37. qang-0.4.0/tests/test_bell_pairs_network_qg.py +50 -0
  38. qang-0.4.0/tests/test_chemistry_lih_deep_circuit.py +39 -0
  39. qang-0.4.0/tests/test_chemistry_qg_symmetry_witness.py +81 -0
  40. qang-0.4.0/tests/test_chemistry_spin_resolved_qg_filter.py +74 -0
  41. qang-0.4.0/tests/test_circuit_knitting_qg_cut_selection.py +97 -0
  42. qang-0.4.0/tests/test_circuits.py +331 -0
  43. qang-0.4.0/tests/test_cirq_gate.py +80 -0
  44. qang-0.4.0/tests/test_coherent_drift_filter_zne.py +69 -0
  45. qang-0.4.0/tests/test_control_quantization_qg_vs_theta.py +76 -0
  46. qang-0.4.0/tests/test_core.py +211 -0
  47. qang-0.4.0/tests/test_deutsch_jozsa_bv.py +137 -0
  48. qang-0.4.0/tests/test_erasure_calibrated_qg.py +36 -0
  49. qang-0.4.0/tests/test_erasure_qubits_qg.py +47 -0
  50. qang-0.4.0/tests/test_error_mitigation_qg_vs_zne.py +80 -0
  51. qang-0.4.0/tests/test_few_shot_tomography_qg.py +56 -0
  52. qang-0.4.0/tests/test_filter_scaling_lih_qg.py +51 -0
  53. qang-0.4.0/tests/test_ghz_metrology_qg.py +50 -0
  54. qang-0.4.0/tests/test_gradients.py +345 -0
  55. qang-0.4.0/tests/test_grover_noise_qg.py +43 -0
  56. qang-0.4.0/tests/test_h2_vqe_multi_parameter_ansatz.py +132 -0
  57. qang-0.4.0/tests/test_hardware_characterization_qg.py +111 -0
  58. qang-0.4.0/tests/test_hubbard_trotter_qg_filters.py +102 -0
  59. qang-0.4.0/tests/test_ionq_hardware_predictions.py +81 -0
  60. qang-0.4.0/tests/test_ionq_sim_bb84.py +124 -0
  61. qang-0.4.0/tests/test_ionq_sim_hubbard_qaoa.py +56 -0
  62. qang-0.4.0/tests/test_ionq_sim_lih_mod4.py +42 -0
  63. qang-0.4.0/tests/test_ionq_sim_qrng.py +93 -0
  64. qang-0.4.0/tests/test_ionq_sim_xxz_filter.py +49 -0
  65. qang-0.4.0/tests/test_ionq_sim_zne_grover.py +87 -0
  66. qang-0.4.0/tests/test_ionq_validation.py +60 -0
  67. qang-0.4.0/tests/test_ising_coherence_witness_qg.py +64 -0
  68. qang-0.4.0/tests/test_knitting.py +115 -0
  69. qang-0.4.0/tests/test_lattice_gauge_gauss_qg.py +47 -0
  70. qang-0.4.0/tests/test_lih_parity_verification_qg.py +61 -0
  71. qang-0.4.0/tests/test_lih_vqe_ry_rx_ansatz.py +280 -0
  72. qang-0.4.0/tests/test_mixed.py +107 -0
  73. qang-0.4.0/tests/test_multi_parameter_pole_damped_vqe.py +98 -0
  74. qang-0.4.0/tests/test_multiqubit.py +338 -0
  75. qang-0.4.0/tests/test_multiqubit_error_propagation.py +88 -0
  76. qang-0.4.0/tests/test_nisq_hardware_validation.py +116 -0
  77. qang-0.4.0/tests/test_noise_type_detection_qg_vs_xeb.py +59 -0
  78. qang-0.4.0/tests/test_ode_qg_vs_angle.py +48 -0
  79. qang-0.4.0/tests/test_pennylane_gate.py +144 -0
  80. qang-0.4.0/tests/test_phase.py +145 -0
  81. qang-0.4.0/tests/test_pole_damped_gradient_descent_robustness.py +100 -0
  82. qang-0.4.0/tests/test_qaoa_k_constraint_qg.py +104 -0
  83. qang-0.4.0/tests/test_qec.py +125 -0
  84. qang-0.4.0/tests/test_qec_leung_code_t1_qg.py +72 -0
  85. qang-0.4.0/tests/test_qec_repetition_code_choice_qg.py +70 -0
  86. qang-0.4.0/tests/test_qec_syndrome_drift_tracking_qg.py +66 -0
  87. qang-0.4.0/tests/test_qec_syndrome_extraction.py +129 -0
  88. qang-0.4.0/tests/test_qg_s_error_bars.py +71 -0
  89. qang-0.4.0/tests/test_qiskit_gate.py +69 -0
  90. qang-0.4.0/tests/test_qml_encoding_qg_vs_angle.py +74 -0
  91. qang-0.4.0/tests/test_qml_multiqubit_and_shots.py +59 -0
  92. qang-0.4.0/tests/test_qrng_qg_certified.py +55 -0
  93. qang-0.4.0/tests/test_quantum_phase_estimation_qg_phi.py +100 -0
  94. qang-0.4.0/tests/test_quantum_volume_qg_s.py +104 -0
  95. qang-0.4.0/tests/test_quantum_volume_qg_s_finite_shots.py +111 -0
  96. qang-0.4.0/tests/test_quantum_volume_qg_s_realistic_noise.py +173 -0
  97. qang-0.4.0/tests/test_quantum_volume_qg_s_vs_xeb.py +145 -0
  98. qang-0.4.0/tests/test_qutrit_bayes_weight_qg.py +48 -0
  99. qang-0.4.0/tests/test_qutrit_leakage_qg.py +51 -0
  100. qang-0.4.0/tests/test_qutrit_leakage_rounds_qg.py +51 -0
  101. qang-0.4.0/tests/test_ramsey_qg_operating_point.py +46 -0
  102. qang-0.4.0/tests/test_randomized_benchmarking_qg_z.py +105 -0
  103. qang-0.4.0/tests/test_rbm_mutual_information_qg.py +84 -0
  104. qang-0.4.0/tests/test_rfc_v2_api.py +73 -0
  105. qang-0.4.0/tests/test_sectors_and_signed_gate.py +72 -0
  106. qang-0.4.0/tests/test_shadows_vs_direct_qg.py +69 -0
  107. qang-0.4.0/tests/test_shot_budget_adaptive_zne_qg.py +39 -0
  108. qang-0.4.0/tests/test_signed_qg_range_qg.py +53 -0
  109. qang-0.4.0/tests/test_spin_checks_qg.py +47 -0
  110. qang-0.4.0/tests/test_spin_squared_check_qg.py +33 -0
  111. qang-0.4.0/tests/test_statistics.py +191 -0
  112. qang-0.4.0/tests/test_surface_code_circuit_t1_qg.py +51 -0
  113. qang-0.4.0/tests/test_surface_code_d3_qg.py +93 -0
  114. qang-0.4.0/tests/test_symmetry_checks_scaling_qg.py +52 -0
  115. qang-0.4.0/tests/test_thermal_states_qg_tanh.py +98 -0
  116. qang-0.4.0/tests/test_transformations.py +88 -0
  117. qang-0.4.0/tests/test_transmon_leakage_channel_qg.py +62 -0
  118. qang-0.4.0/tests/test_vqe_h2.py +147 -0
  119. qang-0.4.0/tests/test_xxz_trotter_filter_qg.py +92 -0
  120. qang-0.4.0/tests/test_zne_qg_vs_theta_space.py +94 -0
qang-0.4.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vicente Humberto Monteverde
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.
qang-0.4.0/PKG-INFO ADDED
@@ -0,0 +1,232 @@
1
+ Metadata-Version: 2.4
2
+ Name: qang
3
+ Version: 0.4.0
4
+ Summary: The Qang (qg): a unified angular-probability unit and metric for parametric quantum circuit design.
5
+ Author-email: Vicente Humberto Monteverde <viny01958@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/Viny2030/qang
8
+ Project-URL: Repository, https://github.com/Viny2030/qang.git
9
+ Project-URL: Bug Tracker, https://github.com/Viny2030/qang/issues
10
+ Project-URL: Paper, https://doi.org/10.5281/zenodo.22832150
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Topic :: Scientific/Engineering :: Physics
14
+ Classifier: Intended Audience :: Science/Research
15
+ Requires-Python: >=3.9
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: numpy>=1.24
19
+ Provides-Extra: qiskit
20
+ Requires-Dist: qiskit>=1.0; extra == "qiskit"
21
+ Requires-Dist: qiskit-aer; extra == "qiskit"
22
+ Provides-Extra: cirq
23
+ Requires-Dist: cirq>=1.0; extra == "cirq"
24
+ Provides-Extra: pennylane
25
+ Requires-Dist: pennylane>=0.42; python_version >= "3.10" and extra == "pennylane"
26
+ Provides-Extra: hardware
27
+ Requires-Dist: qiskit>=1.0; extra == "hardware"
28
+ Requires-Dist: qiskit-aer; extra == "hardware"
29
+ Requires-Dist: qiskit-ibm-runtime>=0.40; extra == "hardware"
30
+ Provides-Extra: knitting
31
+ Requires-Dist: qiskit>=1.0; extra == "knitting"
32
+ Requires-Dist: qiskit-aer; extra == "knitting"
33
+ Requires-Dist: qiskit-addon-cutting>=0.9; extra == "knitting"
34
+ Provides-Extra: ionq
35
+ Requires-Dist: qiskit>=1.0; extra == "ionq"
36
+ Requires-Dist: qiskit-aer; extra == "ionq"
37
+ Requires-Dist: qiskit-ionq>=1.0; python_version >= "3.10" and extra == "ionq"
38
+ Requires-Dist: requests; extra == "ionq"
39
+ Provides-Extra: qec
40
+ Requires-Dist: pymatching>=2.0; extra == "qec"
41
+ Provides-Extra: chemistry
42
+ Requires-Dist: pyscf>=2.3; sys_platform != "win32" and extra == "chemistry"
43
+ Requires-Dist: openfermion>=1.6; extra == "chemistry"
44
+ Requires-Dist: openfermionpyscf>=0.5; sys_platform != "win32" and extra == "chemistry"
45
+ Provides-Extra: examples
46
+ Requires-Dist: scipy>=1.10; extra == "examples"
47
+ Requires-Dist: matplotlib>=3.7; extra == "examples"
48
+ Provides-Extra: dev
49
+ Requires-Dist: pytest>=7.0; extra == "dev"
50
+ Requires-Dist: matplotlib>=3.7; extra == "dev"
51
+ Requires-Dist: scipy>=1.10; extra == "dev"
52
+ Provides-Extra: all
53
+ Requires-Dist: qiskit>=1.0; extra == "all"
54
+ Requires-Dist: qiskit-aer; extra == "all"
55
+ Requires-Dist: qiskit-ibm-runtime>=0.40; extra == "all"
56
+ Requires-Dist: qiskit-addon-cutting>=0.9; extra == "all"
57
+ Requires-Dist: qiskit-ionq>=1.0; python_version >= "3.10" and extra == "all"
58
+ Requires-Dist: requests; extra == "all"
59
+ Requires-Dist: pymatching>=2.0; extra == "all"
60
+ Requires-Dist: cirq>=1.0; extra == "all"
61
+ Requires-Dist: pennylane>=0.42; python_version >= "3.10" and extra == "all"
62
+ Requires-Dist: scipy>=1.10; extra == "all"
63
+ Requires-Dist: pytest>=7.0; extra == "all"
64
+ Requires-Dist: matplotlib>=3.7; extra == "all"
65
+ Dynamic: license-file
66
+
67
+ # qang — The Qang (qg) Python Framework
68
+
69
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Viny2030/qang/blob/main/notebooks/qang_full_reference.ipynb)
70
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
71
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.22832150.svg)](https://doi.org/10.5281/zenodo.22832150)
72
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
73
+ [![Tests](https://github.com/Viny2030/qang/actions/workflows/tests.yml/badge.svg)](https://github.com/Viny2030/qang/actions/workflows/tests.yml)
74
+
75
+ Reference implementation and computational toolkit for:
76
+
77
+ > V. H. Monteverde, *"The Qang (qg): A Unified Angular-Probability Unit and Metric for Parametric Quantum Circuit Design."*
78
+ > ORCID: [0000-0001-8884-4811](https://orcid.org/0000-0001-8884-4811) · DOI: [10.5281/zenodo.22832150](https://doi.org/10.5281/zenodo.22832150)
79
+
80
+ `qang` bridges the gap between continuous Bloch-sphere rotation angles ($\theta \in [0, \pi]$) and projective measurement spaces in parameterized quantum circuits (PQAs). It provides native representations for:
81
+ - **Polar Bias Qang ($qg_Z$):** $qg_Z(\theta) = \cos\theta = \langle\sigma_z\rangle \in [-1, 1]$.
82
+ - **Measurement-Outcome Entropy Qang ($qg_S$):** $qg_S(\theta) = H(\cos^2(\theta/2)) \in [0, 1]$ (Shannon entropy of computational-basis outcomes).
83
+ - Native SDK gate classes for **Qiskit**, **Cirq** and **PennyLane** (differentiable in qg_Z), regularized gradient optimizers, shot-noise error propagation, and density matrix/POVM metrics.
84
+
85
+ ---
86
+
87
+ ## Installation
88
+
89
+ Install the minimal core library (NumPy only):
90
+ ```bash
91
+ pip install "qang @ git+https://github.com/Viny2030/qang.git@v0.4.0" # from GitHub
92
+ pip install . # or from a local clone
93
+ ```
94
+
95
+ ```bash
96
+ pip install ".[qiskit]" # Native Qiskit gate integration
97
+ pip install ".[cirq]" # Native Cirq gate integration
98
+ pip install ".[pennylane]" # Native PennyLane operations (autodiff in qg_Z)
99
+ pip install ".[hardware]" # IBM Quantum hardware / calibrated fake backends
100
+ pip install ".[ionq]" # IonQ simulator / hardware scripts (qiskit-ionq)
101
+ pip install ".[qec]" # Surface-code decoding examples (pymatching)
102
+ pip install ".[chemistry]" # PySCF/OpenFermion molecules (Linux/macOS or WSL)
103
+ pip install ".[all]" # Everything except chemistry (Qiskit, IBM Runtime, IonQ, pymatching, Cirq, PennyLane, SciPy, Pytest, Matplotlib)
104
+ pip install -r requirements.txt # same as .[all], without installing qang itself
105
+ ```
106
+
107
+ ## Quickstart
108
+
109
+ ### 1. Basic Unit Conversions & Inversion
110
+ ```python
111
+ from qang import Qang
112
+
113
+ # Anchor values
114
+ q_zero = Qang.from_angles(0.0, mode="polar")
115
+ print(q_zero.value) # +1.0 (|0>)
116
+
117
+ q_max_ent = Qang.from_angles(1.5707963, mode="entropic")
118
+ print(q_max_ent.value) # 1.0 (Maximum measurement uncertainty)
119
+
120
+ # Full Bloch sphere and statevector round-trip
121
+ q = Qang.from_angles(theta=0.9, phi=1.1, mode="polar")
122
+ bx, by, bz = q.to_bloch_vector()
123
+ alpha, beta = q.to_statevector()
124
+
125
+ # Engineering subunit (milliqang)
126
+ print(Qang(0.5).milliqang) # 500.0 m-qg
127
+ ```
128
+
129
+ ### 2. Qiskit Native Gate Integration
130
+ ```python
131
+ from qang import Qang
132
+ from qang.qiskit_gate import FullRQangGate
133
+ from qiskit import QuantumCircuit
134
+
135
+ qc = QuantumCircuit(1, 1)
136
+ # Append gate directly parameterized in qg_Z without manual arccos conversion
137
+ qc.append(FullRQangGate(Qang(0.5, phi=0.3)), [0])
138
+ qc.measure(0, 0)
139
+ ```
140
+
141
+ ### 3. Cirq Native Gate Integration
142
+ ```python
143
+ import cirq
144
+ from qang import Qang
145
+ from qang.cirq_gate import full_rqang_gate
146
+
147
+ q = cirq.LineQubit(0)
148
+ circuit = cirq.Circuit(
149
+ full_rqang_gate(Qang(0.5, phi=0.3)).on(q),
150
+ cirq.measure(q, key="m")
151
+ )
152
+ ```
153
+
154
+ ### 3b. PennyLane: optimize directly in qg_Z
155
+ ```python
156
+ import pennylane as qml
157
+ from pennylane import numpy as pnp
158
+ from qang.pennylane_gate import rqang
159
+
160
+ dev = qml.device("default.qubit", wires=1)
161
+
162
+ @qml.qnode(dev)
163
+ def z_expval(qg):
164
+ rqang(qg, wires=0) # RY(arccos(qg)), differentiable in qg
165
+ return qml.expval(qml.PauliZ(0))
166
+
167
+ qg = pnp.array(0.3, requires_grad=True)
168
+ print(qml.grad(z_expval)(qg)) # 1.0: <Z> = qg_Z exactly
169
+ ```
170
+
171
+ ### 4. Error Propagation & Shot Budgeting
172
+ ```python
173
+ from qang.statistics import propagated_theta_std, confidence_interval_theta
174
+
175
+ # First-order delta-method uncertainty: invariant across the Bloch sphere (~1/sqrt(N))
176
+ std_theta = propagated_theta_std(theta=1.0, n_shots=10000)
177
+ ci_lower, ci_upper = confidence_interval_theta(theta_hat=1.0, n_shots=10000, confidence=0.95)
178
+ print(f"Theta 95% CI: [{ci_lower:.4f}, {ci_upper:.4f}] rad")
179
+ ```
180
+
181
+ ## Full Reference Notebook
182
+
183
+ `notebooks/qang_full_reference.ipynb` is the single canonical, self-contained walkthrough
184
+ of the whole project — the `Qang` class, the Section 4.1 gradient singularity (regularized
185
+ and benchmarked), mixed states/POVMs, multi-qubit profiles, the native Qiskit and Cirq
186
+ gates, shot-noise error propagation, Quantum Natural Gradient, a live round-trip against
187
+ IonQ's cloud simulator, and a closing section that reformulates every result above into
188
+ concrete, measured speed/cost comparisons (including one negative result, kept in on
189
+ purpose). Open it directly in Colab with the badge above.
190
+
191
+ Three further notebooks (in Spanish) cover the research notes:
192
+
193
+ * `notebooks/qang_verificado.ipynb` — §1–§19: exact identities, blind spots, noise
194
+ diagnostics, optimization, knitting, few-shot estimation, QML, control quantization.
195
+ * `notebooks/qang_avances_colab.ipynb` — §20–§39: the qg symmetry witness and filter
196
+ (chemistry, Hubbard, constrained QAOA), filter vs ZNE, qubit characterization, error
197
+ correction (Leung code, syndrome tracking), coherence, few-shot estimation, and the
198
+ recorded IonQ noisy-simulator runs, each with an honest "for / against" reading.
199
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Viny2030/qang/blob/main/notebooks/qang_avances_colab.ipynb)
200
+ * `notebooks/qang_criptografia_colab.ipynb` — cryptography line, kept separate: why qg does
201
+ not apply to post-quantum cryptography, BB84 drift-vs-eavesdropper monitoring (§40) and
202
+ certified quantum random numbers (§41); companion PDF `manuscript/qang_criptografia.pdf`.
203
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Viny2030/qang/blob/main/notebooks/qang_criptografia_colab.ipynb)
204
+
205
+ ## Testing
206
+ The package includes an extensive test suite (1108 tests, run in CI on Python 3.9–3.12) verifying analytical anchors, numerical stability, gradient regularizations, backend fidelity, and every numerical finding quoted in `RESEARCH_NOTES.md`:
207
+
208
+ ```bash
209
+ pytest -v
210
+ ```
211
+
212
+ ## Contributing & Community
213
+ We welcome contributions, bug reports, and suggestions!
214
+
215
+ Issues: Please use the [GitHub Issue Tracker](https://github.com/Viny2030/qang/issues) to report bugs or request features.
216
+
217
+ Contributions: See [CONTRIBUTING.md](CONTRIBUTING.md) for local development and pull request guidelines.
218
+
219
+ ## Citation
220
+ If you use qang in your research, please cite the paper that defines the unit:
221
+
222
+ ```bibtex
223
+ @article{monteverde2026qang,
224
+ title = {The Qang (qg): A Unified Angular-Probability Unit and Metric for Parametric Quantum Circuit Design},
225
+ author = {Monteverde, Vicente Humberto},
226
+ year = {2026},
227
+ publisher = {Zenodo},
228
+ doi = {10.5281/zenodo.22832150}
229
+ }
230
+ ```
231
+
232
+ and, for the software itself, the repository: <https://github.com/Viny2030/qang>.
qang-0.4.0/README.md ADDED
@@ -0,0 +1,166 @@
1
+ # qang — The Qang (qg) Python Framework
2
+
3
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Viny2030/qang/blob/main/notebooks/qang_full_reference.ipynb)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.22832150.svg)](https://doi.org/10.5281/zenodo.22832150)
6
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
7
+ [![Tests](https://github.com/Viny2030/qang/actions/workflows/tests.yml/badge.svg)](https://github.com/Viny2030/qang/actions/workflows/tests.yml)
8
+
9
+ Reference implementation and computational toolkit for:
10
+
11
+ > V. H. Monteverde, *"The Qang (qg): A Unified Angular-Probability Unit and Metric for Parametric Quantum Circuit Design."*
12
+ > ORCID: [0000-0001-8884-4811](https://orcid.org/0000-0001-8884-4811) · DOI: [10.5281/zenodo.22832150](https://doi.org/10.5281/zenodo.22832150)
13
+
14
+ `qang` bridges the gap between continuous Bloch-sphere rotation angles ($\theta \in [0, \pi]$) and projective measurement spaces in parameterized quantum circuits (PQAs). It provides native representations for:
15
+ - **Polar Bias Qang ($qg_Z$):** $qg_Z(\theta) = \cos\theta = \langle\sigma_z\rangle \in [-1, 1]$.
16
+ - **Measurement-Outcome Entropy Qang ($qg_S$):** $qg_S(\theta) = H(\cos^2(\theta/2)) \in [0, 1]$ (Shannon entropy of computational-basis outcomes).
17
+ - Native SDK gate classes for **Qiskit**, **Cirq** and **PennyLane** (differentiable in qg_Z), regularized gradient optimizers, shot-noise error propagation, and density matrix/POVM metrics.
18
+
19
+ ---
20
+
21
+ ## Installation
22
+
23
+ Install the minimal core library (NumPy only):
24
+ ```bash
25
+ pip install "qang @ git+https://github.com/Viny2030/qang.git@v0.4.0" # from GitHub
26
+ pip install . # or from a local clone
27
+ ```
28
+
29
+ ```bash
30
+ pip install ".[qiskit]" # Native Qiskit gate integration
31
+ pip install ".[cirq]" # Native Cirq gate integration
32
+ pip install ".[pennylane]" # Native PennyLane operations (autodiff in qg_Z)
33
+ pip install ".[hardware]" # IBM Quantum hardware / calibrated fake backends
34
+ pip install ".[ionq]" # IonQ simulator / hardware scripts (qiskit-ionq)
35
+ pip install ".[qec]" # Surface-code decoding examples (pymatching)
36
+ pip install ".[chemistry]" # PySCF/OpenFermion molecules (Linux/macOS or WSL)
37
+ pip install ".[all]" # Everything except chemistry (Qiskit, IBM Runtime, IonQ, pymatching, Cirq, PennyLane, SciPy, Pytest, Matplotlib)
38
+ pip install -r requirements.txt # same as .[all], without installing qang itself
39
+ ```
40
+
41
+ ## Quickstart
42
+
43
+ ### 1. Basic Unit Conversions & Inversion
44
+ ```python
45
+ from qang import Qang
46
+
47
+ # Anchor values
48
+ q_zero = Qang.from_angles(0.0, mode="polar")
49
+ print(q_zero.value) # +1.0 (|0>)
50
+
51
+ q_max_ent = Qang.from_angles(1.5707963, mode="entropic")
52
+ print(q_max_ent.value) # 1.0 (Maximum measurement uncertainty)
53
+
54
+ # Full Bloch sphere and statevector round-trip
55
+ q = Qang.from_angles(theta=0.9, phi=1.1, mode="polar")
56
+ bx, by, bz = q.to_bloch_vector()
57
+ alpha, beta = q.to_statevector()
58
+
59
+ # Engineering subunit (milliqang)
60
+ print(Qang(0.5).milliqang) # 500.0 m-qg
61
+ ```
62
+
63
+ ### 2. Qiskit Native Gate Integration
64
+ ```python
65
+ from qang import Qang
66
+ from qang.qiskit_gate import FullRQangGate
67
+ from qiskit import QuantumCircuit
68
+
69
+ qc = QuantumCircuit(1, 1)
70
+ # Append gate directly parameterized in qg_Z without manual arccos conversion
71
+ qc.append(FullRQangGate(Qang(0.5, phi=0.3)), [0])
72
+ qc.measure(0, 0)
73
+ ```
74
+
75
+ ### 3. Cirq Native Gate Integration
76
+ ```python
77
+ import cirq
78
+ from qang import Qang
79
+ from qang.cirq_gate import full_rqang_gate
80
+
81
+ q = cirq.LineQubit(0)
82
+ circuit = cirq.Circuit(
83
+ full_rqang_gate(Qang(0.5, phi=0.3)).on(q),
84
+ cirq.measure(q, key="m")
85
+ )
86
+ ```
87
+
88
+ ### 3b. PennyLane: optimize directly in qg_Z
89
+ ```python
90
+ import pennylane as qml
91
+ from pennylane import numpy as pnp
92
+ from qang.pennylane_gate import rqang
93
+
94
+ dev = qml.device("default.qubit", wires=1)
95
+
96
+ @qml.qnode(dev)
97
+ def z_expval(qg):
98
+ rqang(qg, wires=0) # RY(arccos(qg)), differentiable in qg
99
+ return qml.expval(qml.PauliZ(0))
100
+
101
+ qg = pnp.array(0.3, requires_grad=True)
102
+ print(qml.grad(z_expval)(qg)) # 1.0: <Z> = qg_Z exactly
103
+ ```
104
+
105
+ ### 4. Error Propagation & Shot Budgeting
106
+ ```python
107
+ from qang.statistics import propagated_theta_std, confidence_interval_theta
108
+
109
+ # First-order delta-method uncertainty: invariant across the Bloch sphere (~1/sqrt(N))
110
+ std_theta = propagated_theta_std(theta=1.0, n_shots=10000)
111
+ ci_lower, ci_upper = confidence_interval_theta(theta_hat=1.0, n_shots=10000, confidence=0.95)
112
+ print(f"Theta 95% CI: [{ci_lower:.4f}, {ci_upper:.4f}] rad")
113
+ ```
114
+
115
+ ## Full Reference Notebook
116
+
117
+ `notebooks/qang_full_reference.ipynb` is the single canonical, self-contained walkthrough
118
+ of the whole project — the `Qang` class, the Section 4.1 gradient singularity (regularized
119
+ and benchmarked), mixed states/POVMs, multi-qubit profiles, the native Qiskit and Cirq
120
+ gates, shot-noise error propagation, Quantum Natural Gradient, a live round-trip against
121
+ IonQ's cloud simulator, and a closing section that reformulates every result above into
122
+ concrete, measured speed/cost comparisons (including one negative result, kept in on
123
+ purpose). Open it directly in Colab with the badge above.
124
+
125
+ Three further notebooks (in Spanish) cover the research notes:
126
+
127
+ * `notebooks/qang_verificado.ipynb` — §1–§19: exact identities, blind spots, noise
128
+ diagnostics, optimization, knitting, few-shot estimation, QML, control quantization.
129
+ * `notebooks/qang_avances_colab.ipynb` — §20–§39: the qg symmetry witness and filter
130
+ (chemistry, Hubbard, constrained QAOA), filter vs ZNE, qubit characterization, error
131
+ correction (Leung code, syndrome tracking), coherence, few-shot estimation, and the
132
+ recorded IonQ noisy-simulator runs, each with an honest "for / against" reading.
133
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Viny2030/qang/blob/main/notebooks/qang_avances_colab.ipynb)
134
+ * `notebooks/qang_criptografia_colab.ipynb` — cryptography line, kept separate: why qg does
135
+ not apply to post-quantum cryptography, BB84 drift-vs-eavesdropper monitoring (§40) and
136
+ certified quantum random numbers (§41); companion PDF `manuscript/qang_criptografia.pdf`.
137
+ [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Viny2030/qang/blob/main/notebooks/qang_criptografia_colab.ipynb)
138
+
139
+ ## Testing
140
+ The package includes an extensive test suite (1108 tests, run in CI on Python 3.9–3.12) verifying analytical anchors, numerical stability, gradient regularizations, backend fidelity, and every numerical finding quoted in `RESEARCH_NOTES.md`:
141
+
142
+ ```bash
143
+ pytest -v
144
+ ```
145
+
146
+ ## Contributing & Community
147
+ We welcome contributions, bug reports, and suggestions!
148
+
149
+ Issues: Please use the [GitHub Issue Tracker](https://github.com/Viny2030/qang/issues) to report bugs or request features.
150
+
151
+ Contributions: See [CONTRIBUTING.md](CONTRIBUTING.md) for local development and pull request guidelines.
152
+
153
+ ## Citation
154
+ If you use qang in your research, please cite the paper that defines the unit:
155
+
156
+ ```bibtex
157
+ @article{monteverde2026qang,
158
+ title = {The Qang (qg): A Unified Angular-Probability Unit and Metric for Parametric Quantum Circuit Design},
159
+ author = {Monteverde, Vicente Humberto},
160
+ year = {2026},
161
+ publisher = {Zenodo},
162
+ doi = {10.5281/zenodo.22832150}
163
+ }
164
+ ```
165
+
166
+ and, for the software itself, the repository: <https://github.com/Viny2030/qang>.
@@ -0,0 +1,45 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "qang"
7
+ version = "0.4.0"
8
+ description = "The Qang (qg): a unified angular-probability unit and metric for parametric quantum circuit design."
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "MIT"
12
+ authors = [
13
+ { name = "Vicente Humberto Monteverde", email = "viny01958@gmail.com" }
14
+ ]
15
+ classifiers = [
16
+ "Programming Language :: Python :: 3",
17
+ "Operating System :: OS Independent",
18
+ "Topic :: Scientific/Engineering :: Physics",
19
+ "Intended Audience :: Science/Research",
20
+ ]
21
+ dependencies = [
22
+ "numpy>=1.24",
23
+ ]
24
+
25
+ [project.optional-dependencies]
26
+ qiskit = ["qiskit>=1.0", "qiskit-aer"]
27
+ cirq = ["cirq>=1.0"]
28
+ pennylane = ['pennylane>=0.42; python_version >= "3.10"']
29
+ hardware = ["qiskit>=1.0", "qiskit-aer", "qiskit-ibm-runtime>=0.40"]
30
+ knitting = ["qiskit>=1.0", "qiskit-aer", "qiskit-addon-cutting>=0.9"]
31
+ ionq = ["qiskit>=1.0", "qiskit-aer", 'qiskit-ionq>=1.0; python_version >= "3.10"', "requests"]
32
+ qec = ["pymatching>=2.0"]
33
+ chemistry = ['pyscf>=2.3; sys_platform != "win32"', "openfermion>=1.6", 'openfermionpyscf>=0.5; sys_platform != "win32"']
34
+ examples = ["scipy>=1.10", "matplotlib>=3.7"]
35
+ dev = ["pytest>=7.0", "matplotlib>=3.7", "scipy>=1.10"]
36
+ all = ["qiskit>=1.0", "qiskit-aer", "qiskit-ibm-runtime>=0.40", "qiskit-addon-cutting>=0.9", 'qiskit-ionq>=1.0; python_version >= "3.10"', "requests", "pymatching>=2.0", "cirq>=1.0", 'pennylane>=0.42; python_version >= "3.10"', "scipy>=1.10", "pytest>=7.0", "matplotlib>=3.7"]
37
+
38
+ [project.urls]
39
+ Homepage = "https://github.com/Viny2030/qang"
40
+ Repository = "https://github.com/Viny2030/qang.git"
41
+ "Bug Tracker" = "https://github.com/Viny2030/qang/issues"
42
+ Paper = "https://doi.org/10.5281/zenodo.22832150"
43
+
44
+ [tool.setuptools.packages.find]
45
+ include = ["qang*"]
@@ -0,0 +1,43 @@
1
+ """
2
+ qang — A Unified Angular-Probability Unit for Parametric Quantum Circuit Design.
3
+
4
+ Reference implementation for:
5
+ V. H. Monteverde, "The Qang (qg): A Unified Angular-Probability Unit and
6
+ Metric for Parametric Quantum Circuit Design." ORCID: 0000-0001-8884-4811
7
+ https://doi.org/10.5281/zenodo.22832150
8
+
9
+ This package covers, in order:
10
+ - qang.core the qg_Z / qg_S unit exactly as defined in the paper
11
+ (Section 2), plus the full Bloch-sphere (theta, phi)
12
+ representation consolidated from the author's
13
+ exploratory notebook.
14
+ - qang.gradients the coordinate-singularity limitation from Section 4.1,
15
+ a regularized alternative, and a toy VQE benchmark
16
+ comparing theta-space vs qg-space optimization
17
+ (Future Research Direction #3).
18
+ - qang.mixed generalization to mixed states and POVMs
19
+ (Future Research Direction #4, part 1).
20
+ - qang.multiqubit generalization to multi-qubit tensor-product
21
+ projection profiles (Future Research Direction #4,
22
+ part 2).
23
+ - qang.qiskit_gate qg as a native single-qubit gate for Qiskit
24
+ (Future Research Direction #1). Optional: only
25
+ importable if qiskit is installed.
26
+ - qang.cirq_gate the same for Cirq (optional: needs cirq).
27
+ - qang.statistics shot-noise error propagation theta <-> qg, and
28
+ few-shot qg_Z intervals (Haar-prior Bayes, Wilson).
29
+ - qang.phase the qg_Phi phase unit.
30
+ - qang.transformations closed-form transition probabilities.
31
+ - qang.knitting the sampling cost of circuit cutting in qg units.
32
+ - qang.circuits, qang.ansatze, qang.qec, qang.algorithms
33
+ Qiskit circuit builders, variational ansatze, the
34
+ 3-qubit bit-flip code, and textbook algorithms
35
+ (optional: need qiskit).
36
+
37
+ See RESEARCH_NOTES.md for the derivations and results behind each module.
38
+ """
39
+
40
+ from .core import Qang, MILLIQANG_PER_QANG
41
+
42
+ __all__ = ["Qang", "MILLIQANG_PER_QANG"]
43
+ __version__ = "0.4.0"