L2 原生调度接口

从 qaiji.core.native 显式导入;包根与 qaiji.core 不导出这些名称。

相关页面:数值范围与不支持的情形见 L2 原生调度; 完整往返示例见 L2 原生调度:生成、认证与桥接。

入口与异常

lower_to_native(circuit, config, *, conditional_frame="physical") 返回已独立认证的 NativeScheduleIR。conditional_frame 只能用关键字传入,取值为 "physical" 或 "tracked";其他取值抛出 NativeInputError。"physical" 在条件体内用 RX90 补偿净帧。 "tracked" 保留净帧非零的比特上的 RZ 与 Z,并把这些比特列入 tracked_qubits。 validate_native_schedule(circuit, schedule, config) 返回 NativeValidationReport; 语义失败由报告表达,结构或输入类型错误仍可能抛出异常。 qubic_mapping(circuit, schedule, config) 重新认证后返回 NativeProjection。 投影不支持经典特性。认证通过后,它仍拒收含经典变量、经典赋值、谓词或追踪比特的调度, 并抛出 NativeInputError。异常的 path 指向首个经典特性。检查次序为 tracked_qubits、 assignments、谓词、classical_vars。 配置始终由调用者提供,没有设备默认值。

NativeInputError 继承 QaijiIRError 与 ValueError,含 code、path;构造记录时, 以及 JSON、来源或配置中出现的结构错误,使用此异常。NativeValidationError 继承 QaijiIRError,含 report 与展平的 issues;生成调度或投影 遇到认证失败时抛出。调用方应分别捕获输入错误与认证失败;JSON 解码成功不表示认证成功。

报告按 source、rules、hp、schedule 分层,组证据另见 groups。 CheckResult.status 的取值为 pass、fail、not_run、 not_applicable;仅 fail 状态包含 issues。 valid 要求来源层与时序层通过,规则层与矩阵层通过或不适用;未运行不算通过。 失败报告的 all_results_ready_ns 为 None。

记录字段

下列记录均不可修改、采用 slots、仅接受关键字参数,且不可哈希; 列表或元组输入会复制为元组。 NativeScheduleIR 的两个版本字段、classical_vars、assignments 与 tracked_qubits 有默认值,后三项默认为空。ConditionRegion 的 bit_index 与 predicate 默认为 None。 其余字段均显式提供。 source_kernel_ref 使用现有 L5 固定配方的 sha256: 引用。 SourceLocation.gate_index 为顶层索引;顶层操作为 body_offset=None,条件体内操作的 body_offset 为体内索引。 SourceGroup 的 [op_start, op_stop) 连续覆盖操作,每组的 ordinal 从零开始。 测量 event_id 按事件列表顺序为 m0、m1……;条件标识为 c 加顶层索引。 ConditionRead 按寄存器位序关联最新事件。 ConditionRegion.predicate 是结果为 BitType 的表达式。给出谓词时,register_name、width、 value 与 bit_index 都为 None。bit_index 给出时,条件只检测寄存器的这一位。 ClassicalAssignment 记录源序第 gate_index 个节点,它把 expr 的值写入经典变量 target。 reads 按比特序列出表达式引用的每个寄存器比特所读的测量事件,at_ns 是值可用的时刻。

公开记录字段(构造时均仅接受关键字参数)

类型

字段

CheckResult

status, issues

ClassicalAssignment

gate_index, target, expr, reads, at_ns

ConditionRead

bit_index, event_id

ConditionRegion

condition_id, gate_index, register_name, width, value, reads, op_start, op_stop, start_ns, end_ns, bit_index, predicate

GroupEvidence

source, rule_id, rule, hp, expected_phase_rad, max_abs_residual

MeasurementEvent

event_id, source, operation_index, qubit, register_name, bit_index, end_ns, ready_ns

NativeIssue

code, path, source, operation_index, message

NativeOperation

