Block-encoding composition

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)[source]

Append the sign-flip reflection I-2|0><0| about the zero state of the given register.

Parameters:
  • 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|-I with the zero-state component positive.

Shared by walk-type and amplitude-amplification-type algorithms.

oracq.algorithms.input_model.block_encoding.pad_signal(a, width)[source]

Widen the signal register of a BE to the given width.

Parameters:
  • a – Input block encoding.

  • width – New signal bit width; must not be smaller than the original signal width.

Returns:

Corner-block semantics and alpha unchanged, with the new high signal bits always zero, enabling late binding under the same signature.

Return type:

BlockEncoding

Raises:

ValidationError – Attempted to shrink the signal space.

oracq.algorithms.input_model.block_encoding.tensor(a, b)[source]

Build the tensor product of two BEs.

Parameters:
  • a – BE acting on the high target bits.

  • b – BE acting on the low target bits.

Returns:

Encodes A⊗B with alpha the product of the two; signal is likewise concatenated with a low and b high.

Return type:

BlockEncoding

oracq.algorithms.input_model.block_encoding.adjoint_be(a)[source]

Return the BE encoding the adjoint matrix A†.

Parameters:

a – Input block encoding.

Returns:

Invokes the original operation inside an adjoint context, with alpha unchanged.

Return type:

BlockEncoding

oracq.algorithms.input_model.block_encoding.lcu(terms)[source]

Assemble a linear combination of BEs in PREPARE/SELECT structure.

Parameters:

terms – Sequence of (coefficient, BE) pairs; zero-coefficient terms are dropped.

Returns:

Encodes Σ c_j A_j with alpha Σ |c_j|*alpha_j; degenerates to scale for a single term.

Return type:

BlockEncoding

Raises:

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)[source]

Build the Kronecker sum A⊗I+I⊗B of two BEs.

Parameters:
  • a – First BE.

  • b – Second BE; defaults to a itself when omitted.

Returns:

LCU of the two tensor terms, with alpha the sum of the two alphas.

Return type:

BlockEncoding

oracq.algorithms.input_model.block_encoding.projector(width, accepted)[source]

Build the projector BE onto the specified basis-state subspace.

Parameters:
  • width – Target bit width.

  • accepted – Set of accepted basis-state integer values; duplicates are merged and sorted.

Returns:

The zero-signal corner block is the diagonal projector; basis states outside the set are kicked into the signal branch, with alpha 1.

Return type:

BlockEncoding

oracq.algorithms.input_model.block_encoding.direct_sum(a, b)[source]

Build the direct sum of same-width matrices.

Parameters:
  • 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.

Returns:

Block-diagonal composition using the target’s most significant bit as the select bit, with alpha the sum of the two.

Return type:

BlockEncoding

Raises:

ValidationError – The two BE widths differ.

oracq.algorithms.input_model.block_encoding.truncated_shift(width, last)[source]

Build the truncated up-shift BE.

Parameters:
  • width – Target bit width.

  • last – Truncation threshold, in the range 1..2**width-1.

Returns:

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.

Return type:

BlockEncoding

Raises:

ValidationError – last is outside the allowed range.

oracq.algorithms.input_model.block_encoding.pauli_word(word)[source]

Encode a Pauli string as a BE without signal bits.

Parameters:

word – String over I/X/Y/Z whose first character acts on the least significant bit.

Returns:

Explicit per-bit single-qubit gate sequence, with alpha 1.

Return type:

BlockEncoding

Raises:

ValidationError – A character outside I/X/Y/Z appears.

oracq.algorithms.input_model.block_encoding.matrix_pauli_encoding(matrix, *, drop_tolerance=1e-12)[source]

Explicit gate implementation for small applications; claims no quantum speedup for matrix input or classical expansion.

Parameters:
  • 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.

Returns:

LCU block encoding of the Pauli expansion; the zero operator when all coefficients are dropped.

Return type:

BlockEncoding