qrisp.QuantumVariable.app_phase_function#
- QuantumVariable.app_phase_function(phi)[source]#
Applies a previously specified phase function to each computational basis state of the QuantumVariable using Gray-Synthesis.
For a given phase function \(\phi(x)\) and a QuantumVariable in state \(\ket{\psi} = \sum_{x \in \text{Labels}} a_x \ket{x}\) this method acts as:
\[U_{\phi} \sum_{x \in \text{Labels}} a_x \ket{x} = \sum_{x \in \text{Labels}} \text{exp}(i\phi(x)) a_x \ket{x}\]- Parameters:
- phiPython function
A Python function which turns the labels of the QuantumVariable into floats.
Examples
We create a QuantumFloat and encode the k-th basis state of the Fourier basis. Finally, we will apply an inverse Fourier transformation to measure k in the computational basis.
>>> import numpy as np >>> from qrisp import QuantumFloat, h, QFT >>> n = 5 >>> qf = QuantumFloat(n, signed = False) >>> h(qf)
After this, qf is in the state
\[\ket{\text{qf}} = \frac{1}{\sqrt{2^n}} \sum_{x = 0}^{2^n} \ket{x}\]We specify phi
>>> k = 4 >>> def phi(x): >>> return 2*np.pi*x*k/2**n
And apply phi as a phase function
>>> qf.app_phase_function(phi)
qf is now in the state
\[\ket{\text{qf}} = \frac{1}{\sqrt{2^n}} \sum_{x = 0}^{2^n} \text{exp}\left( \frac{2\pi ikx}{2^n}\right) \ket{x}\]Finally we apply the inverse Fourier transformation and measure:
>>> QFT(qf, inv = True) >>> print(qf) {4: 1.0}