qrisp.QuantumVariable.delete#

QuantumVariable.delete(verify=False, recompute=False)[source]#

This method is for deleting a QuantumVariable and thus freeing up and resetting the used qubits.

Note that this method has a different function than the destructor. Calling this method will tell the QuantumSession to mark the used qubits as free and apply a reset gate. If set to True, the keyword verify will cause a simulation to check, wether the deleted qubits are in the \(\ket{0}\) state prior to resetting. This is helpfull during debugging, as it indicates wether the uncomputation of this QuantumVariable was successfull.

After deletion, the QuantumVariable object is basically unchanged but an error will be raised if further operations on the deleted qubits are attempted.

Parameters:
verifybool, optional

If this bool is set to True, Qrisp will verify that the deleted qubits are indeed in the \(\ket{0}\) state. The default is False.

recomputebool, optional

If set to True, this QuantumVariable can be recomputed if it is required for the uncomputation of another QuantumVariable. For more information on the (dis)advantages check recomputation. The default is False.

Raises:
Exception

Tried to delete qubits not in |0> state.

Examples

We create a QuantumVariable, execute some gates and try to delete with verify = True

>>> from qrisp import QuantumVariable, x, h
>>> qv = QuantumVariable(2)
>>> x(qv[0])
>>> h(qv[1])
>>> qv.delete(verify = True)
Exception: Tried to delete qubits not in |0> state.

We now (manually) uncompute the gates

>>> x(qv[0])
>>> h(qv[1])
>>> qv.delete(verify = True)
>>> qv.is_deleted()
True
>>> x(qv[0])
Exception: Tried to perform operation x on unallocated qubit qv_1.0.