Quantum State Preparation#

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

This method performs quantum state preparation. Given a vector \(b=(b_0,\dotsc,b_{N-1})\), the function acts as

\[\ket{0} \rightarrow \sum_{i=0}^{N-1}b_i\ket{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.

methodstr, optional

String to specify the compilation method. Available are qiskit, qswitch and auto. qiskit is more gate-efficient but qswitch can also process dynamic arrays. The default is auto.

Examples

We create a QuantumFloat and prepare the state \(\sum_{i=0}^3b_i\ket{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}