qrisp.QuantumFloat.quantum_bit_shift#
- QuantumFloat.quantum_bit_shift(shift_amount: int | QuantumFloat) None[source]#
Performs a bit shift in the quantum device.
While
exp_shiftperforms a bit shift in the compiler (thus costing no quantum gates), this method performs the bit shift on the hardware.This has the advantage that it can be controlled if called within a ControlEnvironment and furthermore admits bit shifts based on the state of a QuantumFloat.
Note
Bit shifts based on a QuantumFloat are currently only possible if both self and
shift_amountare unsigned.Warning
Quantum bit shifting extends the QuantumFloat (ie. it allocates additional qubits).
- Parameters:
- shift_amountint or QuantumFloat
The amount to shift.
- Raises:
- TypeError
Tried to shift QuantumFloat exponent by non-integer value
- Exception
Quantum-quantum bitshifting is currently only supported for unsigned arguments
Examples
We create a QuantumFloat and a QuantumBool to perform a controlled bit shift, then evaluate the resulting (superposed) state:
from qrisp import QuantumFloat, QuantumBool, h qf = QuantumFloat(4) qf[:] = 1 qbl = QuantumBool() h(qbl) with qbl: qf.quantum_bit_shift(2) print(qf.qs.statevector()) # Yields # sqrt(2)*(|1>*|False> + |4>*|True>)/2