qrisp.lifted#

lifted(*args, verify=False)[source]#

Shorthand for gate_wrap(permability = "args", is_qfree = True).

A lifted function is qfree and permeable on its inputs. The results of lifted functions can be automatically uncomputed even if they contain functions that could not be uncomputed on their own.

You can find more information about these concepts here or here. Note that the concept of permeability in Qrisp is a more general version of Silq’s const.

Warning

Incorrect information about permeability and qfree-ness can yield incorrect compilation results. If you are unsure, use the verify keyword on a small scale first.

Parameters:
verifybool, optional

If set to True, the specified information about permeability and qfree-ness will be checked numerically. The default is False.

Examples

We create a function performing the Margolus gate. As it contains ry rotations, there are non-qfree steps involved. Putting on the lifted decorator however marks the function as qfree as a whole.

from qrisp import QuantumVariable, cx, ry, lifted
from numpy import pi

@lifted(verify = True)
def margolus(control):

    res = QuantumVariable(1)
    ry(pi/4, res)
    cx(control[1], res)
    ry(-pi/4, res)
    cx(control[0], res)
    ry(pi/4, res)
    cx(control[1], res)
    ry(-pi/4, res)

    return res

control = QuantumVariable(2)
res = margolus(control)
>>> print(res.qs)
QuantumCircuit:
--------------
           ┌───────────┐
control.0: ┤0          ├
           │           │
control.1: ┤1 margolus ├
           │           │
    res.0: ┤2          ├
           └───────────┘
Live QuantumVariables:
---------------------
QuantumVariable control
QuantumVariable res
>>> res.uncompute()
>>> print(res.qs)
QuantumCircuit:
--------------
           ┌───────────┐┌──────────────┐
control.0: ┤0          ├┤0             ├
           │           ││              │
control.1: ┤1 margolus ├┤1 margolus_dg ├
           │           ││              │
    res.0: ┤2          ├┤2             ├
           └───────────┘└──────────────┘
Live QuantumVariables:
---------------------
QuantumVariable control

Note that we set the verify keyword to True in this example. In more complex functions, involving many qubits this feature should only be used for bug-fixing on a small scale, since the verification can be time-consuming.