Skip to main content

HyQ: hybrid quantum algorithms toolkit with backend-agnostic circuits and solvers

Project description

HyQ

HyQpip install hyq)是用于混合量子算法的 Python 工具包:后端无关的线路抽象、可插拔模拟器,以及 VQE / QITE 系列求解器与常用算法工具。

  • Python:3.10、3.11(见 requires-python
  • 核心依赖(随 pip install hyq 自动安装):NumPy、SciPy、PyTorch
  • 量子后端与化学功能:通过可选 extra 安装(见下表)

安装

pip install hyq

至少安装一个后端后再使用线路与求解器(推荐):

pip install "hyq[tensorcircuit]"              # VQE / VarQITE 等可微分算法
pip install "hyq[qiskit]"                     # 采样、QASM、线路转换
pip install "hyq[qiskit,tensorcircuit]"       # 常用组合
pip install "hyq[all]"                        # 全部可选 Python 依赖(体积较大)

可选依赖(extras)

Extra 用途
qiskit Qiskit / Aer 后端
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

链接

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

hyq-26.1.1.tar.gz (73.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hyq-26.1.1-py3-none-any.whl (93.7 kB view details)

Uploaded Python 3

File details

Details for the file hyq-26.1.1.tar.gz.

File metadata

  • Download URL: hyq-26.1.1.tar.gz
  • Upload date:
  • Size: 73.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for hyq-26.1.1.tar.gz
Algorithm Hash digest
SHA256 be38e590aa819bb4f818ad1d439aa6f50fdbbe191d50b28c506342fb3f3f104c
MD5 50653c519d102042ee8648a82b73c653
BLAKE2b-256 ffc78c5e994b89df223966fe31fb5a6c01acfa29ce9ddcd295a659ed4f2d8693

See more details on using hashes here.

File details

Details for the file hyq-26.1.1-py3-none-any.whl.

File metadata

  • Download URL: hyq-26.1.1-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

Hashes for hyq-26.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 882a95dcd99ab624ae6bbe2eb044d769cf6ba61dcdeb96e67bc5df4a63f12544
MD5 6a282d51ba17e2e1351c81d2280d4439
BLAKE2b-256 a3970360cc6ab927f51aa171a5cb0e5f31994bfea5c8029aa820e3c744a3497c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page