空间离散与经典参考¶
oracq.applications.qham.reference
Small-scale mathematical witnesses: finite-difference ports and independent HAM/chain-rule evaluation, not quantum simulation.
- class oracq.applications.qham.reference.SpatialGrid(*args, **kwargs)[源代码]¶
基类:
ProtocolGrid access needed by polynomial PDE discretization.
A grid defines discrete derivative rows; coordinates alone do not specify a discretization. Quantum implementations may supply their own encodings.
- property axes¶
Names of the spatial axes, in index order.
- property size¶
Total number of grid samples across all axes.
- property spatial_width¶
Address width in qubits of the padded spatial coordinate.
- oracq.applications.qham.reference.centered_weights(order)[源代码]¶
Compute the weights of a unit-step one-dimensional centered difference stencil.
The derivative interpolation conditions are solved by exact rational elimination on integer lattice points centered at the origin; the result is exact for polynomials of degree below the point count. Zero weights are dropped.
- 参数:
order -- Derivative order, a non-negative integer.
- 返回:
(lattice offset, weight)pairs where the weight is a float for unit step size; usage still requires division byspacing**order. The result is cached per order.- 返回类型:
tuple
- class oracq.applications.qham.reference.Grid(axes, shape, spacing, boundary='periodic')[源代码]¶
基类:
objectSpatial discretization grid: axes, shape, spacing, and boundary type, with indexing and difference stencils.
Linear grid indices use a mixed-radix layout with axis 0 in the least significant position;
coordinatesandaddressare inverse mappings of each other.- 变量:
axes (tuple[str, ...]) -- Tuple of spatial axis names, must match the PDE axes.
shape (tuple[int, ...]) -- Number of grid points per axis, all positive integers.
spacing (tuple[float, ...]) -- Grid point spacing per axis, all positive finite values.
boundary (str) -- Boundary type:
periodicwraps out-of-range coordinates by the axis length;dirichlet_zerodrops out-of-range stencil points by zero extension.
- 抛出:
ValidationError -- Axis counts disagree, the shape or spacing is invalid, or the boundary type is unsupported.
- axes¶
- shape¶
- spacing¶
- boundary = 'periodic'¶
- property size¶
Total number of grid points, i.e. the product of all
shapeentries.
- property spatial_width¶
Bit width required to index a spatial coordinate, at least 1.
Spatial storage is aligned to
1 << spatial_width, which may exceedsize.
- coordinates(index)[源代码]¶
Decompose a linear grid index into per-axis coordinates; inverse of
address.- 参数:
index -- Linear grid index.
- 返回:
Per-axis coordinates, axis 0 in the least significant position, with the same length as
shape.- 返回类型:
list[int]
- address(coords)[源代码]¶
Combine per-axis coordinates into a linear grid index.
- 参数:
coords -- Sequence of per-axis coordinates; its length must match
shape.- 返回:
Linear grid index under the mixed-radix layout.
- 返回类型:
int
- derivative_row(derivative, row)[源代码]¶
Compute the sparse difference row of a mixed spatial derivative at a given grid point.
One-dimensional centered difference stencils are composed axis by axis, with weights already divided by the matching power of
spacing; the periodic boundary wraps out-of-range points whiledirichlet_zerodrops them.- 参数:
derivative -- Derivative specification built from
(axis name, order)pairs.row -- Linear grid index.
- 返回:
(column address, weight)pairs sorted by column address, zero weights dropped; an empty tuple whenrowis out of range. The result is cached by(derivative, row).- 返回类型:
tuple
- 抛出:
ValueError --
derivativereferences an axis not present inaxes.
- oracq.applications.qham.reference.tensor_values(vectors)[源代码]¶
Compute the tensor product of several vectors flattened into a one-dimensional complex list.
Factor 0 occupies the least significant position: the index stride of the k-th factor is the product of the lengths of the preceding factors; with no factors a single-element
[1+0j]is returned.- 参数:
vectors -- Sequence of factor vectors.
- 返回:
Flattened tensor product, with length equal to the product of the factor lengths.
- 返回类型:
list[complex]
- oracq.applications.qham.reference.digits(value, dimension, count)[源代码]¶
Decompose a non-negative integer into
countdigits in a fixed radix, least significant digit first.Inverse of
pack; the part ofvalueabovecountdigits is discarded.- 参数:
value -- Non-negative integer to decompose.
dimension -- Radix base.
count -- Number of output digits.
- 返回:
Tuple of digits with length
count.- 返回类型:
tuple[int, ...]
- oracq.applications.qham.reference.pack(values, dimension)[源代码]¶
Combine a least-significant-first digit sequence into an integer in a fixed radix; inverse of
digits.- 参数:
values -- Digit sequence; the i-th entry carries weight
dimension**i.dimension -- Radix base.
- 返回:
Weighted sum of the digits.
- 返回类型:
int
- class oracq.applications.qham.reference.Discretization(pde, grid, known=None)[源代码]¶
基类:
objectClassical spatial discretization reference for a polynomial PDE on a grid.
The single-component state is addressed with
widthbits: the lowgrid.spatial_widthbits are the padded spatial coordinates and the highcomponent_widthbits select the field component; the row rules for port matrix elements and closure generators are both evaluated from difference stencils and cached.- 参数:
pde -- The
PolynomialPDEto discretize; validated again at construction.grid -- Grid whose spatial axes match the PDE.
known -- Known coefficient and forcing data, keyed by known field name with numeric sequences of length equal to the grid point count as values; must cover every known field referenced by the PDE.
- 变量:
component_width -- Bit width of the field component index.
width -- Total bit width of a single-component state.
dimension -- Dimension of a single-component state,
2**width.spatial_storage -- Storage length occupied by each field component,
2**spatial_width.ports -- Mapping from port name to
OperatorPort.
- 抛出:
ValidationError -- The PDE fails validation, the PDE and grid spatial axes differ, known data is missing, or a known data length differs from the grid point count.
- pde¶
- grid¶
- component_width¶
- width¶
- dimension¶
- spatial_storage¶
- known¶
- ports¶
- known_value(atom, row)[源代码]¶
Evaluate a known-field atom at a physical grid point.
The difference stencil of
atom.derivativeis applied to the known data foratom.nameand summed with weights.- 参数:
atom -- Known-field atom, possibly carrying a spatial derivative specification.
row -- Physical grid point index.
- 返回:
Value of the known field or its derivative at the grid point, cached by
(atom, row).- 返回类型:
complex
- known_product(monomial, row)[源代码]¶
Evaluate the product of the known part of a monomial at a physical grid point.
- 参数:
monomial -- PDE monomial.
row -- Physical grid point index.
- 返回:
Running product of
monomial.coefficientand the values of the known-field atoms, each carrying its own difference.- 返回类型:
complex
- entry(key, row, column)[源代码]¶
Evaluate a single matrix element of a multilinear port.
The row is a single-component state index (component and spatial coordinates) and the column packs
arityinput state indices in a least-significant-first mixed radix; after matching output and input components term by term, the contributions of the outer derivative, known coefficients, and each field derivative are computed with difference stencils.- 参数:
key -- Port name, e.g.
L,F, orB_i.row -- Output row index.
column -- Packed input column index.
- 返回:
The matrix element; 0 when the row or column is out of range. The result is cached by
(key, row, column).- 返回类型:
complex
- row_entries(key, row)[源代码]¶
Enumerate a row from the base difference stencils without scanning N^arity input coordinates.
- 参数:
key -- Port name, e.g.
L,F, orB_i.row -- Output row index.
- 返回:
(packed column index, weight)pairs sorted by column, zero weights dropped; an empty tuple whenrowis out of range. The result is cached by(key, row).- 返回类型:
tuple
- qcl_row(plan, eta, row)[源代码]¶
Enumerate one row of the QCL closure generator under global lifted indices.
plan.locatefirst locates the owning block of the row and its local index, then each linear edge embeds the portrow_entriesinto the source block coordinates and multiplies the homotopy weight evaluated ateta.- 参数:
plan --
QHAMPlanclosure plan.eta -- Homotopy parameter.
row -- Global row index within the closure system.
- 返回:
(global column index, weight)pairs sorted by column, zero weights dropped; an empty tuple whenrowis out of range.- 返回类型:
tuple
- qcl_entry(plan, eta, row, column)[源代码]¶
Classical entry reference usable for review; does not masquerade as a reversible quantum oracle.
- 参数:
plan --
QHAMPlanclosure plan.eta -- Homotopy parameter.
row -- Global row index within the closure system.
column -- Global column index within the closure system.
- 返回:
Matrix element of the closure generator at the given row and column; 0 when either index is out of range.
- 返回类型:
complex
- apply_port(key, vectors)[源代码]¶
Differentiate and multiply the fields directly, for independent validation of the port and closure rules.
- 参数:
key -- Port name, e.g.
L,F, orB_i.vectors -- Sequence of input state vectors; its length must equal the port arity and each vector must have length
dimension.
- 返回:
Multilinear evaluation of the port with length
dimension.- 返回类型:
list[complex]
- ham_rhs(values, eta)[源代码]¶
Compute the classical right-hand sides of the order components
Ui'by the HAM recursion.U0' = L U0 + f;Ui' = L Ui - eta*sum_l (1+eta)^(i-1-l) C_l, whereC_lis the multilinear evaluation of the nonlinear ports on the order splitl.- 参数:
values -- Order components
[U0, ..., Um], each a vector of lengthdimension.eta -- Homotopy parameter.
- 返回:
List of vectors with the same length as
values; the i-th entry isUi'.- 返回类型:
list
- 抛出:
ValidationError -- Some vector length differs from
dimension.
- lift(plan, values)[源代码]¶
Lift the order components into the block layout of the closure system.
The physical block holds the sum of the order components; tensor blocks hold the tensor products of their factors via
tensor_values; the empty-word constant block is identically 1.- 参数:
plan --
QHAMPlanclosure plan.values -- Order-component vectors
[U0, ..., Um].
- 返回:
Lifted vector with length
plan.raw_dimension(dimension).- 返回类型:
list[complex]
- chain_rule(plan, values, eta)[源代码]¶
Compute the time derivative of the lifted vector directly with the product rule.
Each tensor-factor position of the
liftoutput is differentiated and the order-wiseUi'fromham_rhssubstituted; the result should agree component by component with the generator matrix acting on the lifted vector, forming an independent mathematical witness.- 参数:
plan --
QHAMPlanclosure plan.values -- Order-component vectors
[U0, ..., Um].eta -- Homotopy parameter.
- 返回:
Derivative vector with length
plan.raw_dimension(dimension).- 返回类型:
list[complex]
- 抛出:
ValidationError -- Some vector length differs from
dimension.
- linear_action(plan, eta, values)[源代码]¶
Act block row by block row, avoiding storage of raw_dimension^2 matrix elements.
- 参数:
plan --
QHAMPlanclosure plan.eta -- Homotopy parameter.
values -- Lifted vector of length
plan.raw_dimension(dimension).
- 返回:
Vector after the closure generator acts, with the same length as the input vector.
- 返回类型:
list[complex]
- matrix(plan, eta, *, max_dimension=512)[源代码]¶
Materialize the full square matrix of the closure generator.
- 参数:
plan --
QHAMPlanclosure plan.eta -- Homotopy parameter.
max_dimension -- Maximum total dimension allowed for materialization.
- 返回:
Square complex matrix of order
plan.raw_dimension(dimension), organized by row.- 返回类型:
list
- 抛出:
ValidationError -- The total dimension exceeds
max_dimension.
- encode_fields(values)[源代码]¶
Pack initial data given per field component into a single-component state vector.
- 参数:
values -- Mapping keyed by field component name with data sequences of length equal to the grid point count as values; must cover all components.
- 返回:
Vector of length
dimensionwhose c-th component occupies the coordinates[c*spatial_storage, c*spatial_storage+size).- 返回类型:
tuple[complex]
- 抛出:
ValidationError -- The component set is incomplete or a data length mismatches.