QFVM 应用¶
oracq.applications.qfvm
Build QFVM sparse inputs and a replaceable QLSS problem from a QRAM flow field and Roe arithmetic.
- class oracq.applications.qfvm.RoeQfvmInputs(cell_width, fmt, angle_width, rho, momentum, energy, geometry, theta, rhs, residual)[源代码]¶
基类:
objectThe set of abstract slots declared by the QFVM input model: raw field values, geometry, residual values and residual state preparation.
The slots themselves carry no data; implementations are bound by
bind_qfvmand runtime memory tables are materialized byqfvm_memories. Matrix elements are not pre-stored in any slot but are computed on the fly at query time by reversible Roe arithmetic.- 变量:
cell_width (int) -- Bit width of cell indices; the grid has
2**cell_widthcells.fmt (oracq.algorithms.common.arithmetic.FixedFormat) -- Fixed-point format used by conserved variables and residual values.
angle_width (int) -- Bit width of rotation angle words.
rho (oracq.algorithms.input_model.oracles.XorDatabase) -- Abstract declared slot of the density (first conserved variable) database.
momentum (oracq.algorithms.input_model.oracles.XorDatabase) -- Abstract declared slot of the momentum (second conserved variable) database.
energy (oracq.algorithms.input_model.oracles.XorDatabase) -- Abstract declared slot of the energy (third conserved variable) database.
geometry (oracq.algorithms.input_model.oracles.XorDatabase) -- Slot of the geometry table database; encodes only sparse positions and indices, no matrix values.
theta (oracq.algorithms.input_model.oracles.XorDatabase) -- Slot of the conversion table from residual fixed-point words to rotation angle words (reserved data plane).
rhs (oracq.algorithms.input_model.oracles.StatePreparation) -- Abstract slot of the normalized residual state preparation.
residual (oracq.algorithms.input_model.oracles.XorDatabase) -- Slot of the database of quantized residual values per (cell, component).
- cell_width¶
- fmt¶
- angle_width¶
- rho¶
- momentum¶
- energy¶
- geometry¶
- theta¶
- rhs¶
- residual¶
- property width¶
2 component bits + cell_width cell bits + 1 dilation half-block flag bit.
- Type:
Bit width of full matrix coordinates
- property geometry_width¶
seven packed segments for partner coordinate, symmetric slot, source cell, row and column components, source band and the valid bit.
- Type:
Bit width of geometry table words
- oracq.applications.qfvm.roe_qfvm_inputs(*, cell_width=2, fmt=None, angle_width=8, prefix='RoeQfvm')[源代码]¶
Declare the full set of abstract QFVM input slots: six databases plus one RHS state preparation.
Everything returned is an open slot without data; data only appears at binding time (
bind_qfvm) and execution time (qfvm_memories).- 参数:
cell_width -- Bit width of cell indices, in the range 2..25.
fmt -- Fixed-point format of conserved variables; defaults to
FixedFormat(6, 2).angle_width -- Bit width of rotation angle words, in the range 1..64.
prefix -- Prefix of the module names of the abstract slots.
- 返回:
The declared set, containing the three conserved-variable databases, the geometry table, the theta table, the residual value database and the abstract RHS preparation.
- 返回类型:
- 抛出:
ValidationError -- cell_width or angle_width out of range.
- oracq.applications.qfvm.geometry_cells(inputs)[源代码]¶
Encode only sparse positions and raw data indices; contains no flow field matrix values.
- 参数:
inputs -- The slot set declared by
roe_qfvm_inputs, determining coordinate widths and the geometry table layout.- 返回:
The geometry table contents; the address is a matrix coordinate concatenated with a 4-bit slot number, and the value is the seven-segment packed word of partner coordinate, reverse slot, source cell, row and column components, source band and valid bit.
- 返回类型:
dict[int, int]
- oracq.applications.qfvm.ptheta_cells(fmt, angle_width, amax)[源代码]¶
Generate the theta table: conversion from residual fixed-point words to rotation angle words
2*acos(min(1, |v|/amax)).- 参数:
fmt -- The fixed-point format; addresses cover all
2**fmt.widthraw words of the format.angle_width -- Bit width of output angle words.
amax -- Magnitude upper bound of elements, used to clamp the acos argument.
- 返回:
Mapping from raw fixed-point words to quantized angle words; angle words wrap modulo
2**angle_width.- 返回类型:
dict
- 抛出:
ValueError -- amax non-positive.
- oracq.applications.qfvm.roe_entry(inputs, *, gamma=1.4, entropy_delta=0.125, mass=1.0, dx=1.0)[源代码]¶
Build the reversible arithmetic circuit for a single Roe matrix element (without sparse addressing).
The three conserved-variable databases are queried for
sourceand its left and right neighbor cells (with periodic boundary wraparound),roe_facecomputes the flux characteristic components of the two faces, and the west, center and east candidate values are assembled byband; the mass term is added to the center block diagonal only when the row and column components coincide.- 参数:
inputs -- The slot set declared by
roe_qfvm_inputs, providing the conserved-variable databases and fixed-point format.gamma -- Ratio of specific heats.
entropy_delta -- Roe entropy fix coefficient.
mass -- The mass term, applied only to the component diagonal of the center block.
dx -- Grid step size.
- 返回:
Registers are source, row, col, band, value, status; value writes out the selected matrix element, and status aggregates the failure flags of the arithmetic nodes (non-zero means overflow or division by zero).
- 返回类型:
- oracq.applications.qfvm.roe_qfvm_block_encoding(inputs, *, amax=8.0, padding_value=1.0, **entry_options)[源代码]¶
Explicit conversion from sparse inputs to a block encoding; QFVM itself no longer forces exposing only a block encoding.
- 参数:
inputs -- The slot set declared by
roe_qfvm_inputs.amax -- Magnitude upper bound of sparse elements, used as the scaling factor of the block encoding.
padding_value -- The padding diagonal value; must be positive and no greater than
amax.**entry_options -- Arithmetic options forwarded to
roe_entry(gamma, mass and so on).
- 返回:
The real symmetric sparse block encoding of the Hermitian dilation of the Roe matrix.
- 返回类型:
- oracq.applications.qfvm.rhs_qram_preparation(inputs)[源代码]¶
Build the QRAM preparation of the normalized residual state: amplitudes come from the squared-norm tree, signs are written by phase kickback.
Amplitudes are obtained by
qram_state_prepquerying therhs_anglesangle word bank layer by layer; signs use the one-bitrhs_signbank, turning negative residual components into a pi phase through Load, Z and un-Load. The input is the zero state and work returns clean.- 参数:
inputs -- The slot set declared by
roe_qfvm_inputs, from which coordinate and angle word widths are taken.- 返回:
target holds the full matrix coordinate (cell_width+3 bits); amplitudes are written only on the first cell_width+2 bits, and the dilation half-block flag stays zero.
- 返回类型:
- oracq.applications.qfvm.qram_bindings(inputs)[源代码]¶
Provide the complete binding map from abstract QFVM slots to QRAM implementations.
The three conserved-variable databases, the geometry table and the theta table bind to actual
qram_databaselibraries (the table resource maps to the like-named classical bank); the residual value slot binds to theRoeResidualValuesdatabase (rhs_values); the RHS preparation slot binds to therhs_qram_preparationcircuit (angle word and sign resources map to rhs_angles and rhs_sign respectively).- 参数:
inputs -- The slot set declared by
roe_qfvm_inputs, providing all abstract slots to bind.- 返回:
Mapping from abstract slot module names to
Bindingobjects, ready to hand tobind.- 返回类型:
dict
- oracq.applications.qfvm.bind_qfvm(program, inputs)[源代码]¶
Bind the still-unresolved abstract QFVM slots in a program to QRAM implementations and the signed residual tree preparation.
- 参数:
program -- The program containing calls to abstract QFVM slots.
inputs -- The slot set declared by
roe_qfvm_inputs.
- 返回:
The program with only unresolved slots replaced; open slots unrelated to QFVM are left untouched.
- 返回类型:
- oracq.applications.qfvm.qfvm_memories(inputs, flow, *, amax=8.0)[源代码]¶
Materialize the runtime memory tables of the QFVM path: a flow field snapshot plus the static geometry table and theta table.
- 参数:
inputs -- The slot set declared by
roe_qfvm_inputs.flow -- Classical-side flow field data providing the snapshot of the six banks.
amax -- Magnitude upper bound of elements used by the theta table.
- 返回:
Memory tables handed to the execution backend by name: rho, momentum, energy, rhs_values, rhs_sign, rhs_angles, geometry and theta.
- 返回类型:
dict
- 抛出:
ValidationError -- The flow field mismatches the declared cell count, fixed-point format or angle format.
- oracq.applications.qfvm.roe_qfvm_problem(inputs, *, spectrum, rhs_norm=None, amax=8.0, padding_value=1.0, **entry_options)[源代码]¶
D=([[0,M],[M.T,0]] on physical coordinates) + padding_value*I_pad.
- 参数:
inputs -- The slot set declared by
roe_qfvm_inputs.spectrum -- A
SpectralPromisecovering the spectral bounds of the quantized Roe matrix; required.rhs_norm -- Classical right-hand-side norm; the physical magnitude of the solution can be recovered only when provided.
amax -- Magnitude upper bound of sparse elements.
padding_value -- The padding diagonal value; must be positive and no greater than
amax.**entry_options -- Arithmetic options forwarded to
roe_entry(gamma, mass and so on).
- 返回:
The QLSS linear system composed of the sparse access, the residual preparation and the extended spectral bounds with the padding value merged in.
- 返回类型:
- oracq.applications.qfvm.roe_qfvm_step(inputs, qlss, *, spectrum=None, rhs_norm=None, **options)[源代码]¶
Hand the QFVM problem to a replaceable QLSS protocol for solving.
- 参数:
inputs -- The slot set declared by
roe_qfvm_inputs.qlss -- A
QLSSProtocolthat declaresinput_model.spectrum -- A
SpectralPromisecovering the actually quantized matrix; required.rhs_norm -- Classical right-hand-side norm; only when provided can the solution magnitude be recovered via
SolveResult.recover_norm.**options -- Remaining keyword arguments forwarded to
roe_qfvm_problem, including amax, padding_value and matrix element arithmetic options.
- 返回:
The solution state, norm probe and adaptation records produced by the protocol.
- 返回类型:
- 抛出:
ValidationError -- qlss is not a
QLSSProtocoldeclaringinput_model, or spectrum is not provided.
- oracq.applications.qfvm.qfvm_sparse_access(inputs, *, padding_value=1.0, **entry_options)[源代码]¶
Build the CKS sparse access for QFVM: two oracles, an in-place position permutation and an arbitrary-coordinate matrix element XOR.
The location oracle queries the nine structural slots of each column and completes them into a full permutation via nine coherent value transpositions; the padded component has no neighbor structure, and its partner coordinate is rewritten as
column + rankto yield the padding diagonal. The entry oracle selects the source cell and component with the geometry table and callsroe_entryto compute the element on the fly: entries outside the structural domain are zero, entries with failed arithmetic are zeroed, and the diagonal of padded coordinates writes padding_value.- 参数:
inputs -- The slot set declared by
roe_qfvm_inputs.padding_value -- The padding diagonal value; must be a positive number exactly representable in the fixed-point format.
**entry_options -- Arithmetic options forwarded to
roe_entry(gamma, mass and so on).
- 返回:
Coordinate width
inputs.width, value widthinputs.fmt.width, sparsity 9.- 返回类型:
- 抛出:
ValidationError -- padding_value is non-positive or not exactly representable in the fixed-point format.