qrisp.lifted#
- lifted(*args, verify=False)[source]#
Shorthand for
gate_wrap(permability = "args", is_qfree = True).A lifted function is
qfreeand 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 theverifykeyword on a small scale first.- Parameters:
- verifybool, optional
If set to
True, the specified information about permeability andqfree-ness will be checked numerically. The default isFalse.
Examples
We create a function performing the Margolus gate. As it contains
ryrotations, there are non-qfreesteps involved. Putting on thelifteddecorator however marks the function asqfreeas 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 controlNote that we set the
verifykeyword toTruein 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.