Swapping QODE methods for the same linear problem

English · 简体中文

This example considers u'=-u. We represent the generator via a BE of -I, prepare the initial state with a single X gate, and then choose LCHS and Schrödingerization respectively. The generator is written as scale applied to identity, and the problem, together with its initial state, is packed into a QODEProblem.

from oracq import Bits, Builder, QODEProblem, identity, scale
from oracq.algorithms.qode.ode import linear_qode
from oracq.algorithms.common.hamiltonian import taylor_hamiltonian
from functools import partial

b = Builder("initial_one", {"q": Bits(1)})
b.x(b["q"])
problem = QODEProblem(scale(-1, identity(1)), b.finish(),
                      dissipative=True, initial_norm=1.0)
kernel = partial(taylor_hamiltonian, degree=1)
lchs = linear_qode("lchs", hamiltonian_function=kernel)
schrodinger = linear_qode("schrodingerization", hamiltonian_function=kernel)

assert lchs.check(problem, time=0.05).ok
assert schrodinger.check(problem, time=0.05).ok
first = lchs.solve(problem, 0.05)
second = schrodinger.solve(problem, 0.05)
print(first.width, second.width)
print(len(first.operation.program().modules), len(second.operation.program().modules))
assert first.width == second.width == 1
1 1
31 28

Both entry points are generated by linear_qode from the method name and share taylor_hamiltonian as the approximate simulation kernel. The printed results show: the two generators give the same target width 1 but differ in the number of internal modules (31 for LCHS, 28 for Schrödingerization), corresponding to different ancilla registers, approximation schemes, and recovery conditions. What this example checks is the assembly interface; a finite first-order Taylor kernel does not mean an arbitrary-accuracy solution of the differential equation has been obtained.

dissipative=True is part of the problem declaration. LCHS’s problem-level entry requires it to be stated explicitly; Schrödingerization relies on other mathematical conditions, in particular the choice of a suitable auxiliary window and recovery channel.

Starting from a PDE

A linear PDE first goes through spatial discretization into a DiscretePDE(generator, initial), which is then handed to make_qpde(qode). A nonlinear polynomial PDE can be turned into a PolynomialODE; Carleman generates the lifted system, which then calls the same three-argument linear-solver protocol.

Complete heat-equation, Burgers-equation, and various given-oracle examples live in:

uv run python examples/ode_input_models.py