Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Cqlib-QML

英文版见 English version。

本项目是基于 Cqlib 的量子机器学习 Python 工具包,提供经典数据量子编码、参数化量子线路、纯量子与混合量子—经典神经网络、量子核方法及模型训练组件。

量子层现在支持显式输入/权重角色、端到端梯度和微批次累积。VQC 支持可复现重训、warm start 及版本化 checkpoint 完整续训。API、恢复边界和行为迁移见 训练契约教程。

安装说明

环境要求:Python 3.11 及以上版本,cqlib 2.0.0b3 及以上版本。

从源码安装:

git clone https://github.com/cq-lib/cqlib-qml.git
cd cqlib-qml
pip install .

发布到 PyPI 后,也可以直接安装:

pip install cqlib-qml

开发环境安装:

pip install -r requirements-dev.txt
pip install -e .

主要功能

  • encoder:将经典向量和图像编码为量子线路,支持振幅编码、角度编码、基态编码、FRQI、NEQR、Qubit Lattice 和 ZZ Feature Map。
  • ansatz:参数化量子线路,包含硬件高效线路、BasicQNN、CRADL 和 CRAML。
  • models:纯量子神经网络 QNN、混合量子—经典神经网络 HQNN,以及用于组合量子与经典组件的 Module。
  • algorithms:量子核方法 QKM、量子支持向量机 QSVM 和兼容 scikit-learn 接口的变分量子分类器 VQC。
  • differentiator:伴随法和参数偏移法量子梯度计算。
  • layer:全连接层与常用激活函数,用于构建混合模型的经典部分。
  • data:数据集、批加载和图像数据预处理工具。
  • loss / optimizer / scheduler:常用损失函数、参数优化器和学习率调度器。
  • utils:量子门梯度矩阵等辅助工具。

快速开始

下面使用角度编码和量子核构造核矩阵:

import numpy as np

from cqlib_qml.algorithms import QKM
from cqlib_qml.encoder import AngleEncoder

encoder = AngleEncoder(mode="classical")
kernel = QKM(encoder=encoder)

samples = np.array([
    [0.1, 0.2],
    [0.3, 0.4],
    [0.5, 0.6],
])

kernel_matrix = kernel.kernel(samples)
print(kernel_matrix)

构建量子神经网络:

from cqlib_qml.ansatz import HEAnsatz
from cqlib_qml.models import QNN

ansatz = HEAnsatz(n_qubits=4, d=2, layers=["RY", "CX"])
ansatz.set_measurement(readouts=[0])
model = QNN(ansatz=ansatz)

更多说明参见 docs/tutorials。

测试

pytest

License

Apache License 2.0,详见 LICENSE。

Contributing

欢迎贡献!如需改进功能或修复缺陷,请提交 Issue 或发起 Pull Request。

Metadata

Release files for cqlib-qml 0.1.0b2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cqlib-qml 0.1.0b2
File Size Uploaded
cqlib_qml-0.1.0b2.tar.gz 201.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cqlib-qml 0.1.0b2
File Interpreter ABI Platform
cqlib_qml-0.1.0b2-py3-none-any.whl Python 3 none any Details

Total release size: 325.2 kB

Release files / cqlib_qml-0.1.0b2.tar.gz

Download URL cqlib_qml-0.1.0b2.tar.gz
Size 201.0 kB
Tags Source
SHA-256 checksum
How to use checksums
32182de348a13caecb3276c24e26c8480805410e9b6cf2937e04c28f8e8a172c
BLAKE2b-256 checksum
How to use checksums
fa39e2e04e4b34898cbdb2df3ceb4c48b9d183c40411606a3fcfb6794f18abc7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.20

Release files / cqlib_qml-0.1.0b2-py3-none-any.whl

Download URL cqlib_qml-0.1.0b2-py3-none-any.whl
Size 124.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
13ff90b7d6a80c3a388bd3c49d99cd066280bfdbb2ddf341441b142596540934
BLAKE2b-256 checksum
How to use checksums
78b8f6bdd13689cdb7be285123e4b63963b763acb5a3434f83e6dd7f2368e9e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.20
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page