HyQ: hybrid quantum algorithms toolkit with backend-agnostic circuits and solvers
Project description
HyQ
HyQ(pip install hyq)是用于混合量子算法的 Python 工具包:后端无关的线路抽象、可插拔模拟器,以及 VQE / QITE 系列求解器与常用算法工具。
- Python:3.10、3.11(见
requires-python) - 核心依赖(随
pip install hyq自动安装):NumPy、SciPy、PyTorch、Qiskit、qiskit-aer - 其他后端与化学功能:通过可选 extra 安装(见下表)
安装
pip install hyq
默认可用 Qiskit 后端(线路构建、采样、QASM 等)。若需要可微分或其它模拟器,可加装 extras:
pip install "hyq[tensorcircuit]" # VQE / VarQITE 等可微分算法
pip install "hyq[tensorcircuit,pennylane]" # 常用组合
pip install "hyq[all]" # 全部可选 Python 依赖(体积较大)
可选依赖(extras)
| Extra | 用途 |
|---|---|
pennylane |
PennyLane 后端 |
tensorcircuit |
TensorCircuit 后端(推荐可微分流程) |
optional-backends |
Cirq、Qulacs、QuTiP |
chemistry |
OpenFermion、PySCF 等(分子哈密顿量) |
notebooks |
运行 notebook 的辅助包 |
dev |
pytest、black 等开发工具 |
all |
上述除 dev 外的组合 |
Psi4 不在 PyPI 上,无法通过
pip安装。需要 Psi4 时请用 Conda 单独安装,并参考仓库内的开发文档。
导入方式
安装后统一从 hyq 命名空间导入(与 pip 包名一致):
import hyq
print(hyq.__version__)
from hyq.backends import get_backend, available_backends, set_backend
from hyq.backends.core import QuantumCircuit
from hyq.backends.Tensorcircuit import TensorCircuitBackend
from hyq.solvers import VQESolver
from hyq.algorithms import exact_diagonalization, build_qpe_circuit
from hyq.ansatz import HEAAnsatz, UCCSD
from hyq.chemistry import Hamiltonian
选择默认后端
export HYQ_BACKEND=tensorcircuit # 或 qiskit、pennylane 等
from hyq.backends import available_backends, set_backend
print(available_backends())
backend = set_backend("tensorcircuit")
快速示例(VQE)
import torch
from hyq.backends.core import QuantumCircuit
from hyq.backends.Tensorcircuit import TensorCircuitBackend
from hyq.solvers import VQESolver
backend = TensorCircuitBackend()
solver = VQESolver(backend)
def ansatz(params):
qc = QuantumCircuit(2)
qc.ry(0, params[0])
qc.cx(0, 1)
return qc
hamiltonian = [(-1.0, "ZI"), (-1.0, "IZ"), (0.5, "XX")]
init_params = torch.tensor([0.1], dtype=torch.float64)
energy, params, history = solver.solve(
ansatz, init_params, hamiltonian, steps=100, lr=0.1
)
print(energy, params)
哈密顿量格式
hamiltonian = [
(-1.0, "ZI"),
(-1.0, "IZ"),
(0.5, "XX"),
]
字符串中第 i 个字符对应第 i 个 qubit,支持 I / X / Y / Z。
包结构
hyq/
├── algorithms/ # QPE、Trotter、QSE、VQD、shadow 等
├── ansatz/ # HEA、UCCSD、ADAPT 等
├── backends/ # 线路抽象与各模拟器后端
├── chemistry/ # 分子与哈密顿量(可选)
└── solvers/ # VQE、VarQITE、SA-QITE、SS-QITE、RITE
链接
- PyPI:https://pypi.org/project/hyq/
- 问题与示例 notebook:请使用项目 Git 仓库的 Issues /
examples/目录
Project details
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 hyq-26.1.2.tar.gz.
File metadata
- Download URL: hyq-26.1.2.tar.gz
- Upload date:
- Size: 73.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be0d0e7ea120362895235ab02567a96fac9a3d7f352802a0642f35ce8124d810
|
|
| MD5 |
fd5526bc94aaa3ef42e06736acd5a051
|
|
| BLAKE2b-256 |
c918117b796a4a33613ccb0bda21ce873f626406e09cd874a8e940ee510fe3f3
|
File details
Details for the file hyq-26.1.2-py3-none-any.whl.
File metadata
- Download URL: hyq-26.1.2-py3-none-any.whl
- Upload date:
- Size: 93.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e0488c8345a7dc51bddd30321d10d26fb78c5d764183f500e59d63b2268f9d2
|
|
| MD5 |
69f36c8895628a2a96208694578bc8ef
|
|
| BLAKE2b-256 |
79dbd289a1efb1fc553d80e629c16e912852f781ed50561b2aec9cc82a5cd879
|