Iterable Shifting#

cyclic_shift(iterable, shift_amount=1)[source]#

Performs a cyclic shift of the values of an iterable with logarithmic depth. The shifting amount can be specified.

Parameters
iterablelist[Qubit] or list[QuantumVariable] or QuantumArray

The iterable to be shifted.

shift_amountinteger or QuantumFloat, optional

The iterable will be shifted by that amount. The default is 1.

Examples

We create a QuantumArray, initiate a sequence of increments and perform a cyclic shift.

>>> from qrisp import QuantumFloat, QuantumArray, cyclic_shift
>>> import numpy as np
>>> qa = QuantumArray(QuantumFloat(3), 8)
>>> qa[:] = np.arange(8)
>>> cyclic_shift(qa, shift_amount = 2)
>>> print(qa)
{OutcomeArray([6, 7, 0, 1, 2, 3, 4, 5]): 1.0}

We do something similar to demonstrate the shift by quantum values. For this we initiate a QuantumFloat in the superposition of 0, 1 and -3.

>>> shift_amount = QuantumFloat(3, signed = True)
>>> shift_amount[:] = {0 : 3**-0.5, 1: 3**-0.5, -3 : 3**-0.5}
>>> qa = QuantumArray(QuantumFloat(3), 8)
>>> qa[:] = np.arange(8)
>>> cyclic_shift(qa, shift_amount)
>>> print(qa)
{OutcomeArray([0, 1, 2, 3, 4, 5, 6, 7]): 0.3333, OutcomeArray([7, 0, 1, 2, 3, 4, 5, 6]): 0.3333, OutcomeArray([3, 4, 5, 6, 7, 0, 1, 2]): 0.3333}