A user-friendly wrapper for setting up and running VQE calculations with Qiskit.
Project description
Easy VQE
A user-friendly Python package for setting up and running Variational Quantum Eigensolver (VQE) calculations using Qiskit. Define Hamiltonians as simple strings and ansatz circuits using nested lists/tuples.
Features
- Simple Hamiltonian Definition: Define Hamiltonians using intuitive strings (e.g.,
"1.0 * XX - 0.5 * ZI + YZ"). Handles various formats, signs, and spacing. - Flexible Ansatz Creation: Build parameterized circuits using a list-based structure with standard Qiskit gate names. Auto-generates parameters.
- Automated VQE Workflow: Handles parameter management, basis rotations, measurement simulation, expectation value calculation, and optimization loop.
- Built-in Optimization: Uses
scipy.optimize.minimizewith configurable methods (COBYLA, Nelder-Mead, etc.) and options. - Simulation Backend: Leverages
qiskit-aerfor efficient classical simulation. - Convergence Plotting: Optionally save plots of the energy convergence during optimization.
- Flexible Initial Parameters: Supports random initialization, zero initialization, or providing specific lists/NumPy arrays for starting parameters.
- Result Summarization: Includes helper functions to print a clean summary of the VQE results.
- Theoretical Energy Calculation: Provides a utility to compute the exact ground state energy via matrix diagonalization for comparison.
- Circuit Visualization: Includes a helper function to draw the final ansatz circuit with the optimized parameters bound.
Installation
You can install easy_vqe using pip:
pip install easy-vqe
Or, for development, clone this repository and install in editable mode:
git clone https://github.com/7Abdoman7/easy_vqe.git
cd easy_vqe
pip install -e .[dev]
Quick Start
Here's a basic example to find the ground state energy of a 3-qubit Hamiltonian:
import numpy as np
from easy_vqe import find_ground_state
# 1. Define the Hamiltonian string
hamiltonian_str = "-1.0 * ZZI + 0.9 * ZIZ - 0.5 * IZZ + 0.2 * XXX"
# 2. Define the Ansatz Structure
ansatz_block = [
('ry', [0, 1, 2]), # Ry on qubits 0, 1, 2 (each gets a parameter)
('cx', [0, 1]), # CNOT 0 -> 1
('cx', [1, 2]), # CNOT 1 -> 2
('rz', [0, 1, 2]), # Rz on qubits 0, 1, 2 (each gets a parameter)
]
# Build the full ansatz: Hadamard layer, block, CNOT, block
ansatz_structure = [
('h', [0, 1, 2]),
ansatz_block,
('cx', [0, 2]),
('barrier', []), # Optional barrier for visual separation
ansatz_block,
]
# 3. Run the VQE algorithm
results = find_ground_state(
ansatz_structure=ansatz_structure,
hamiltonian_expression=hamiltonian_str,
optimizer_method='COBYLA',
optimizer_options={'maxiter': 200, 'tol': 1e-5}, # Optimizer settings
n_shots=4096, # Number of shots for expectation value
plot_filename="vqe_convergence.png" # Save the plot
)
# 4. Print Results
if 'error' not in results:
print(f"Optimization Successful: {results['success']}")
print(f"Optimizer Message: {results['message']}")
print(f"Minimum Energy Found: {results['optimal_value']:.6f}")
print(f"Optimal Parameters: {np.round(results['optimal_params'], 4)}")
else:
print(f"VQE Failed: {results['error']}")
See the examples/ directory for more usage scenarios.
Contributing
Contributions are welcome! Please feel free to submit issues or pull requests. (Add more details here if you like - code style, testing requirements etc.)
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file easy_vqe-1.2.0.tar.gz.
File metadata
- Download URL: easy_vqe-1.2.0.tar.gz
- Upload date:
- Size: 39.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
acd661a41d82e6aed3410d49d4c97293d4d4d88300af95a06ca94effce823147
|
|
| MD5 |
de2da9bd6f50eeb17dbbf308cbf3acdd
|
|
| BLAKE2b-256 |
515079f5c904898ee913c9fe3eccea8b9d046b5c25b5da313319a1e9b7d1fabe
|
File details
Details for the file easy_vqe-1.2.0-py3-none-any.whl.
File metadata
- Download URL: easy_vqe-1.2.0-py3-none-any.whl
- Upload date:
- Size: 26.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48ef70c5dfadbd715951139a73363572eefd254316078435efd03cba97759ddb
|
|
| MD5 |
38bce169720d0e27260e571376f33fc5
|
|
| BLAKE2b-256 |
d5f7426b8c1326f7f25a9cc4a98900ecd53b11bda689a7c1bf96bc9eab8e3e65
|