QHAM 有限闭包

oracq.applications.qham.linearization

Lazily generate the QCL by HAM order and ordered tensor words; spatial matrices are not materialized.

oracq.applications.qham.linearization.compositions(total, length)[源代码]

Lazily enumerate all ordered splits of length non-negative integers summing to total, in increasing first-component order.

参数:
  • total -- Target sum, a non-negative integer.

  • length -- Number of components in each split.

返回:

Lazy generator yielding one split at a time without materializing all splits.

返回类型:

Iterator[tuple[int, ...]]

生成器:

tuple[int, ...] --

Ordered tuples of length length whose elements

sum to total; when length is 0 the empty tuple is yielded only if total is 0.

class oracq.applications.qham.linearization.HomotopyWeight(kind='one', power=0)[源代码]

基类:object

Coefficient on a QCL linear edge that varies with the homotopy parameter eta.

变量:
  • kind (str) -- Weight kind: one (identically 1), correction, or physical.

  • power (int) -- Exponent used by the correction and physical kinds.

kind = 'one'
power = 0
evaluate(eta)[源代码]

Evaluate the weight at the homotopy parameter eta.

参数:

eta -- Homotopy parameter value.

返回:

one is identically 1, correction is -eta*(1+eta)**power, and physical is 1-(1+eta)**power.

抛出:

ValidationError -- kind is not a supported weight kind.

formula()[源代码]

Return the formula text of the weight, with the homotopy parameter written eta.

返回:

Infix expression matching evaluate, e.g. -eta*(1+eta)^3.

返回类型:

str

class oracq.applications.qham.linearization.Block(kind, orders=())[源代码]

基类:object

One block variable of the QCL finite closure.

变量:
  • kind (str) -- Block kind; physical is the physical output block, the sum of the HAM order components, and tensor is a tensor block on independent coordinates.

  • orders (tuple[int, ...]) -- Tensor word, i.e. the ordered tuple of HAM orders of the factors; always the empty tuple for physical blocks, and the empty tuple with tensor denotes the constant block introduced by forcing homogenization.

kind
orders = ()
property rank

Number of tensor factors of the block; 1 for physical blocks and 0 for the empty-word constant block.

property label

Return the human-readable label of the block.

Physical blocks are u_sum, the empty-word constant block is one, and other tensor blocks are Y_ followed by the underscore-joined orders.

class oracq.applications.qham.linearization.Coupling(row, column, operator, position, arity, weight=HomotopyWeight(kind='one', power=0))[源代码]

基类:object

One linear edge of the QCL closure, delivering a column block's contribution into the row block's equation.

变量:
row
column
operator
position
arity
weight = HomotopyWeight(kind='one', power=0)
class oracq.applications.qham.linearization.QHAMPlan(pde, order, version='0.1')[源代码]

基类:object

QCL finite closure plan of a polynomial PDE at a HAM truncation order.

The closure is bounded by the weight criterion p*sum(orders)+len(orders) <= p*m+1, where p = max(1, D-1), D is the PDE polynomial degree, and m is the truncation order. The block set and each row rule are enumerated lazily; the closure matrix is never materialized.

变量:
  • pde (oracq.applications.qham.pde.PolynomialPDE) -- The PolynomialPDE, validated at construction.

  • order (int) -- HAM truncation order m, must be a non-negative integer.

  • version (str) -- Serialization format version, currently 0.1.

抛出:

ValidationError -- pde fails validation, or order is not a non-negative integer, or version is not 0.1.

pde
order
version = '0.1'
property grade

Degree scaling of the closure weight criterion, p = max(1, D-1), with D the PDE polynomial degree.

property max_rank

Closure weight bound p*m+1, the maximum tensor rank allowed for tensor blocks.

property has_forcing

Whether the PDE has a constant forcing term, i.e. port F exists and the closure needs the empty-word constant block.

weight(word)[源代码]

Compute the closure weight p*sum(word)+len(word) of a tensor word.

参数:

word -- Tuple of the HAM orders of the factors.

返回:

The closure weight of this tensor word.

返回类型:

int

contains(block)[源代码]

