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、Qiskitqiskit-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

链接

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.2.tar.gz (73.0 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.2-py3-none-any.whl (93.7 kB view details)

Uploaded Python 3

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

Hashes for hyq-26.1.2.tar.gz
Algorithm Hash digest
SHA256 be0d0e7ea120362895235ab02567a96fac9a3d7f352802a0642f35ce8124d810
MD5 fd5526bc94aaa3ef42e06736acd5a051
BLAKE2b-256 c918117b796a4a33613ccb0bda21ce873f626406e09cd874a8e940ee510fe3f3

See more details on using hashes here.

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

Hashes for hyq-26.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8e0488c8345a7dc51bddd30321d10d26fb78c5d764183f500e59d63b2268f9d2
MD5 69f36c8895628a2a96208694578bc8ef
BLAKE2b-256 79dbd289a1efb1fc553d80e629c16e912852f781ed50561b2aec9cc82a5cd879

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