Generating QHAM input from a PDE expression

English · 简体中文

This example first defines the Burgers equation, then sets up a second-order HAM plan. Creating the plan expands no tensor block and builds no complete matrix. The unknown field is a Field, the equation is frozen into a PolynomialPDE, and the second-order plan is stored in a QHAMPlan.

from oracq.applications.qham import Field, PolynomialPDE, QHAMPlan

u = Field("u")
pde = PolynomialPDE.from_equations({"u": 0.1*u.d("x", 2) - u*u.d("x")})
plan = QHAMPlan(pde, order=2)
restored = QHAMPlan.loads(plan.dumps())
print([(port.name, port.arity) for port in pde.ports])
print(plan.block_count, plan.max_rank, plan.order)
assert restored == plan
assert any(port.arity == 2 for port in pde.ports)
[('L', 1), ('B_1', 2)]
8 3 2

The printed results show: the PDE decomposes into one linear port L and one second-order multilinear port B_1; the plan records only 8 tensor blocks, a maximum rank of 3, and a truncation order of 2 — no block is expanded and no complete matrix is built. The nonlinear terms of the PDE are represented as multilinear ports. Once a grid and boundary are chosen, structured_fd_bindings can produce BEs for these ports from shifts, coefficient multipliers, and same-point contractions; alternatively, declare the ports open first and wait for a data-access implementation.

The quantum assembly entry point qham_input_model produces the lifted operator and the initial state required by QODE. From there the linear solution method can be replaced, and a physical output channel representing the sum of the HAM orders can be chosen.

For a cached prepare() / inspect / execute workflow with independently replaceable grids and initial oracles, see Composing PDE inputs and solve instances.

Run the complete example:

uv run python examples/general_qham.py
uv run python -m oracq.applications.qham --example burgers --order 2 --eta=-0.4

To check the derivation formulas, read the QHAM mathematical derivation. To bind concrete oracles, read the QHAM implementation notes. The algebraic representation of the truncated HAM and the convergence towards the original PDE must be validated separately.

The complete script and its step-by-step walkthrough are in Scientific computing workflows, which also contrasts the inputs, solver choices, and binding boundaries of Carleman, LCHS, and CBMD.