qrisp.QuantumVariable.duplicate#
- QuantumVariable.duplicate(name: str | None = None, qs=None, init=False, qubits=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.
- initbool, optional
If set to True, the
init_frommethod 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.sizeis used for qubits extraction. The object is used as the duplicate’s register as is (not copied), so passing another QuantumVariable’sregmakes 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
qsfails.- TracingModeError
If
initis True while tracing, since initializing from another QuantumVariable is not supported in aTracingQuantumSession.- Exception
If
initis True and the providedqubitsare 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