Quantum gradient estimation¶
oracq.algorithms.optimization.gradient
Jordan quantum gradient estimation: a phase oracle input model and single-query gradient readout.
Implements the gradient estimation of Jordan 2005 (PRL 95, 050501). Grid
convention: the i-th coordinate register occupies the bit segment
[i*grid_bits, (i+1)*grid_bits), and the integer value k corresponds to the
fixed-point grid point x = k/N with N = 2**grid_bits. The scaling convention
matches the generalization of Gilyén–Arunachalam–Wiebe 2019: the phase
oracle implements O|x> = exp(2πi·N·f(x))|x>, i.e. phase_scale must equal
N. When f is approximately linear on the grid, a single oracle call plus an
inverse QFT per coordinate writes N·∂f/∂x_i into the i-th coordinate
register; one query yields all d components, while classical deterministic
evaluation of the same gradient takes O(d) function queries.
- class oracq.algorithms.optimization.gradient.PhaseOracle(operation)[source]¶
Bases:
OracleViewGrid phase oracle view: the diagonal phase action of
O|x> = exp(2πi·phase_scale·f(x))|x>.Integer values of target encode d-dimensional fixed-point grid points; the scaling factor is recorded in the phase_scale attribute so the algorithm side can verify the scaling convention at generation time.
- oracle_kind = 'phase_oracle'¶
- operation¶
- phase_oracle()[source]¶
Return the phase oracle view; this class itself wraps a phase oracle, so it returns itself.
- Returns:
A reference to itself, keeping the role accessor interface uniform.
- Return type:
- property width¶
Bit width of the target register, i.e. the total width of the grid register the phase oracle acts on.
- property phase_scale¶
The phase scaling factor declared by the oracle, i.e. the scale in
O|x> = exp(2πi·phase_scale·f(x))|x>.
- oracq.algorithms.optimization.gradient.abstract_phase_oracle(name, width, *, phase_scale)[source]¶
Open-declare a phase oracle; the phase scale is written into the phase_scale attribute and the implementation is left for bind.
- Parameters:
name – Declared module name of the phase oracle slot.
width – Bit width of the target register, in 1..64.
phase_scale – Phase scaling factor, a positive real, registered along with the attribute declaration.
- Returns:
Handle of the phase oracle slot with an empty body, whose implementation is bound later by bind.
- Return type:
- oracq.algorithms.optimization.gradient.gate_phase_oracle(width, angles, *, phase_scale, name=None)[source]¶
Build a diagonal phase oracle from an explicit phase table; angles[x] is the phase in radians gained by basis state
|x>.Small-scale witnesses can enumerate all 2**width phases directly; larger grids should use function_phase_oracle instead or bind another implementation.
- Parameters:
width – Bit width of the target register, in 1..64.
angles – Table of phases in radians per basis state, of length exactly 2**width.
phase_scale – Phase scaling factor, a positive real, registered into the attributes.
name – Name of the generated module; generated from the parameters by default.
- Returns:
Oracle handle that applies the diagonal phase per basis state according to the phase table.
- Return type:
- oracq.algorithms.optimization.gradient.function_phase_oracle(source, *, dimension, grid_bits, fmt=None, scale=None, name=None, constants=None, helpers=None, config=None, max_unroll=128, entry=None)[source]¶
Build a phase oracle from mathfunc arithmetic: compute fixed-point f(x), kick the phase back from the output, then restore.
- Parameters:
source – Source of a pure Python function with signature f(x0, …, x{d-1}) returning a single real.
dimension – Grid dimension d, in 1..16.
grid_bits – Bits m per coordinate; the grid points x = k/2**m must be exactly representable by fmt.
fmt – Fixed-point format, default FixedFormat(grid_bits+12, grid_bits+8); must be signed with fraction >= grid_bits.
scale – Phase scale, default 2**grid_bits, i.e. the Jordan scaling convention.
name – Overrides the automatically generated module name.
constants – Constant bindings passed to the mathfunc frontend.
helpers – Helper functions passed to the mathfunc frontend.
config – MathConfig passed to the mathfunc frontend.
max_unroll – Unrolling cap passed to the mathfunc frontend.
entry – Entry function name passed to the mathfunc frontend.
- Returns:
Phase
exp(2πi·scale·f(x)); when f leaves the value range of fmt this is flagged by status and the value is not guaranteed.- Return type:
The coordinate registers write the function inputs through zero-state work bits, the phase kickback decodes the output in two’s complement, and a subsequent inverse invocation restores all work bits.
- oracq.algorithms.optimization.gradient.gradient_estimation(oracle, *, dimension, grid_bits)[source]¶
Generate the Jordan gradient estimation circuit.
- Parameters:
oracle – A PhaseOracle or a phase oracle operation with the target signature implementing
O|x> = exp(2πi·N·f(x))|x>.dimension – Grid dimension d, in 1..16.
grid_bits – Bits m per coordinate register, N = 2**m, in 1..32.
- Returns:
Register target of width d*m. Decode the gradient components with gradient_from_readout after readout.
- Return type:
- Raises:
ValidationError – Invalid grid parameters, a mismatched oracle width,
or a phase_scale not equal to 2**grid_bits. –
Each coordinate register is prepared in uniform superposition, the phase oracle is invoked once, then an inverse QFT is applied per coordinate. When f is approximately linear the phase writes N·∂f/∂x_i into the Fourier basis of coordinate register i, and after the inverse QFT the readout is the fixed-point approximation of each component. One query yields all d components, while classical deterministic gradient evaluation takes O(d) function queries (Jordan 2005, PRL 95, 050501).
- oracq.algorithms.optimization.gradient.gradient_from_readout(value, *, dimension, grid_bits)[source]¶
Decode the integer readout of target into per-component gradient estimates.
- Parameters:
value – Integer readout of the target register.
dimension – Grid dimension.
grid_bits – Bits m per coordinate register.
- Returns:
The i-th component interprets the bit segment [i*m, (i+1)*m) in two’s complement and divides by 2**m.
- Return type:
tuple