kind, qubits, params, source, ordinal, start_ns, duration_ns, resources, condition_id

NativeProjection

source_kernel_ref, operations, conditions, events, end_ns, all_results_ready_ns

NativeScheduleIR

source_kernel_ref, num_qubits, registers, operations, groups, events, conditions, end_ns, schema_version, ruleset_version, classical_vars, assignments, tracked_qubits

NativeValidationReport

source, rules, hp, schedule, groups, all_results_ready_ns

OperationSpec

kind, qubits, duration_ns, resources, result_latency_ns

ProjectedOperation

operation_index, operation, labels, event_id, result_ready_ns

QubitResource

qubit, resource

RegisterDecl

name, size

ScheduleConfig

qubit_resources, operation_specs, cz_couplings

SourceGroup

source, rule_id, op_start, op_stop, phase_rad

SourceLocation

gate_index, body_offset

ProjectedOperation.labels 为中性消费标签,测量项同时带 event_id 与 result_ready_ns。NativeProjection.events 和 conditions 保留完整关联。 NativeScheduleIR.to_json() 先重新检查声明字段,再序列化这些字段; NativeScheduleIR.from_json(text) 恢复完整调度记录,不保存配置或认证报告; 读回记录后,须再次调用 validate_native_schedule 认证。

自动生成的接口说明

原生调度的不可修改记录、显式配置及认证接口。

class qaiji.core.native.CheckResult(*, status: 'str', issues: 'tuple[NativeIssue, ...]')[源代码]

基类:object

参数:
status: str
issues: tuple[NativeIssue, ...]
class qaiji.core.native.ClassicalAssignment(*, gate_index, target, expr, reads, at_ns)[源代码]

基类:object

源序第 gate_index 个节点:把 expr 的值写入经典变量 target。

reads 按比特序列出表达式引用的每个寄存器比特所读的测量事件;at_ns 是值可用的时刻。

参数:
gate_index: int
target: str
expr: Const | Var | Not | Binary
reads: tuple[ConditionRead, ...]
at_ns: int
class qaiji.core.native.ConditionRead(*, bit_index: 'int', event_id: 'str')[源代码]

基类:object

参数:
  • bit_index (int)

  • event_id (str)

bit_index: int
event_id: str
class qaiji.core.native.ConditionRegion(*, condition_id: 'str', gate_index: 'int', register_name: 'str | None', width: 'int | None', value: 'int | None', reads: 'tuple[ConditionRead, ...]', op_start: 'int', op_stop: 'int', start_ns: 'int', end_ns: 'int', bit_index: 'int | None' = None, predicate: 'ClassicalExpr | None' = None)[源代码]

基类:object

参数:
  • condition_id (str)

  • gate_index (int)

  • register_name (str | None)

  • width (int | None)

  • value (int | None)

  • reads (tuple[ConditionRead, ...])

  • op_start (int)

  • op_stop (int)

  • start_ns (int)

  • end_ns (int)

  • bit_index (int | None)

  • predicate (Const | Var | Not | Binary | None)

condition_id: str
gate_index: int
register_name: str | None
width: int | None
value: int | None
reads: tuple[ConditionRead, ...]
op_start: int
op_stop: int
start_ns: int
end_ns: int
bit_index: int | None
predicate: Const | Var | Not | Binary | None

结果为 BitType 的谓词;给出时寄存器字段与 bit_index 都为 None。

class qaiji.core.native.GroupEvidence(*, source: 'SourceLocation', rule_id: 'str', rule: 'CheckResult', hp: 'CheckResult', expected_phase_rad: 'float | None', max_abs_residual: 'float | None')[源代码]

基类:object

参数:
source: SourceLocation
rule_id: str
rule: CheckResult
hp: CheckResult
expected_phase_rad: float | None
max_abs_residual: float | None
class qaiji.core.native.MeasurementEvent(*, event_id: 'str', source: 'SourceLocation', operation_index: 'int', qubit: 'int', register_name: 'str', bit_index: 'int', end_ns: 'int', ready_ns: 'int')[源代码]

