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

Python API

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

The most common entry points of the qalgora-Q Python package, grouped by purpose.

Reference-build status
The Status column reflects the open reference build: Supported = runs today on the local CPU NumPy simulator; Spec API = documented specification interface, not implemented in the open build yet; Planned = a distribution or hardware path not released yet. See Capability Coverage for the full matrix.

Program construction

SymbolPurposeStatus
@qalgora.kernelDecorate a function as a quantum kernelSupported
qalgora.make_kernel()Build a kernel imperatively at runtimeSpec API
qalgora.qubit / qvector / qviewAllocate qubits inside a kernelSupported

Kernel execution

FunctionReturnsStatus
sample() / sample_async()Measured bitstring histogramSupported
run() / run_async()List of typed kernel return valuesSpec API
observe() / observe_async()Expectation valuesSupported
get_state() / get_state_async()Full simulated stateSupported
vqe()Run a variational eigensolver loopSpec API
evolve() / evolve_async()Time-evolve a systemSupported

Backend configuration

FunctionPurposeStatus
set_target() / get_target()Choose / query the execution backendSupported
get_targets()List available targetsSupported
set_noise() / unset_noise()Attach a global noise modelSupported
num_available_gpus()Count usable GPUsPlanned

Data types

TypeRole
SampleResultCounts; most_probable(), probability(b), expectation(), get_marginal_counts()
ObserveResultExpectation values; expectation(), per-term access
EvolveResultDynamics output of evolve; expectation_values() returns a 2-D array of shape [n_observables, n_steps] (one row per observable, one column per time step), plus the final and any saved intermediate State objects
StateStatevector / density matrix; indexable, amplitude(b), dump()
SpinOperatorPauli sum; get_term_count(), get_qubit_count(), iterable
Targetnum_qubits, native_gates, connectivity

Submodules

ModuleKey members
qalgora.optimizersCOBYLA, NelderMead, LBFGS, Adam, SGD, SPSA
qalgora.gradientsParameterShift, CentralDifference, ForwardDifference
qalgora.spinx(i), y(i), z(i), i(i)
qalgora.operatorsboson, fermion, scalar, spin (dynamics)
qalgora.dynamics / ScheduleIntegrators and time schedules for evolve
qalgora.mpiinitialize(), rank(), num_ranks(), all_gather(), finalize()

Inspection & utilities

FunctionPurposeStatus
draw(kernel, *args, format=)ASCII or LaTeX circuit diagramSpec API
get_ir(kernel)Dump the qalgora IRSpec API
estimate_resources(kernel, *args)Gate count, depth, qubit countSpec API
set_random_seed(n)Reproducible samplingSupported
register_operation(name, matrix)Add a custom unitary gateSpec API · not implemented
Python ↔ C++ parity
In the planned full interface, the Python and C++ API aim to stay conceptually aligned in the qalgora:: namespace; the current public reference build provides only a subset of these features, on the Python side. See also the operations reference.

Python API

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

qalgora-Q Python 包中最常用的入口,按用途分组整理。

参考实现状态
状态列反映开放参考实现的现状:参考实现已支持表示当前可在本地 CPU NumPy 模拟器上运行;规范接口·暂未实现表示已写入规范、开放实现暂未提供;规划中·尚未发布表示分发或硬件路径尚未发布。完整对照见能力覆盖

程序构建

符号用途状态
@qalgora.kernel将函数修饰为量子内核参考实现已支持
qalgora.make_kernel()在运行时以命令式方式构建内核规范接口·暂未实现
qalgora.qubit / qvector / qview在内核内部分配量子比特参考实现已支持

内核执行

函数返回值状态
sample() / sample_async()测量比特串直方图参考实现已支持
run() / run_async()带类型的内核返回值列表规范接口·暂未实现
observe() / observe_async()期望值参考实现已支持
get_state() / get_state_async()完整模拟态参考实现已支持
vqe()运行变分本征求解器循环规范接口·暂未实现
evolve() / evolve_async()对系统进行时间演化参考实现已支持

后端配置

函数用途状态
set_target() / get_target()选择或查询执行后端参考实现已支持
get_targets()列出可用目标后端参考实现已支持
set_noise() / unset_noise()附加或移除全局噪声模型参考实现已支持
num_available_gpus()统计可用 GPU 数量规划中·尚未发布

数据类型

类型说明
SampleResult计数;包含 most_probable()probability(b)expectation()get_marginal_counts()
ObserveResult期望值;包含 expectation() 及逐项访问
EvolveResultevolve 的动力学输出;expectation_values() 返回形状为 [n_observables, n_steps] 的二维数组(每个可观测量一行,每个时间步一列),并附带末态及保存的中间 State
State态矢量 / 密度矩阵;支持索引、amplitude(b)dump()
SpinOperatorPauli 和;包含 get_term_count()get_qubit_count(),可迭代
Targetnum_qubitsnative_gatesconnectivity

子模块

模块主要成员
qalgora.optimizersCOBYLANelderMeadLBFGSAdamSGDSPSA
qalgora.gradientsParameterShiftCentralDifferenceForwardDifference
qalgora.spinx(i)y(i)z(i)i(i)
qalgora.operatorsbosonfermionscalarspin(动力学)
qalgora.dynamics / Schedule用于 evolve 的积分器与时间表
qalgora.mpiinitialize()rank()num_ranks()all_gather()finalize()

检查与工具

函数用途状态
draw(kernel, *args, format=)ASCII 或 LaTeX 格式的电路图规范接口·暂未实现
get_ir(kernel)导出 qalgora IR规范接口·暂未实现
estimate_resources(kernel, *args)门数、深度、量子比特数规范接口·暂未实现
set_random_seed(n)可复现采样参考实现已支持
register_operation(name, matrix)添加自定义幺正门规范接口·暂未实现
Python 与 C++ 对应
在规划中的完整接口中,Python 与 C++ APIqalgora:: 命名空间下尽量保持概念对应;当前公开参考实现仅提供 Python 侧的一部分功能。另请参阅操作参考