vqe-pennylane 0.2.2__py3-none-any.whl
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.
- qpe/__init__.py +77 -0
- qpe/__main__.py +233 -0
- qpe/core.py +317 -0
- qpe/hamiltonian.py +100 -0
- qpe/io_utils.py +132 -0
- qpe/noise.py +47 -0
- qpe/visualize.py +212 -0
- vqe/__init__.py +118 -0
- vqe/__main__.py +318 -0
- vqe/ansatz.py +420 -0
- vqe/core.py +907 -0
- vqe/engine.py +390 -0
- vqe/hamiltonian.py +260 -0
- vqe/io_utils.py +265 -0
- vqe/optimizer.py +58 -0
- vqe/ssvqe.py +271 -0
- vqe/visualize.py +308 -0
- vqe_pennylane-0.2.2.dist-info/METADATA +239 -0
- vqe_pennylane-0.2.2.dist-info/RECORD +28 -0
- vqe_pennylane-0.2.2.dist-info/WHEEL +5 -0
- vqe_pennylane-0.2.2.dist-info/entry_points.txt +3 -0
- vqe_pennylane-0.2.2.dist-info/licenses/LICENSE +21 -0
- vqe_pennylane-0.2.2.dist-info/top_level.txt +3 -0
- vqe_qpe_common/__init__.py +67 -0
- vqe_qpe_common/geometry.py +52 -0
- vqe_qpe_common/hamiltonian.py +58 -0
- vqe_qpe_common/molecules.py +107 -0
- vqe_qpe_common/plotting.py +167 -0
vqe/visualize.py
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
"""
|
|
2
|
+
vqe.visualize
|
|
3
|
+
-------------
|
|
4
|
+
Unified plotting utilities for VQE and SSVQE.
|
|
5
|
+
All plots save into vqe/io_utils.IMG_DIR.
|
|
6
|
+
|
|
7
|
+
This module intentionally avoids external dependencies (e.g. common.plotting)
|
|
8
|
+
for maximum portability and internal cohesion.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import os
|
|
14
|
+
import matplotlib.pyplot as plt
|
|
15
|
+
|
|
16
|
+
from .io_utils import IMG_DIR
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# ================================================================
|
|
20
|
+
# INTERNAL HELPERS
|
|
21
|
+
# ================================================================
|
|
22
|
+
def _safe_filename(*parts):
|
|
23
|
+
"""
|
|
24
|
+
Build a safe filename from components such as:
|
|
25
|
+
("VQE", "H2", "Adam", "UCCSD", "noisy")
|
|
26
|
+
"""
|
|
27
|
+
clean = []
|
|
28
|
+
for p in parts:
|
|
29
|
+
if p is None:
|
|
30
|
+
continue
|
|
31
|
+
# Basic sanitisation
|
|
32
|
+
p = str(p).replace(" ", "_").replace("+", "plus")
|
|
33
|
+
clean.append(p)
|
|
34
|
+
return "_".join(clean) + ".png"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _safe_title(*parts):
|
|
38
|
+
"""
|
|
39
|
+
Build a human-readable plot title.
|
|
40
|
+
"""
|
|
41
|
+
return " — ".join([str(p) for p in parts if p is not None])
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _save_plot(fname):
|
|
45
|
+
os.makedirs(IMG_DIR, exist_ok=True)
|
|
46
|
+
path = os.path.join(IMG_DIR, fname)
|
|
47
|
+
plt.savefig(path, dpi=300, bbox_inches="tight")
|
|
48
|
+
print(f"📁 Saved → {path}")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
# ================================================================
|
|
52
|
+
# BASIC VQE CONVERGENCE
|
|
53
|
+
# ================================================================
|
|
54
|
+
def plot_convergence(
|
|
55
|
+
energies_noiseless,
|
|
56
|
+
molecule: str,
|
|
57
|
+
energies_noisy=None,
|
|
58
|
+
optimizer: str = "Adam",
|
|
59
|
+
ansatz: str = "UCCSD",
|
|
60
|
+
dep_prob: float = 0.0,
|
|
61
|
+
amp_prob: float = 0.0,
|
|
62
|
+
show=True,
|
|
63
|
+
):
|
|
64
|
+
"""
|
|
65
|
+
Plot VQE energy convergence (noisy + noiseless overlay).
|
|
66
|
+
"""
|
|
67
|
+
plt.figure(figsize=(8, 5))
|
|
68
|
+
steps = range(len(energies_noiseless))
|
|
69
|
+
plt.plot(steps, energies_noiseless, label="Noiseless", lw=2)
|
|
70
|
+
|
|
71
|
+
noisy = energies_noisy is not None
|
|
72
|
+
if noisy:
|
|
73
|
+
plt.plot(range(len(energies_noisy)), energies_noisy,
|
|
74
|
+
label="Noisy", lw=2, linestyle="--")
|
|
75
|
+
|
|
76
|
+
# Title
|
|
77
|
+
if noisy:
|
|
78
|
+
title = _safe_title(
|
|
79
|
+
f"{molecule}",
|
|
80
|
+
f"VQE Convergence ({optimizer}, {ansatz})",
|
|
81
|
+
f"Noise: dep={dep_prob}, amp={amp_prob}",
|
|
82
|
+
)
|
|
83
|
+
else:
|
|
84
|
+
title = _safe_title(
|
|
85
|
+
f"{molecule}", f"VQE Convergence ({optimizer}, {ansatz})"
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
plt.title(title)
|
|
89
|
+
plt.xlabel("Iteration")
|
|
90
|
+
plt.ylabel("Energy (Ha)")
|
|
91
|
+
plt.grid(True, alpha=0.4)
|
|
92
|
+
plt.legend()
|
|
93
|
+
plt.tight_layout()
|
|
94
|
+
|
|
95
|
+
# Filename
|
|
96
|
+
fname = _safe_filename(
|
|
97
|
+
"VQE_Convergence",
|
|
98
|
+
molecule,
|
|
99
|
+
optimizer,
|
|
100
|
+
ansatz,
|
|
101
|
+
"noisy" if noisy else "noiseless",
|
|
102
|
+
f"dep{dep_prob}" if noisy else "",
|
|
103
|
+
f"amp{amp_prob}" if noisy else "",
|
|
104
|
+
)
|
|
105
|
+
_save_plot(fname)
|
|
106
|
+
|
|
107
|
+
if show:
|
|
108
|
+
plt.show()
|
|
109
|
+
else:
|
|
110
|
+
plt.close()
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
# ================================================================
|
|
114
|
+
# OPTIMIZER COMPARISON
|
|
115
|
+
# ================================================================
|
|
116
|
+
def plot_optimizer_comparison(molecule: str, results: dict, ansatz: str = "UCCSD", show=True):
|
|
117
|
+
"""
|
|
118
|
+
Plot multiple optimizers on a shared convergence graph.
|
|
119
|
+
"""
|
|
120
|
+
plt.figure(figsize=(8, 5))
|
|
121
|
+
|
|
122
|
+
min_len = min(len(v) for v in results.values())
|
|
123
|
+
|
|
124
|
+
for opt, energies in results.items():
|
|
125
|
+
plt.plot(range(min_len), energies[:min_len], label=opt)
|
|
126
|
+
|
|
127
|
+
plt.title(_safe_title(molecule, f"VQE Optimizer Comparison ({ansatz})"))
|
|
128
|
+
plt.xlabel("Iteration")
|
|
129
|
+
plt.ylabel("Energy (Ha)")
|
|
130
|
+
plt.legend()
|
|
131
|
+
plt.grid(True, alpha=0.4)
|
|
132
|
+
plt.tight_layout()
|
|
133
|
+
|
|
134
|
+
fname = _safe_filename("VQE_Optimizer_Comparison", molecule, ansatz)
|
|
135
|
+
_save_plot(fname)
|
|
136
|
+
|
|
137
|
+
if show:
|
|
138
|
+
plt.show()
|
|
139
|
+
else:
|
|
140
|
+
plt.close()
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
# ================================================================
|
|
144
|
+
# ANSATZ COMPARISON
|
|
145
|
+
# ================================================================
|
|
146
|
+
def plot_ansatz_comparison(molecule: str, results: dict, show=True, optimizer: str = "Adam"):
|
|
147
|
+
"""
|
|
148
|
+
Plot multiple ansatzes on a shared convergence graph.
|
|
149
|
+
"""
|
|
150
|
+
plt.figure(figsize=(8, 5))
|
|
151
|
+
|
|
152
|
+
min_len = min(len(v) for v in results.values())
|
|
153
|
+
|
|
154
|
+
for ans, energies in results.items():
|
|
155
|
+
plt.plot(range(min_len), energies[:min_len], label=ans)
|
|
156
|
+
|
|
157
|
+
plt.title(_safe_title(molecule, f"VQE Ansatz Comparison ({optimizer})"))
|
|
158
|
+
plt.xlabel("Iteration")
|
|
159
|
+
plt.ylabel("Energy (Ha)")
|
|
160
|
+
plt.legend()
|
|
161
|
+
plt.grid(True, alpha=0.4)
|
|
162
|
+
plt.tight_layout()
|
|
163
|
+
|
|
164
|
+
fname = _safe_filename("VQE_Ansatz_Comparison", molecule, optimizer)
|
|
165
|
+
_save_plot(fname)
|
|
166
|
+
|
|
167
|
+
if show:
|
|
168
|
+
plt.show()
|
|
169
|
+
else:
|
|
170
|
+
plt.close()
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
# ================================================================
|
|
174
|
+
# NOISE STATISTICS
|
|
175
|
+
# ================================================================
|
|
176
|
+
def plot_noise_statistics(
|
|
177
|
+
molecule: str,
|
|
178
|
+
noise_levels,
|
|
179
|
+
energy_means,
|
|
180
|
+
energy_stds,
|
|
181
|
+
fidelity_means,
|
|
182
|
+
fidelity_stds,
|
|
183
|
+
show=True,
|
|
184
|
+
optimizer_name="Adam",
|
|
185
|
+
ansatz_name="UCCSD",
|
|
186
|
+
noise_type="Depolarizing",
|
|
187
|
+
):
|
|
188
|
+
"""
|
|
189
|
+
Plot (ΔE vs noise) and (fidelity vs noise) as two subplots.
|
|
190
|
+
"""
|
|
191
|
+
fig, (ax1, ax2) = plt.subplots(2, 1, figsize=(8, 8), sharex=True)
|
|
192
|
+
|
|
193
|
+
# ΔE vs noise level
|
|
194
|
+
ax1.errorbar(noise_levels, energy_means, yerr=energy_stds,
|
|
195
|
+
fmt="o-", capsize=4)
|
|
196
|
+
ax1.set_ylabel("ΔE (Ha)")
|
|
197
|
+
ax1.set_title(
|
|
198
|
+
_safe_title(
|
|
199
|
+
molecule,
|
|
200
|
+
f"VQE Noise Impact — {noise_type}",
|
|
201
|
+
f"{optimizer_name}, {ansatz_name}",
|
|
202
|
+
)
|
|
203
|
+
)
|
|
204
|
+
ax1.grid(True, alpha=0.4)
|
|
205
|
+
|
|
206
|
+
# Fidelity vs noise level
|
|
207
|
+
ax2.errorbar(noise_levels, fidelity_means, yerr=fidelity_stds,
|
|
208
|
+
fmt="s-", capsize=4)
|
|
209
|
+
ax2.set_xlabel("Noise Probability")
|
|
210
|
+
ax2.set_ylabel("Fidelity")
|
|
211
|
+
ax2.grid(True, alpha=0.4)
|
|
212
|
+
|
|
213
|
+
plt.tight_layout()
|
|
214
|
+
|
|
215
|
+
fname = _safe_filename(
|
|
216
|
+
"VQE_Noise_Stats",
|
|
217
|
+
molecule,
|
|
218
|
+
optimizer_name,
|
|
219
|
+
ansatz_name,
|
|
220
|
+
noise_type,
|
|
221
|
+
)
|
|
222
|
+
_save_plot(fname)
|
|
223
|
+
|
|
224
|
+
if show:
|
|
225
|
+
plt.show()
|
|
226
|
+
else:
|
|
227
|
+
plt.close()
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
# ---------------------------------------------------------------------
|
|
231
|
+
# SSVQE Multi-State Convergence Plot
|
|
232
|
+
# ---------------------------------------------------------------------
|
|
233
|
+
def plot_ssvqe_convergence_multi(
|
|
234
|
+
energies_per_state,
|
|
235
|
+
*,
|
|
236
|
+
molecule="molecule",
|
|
237
|
+
ansatz="UCCSD",
|
|
238
|
+
optimizer="Adam",
|
|
239
|
+
show=True,
|
|
240
|
+
save=True,
|
|
241
|
+
):
|
|
242
|
+
"""
|
|
243
|
+
Plot convergence for multiple states from SSVQE.
|
|
244
|
+
|
|
245
|
+
Parameters
|
|
246
|
+
----------
|
|
247
|
+
energies_per_state : dict or list
|
|
248
|
+
Either:
|
|
249
|
+
{0: [...], 1: [...], 2: [...]}
|
|
250
|
+
or a list-of-lists:
|
|
251
|
+
[[...], [...], [...]]
|
|
252
|
+
Each entry is the energy trajectory for one state.
|
|
253
|
+
|
|
254
|
+
molecule : str
|
|
255
|
+
Molecule label.
|
|
256
|
+
ansatz : str
|
|
257
|
+
Ansatz name.
|
|
258
|
+
optimizer : str
|
|
259
|
+
Optimizer name.
|
|
260
|
+
show : bool
|
|
261
|
+
Whether to display the plot.
|
|
262
|
+
save : bool
|
|
263
|
+
Whether to save the PNG via common.plotting.
|
|
264
|
+
"""
|
|
265
|
+
|
|
266
|
+
import matplotlib.pyplot as plt
|
|
267
|
+
from vqe_qpe_common.plotting import build_filename, save_plot, format_molecule_name
|
|
268
|
+
|
|
269
|
+
# Normalise molecule name
|
|
270
|
+
mol_norm = format_molecule_name(molecule)
|
|
271
|
+
|
|
272
|
+
# Handle dict or list input
|
|
273
|
+
if isinstance(energies_per_state, dict):
|
|
274
|
+
trajectories = [energies_per_state[k] for k in sorted(energies_per_state.keys())]
|
|
275
|
+
else:
|
|
276
|
+
trajectories = energies_per_state
|
|
277
|
+
|
|
278
|
+
n_states = len(trajectories)
|
|
279
|
+
|
|
280
|
+
# Plot
|
|
281
|
+
plt.figure(figsize=(7, 4.5))
|
|
282
|
+
for i, E_list in enumerate(trajectories):
|
|
283
|
+
plt.plot(E_list, label=f"State {i}")
|
|
284
|
+
|
|
285
|
+
plt.xlabel("Iteration")
|
|
286
|
+
plt.ylabel("Energy (Ha)")
|
|
287
|
+
plt.title(f"{molecule} SSVQE ({n_states} states) – {ansatz}, {optimizer}")
|
|
288
|
+
plt.grid(True, alpha=0.3)
|
|
289
|
+
plt.legend()
|
|
290
|
+
plt.tight_layout()
|
|
291
|
+
|
|
292
|
+
# Save if requested
|
|
293
|
+
if save:
|
|
294
|
+
fname = build_filename(
|
|
295
|
+
molecule=mol_norm,
|
|
296
|
+
topic="ssvqe_convergence",
|
|
297
|
+
extras={
|
|
298
|
+
"states": n_states,
|
|
299
|
+
"ans": ansatz,
|
|
300
|
+
"opt": optimizer,
|
|
301
|
+
}
|
|
302
|
+
)
|
|
303
|
+
save_plot(fname)
|
|
304
|
+
|
|
305
|
+
if show:
|
|
306
|
+
plt.show()
|
|
307
|
+
else:
|
|
308
|
+
plt.close()
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: vqe-pennylane
|
|
3
|
+
Version: 0.2.2
|
|
4
|
+
Summary: Lightweight Quantum Simulation Suite with VQE and QPE modules (PennyLane-based)
|
|
5
|
+
Author-email: Sid Richards <siddrichards@hotmail.co.uk>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/SidRichardsQuantum/Variational_Quantum_Eigensolver
|
|
8
|
+
Project-URL: Issues, https://github.com/SidRichardsQuantum/Variational_Quantum_Eigensolver/issues
|
|
9
|
+
Project-URL: Documentation, https://github.com/SidRichardsQuantum/Variational_Quantum_Eigensolver#readme
|
|
10
|
+
Keywords: quantum,VQE,QPE,simulation,pennylane,quantum-chemistry
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: pennylane<0.45,>=0.42
|
|
24
|
+
Requires-Dist: numpy<2.0,>=1.23
|
|
25
|
+
Requires-Dist: scipy<2.0,>=1.10; python_version >= "3.10"
|
|
26
|
+
Requires-Dist: scipy<2.0,>=1.9; python_version == "3.9"
|
|
27
|
+
Requires-Dist: matplotlib
|
|
28
|
+
Requires-Dist: openfermion
|
|
29
|
+
Requires-Dist: openfermionpyscf
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
32
|
+
Requires-Dist: black; extra == "dev"
|
|
33
|
+
Requires-Dist: flake8; extra == "dev"
|
|
34
|
+
Requires-Dist: mypy; extra == "dev"
|
|
35
|
+
Requires-Dist: jupyterlab; extra == "dev"
|
|
36
|
+
Provides-Extra: docs
|
|
37
|
+
Requires-Dist: sphinx; extra == "docs"
|
|
38
|
+
Requires-Dist: furo; extra == "docs"
|
|
39
|
+
Dynamic: license-file
|
|
40
|
+
|
|
41
|
+
# Quantum Simulation Suite — VQE + QPE (PennyLane)
|
|
42
|
+
|
|
43
|
+
<p align="center">
|
|
44
|
+
|
|
45
|
+
<a href="https://pypi.org/project/vqe-pennylane/">
|
|
46
|
+
<img src="https://img.shields.io/pypi/v/vqe-pennylane?style=flat-square" alt="PyPI Version">
|
|
47
|
+
</a>
|
|
48
|
+
|
|
49
|
+
<a href="https://pypi.org/project/vqe-pennylane/">
|
|
50
|
+
<img src="https://img.shields.io/pypi/dm/vqe-pennylane?style=flat-square" alt="PyPI Downloads">
|
|
51
|
+
</a>
|
|
52
|
+
|
|
53
|
+
<a href="https://github.com/SidRichardsQuantum/Variational_Quantum_Eigensolver/actions/workflows/tests.yml">
|
|
54
|
+
<img src="https://img.shields.io/github/actions/workflow/status/SidRichardsQuantum/Variational_Quantum_Eigensolver/tests.yml?label=tests&style=flat-square" alt="Tests">
|
|
55
|
+
</a>
|
|
56
|
+
|
|
57
|
+
<img src="https://img.shields.io/pypi/pyversions/vqe-pennylane?style=flat-square" alt="Python Versions">
|
|
58
|
+
|
|
59
|
+
<img src="https://img.shields.io/github/license/SidRichardsQuantum/Variational_Quantum_Eigensolver?style=flat-square" alt="License">
|
|
60
|
+
|
|
61
|
+
</p>
|
|
62
|
+
|
|
63
|
+
A modern, modular, and fully reproducible **quantum-chemistry simulation suite** built on
|
|
64
|
+
**PennyLane**, featuring:
|
|
65
|
+
|
|
66
|
+
- **Variational Quantum Eigensolver (VQE)**
|
|
67
|
+
- **State-Specific VQE (SSVQE)**
|
|
68
|
+
- **Quantum Phase Estimation (QPE)**
|
|
69
|
+
- **Unified molecule registry, geometry generators, and plotting tools**
|
|
70
|
+
- **Consistent caching and reproducibility across all solvers**
|
|
71
|
+
|
|
72
|
+
This project refactors all previous notebooks into a clean Python package with
|
|
73
|
+
a shared `vqe_qpe_common/` layer for Hamiltonians, molecules, geometry, and plotting.
|
|
74
|
+
|
|
75
|
+
- **[THEORY.md](THEORY.md)** — Full background on VQE, QPE, ansatzes, optimizers, mappings, and noise models.
|
|
76
|
+
- **[USAGE.md](USAGE.md)** — Practical guide for installation, CLI usage, running simulations, caching, and plotting.
|
|
77
|
+
|
|
78
|
+
These documents complement the README and provide both the *theoretical foundation* and the *hands-on execution details* of the VQE/QPE suite.
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
# Project Structure
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
Variational_Quantum_Eigensolver/
|
|
86
|
+
├── README.md
|
|
87
|
+
├── THEORY.md
|
|
88
|
+
├── USAGE.md
|
|
89
|
+
├── LICENSE
|
|
90
|
+
├── pyproject.toml
|
|
91
|
+
│
|
|
92
|
+
├── vqe_qpe_common/ # Shared logic for VQE + QPE
|
|
93
|
+
│ ├── molecules.py # Unified molecule registry
|
|
94
|
+
│ ├── geometry.py # Bond/angle geometry generators
|
|
95
|
+
│ ├── hamiltonian.py # Unified Hamiltonian builder (PennyLane/OpenFermion)
|
|
96
|
+
│ └── plotting.py # Shared plotting + filename builders
|
|
97
|
+
│
|
|
98
|
+
├── vqe/ # Variational Quantum Eigensolver package
|
|
99
|
+
│ ├── __main__.py # CLI: python -m vqe
|
|
100
|
+
│ ├── core.py # VQE orchestration (runs, scans, sweeps)
|
|
101
|
+
│ ├── engine.py # Devices, noise, ansatz/optimizer plumbing
|
|
102
|
+
│ ├── ansatz.py # UCCSD, RY-CZ, HEA, minimal ansätze
|
|
103
|
+
│ ├── optimizer.py # Adam, GD, Momentum, SPSA, etc.
|
|
104
|
+
│ ├── hamiltonian.py # VQE-specific wrapper → uses vqe_qpe_common.hamiltonian
|
|
105
|
+
│ ├── io_utils.py # JSON caching, run signatures
|
|
106
|
+
│ ├── visualize.py # Convergence, scans, noise plots
|
|
107
|
+
│ └── ssvqe.py # Subspace-search VQE (excited states)
|
|
108
|
+
│
|
|
109
|
+
├── qpe/ # Quantum Phase Estimation package
|
|
110
|
+
│ ├── __main__.py # CLI: python -m qpe
|
|
111
|
+
│ ├── core.py # Controlled-U, trotterized dynamics, iQFT
|
|
112
|
+
│ ├── hamiltonian.py # QPE-specific wrapper → uses vqe_qpe_common.hamiltonian
|
|
113
|
+
│ ├── io_utils.py # JSON caching, run signatures
|
|
114
|
+
│ ├── noise.py # Depolarizing + amplitude damping channels
|
|
115
|
+
│ └── visualize.py # Phase histograms + sweep plots
|
|
116
|
+
│
|
|
117
|
+
├── results/ # JSON outputs
|
|
118
|
+
├── images/ # Saved plots (VQE + QPE)
|
|
119
|
+
├── data/ # Optional molecule configs, external data
|
|
120
|
+
│
|
|
121
|
+
└── notebooks/ # Notebooks importing from the vqe/ and qpe/ packages
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
This structure ensures:
|
|
125
|
+
|
|
126
|
+
- **VQE and QPE share the same chemistry** (`vqe_qpe_common/`)
|
|
127
|
+
- **All results are cached consistently** (`results/`)
|
|
128
|
+
- **All plots use one naming system** (`vqe_qpe_common/plotting.py`)
|
|
129
|
+
- **Notebooks import from the real package** (no duplicated code)
|
|
130
|
+
- **CLI tools are production-ready** (`python -m vqe`, `python -m qpe`)
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
# ⚙️ Installation
|
|
135
|
+
|
|
136
|
+
### Install from PyPI
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
pip install vqe-pennylane
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Install from source (development mode)
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
git clone https://github.com/SidRichardsQuantum/Variational_Quantum_Eigensolver.git
|
|
146
|
+
cd Variational_Quantum_Eigensolver
|
|
147
|
+
pip install -e .
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### Confirm installation
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
python -c "import vqe, qpe; print('VQE+QPE imported successfully!')"
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
# Common Core (Shared by VQE & QPE)
|
|
159
|
+
|
|
160
|
+
The following modules ensure full consistency between solvers:
|
|
161
|
+
|
|
162
|
+
| Module | Purpose |
|
|
163
|
+
|--------|---------|
|
|
164
|
+
| `vqe_qpe_common/molecules.py` | Canonical molecule definitions |
|
|
165
|
+
| `vqe_qpe_common/geometry.py` | Bond/angle/coordinate generators |
|
|
166
|
+
| `vqe_qpe_common/hamiltonian.py` | Hamiltonian construction + OpenFermion fallback |
|
|
167
|
+
| `vqe_qpe_common/plotting.py` | Unified filename builder + PNG export |
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
# 🔹 VQE Package
|
|
172
|
+
|
|
173
|
+
Features:
|
|
174
|
+
- Ground-state VQE
|
|
175
|
+
- Excited-state SSVQE
|
|
176
|
+
- Geometry scans
|
|
177
|
+
- Noise sweeps
|
|
178
|
+
- Mapping comparisons
|
|
179
|
+
- Optimizer registry
|
|
180
|
+
- Result caching
|
|
181
|
+
|
|
182
|
+
Run example:
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
from vqe.core import run_vqe
|
|
186
|
+
result = run_vqe("H2", ansatz_name="UCCSD", optimizer_name="Adam", n_steps=50)
|
|
187
|
+
print(result["energy"])
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
# 🔹 QPE Package
|
|
193
|
+
|
|
194
|
+
Features:
|
|
195
|
+
- Noiseless & noisy QPE
|
|
196
|
+
- Trotterized exp(-iHt)
|
|
197
|
+
- Inverse QFT
|
|
198
|
+
- Noise channels
|
|
199
|
+
- Cached results
|
|
200
|
+
|
|
201
|
+
Example:
|
|
202
|
+
|
|
203
|
+
```python
|
|
204
|
+
from vqe_qpe_common.hamiltonian import build_hamiltonian
|
|
205
|
+
from qpe.core import run_qpe
|
|
206
|
+
|
|
207
|
+
H, n_qubits, hf_state = build_hamiltonian(["H","H"], coords, 0, "STO-3G")
|
|
208
|
+
result = run_qpe(H, hf_state, n_ancilla=4)
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
# CLI Usage
|
|
214
|
+
|
|
215
|
+
### VQE
|
|
216
|
+
```bash
|
|
217
|
+
python -m vqe -m H2 -a UCCSD -o Adam --steps 50
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### QPE
|
|
221
|
+
```bash
|
|
222
|
+
python -m qpe --molecule H2 --ancillas 4 --shots 2000
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
---
|
|
226
|
+
|
|
227
|
+
# 🧪 Tests
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
pytest -v
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
---
|
|
234
|
+
|
|
235
|
+
📘 Author: Sid Richards (SidRichardsQuantum)
|
|
236
|
+
|
|
237
|
+
<img src="https://cdn.jsdelivr.net/gh/devicons/devicon/icons/linkedin/linkedin-original.svg" width="20" /> LinkedIn: https://www.linkedin.com/in/sid-richards-21374b30b/
|
|
238
|
+
|
|
239
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
qpe/__init__.py,sha256=YByDVRXUEA4jGTT4m-TlP0i6ycQ7xbhaOipw0Tr7KMs,1789
|
|
2
|
+
qpe/__main__.py,sha256=WGNEigwfRf3icEmTmUWKD1nAvZ0MzDtRxDzQV5zs-d0,6743
|
|
3
|
+
qpe/core.py,sha256=jj3LIfKVytTTEscWbUcD59-BUhWo8ulWALZHuo0aDYU,9666
|
|
4
|
+
qpe/hamiltonian.py,sha256=4AIWbfpN-HpL2Z1zKcRWrSO1_Pw-rIDGcshr7INfRSc,3099
|
|
5
|
+
qpe/io_utils.py,sha256=4KZQrNzF9iLE_yd4hFOmxTC4lLREMAfwR72X2Tt0dNs,3814
|
|
6
|
+
qpe/noise.py,sha256=MjK_x38FxxEatt21Rv3rrvBxF8fK8CL5uIsii8samSM,1303
|
|
7
|
+
qpe/visualize.py,sha256=rwfCxeq8_NWWX53S-wbBQEnkqumhyM2240frvkfiBJM,5631
|
|
8
|
+
vqe/__init__.py,sha256=9D-HoWKOzxL7g0lupHix-mrbYv9CIQMdf4W5XtJL8ko,3102
|
|
9
|
+
vqe/__main__.py,sha256=dQq3tHeQQZst3Q8hGikv75K9FT87RXb_OnkZT-Mq_BE,11072
|
|
10
|
+
vqe/ansatz.py,sha256=DMFBWF7qItFIoz1nXxBo8Dqb6JQeUROYpO2JqX9Ydeo,12573
|
|
11
|
+
vqe/core.py,sha256=vh9eWg3qX1D8VU_JrnO3O1gvAMkJd5czdExwLzTzCv0,26137
|
|
12
|
+
vqe/engine.py,sha256=zNpgXFko8u_ZEo18auriUuerOiGSAmVGctSLP1NPnuM,10372
|
|
13
|
+
vqe/hamiltonian.py,sha256=tbxueGC1Ya6C6zr7oPgvpuFzolHyEMO_vVYb-nYc3zE,8334
|
|
14
|
+
vqe/io_utils.py,sha256=f6YAw8uKZBWzmbOdyKndxfAnuskSLthzilF_SOlHux4,7528
|
|
15
|
+
vqe/optimizer.py,sha256=nm04mxh4PW_c0iEQuKfF5vrfpopq9vNjSOjWCCu2TiI,1520
|
|
16
|
+
vqe/ssvqe.py,sha256=mws-L1sqx4fr9bV9KOACBOFF59u1nQckU9C-MUdYuec,9139
|
|
17
|
+
vqe/visualize.py,sha256=knIHDiXaRfK3gUuY48oNV2kaw3fv3hOVRZ1yjW8pMDU,8061
|
|
18
|
+
vqe_pennylane-0.2.2.dist-info/licenses/LICENSE,sha256=8yjLrHRw7qIlfoogu8raXR4DVceIzWyMgJJ9veAAoKo,1069
|
|
19
|
+
vqe_qpe_common/__init__.py,sha256=JTEF58TToTefiIQFFIUccV2dIzIrPw1MRZzO8FwfZtw,1658
|
|
20
|
+
vqe_qpe_common/geometry.py,sha256=JZsseVexsOWw9OV0M1SX-VvSR05ZkEM-5WPtko-vNEY,1276
|
|
21
|
+
vqe_qpe_common/hamiltonian.py,sha256=7kIaaMI86R9eQdpIQ4Bwwc0DWHeXZhTnIx8OJNPxKoE,1744
|
|
22
|
+
vqe_qpe_common/molecules.py,sha256=Farn5t5Wmu_C4T7IGhPZM3aGeUQrMSimMnmqMMJsI5I,2582
|
|
23
|
+
vqe_qpe_common/plotting.py,sha256=gOaqXq_Yspv9Q6_13Xalg9axgRYlBFH96k8ETfFzw-U,4495
|
|
24
|
+
vqe_pennylane-0.2.2.dist-info/METADATA,sha256=syiTmdgyAv3qaXzBRsorztasdgzSflka7_ot8LMZDhU,8102
|
|
25
|
+
vqe_pennylane-0.2.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
26
|
+
vqe_pennylane-0.2.2.dist-info/entry_points.txt,sha256=bFCrloF0q0q5nI7AXJBOpq5jUQ9Self-bwEPN3j44qg,66
|
|
27
|
+
vqe_pennylane-0.2.2.dist-info/top_level.txt,sha256=S9LETqg-fWOc2Xq4YrzYAivDGdSntsQP5uLRPFhi6v8,23
|
|
28
|
+
vqe_pennylane-0.2.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Sid Richards
|
|
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,67 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
__version__ = "0.2.0"
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
vqe_qpe_common
|
|
7
|
+
======
|
|
8
|
+
|
|
9
|
+
Shared utilities used across VQE, QPE, and future solvers.
|
|
10
|
+
|
|
11
|
+
This subpackage contains:
|
|
12
|
+
• vqe_qpe_common.molecules — canonical molecule registry
|
|
13
|
+
• vqe_qpe_common.geometry — unified geometry generators (bond/angle scans)
|
|
14
|
+
• vqe_qpe_common.hamiltonian — single source of truth for Hamiltonian construction
|
|
15
|
+
• vqe_qpe_common.plotting — global plotting + filename/dir management
|
|
16
|
+
|
|
17
|
+
All high-level solvers (VQE, QPE, QSVT, etc.) should import molecule
|
|
18
|
+
definitions, geometry logic, Hamiltonians, and plotting helpers from here
|
|
19
|
+
to avoid duplication and ensure reproducibility.
|
|
20
|
+
|
|
21
|
+
Example
|
|
22
|
+
-------
|
|
23
|
+
from vqe_qpe_common import (
|
|
24
|
+
MOLECULES,
|
|
25
|
+
get_molecule_config,
|
|
26
|
+
generate_geometry,
|
|
27
|
+
build_hamiltonian,
|
|
28
|
+
build_filename,
|
|
29
|
+
save_plot,
|
|
30
|
+
)
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
# Molecule data + helpers
|
|
34
|
+
from .molecules import MOLECULES, get_molecule_config # noqa: F401
|
|
35
|
+
|
|
36
|
+
# Geometry (bond length, angle scans, parametrized coordinates)
|
|
37
|
+
from .geometry import generate_geometry # noqa: F401
|
|
38
|
+
|
|
39
|
+
# Hamiltonian construction (PennyLane + OpenFermion fallback)
|
|
40
|
+
from .hamiltonian import build_hamiltonian # noqa: F401
|
|
41
|
+
|
|
42
|
+
# Plotting utilities shared across VQE + QPE
|
|
43
|
+
from .plotting import (
|
|
44
|
+
build_filename,
|
|
45
|
+
save_plot,
|
|
46
|
+
format_molecule_name,
|
|
47
|
+
format_token,
|
|
48
|
+
) # noqa: F401
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
__all__ = [
|
|
52
|
+
# Molecules
|
|
53
|
+
"MOLECULES",
|
|
54
|
+
"get_molecule_config",
|
|
55
|
+
|
|
56
|
+
# Geometry
|
|
57
|
+
"generate_geometry",
|
|
58
|
+
|
|
59
|
+
# Hamiltonian
|
|
60
|
+
"build_hamiltonian",
|
|
61
|
+
|
|
62
|
+
# Plotting
|
|
63
|
+
"build_filename",
|
|
64
|
+
"save_plot",
|
|
65
|
+
"format_molecule_name",
|
|
66
|
+
"format_token",
|
|
67
|
+
]
|