基类:object

参数:
event_id: str
source: SourceLocation
operation_index: int
qubit: int
register_name: str
bit_index: int
end_ns: int
ready_ns: int
exception qaiji.core.native.NativeInputError(code, path, message)[源代码]

基类:QaijiIRError, ValueError

原生调度的输入或结构不符合要求。

参数:
class qaiji.core.native.NativeIssue(*, code: 'str', path: 'str', source: 'SourceLocation | None', operation_index: 'int | None', message: 'str')[源代码]

基类:object

参数:
code: str
path: str
source: SourceLocation | None
operation_index: int | None
message: str
class qaiji.core.native.NativeOperation(*, kind: 'str', qubits: 'tuple[int, ...]', params: 'tuple[float, ...]', source: 'SourceLocation', ordinal: 'int', start_ns: 'int', duration_ns: 'int', resources: 'tuple[str, ...]', condition_id: 'str | None')[源代码]

基类:object

参数:
kind: str
qubits: tuple[int, ...]
params: tuple[float, ...]
source: SourceLocation
ordinal: int
start_ns: int
duration_ns: int
resources: tuple[str, ...]
condition_id: str | None
class qaiji.core.native.NativeProjection(*, source_kernel_ref: 'str', operations: 'tuple[ProjectedOperation, ...]', conditions: 'tuple[ConditionRegion, ...]', events: 'tuple[MeasurementEvent, ...]', end_ns: 'int', all_results_ready_ns: 'int')[源代码]

基类:object

参数:
source_kernel_ref: str
operations: tuple[ProjectedOperation, ...]
conditions: tuple[ConditionRegion, ...]
events: tuple[MeasurementEvent, ...]
end_ns: int
all_results_ready_ns: int
class qaiji.core.native.NativeScheduleIR(*, source_kernel_ref: 'str', num_qubits: 'int', registers: 'tuple[RegisterDecl, ...]', operations: 'tuple[NativeOperation, ...]', groups: 'tuple[SourceGroup, ...]', events: 'tuple[MeasurementEvent, ...]', conditions: 'tuple[ConditionRegion, ...]', end_ns: 'int', schema_version: 'str' = 'qaiji.native_schedule.v0', ruleset_version: 'str' = 'qaiji.cz_basis.v1', classical_vars: 'tuple[ClassicalVar, ...]' = (), assignments: 'tuple[ClassicalAssignment, ...]' = (), tracked_qubits: 'tuple[int, ...]' = ())[源代码]

基类:object

参数:
source_kernel_ref: str
num_qubits: int
registers: tuple[RegisterDecl, ...]
operations: tuple[NativeOperation, ...]
groups: tuple[SourceGroup, ...]
events: tuple[MeasurementEvent, ...]
conditions: tuple[ConditionRegion, ...]
end_ns: int
schema_version: str
ruleset_version: str
classical_vars: tuple[ClassicalVar, ...]
assignments: tuple[ClassicalAssignment, ...]
tracked_qubits: tuple[int, ...]
to_json()[源代码]

Serialize a revalidated projection of the declared schedule fields.

返回类型:

str

static from_json(text)[源代码]

Restore a complete schedule from strict JSON text.

参数:

text (str)

返回类型:

NativeScheduleIR

exception qaiji.core.native.NativeValidationError(report)[源代码]

基类:QaijiIRError

原生调度未通过独立认证。

参数:

report (NativeValidationReport)

property issues: tuple[NativeIssue, ...]
class qaiji.core.native.NativeValidationReport(*, source: 'CheckResult', rules: 'CheckResult', hp: 'CheckResult', schedule: 'CheckResult', groups: 'tuple[GroupEvidence, ...]', all_results_ready_ns: 'int | None')[源代码]

基类:object

