is_two_power#
Functionality#
There are two versions to identify whether an integer \(y\) is a power of \(2\).
is_two_power_phase.py#
Callaee: Is2PowerPhase
Given an \(n\)-qubit computational basis state \(\ket{y}_n\), this phase-version program computes a Boolean function:
The Boolean function is defined as:
The input state is defined as \(\ket{y}_n = |q_{n-1} \cdots q_1 q_0\rangle_n\), where \(y\) is the decimal value of the binary string \(q_{n-1} \cdots q_0\). We regard \(q_0\) as the least significant qubit and \(q_{n-1}\) as the most significant qubit.
Test expectations:
The result is encoded as a phase flip on the corresponding basis state of \(y\). It is a global phase, which can be directly inspected on a statevector-based backend, but not directly observable by measurement.
Doc references: [5]
is_two_power_qubit.py#
Callable: Is2PowerQubit
The qubit version stores the result into the most significant qubit involved in the entire quantum circuit:
Test expectations:
The result is encoded in one auxiliary qubit via XOR. When \(\ket{x}_1\) is initialized as \(\ket{0}_1\), its final state turns out to be \(\ket{\mathrm{IS2POWER}(y)}_1\), which can be directly observed by measurement.
Doc references: [5]
API#
qolumbina.programs.is_two_power.is_two_power_phase#
- class Is2PowerPhase(input_qubits, name=None)[source]#
Bases:
QuantumCircuitImplements Q# operation
Is2Power_P: Checks if the input qubit register represents a 2-power. Uses MultiX (X on all qubits) and MCZ (emulated via H-MCX-H).- Parameters:
input_qubits (int) – Number of qubits in the input register (\(n\)).
name (str | None) – Optional name for the circuit.
qolumbina.programs.is_two_power.is_two_power_qubit#
- class Is2PowerQubit(input_qubits, name=None)[source]#
Bases:
QuantumCircuitQubit version of
Is2Power_Qoperation.Acts on n input qubits and 1 target qubit. Flips the target qubit when the input qubits represent a power of 2, following the original Q#
Is2Power_Qlogic.- Parameters:
input_qubits (int) – Number of qubits in the input register (\(n\)).
name (str | None) – Optional name for the circuit.