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:
ProtocolStructural protocol for quantum-operation generators.
Any callable that is invoked with arbitrary positional and keyword arguments and returns an
Operationstructurally 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:
OracleViewView representing a linear operator by its zero-signal projected corner block.
The wrapped
Operationcontains exactly the two bits registerstargetandsignal, and declares a finite positive normalization constant through the module attributebe_alpha: if the zero-signal corner block of the unitaryUsatisfies<0|U|0> = A/alpha, this view treatsUas a block encoding of the operatorA. 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:
- property alpha¶
The normalization constant declared in the
be_alphamodule attribute.
- property width¶
Bit width of the
targetregister.
- property signal_qubits¶
Bit width of the
signalregister.
- oracq.algorithms.input_model.operators.block_encoding(operation, alpha=1.0)[source]¶
Wrap an operation with the
target/signalsignature as a block encoding.Writes
be_alphaandoracle_paradigminto the module attributes and deterministically renames the module by content; the signature and alpha constraints are checked by theBlockEncodingconstructor.- Parameters:
operation – An
Operationcontaining exactly thetargetandsignalbits registers.alpha – Finite positive normalization constant, defaulting to one.
- Returns:
Block-encoding view with the attributes filled in.
- Return type:
- 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:
- oracq.algorithms.input_model.operators.pauli_x(width)[source]¶
Build the block encoding of the tensor power of
widthX gates; alpha is one with no signal bit.- Parameters:
width – Target register bit width.
- Returns:
Block encoding of
X^⊗width.- Return type:
- 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:
- oracq.algorithms.input_model.operators.product(a, b)[source]¶
Compose the matrix product
A·Bof two block encodings.The two operations act in turn on the shared
target(bfirst, thena), with the signal bits concatenated at the high end fora; the returned block encoding has alphaa.alpha * b.alphaand 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:
- 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 alphaabs(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:
- 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*Bof two block encodings.A single select bit branches in the weight ratio of
abs(ca)*a.alphaandabs(cb)*b.alpha; each branch compensates its coefficient phase viaglobal_phasebefore acting on the sharedtarget. 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 toscale.- 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:
- Raises:
ValidationError – The target widths differ, or any coefficient contains a non-finite component.