qrisp.QuantumArray.duplicate#

QuantumArray.duplicate(init=False, qs=None)[source]#

This method returns a fresh QuantumArray, with equal qtype and shape.

Parameters
initbool, optional

If set to True, the init_from method will be called after creation. The default is False.

qsQuantumSession, optional

The QuantumSession where the duplicate should be registered. By default, the duplicate will be registered in a new QuantumSession.

Returns
resQuantumArray

The duplicated array.

Examples

We duplicate a QuantumArray consisting of QuantumFloats with and without initiation.

>>> from qrisp import QuantumArray, QuantumFloat
>>> qtype = QuantumFloat(4)
>>> q_array_0 = QuantumArray(qtype, (2,2))
>>> q_array_0[:] = np.ones((2,2))
>>> print(q_array_0)
{OutcomeArray([[1, 1],
               [1, 1]]): 1.0}
>>> q_array_1 = q_array_0.duplicate()
>>> print(q_array_1)
{OutcomeArray([[0, 0],
               [0, 0]]): 1.0}

Note that no values have been carried over:

>>> q_array_2 = q_array_0.duplicate(init = True)
>>> print(q_array_2)
{OutcomeArray([[1, 1],
               [1, 1]]): 1.0}

Now the values have been carried over. Note that this does NOT copy the state. For more information on this check the documentation of the init_from method of QuantumVariable.