Test whether a block belongs to this plan's finite closure.

Physical blocks must carry no orders; the empty-word tensor block belongs only when forcing exists; other tensor blocks require every order to be a non-negative integer with closure weight within the bound; block kinds other than these never belong to the closure.

参数:

block -- The block to check.

返回:

True when the block belongs to the closure.

返回类型:

bool

rank_count(rank)[源代码]

Count the closure tensor blocks of a given tensor rank.

参数:

rank -- Number of tensor factors, counted from 1.

返回:

Number of tensor words of this rank satisfying the weight constraint; 0 when the rank is below 1 or above the bound.

返回类型:

int

property block_count

the physical block, the optional empty-word constant block, plus the tensor blocks of each rank.

Type:

Total closure block count

blocks(*, max_blocks=None)[源代码]

Lazily enumerate all blocks of the closure in canonical order.

The physical block comes first, tensor blocks follow by ascending rank and, within a rank, by ascending word sum (ties follow the compositions enumeration order), and the empty-word constant block, when forcing exists, comes last.

参数:

max_blocks -- Budget for explicitly enumerated blocks; when the total block count exceeds it an error is raised immediately, pointing to lazy queries instead.

返回:

Lazy generator yielding closure blocks one at a time without materializing the full block list.

返回类型:

Iterator[Block]

生成器:

Block -- A block of the closure.

抛出:

ValidationError -- max_blocks is given and the closure block count exceeds the budget.

row_terms(row)[源代码]

Enumerate all linear edges of a row block within the closure.

Three edge classes are covered: the same-word linear edge L; forcing insertion edges F (physical rows take the empty-word constant block, tensor rows take the word with that zero-order factor removed); and edges replacing a higher-order factor with a lower-order tuple and applying a nonlinear port, carrying a physical or correction homotopy weight. The row of the empty-word constant block has no edges.

参数:

row -- Row block, must belong to the closure.

返回:

All edges of this row; each edge's row field equals the input.

返回类型:

tuple[Coupling, ...]

抛出:
  • ValidationError -- The row block is outside the finite closure.

  • AssertionError -- A generated column block escapes the closure, i.e. the closure construction invariant is broken.

raw_dimension(dimension)[源代码]

Compute the total dimension of the closure linear system.

参数:

dimension -- Dimension of a single block's local state space.

返回:

Sum of the local dimensions of the physical block and each rank's tensor blocks (dimension**rank), plus the single coordinate of the empty-word constant block when forcing exists.

返回类型:

int

offset(block, dimension)[源代码]

Return the global start index of local coordinate 0 of a block within the closure system.

Blocks are laid out in the canonical order of blocks: the physical block first, each rank's tensor blocks occupying dimension**rank consecutive coordinates, and the empty-word constant block last with a single coordinate.

参数:
  • block -- A block within the closure.

  • dimension -- Dimension of a single block's local state space.

返回:

The starting global index of this block.

返回类型:

int

抛出:

ValidationError -- The block is outside the closure.

locate(index, dimension)[源代码]

Decompose a global index into its owning block and local index within the block; inverse of offset.

参数:
  • index -- Global index within the closure system.

  • dimension -- Dimension of a single block's local state space.

返回:

The block containing the index and the local index within it.

返回类型:

tuple[Block, int]

抛出:

ValidationError -- The index is outside the closure system's total dimension.

summary()[源代码]

Summarize the plan's key quantities for reports and diagnostics.

返回:

Dictionary with the version, truncation order, PDE degree, maximum tensor rank, total block count, whether forcing exists, a description of the closure criterion, and each port's arity.

返回类型:

dict

dumps()[源代码]

Serialize the plan to canonical JSON text.

返回:

JSON text with version, order, and pde fields, keys sorted, indentation 2, ending with a newline.

返回类型:

str

classmethod loads(text)[源代码]

Rebuild a plan from the JSON text produced by dumps.

参数:

text -- JSON text.

返回:

The rebuilt plan; validation runs again at construction.

返回类型:

QHAMPlan

抛出:

ValidationError -- The JSON structure, field set, or data is invalid.