参数:
source: CheckResult
rules: CheckResult
hp: CheckResult
schedule: CheckResult
groups: tuple[GroupEvidence, ...]
all_results_ready_ns: int | None
property valid: bool
class qaiji.core.native.OperationSpec(*, kind: 'str', qubits: 'tuple[int, ...]', duration_ns: 'int', resources: 'tuple[str, ...]', result_latency_ns: 'int')[源代码]

基类:object

参数:
kind: str
qubits: tuple[int, ...]
duration_ns: int
resources: tuple[str, ...]
result_latency_ns: int
class qaiji.core.native.ProjectedOperation(*, operation_index: 'int', operation: 'NativeOperation', labels: 'tuple[str, ...]', event_id: 'str | None', result_ready_ns: 'int | None')[源代码]

基类:object

参数:
operation_index: int
operation: NativeOperation
labels: tuple[str, ...]
event_id: str | None
result_ready_ns: int | None
class qaiji.core.native.QubitResource(*, qubit: 'int', resource: 'str')[源代码]

基类:object

参数:
qubit: int
resource: str
class qaiji.core.native.RegisterDecl(*, name: 'str', size: 'int')[源代码]

基类:object

参数:
name: str
size: int
class qaiji.core.native.ScheduleConfig(*, qubit_resources: 'tuple[QubitResource, ...]', operation_specs: 'tuple[OperationSpec, ...]', cz_couplings: 'tuple[tuple[int, int], ...]')[源代码]

基类:object

参数:
qubit_resources: tuple[QubitResource, ...]
operation_specs: tuple[OperationSpec, ...]
cz_couplings: tuple[tuple[int, int], ...]
class qaiji.core.native.SourceGroup(*, source: 'SourceLocation', rule_id: 'str', op_start: 'int', op_stop: 'int', phase_rad: 'float')[源代码]

基类:object

参数:
source: SourceLocation
rule_id: str
op_start: int
op_stop: int
phase_rad: float
class qaiji.core.native.SourceLocation(*, gate_index: 'int', body_offset: 'int | None')[源代码]

基类:object

参数:
  • gate_index (int)

  • body_offset (int | None)

gate_index: int
body_offset: int | None
qaiji.core.native.equiv_level_of_native(report)[源代码]

返回原生验证报告支持的符号等价级别。

参数:

report (NativeValidationReport) -- 原生降级的验证报告。

返回:

报告无效时返回 None。每个组相位均为 0 或 None 时返回 EXACT, 否则返回 UP_TO_PHASE。

抛出:

TraceInputError -- report 不是 NativeValidationReport。

返回类型:

EquivLevel | None

qaiji.core.native.lower_to_native(circuit, config, *, conditional_frame='physical')[源代码]

从同一份电路快照生成原生调度,并独立认证其内容。

参数:
  • circuit (Circuit) -- 源电路。

  • config (ScheduleConfig) -- 排程配置。

  • conditional_frame (Literal['physical', 'tracked']) -- 条件体非零净帧的形式。"physical" 在条件体内用 RX90 补偿净帧。 "tracked" 保留这些比特的 RZ 与 Z,并把比特列入 tracked_qubits;它们的帧须在 运行时累加,RX90(φ) 须以 φ − F 播放。没有非零条件净帧时,两种形式的输出相同。

返回:

通过认证的原生调度。

抛出:
返回类型:

NativeScheduleIR

qaiji.core.native.qubic_mapping(circuit, schedule, config)[源代码]

重新捕获并认证电路来源,再构造中性操作记录。

投影不支持经典特性,所以认证通过后仍拒收含经典变量、经典赋值、谓词或追踪比特的调度。

参数:
返回类型:

NativeProjection

qaiji.core.native.validate_native_schedule(circuit, schedule, config)[源代码]

重建输入值,分别报告来源、规则、算符矩阵与时序的检查结果。

参数:
返回类型:

NativeValidationReport