guppyalgos.primitives.subroutines.reflection

Reflection box.

Functions

cntrl_reflection_box(control, qreg, cnx_box)

Apply an externally controlled reflection about the all-zero state.

reflection_box(qreg, cnx_box)

Apply a Householder reflection about the all-zero state.

Classes

Reflection()

Guppy struct representing a reflection operator.

ReflectionCntrl()

Externally controlled reflection about an all-zero register state.

class guppyalgos.primitives.subroutines.reflection.Reflection

Guppy struct representing a reflection operator.

The operator is

\[R = I - 2\lvert 0^n\rangle\langle 0^n\rvert\]

and is used in the qubitization walk operator \(W = R L\).

cnx_method
compose(qreg)

Apply the reflection operator \(R\).

Parameters:

qreg – The qubit register on which to apply the reflection.

class guppyalgos.primitives.subroutines.reflection.ReflectionCntrl

Externally controlled reflection about an all-zero register state.

The struct packages the decomposition needed to apply cntrl_reflection_box() to an arbitrary n_qubits register. Its compose method negates only the joint basis state \(\lvert 1\rangle\lvert 0^n\rangle\), where the first qubit is the external control. It therefore acts as the identity when that control is \(\lvert 0\rangle\) and as \(I - 2\lvert 0^n\rangle\!\langle 0^n\rvert\) when it is \(\lvert 1\rangle\).

This callable wrapper is used by controlled qubitization to apply the reflection part of the walk operator conditionally. Both the external control and reflected register are borrowed and mutated in place.

Variables:

cnx_method – Decomposition of an n_qubits-controlled \(X\) used by the controlled reflection.

cnx_method
compose(control, qreg)

Apply the controlled all-zero reflection in place.

Parameters:
  • control – External control, active on \(\lvert 1\rangle\).

  • qreg – Register reflected about \(\lvert 0^n\rangle\) when control is active.

guppyalgos.primitives.subroutines.reflection.cntrl_reflection_box(control, qreg, cnx_box)

Apply an externally controlled reflection about the all-zero state.

This implements the joint operator

\[C(R) = \lvert 0\rangle\!\langle 0\rvert \otimes I + \lvert 1\rangle\!\langle 1\rvert \otimes \left(I - 2\lvert 0^n\rangle\!\langle 0^n\rvert\right),\]

where the first subsystem is control and the second is qreg. Equivalently, the amplitude of \(\lvert 1\rangle\lvert 0^n\rangle\) is negated and every other computational-basis amplitude is unchanged. If control is in a superposition, this conditional sign becomes a relative phase and may entangle it with qreg.

The qubits in qreg are implemented as open controls by conjugating them with \(X\). The resulting multi-controlled \(Z\) uses qreg as its controls, control as its target, and cnx_box for the underlying multi-controlled \(X\) decomposition. All arguments are borrowed and restored in place; the function allocates no persistent output register.

Parameters:
  • control – External control, active on \(\lvert 1\rangle\).

  • qreg – Register reflected about \(\lvert 0^n\rangle\) when the external control is active.

  • cnx_box – Decomposition of an n_qubits-controlled \(X\), used to implement the multi-controlled \(Z\).

guppyalgos.primitives.subroutines.reflection.reflection_box(qreg, cnx_box)

Apply a Householder reflection about the all-zero state.

The reflection operator is

\[R = I - 2\lvert 0^n\rangle\langle 0^n\rvert,\]

where \(\lvert 0^n\rangle\) is the all-zero state and \(I\) is the identity operator. It flips the sign of the all-zero state and leaves all other states unchanged. For one qubit, \(R = -Z\).

The reflection is implemented using a multi-controlled \(Z\) gate with open controls, decomposed using cnx_box. Thus, the gate is applied when every control qubit is in state \(\lvert 0\rangle\).