Block encoding 组合¶
oracq.algorithms.input_model.block_encoding
Modular BEs, projectors, LCU, and small-matrix representation composition.
- oracq.algorithms.input_model.block_encoding.reflect_zero(builder, register, *, positive=False)[源代码]¶
Append the sign-flip reflection
I-2|0><0|about the zero state of the given register.- 参数:
builder -- Target Builder to append gates to.
register -- Register participating in the reflection; a fused view of several registers is accepted.
positive -- When True an extra global phase pi is applied, giving
2|0><0|-Iwith the zero-state component positive.
Shared by walk-type and amplitude-amplification-type algorithms.
- oracq.algorithms.input_model.block_encoding.pad_signal(a, width)[源代码]¶
Widen the signal register of a BE to the given width.
- 参数:
a -- Input block encoding.
width -- New signal bit width; must not be smaller than the original signal width.
- 返回:
Corner-block semantics and alpha unchanged, with the new high signal bits always zero, enabling late binding under the same signature.
- 返回类型:
- 抛出:
ValidationError -- Attempted to shrink the signal space.
- oracq.algorithms.input_model.block_encoding.tensor(a, b)[源代码]¶
Build the tensor product of two BEs.
- 参数:
a -- BE acting on the high target bits.
b -- BE acting on the low target bits.
- 返回:
Encodes A⊗B with alpha the product of the two; signal is likewise concatenated with a low and b high.
- 返回类型:
- oracq.algorithms.input_model.block_encoding.adjoint_be(a)[源代码]¶
Return the BE encoding the adjoint matrix A†.
- 参数:
a -- Input block encoding.
- 返回:
Invokes the original operation inside an adjoint context, with alpha unchanged.
- 返回类型:
- oracq.algorithms.input_model.block_encoding.lcu(terms)[源代码]¶
Assemble a linear combination of BEs in PREPARE/SELECT structure.
- 参数:
terms -- Sequence of (coefficient, BE) pairs; zero-coefficient terms are dropped.
- 返回:
Encodes Σ c_j A_j with alpha
Σ |c_j|*alpha_j; degenerates toscalefor a single term.- 返回类型:
- 抛出:
ValidationError -- There is no nonzero term, or the terms have inconsistent target widths.
The phases of complex coefficients are realized by selector-controlled global phases; signal is the concatenation of the select bits and each branch's signal bits, with a trailing inverse preparation restoring the selector.
- oracq.algorithms.input_model.block_encoding.kronecker_sum(a, b=None)[源代码]¶
Build the Kronecker sum A⊗I+I⊗B of two BEs.
- 参数:
a -- First BE.
b -- Second BE; defaults to a itself when omitted.
- 返回:
LCU of the two tensor terms, with alpha the sum of the two alphas.
- 返回类型:
- oracq.algorithms.input_model.block_encoding.projector(width, accepted)[源代码]¶
Build the projector BE onto the specified basis-state subspace.
- 参数:
width -- Target bit width.
accepted -- Set of accepted basis-state integer values; duplicates are merged and sorted.
- 返回:
The zero-signal corner block is the diagonal projector; basis states outside the set are kicked into the signal branch, with alpha 1.
- 返回类型:
- oracq.algorithms.input_model.block_encoding.direct_sum(a, b)[源代码]¶
Build the direct sum of same-width matrices.
- 参数:
a -- BE in effect when the select bit is 0.
b -- BE in effect when the select bit is 1; the width must equal a's.
- 返回:
Block-diagonal composition using the target's most significant bit as the select bit, with alpha the sum of the two.
- 返回类型:
- 抛出:
ValidationError -- The two BE widths differ.
- oracq.algorithms.input_model.block_encoding.truncated_shift(width, last)[源代码]¶
Build the truncated up-shift BE.
- 参数:
width -- Target bit width.
last -- Truncation threshold, in the range 1..2**width-1.
- 返回:
The zero-signal corner block maps basis state v to v+1 for v below last; other basis states are kicked into the signal branch, with alpha 1.
- 返回类型:
- 抛出:
ValidationError -- last is outside the allowed range.
- oracq.algorithms.input_model.block_encoding.pauli_word(word)[源代码]¶
Encode a Pauli string as a BE without signal bits.
- 参数:
word -- String over I/X/Y/Z whose first character acts on the least significant bit.
- 返回:
Explicit per-bit single-qubit gate sequence, with alpha 1.
- 返回类型:
- 抛出:
ValidationError -- A character outside I/X/Y/Z appears.
- oracq.algorithms.input_model.block_encoding.matrix_pauli_encoding(matrix, *, drop_tolerance=1e-12)[源代码]¶
Explicit gate implementation for small applications; claims no quantum speedup for matrix input or classical expansion.
- 参数:
matrix -- Square complex matrix of power-of-two dimension, at most 32 (i.e. 5 qubits).
drop_tolerance -- Pauli coefficient terms with magnitude not exceeding this tolerance are dropped.
- 返回:
LCU block encoding of the Pauli expansion; the zero operator when all coefficients are dropped.
- 返回类型: