Operator wrappers and basic composition

oracq.algorithms.input_model.operators

Block-encoding composition library; alpha is stored as an RIR module attribute and precision is not part of the language core.

class oracq.algorithms.input_model.operators.Generator(*args, **kwargs)[source]

Bases: Protocol

Structural protocol for quantum-operation generators.

Any callable that is invoked with arbitrary positional and keyword arguments and returns an Operation structurally satisfies this protocol; the algorithm side thereby accepts operation factories without binding a concrete generation signature.

class oracq.algorithms.input_model.operators.BlockEncoding(operation)[source]

Bases: OracleView

View representing a linear operator by its zero-signal projected corner block.

The wrapped Operation contains exactly the two bits registers target and signal, and declares a finite positive normalization constant through the module attribute be_alpha: if the zero-signal corner block of the unitary U satisfies <0|U|0> = A/alpha, this view treats U as a block encoding of the operator A. alpha participates in the composition algebra at generation time only; the executor does not scale quantum states by it.

Variables:

operation (oracq.infrastructure.builder.Operation) – The wrapped Operation.

oracle_kind = 'block_encoding'
operation
block_encoding()[source]

Return self; the view-adaptation method implementing BlockEncodingProtocol.

Returns:

This view itself.

Return type:

BlockEncoding

property alpha

The normalization constant declared in the be_alpha module attribute.

property width

Bit width of the target register.

property signal_qubits

Bit width of the signal register.

oracq.algorithms.input_model.operators.block_encoding(operation, alpha=1.0)[source]

Wrap an operation with the target/signal signature as a block encoding.

Writes be_alpha and oracle_paradigm into the module attributes and deterministically renames the module by content; the signature and alpha constraints are checked by the BlockEncoding constructor.

Parameters:
  • operation – An Operation containing exactly the target and signal bits registers.

  • alpha – Finite positive normalization constant, defaulting to one.

Returns:

Block-encoding view with the attributes filled in.

Return type:

BlockEncoding

Raises:

ValidationError – The operation violates the block-encoding signature or alpha constraint.

oracq.algorithms.input_model.operators.identity(width)[source]

Build the block encoding of the identity operator; alpha is one and no signal bit is needed.

Parameters:

width – Target register bit width.

Returns:

Block encoding of the identity operator.

Return type:

BlockEncoding

oracq.algorithms.input_model.operators.pauli_x(width)[source]

Build the block encoding of the tensor power of width X gates; alpha is one with no signal bit.

Parameters:

width – Target register bit width.

Returns:

Block encoding of X^⊗width.

Return type:

BlockEncoding

oracq.algorithms.input_model.operators.zero(width)[source]

Build the block encoding of the zero operator; a flipped signal bit makes the zero-signal corner block identically zero, with alpha one.

Parameters:

width – Target register bit width.

Returns:

Block encoding of the zero operator.

Return type:

BlockEncoding

oracq.algorithms.input_model.operators.product(a, b)[source]

Compose the matrix product A·B of two block encodings.

The two operations act in turn on the shared target (b first, then a), with the signal bits concatenated at the high end for a; the returned block encoding has alpha a.alpha * b.alpha and a signal width equal to the sum of both.

Parameters:
  • a – Left-factor block encoding.

  • b – Right-factor block encoding.

Returns:

Block encoding of A·B, with both operations kept as module calls.

Return type:

BlockEncoding

Raises:

ValidationError – The two target widths differ.

oracq.algorithms.input_model.operators.scale(coefficient, a)[source]

Scale the operator represented by a block encoding by a complex coefficient.

The coefficient phase is booked with global_phase, and the returned block encoding has alpha abs(coefficient) * a.alpha; when the coefficient is zero, zero(a.width) is returned directly.

Parameters:
  • coefficient – Finite complex coefficient.

  • a – The block encoding being scaled.

Returns:

Block encoding of coefficient * A.

Return type:

BlockEncoding

Raises:

ValidationError – The real or imaginary part of the coefficient is not finite.

oracq.algorithms.input_model.operators.linear_combination(ca, a, cb, b)[source]

Compose the linear combination ca*A + cb*B of two block encodings.

A single select bit branches in the weight ratio of abs(ca)*a.alpha and abs(cb)*b.alpha; each branch compensates its coefficient phase via global_phase before acting on the shared target. The returned block encoding has alpha equal to the sum of the two weights, and its signal bits carry one extra select bit beyond the two operations’ signals. When one coefficient is zero it degenerates to scale.

Parameters:
  • ca – Finite complex coefficient of a.

  • a – First block encoding.

  • cb – Finite complex coefficient of b.

  • b – Second block encoding.

Returns:

Block encoding of ca*A + cb*B.

Return type:

BlockEncoding

Raises:

ValidationError – The target widths differ, or any coefficient contains a non-finite component.