ConjugationEnvironment#

class ConjugationEnvironment(conjugation_function, args, kwargs)[source]#

This QuantumEnvironment can be used for perfoming conjugated operations. An arbitrary unitary \(U \in SU(2^n)\) can be conjugated by another unitary \(V \in SU(2^n)\):

\[\text{conj}(U,V) = V^\dagger U V\]

This structure appears in many quantum algorithms such as Grover, Quantum backtracking or Fourier arithmetic.

Using the ConjugationEnvironment not only helps to structure the code, but can also grant performance advantages.

This is because the controlled circuit of such a conjugation is can be realized by just controlling \(U\) instead of all three operations.

\[C\text{conj}(U,V) = V^\dagger CU V\]

The ConjugationEnvironment can be called using the alias conjugate. Conjugate takes the conjugation function (in our example \(V\)) and returns a function that takes the arguments for the conjugation function and returns the corresponding ConjugationEnvironment. For more information consult the examples section.

Note

Note that every QuantumVariable that is created by the conjugation function \(V\) must be deleted/uncomputed before function conclusion.

Parameters
conjugation_functionfunction

The function performing the operation \(V\).

argsiterable

The arguments for the conjugation function.

kwargsdict

The keyword arguments for the conjugation function.

Examples

We perform Fourier addition on a QuantumFloat

from qrisp import conjugate, QuantumFloat, p, QFT

def fourier_adder(qf, n):

    with conjugate(QFT)(qf):

        for i in range(qf.size):
            p(n*np.pi*2**(i-qf.size+1), qf[i])
>>> qf = QuantumFloat(5)
>>> fourier_adder(qf, 3)
>>> print(qf)
{3: 1.0}
>>> fourier_adder(qf, 2)
{5: 1.0}

Investigate the effects of a controlled addition:

from qrisp import control

ctrl = QuantumFloat(1)
qf = QuantumFloat(5)

with control(ctrl):
    fourier_adder(qf, 3)

To see that indeed only the conjugand has been controlled we take a look at the circuit:

>>> print(qf.qs.transpile(1))
ctrl.0: ─────────■──────────■─────────■─────────■─────────■─────────────────
        ┌──────┐ │P(3π/16)  │         │         │         │      ┌─────────┐
  qf.0: ┤0     ├─■──────────┼─────────┼─────────┼─────────┼──────┤0        ├
        │      │            │P(3π/8)  │         │         │      │         │
  qf.1: ┤1     ├────────────■─────────┼─────────┼─────────┼──────┤1        ├
        │      │                      │P(3π/4)  │         │      │         │
  qf.2: ┤2 QFT ├──────────────────────■─────────┼─────────┼──────┤2 QFT_dg ├
        │      │                                │P(3π/2)  │      │         │
  qf.3: ┤3     ├────────────────────────────────■─────────┼──────┤3        ├
        │      │                                          │P(3π) │         │
  qf.4: ┤4     ├──────────────────────────────────────────■──────┤4        ├
        └──────┘                                                 └─────────┘