qalgora-Q Docs Hub量子文档 ✦ Ask AI✦ 问问文档

PennyLane Interop

◐ Design-level API
This page documents qalgora-Q API design, architecture, or adaptation workflows. Code examples illustrate intended usage and are not guaranteed to run in the current reference implementation.

Use qalgora-Q as a high-performance device for PennyLane, the popular quantum machine-learning framework, with automatic differentiation through quantum nodes.

The qalgora-Q device

Requires PennyLane and the qalgora PennyLane plugin (for example pennylane-qalgora); qml.device("qalgora.qubit") only becomes available once the plugin is registered, and the current open reference implementation does not include it. The snippet below is the planned interface:

import pennylane as qml
import qalgora

dev = qml.device("qalgora.qubit", wires=2, target="qpp-cpu")
# optional: requires the qalgora-gpu plugin (planned)
# dev = qml.device("qalgora.qubit", wires=2, target="gpu")

@qml.qnode(dev, diff_method="parameter-shift")
def circuit(theta):
    qml.RY(theta, wires=0)
    qml.CNOT(wires=[0, 1])
    return qml.expval(qml.PauliZ(0))

print(circuit(0.5))
Specification API — not in the open reference build yet
This example shows a qalgora-Q specification API (or a third-party library) that the open reference build does not bundle today. It documents the intended interface; to run code now, use the reference build’s supported core API.

Training with autograd

import pennylane.numpy as np

opt = qml.AdamOptimizer(0.1)
theta = np.array(0.1, requires_grad=True)
for _ in range(100):
    # if the plugin declares support for the differentiation method, PennyLane can
    # compute gradients via parameter-shift or another method (depends on plugin capabilities)
    theta = opt.step(circuit, theta)
Specification API — not in the open reference build yet
This example shows a qalgora-Q specification API (or a third-party library) that the open reference build does not bundle today. It documents the intended interface; to run code now, use the reference build’s supported core API.
QML at scale
A planned, optional GPU target could let you train quantum models with more qubits and shots than a CPU device allows, while keeping PennyLane's autodiff workflow. GPU support requires the qalgora-gpu plugin (planned) and is not part of the current open reference implementation.

References

  • V. Bergholm et al., "PennyLane: automatic differentiation of hybrid quantum-classical computations," (2018). arXiv:1811.04968

PennyLane 互操作

◐ 设计接口
本页描述的是 qalgora-Q 的接口设计、架构设计或适配工作流。相关代码用于说明预期用法,当前参考实现不保证可以直接运行。

将 qalgora-Q 用作 PennyLane(主流量子机器学习框架)的高性能设备,通过量子节点实现自动微分。

qalgora-Q 设备

需要安装 PennyLane 和 qalgora PennyLane 插件(如 pennylane-qalgora);qml.device("qalgora.qubit") 只有插件注册后才可用,当前开放参考实现未包含。以下为规划接口:

import pennylane as qml
import qalgora

dev = qml.device("qalgora.qubit", wires=2, target="qpp-cpu")
# 可选:需安装 qalgora-gpu 插件(规划中)
# dev = qml.device("qalgora.qubit", wires=2, target="gpu")

@qml.qnode(dev, diff_method="parameter-shift")
def circuit(theta):
    qml.RY(theta, wires=0)
    qml.CNOT(wires=[0, 1])
    return qml.expval(qml.PauliZ(0))

print(circuit(0.5))
规范接口 · 参考实现暂未包含
此示例展示的是 qalgora-Q 规范中的接口(或第三方库),开放参考实现目前尚未内置,仅用于说明预期用法;如需立即运行,请使用参考实现已支持的核心 API。

使用 autograd 训练

import pennylane.numpy as np

opt = qml.AdamOptimizer(0.1)
theta = np.array(0.1, requires_grad=True)
for _ in range(100):
    # 若插件声明支持相应 differentiation method,PennyLane 可通过参数移位
    # 或其他方法计算梯度(是否支持取决于插件能力)
    theta = opt.step(circuit, theta)
规范接口 · 参考实现暂未包含
此示例展示的是 qalgora-Q 规范中的接口(或第三方库),开放参考实现目前尚未内置,仅用于说明预期用法;如需立即运行,请使用参考实现已支持的核心 API。
规模化 QML
规划中的可选 GPU 目标有望训练比 CPU 设备规模更大的量子模型——更多量子比特、更多采样次数,同时照样用 PennyLane 的自动微分流程。GPU 支持需安装 qalgora-gpu 插件(规划中),当前开放参考实现未包含。

参考文献

  • V. Bergholm et al., "PennyLane: automatic differentiation of hybrid quantum-classical computations," (2018). arXiv:1811.04968