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

Cirq 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.

Convert between Google Cirq circuits and qalgora-Q kernels to run Cirq-authored algorithms on qalgora-Q simulators and hardware.

Importing a Cirq circuit

import qalgora
import cirq

q = cirq.LineQubit.range(2)
circuit = cirq.Circuit(cirq.H(q[0]), cirq.CNOT(q[0], q[1]),
                       cirq.measure(*q))

qalgora.set_target("qpp-cpu")
# Planned adapter:
# kernel = qalgora.from_cirq(circuit)
# print(qalgora.sample(kernel, shots_count=1000))
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.

Exporting back to Cirq

@qalgora.kernel
def bell():
    qb = qalgora.qvector(2)
    h(qb[0]); x.ctrl(qb[0], qb[1]); mz(qb)

# Planned adapter:
# circuit = qalgora.to_cirq(bell)         # hand off to a Cirq workflow
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.
Notes
The from_cirq/to_cirq adapters are planned interfaces. Cirq LineQubit/GridQubit mappings must be preserved; measurement keys, parameter symbols, and moment structure may need adapting. Google hardware targets are not ordinary open cloud backends, so this does not imply direct submission to Willow or similar devices.
OpenFermion
Chemistry problems built with OpenFermion (Cirq's ecosystem) map cleanly onto qalgora-Q spin operators for VQE — see Quantum Chemistry.

Cirq 互操作

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

在 Google Cirq 电路和 qalgora-Q 内核之间互相转换,把用 Cirq 写的算法跑在 qalgora-Q 的模拟器和硬件上。

导入 Cirq 电路

import qalgora
import cirq

q = cirq.LineQubit.range(2)
circuit = cirq.Circuit(cirq.H(q[0]), cirq.CNOT(q[0], q[1]),
                       cirq.measure(*q))

qalgora.set_target("qpp-cpu")
# 规划中的适配器:
# kernel = qalgora.from_cirq(circuit)
# print(qalgora.sample(kernel, shots_count=1000))
规范接口 · 参考实现暂未包含
此示例展示的是 qalgora-Q 规范中的接口(或第三方库),开放参考实现目前尚未内置,仅用于说明预期用法;如需立即运行,请使用参考实现已支持的核心 API。

导出回 Cirq

@qalgora.kernel
def bell():
    qb = qalgora.qvector(2)
    h(qb[0]); x.ctrl(qb[0], qb[1]); mz(qb)

# 规划中的适配器:
# circuit = qalgora.to_cirq(bell)         # hand off to a Cirq workflow
规范接口 · 参考实现暂未包含
此示例展示的是 qalgora-Q 规范中的接口(或第三方库),开放参考实现目前尚未内置,仅用于说明预期用法;如需立即运行,请使用参考实现已支持的核心 API。
注意事项
from_cirq/to_cirq 适配器为规划接口。需保留 Cirq 的 LineQubit/GridQubit 映射;测量键(measurement key)、参数符号和 moment 结构可能需要适配。Google 硬件目标并非普通的开放云后端,因此这并不意味着可以直接向 Willow 等设备提交。
OpenFermion
用 OpenFermion(Cirq 生态的一部分)搭出的化学问题,可以直接映射成 qalgora-Q 的自旋算符做 VQE 计算——详见量子化学