Quantum State Preparation#

prepare(qv, target_array, reversed=False)[source]#

This method performs quantum state preparation. Given a vector b=(b0,,bN1), the function acts as

|0i=0N1bi|i
Parameters:
qvQuantumVariable

The quantum variable on which to apply state preparation.

target_arraynumpy.ndarray

The vector b.

reversedboolean

If set to True, the endianness is reversed. The default is False.

Examples

We create a QuantumFloat and prepare the state i=03bi|i for b=(0,1,2,3).

b = np.array([0,1,2,3])

qf = QuantumFloat(2)
prepare(qf, b)

res_dict = qf.get_measurement()

for k, v in res_dict.items():
    res_dict[k] = v**0.5

for k, v in res_dict.items():
    res_dict[k] = v/res_dict[1.0]

print(res_dict)
# Yields: {3: 2.9999766670425863, 2: 1.999965000393743, 1: 1.0}