qrisp.QuantumVariable.uncompute#
- QuantumVariable.uncompute(do_it=True, recompute=False)[source]#
Method for automatic uncomputation. Uses a generalized form of this algorithm.
For more information check the uncomputation documentation.
- Parameters:
- do_itbool, optional
If set to False, this variable will be appended to the uncomputation stack of itβs QuantumSession and uncomputed once an uncompute call with
do_it = Trueis performed. The default is True.- recomputebool, optional
If set to True, this QuantumVariable will be uncomputed but temporarily recomputed, if it is required for the uncomputation of another QuantumVariable. For more information check recomputation. The default is False.
Examples
We create two QuantumVariables, apply some gates and perform automatic uncomputation:
>>> from qrisp import QuantumVariable, x, cx, h, p, mcx >>> a = QuantumVariable(3) >>> b = QuantumVariable(2) >>> mcx(a, b[0]) >>> h(a[:2]) >>> x(b[0]) >>> cx(b[0], b[1]) >>> p(0.5, b[1]) >>> print(a.qs)
QuantumCircuit: -------------- βββββ a.0: βββ βββ€ H ββββββββββββββββ β βββββ€ a.1: βββ βββ€ H ββββββββββββββββ β βββββ a.2: βββ ββββββββββββββββββββββ βββ΄βββββββ b.0: β€ X ββ€ X ββββ ββββββββββββ βββββββββββββ΄ββββββββββββ b.1: βββββββββββ€ X ββ€ P(0.5) β βββββββββββββββ Live QuantumVariables: --------------------- QuantumVariable a QuantumVariable b>>> b.uncompute() >>> print(b.qs)
QuantumCircuit: -------------- ββββββββββ βββββββββββββββ a.0: β€0 ββββββββββββββββββββββββββββββββ€0 ββ€ H β β β β ββββββ€ a.1: β€1 ββββββββββββββββββββββββββββββββ€1 ββ€ H β β pt3cx β β pt3cx ββββββ a.2: β€2 ββββββββββββββββββββββββββββββββ€2 ββββββ β ββββββ ββββββ β b.0: β€3 ββ€ X ββββ βββββββββββββββ βββ€ X ββ€3 ββββββ ββββββββββββββββββ΄βββββββββββββββ΄βββββββββββββββββ b.1: ββββββββββββββββ€ X ββ€ P(0.5) ββ€ X βββββββββββββββββββββ ββββββββββββββββββββ Live QuantumVariables: --------------------- QuantumVariable a