qrisp.QuantumVariable.duplicate#

QuantumVariable.duplicate(name: str | None = None, qs: QuantumSession | None = None, init=False, qubits: list[Qubit] | DynamicQubitArray | None = None)[source]#

Duplicate a QuantumVariable.

Duplicates the QuantumVariable in the sense that a new QuantumVariable is created with same type and parameters but initialized in the \(\ket{0}\) state.

Parameters:
namestring, optional

A unique name to identify that QuantumVariable. If not given, a name will be generated.

qsQuantumSession, optional

A QuantumSession, where the result should be registered. If not given, a new QuantumSession will be generated. Passing a TracingQuantumSession is ignored gracefully, at run-time.

initbool, optional

If set to True, the init_from method of the result will be called on self. The default is False.

qubitslist[Qubit] | DynamicQubitArray, optional

Qubits to initialize the duplicated quantum variable from. If not provided self.size is used for qubits extraction. The object is used as the duplicate’s register as is (not copied), so passing another QuantumVariable’s reg makes both share it: deleting, extending or reducing the duplicate also affects that QuantumVariable.

Returns:
duplicateType of self

The duplicated QuantumVariable.

Raises:
Exception

If merging the duplicate’s quantum session with qs fails.

TracingModeError

If init is True while tracing, since initializing from another QuantumVariable is not supported in a TracingQuantumSession.

Exception

If init is True and the provided qubits are not fresh.

Examples

We create a QuantumFloat and duplicate:

>>> from qrisp import QuantumFloat
>>> qf_0 = QuantumFloat(4, signed = False)
>>> qf_1 = qf_0.duplicate()
>>> type(qf_1)
qrisp.qtypes.quantum_float.QuantumFloat
>>> qf_1.size
4