qml.BasisRotation

BasisRotation = <Subroutine: BasisRotation>[source]

Implements a circuit that performs an exact single-body basis rotation using Givens rotations and phase shifts.

The BasisRotation template performs the following unitary transformation \(U(u)\) determined by the single-particle fermionic generators as given in arXiv:1711.04789:

\[U(u) = \exp{\left( \sum_{pq} \left[\log u \right]_{pq} (a_p^\dagger a_q - a_q^\dagger a_p) \right)}.\]

The unitary \(U(u)\) is implemented efficiently by performing its Givens decomposition into a sequence of PhaseShift and SingleExcitation gates using the construction scheme given in Optica, 3, 1460 (2016). For real-valued, i.e., orthogonal \(u\), only SingleExcitation gates are required, except for a PauliZ phase flip for \(\operatorname{det}(u)=-1\). This can be expressed concisely by applying PhaseShift((1-det(u)) * π / 2).

See also

givens_decomposition() for the underlying matrix factorization.

Parameters:
  • wires (Iterable[Any]) – wires that the operator acts on

  • unitary_matrix (array) – matrix specifying the basis transformation

  • check (bool) – test unitarity of the provided unitary_matrix

Raises:
  • ValueError – if the provided matrix is not square.

  • ValueError – if length of the wires is less than two.

The BasisRotation template can be used to implement the evolution \(e^{iH}\) where \(H = \sum_{pq} V_{pq} a^\dagger_p a_q\) and \(V\) is an \(N \times N\) Hermitian matrix. When the unitary matrix \(u\) is the transformation matrix that diagonalizes \(V\), the evolution is:

\[e^{i \sum_{pq} V_{pq} a^\dagger_p a_q} = U(u)^\dagger \prod_k e^{i\lambda_k \sigma_z^k} U(u),\]

where \(\lambda_k\) denotes the eigenvalues of matrix \(V\), the Hamiltonian coefficients matrix.

>>> V = np.array([[ 0.53672126+0.j        , -0.1126064 -2.41479668j],
...               [-0.1126064 +2.41479668j,  1.48694623+0.j        ]])
>>> eigen_vals, eigen_vecs = np.linalg.eigh(V)
>>> umat = eigen_vecs.T
>>> wires = range(len(umat))
>>> def circuit():
...    qml.adjoint(qml.BasisRotation)(wires=wires, unitary_matrix=umat)
...    for idx, eigenval in enumerate(eigen_vals):
...        qml.RZ(eigenval, wires=[idx])
...    qml.BasisRotation(wires=wires, unitary_matrix=umat)
>>> circ_unitary = qml.matrix(circuit, wire_order=wires)()
>>> np.round(circ_unitary/circ_unitary[0][0], 3)
array([[ 1.   -0.j   , -0.   +0.j   , -0.   +0.j   , -0.   +0.j   ],
       [-0.   +0.j   , -0.516-0.596j, -0.302-0.536j, -0.   +0.j   ],
       [-0.   +0.j   ,  0.35 +0.506j, -0.311-0.724j, -0.   +0.j   ],
       [-0.   +0.j   , -0.   +0.j   , -0.   +0.j   , -0.438+0.899j]])

The BasisRotation is implemented with PhaseShift and SingleExcitation gates: >>> @qml.decompose(gate_set=qml.gate_sets.ALL_OPS) … def circ(): … qml.BasisRotation(wires=wires, unitary_matrix=umat) >>> print(qml.draw(circ)()) 0: ──Rϕ(-1.52)─╭G(1.38)──Rϕ(-1.62)─┤ 1: ──Rϕ(1.62)──╰G(1.38)────────────┤

For real-valued matrices, the decomposition only consists of SingleExcitation gates, except for one phase gate to account for negative determinants:

>>> from scipy.stats import ortho_group
>>> O = ortho_group.rvs(4, random_state=51)
>>> @qml.decompose(gate_set=qml.gate_sets.ALL_OPS)
... def circ():
...     qml.BasisRotation(wires=range(4), unitary_matrix=O)
>>> print(qml.draw(circ)())
0: ──Rϕ(3.14)─╭G(-3.19)──────────╭G(2.63)─┤
1: ─╭G(-3.13)─╰G(-3.19)─╭G(2.68)─╰G(2.63)─┤
2: ─╰G(-3.13)─╭G(-2.98)─╰G(2.68)─╭G(5.70)─┤
3: ───────────╰G(-2.98)──────────╰G(5.70)─┤

The basis rotation performed by BasisRotation implements a transformation in the qubit Hilbert space that corresponds to a simple basis change of fermionic creation operators, translated to qubits via the Jordan-Wigner mapping. The old fermionic creation operators \(a_p^\dagger\) and the new creation operators \(b_p^\dagger\) are related to each other by the following equation:

\[b_p^\dagger = \sum_{q}u_{pq} a_q^\dagger.\]

The effect of \(U(u)\), the rotation in qubit Hilbert space, is then

\[U(u) A_p^\dagger U(u)^\dagger = B_p^\dagger,\]

where \(A_p^\dagger\) and \(B_p^\dagger\) are the original and transformed creation operators under the Jordan-Wigner transformation, respectively.

Underlying matrix factorization

The rotation is irreducibly represented as a unitary \(N\times N\) matrix \(u\), which can be factorized into nearest-neighbour Givens rotations and individual phase shifts. Such a factorization of \(u\) is implemented in givens_decomposition().

The Givens rotations take the form

\[\begin{split}T_{k}(\theta) = \begin{pmatrix} 1 & 0 & \cdots & 0 & 0 & \cdots & 0 & 0 \\ 0 & 1 & & & & & 0 & 0 \\ \vdots & & \ddots & & & & & \vdots \\ 0 & & & \cos(\theta) & -\sin(\theta) & & & 0 \\ 0 & & & \sin(\theta) & \cos(\theta) & & & 0 \\ \vdots & & & & & \ddots & & \vdots \\ 0 & 0 & & & & & 1 & 0 \\ 0 & 0 & \cdots & 0 & 0 & \cdots & 0 & 1 \\ \end{pmatrix},\end{split}\]

where the four non-trivial entries are at indices \(k\) and \(k+1\). It will also be useful to look at the generator of \(T_{k}\):

\[T_k(\theta) = \exp(\theta E_{k,k+1}),\]

where \(E_{k,\ell}\) is a matrix that is zero everywhere except for a \(-1\) in position \((k,\ell)\) and a \(1\) in position \((\ell,k)\). The phase shifts in the decomposition read

\[P_{j}(\phi) = \operatorname{diag}(1,\cdots, 1, e^{i\phi}, 1, \cdots, 1),\]

with the single non-trivial entry at index \(j\). Such a phase shift is generated in the following form:

\[P_j(\phi) = \exp(i \phi D_{j}),\]

where \(D_j\) is zero everywhere except for a \(1\) in position \((j,j)\).

Next, we consider multiple Lie algebras generated by the \(E_{k,k+1}\) and \(D_j\), and in particular the full Lie algebra \(\mathfrak{g}\) generated by all of them:

\[\begin{split}\langle\{E_{k,k+1}\}_k\rangle_\text{Lie} &= \text{span}_{\mathbb{R}}\{E_{k,\ell} | 1\leq k<\ell\leq N\}\cong\mathfrak{so}(N)\\ \langle\{D_{j}\}_j\rangle_\text{Lie} &= \text{span}_{\mathbb{R}}\{D_{j} | 1\leq j\leq N\}\cong\mathfrak{u}(1)^N\\ \mathfrak{g}=\langle\{D_{j}\}_j\cup\{E_{k,k+1}\}_k\rangle_\text{Lie} &=\text{span}_{\mathbb{R}}\left(\{E_{k,\ell}, F_{k,\ell}| 1\leq k<\ell \leq N\}\cup\{D_{j}\}_j\right) \cong \mathfrak{u}(N).\end{split}\]

The full algebra \(\mathfrak{g}\) contains the matrices \(F_{k,\ell}\) that look like the matrices \(E_{k,\ell}\), but without any minus sign. There are N(N-1) / 2 matrices \(E\) and \(F\) each, and N matrices \(D\). So that all taken together span the \(N^2\)-dimensional algebra \(\mathfrak{u}(N)\).

Mapping the matrix factorization to a circuit

The factorization of \(u\) can be mapped to a quantum circuit by identifying:

\[\begin{split}T_{k}(\theta) &\mapsto \texttt{SingleExcitation}(2\theta,\texttt{wires=[k, k+1]}),\\ P_{j}(\phi) &\mapsto \texttt{PhaseShift}(\phi, \texttt{wires=[j]}).\end{split}\]

This identification is a group homomorphism, which is proven in arXiv:1711.04789. We can understand this by looking at the algebra to which this mapping sends the algebra \(\mathfrak{g}\) from above. The SingleExcitation gates have the generators \(\hat{E}_{k,k+1}=\tfrac{i}{2}(X_k Y_{k+1} - Y_k X_{k+1})\) (note the additional prefactor of \(2\) from the mapping):

>>> qml.generator(qml.SingleExcitation(0.2512, [0, 1]))
(X(0) @ Y(1) + -1.0 * (Y(0) @ X(1)), np.float64(0.25))

Similarly, the PhaseShift gates have the generators \(\hat{D}_j=\tfrac{i}{2}(\mathbb{I}-Z_j)=i|1\rangle\langle 1|_j\):

>>> qml.generator(qml.PhaseShift(0.742, [0]))
(Projector(array([1]), wires=[0]), 1.0)

It turns out that these generators \(\hat{E}_{k,k+1}\) and \(\hat{D}_j\) have commutation relations equivalent to those of the irreducible matrices above, with a crucial feature in how the identification \(E_{k,k+1}\mapsto \hat{E}_{k,k+1}\) generalizes. One could try to map, say, \(E_{2, 4}\) to \(\tfrac{i}{2}(X_2 Y_4 -Y_2 X_4)\), but this will not be consistent with the operators and commutation relations in the algebra. Instead, we need to insert strings of Pauli \(Z\) operators whenever the interaction encoded by the generator is not between nearest neighbours, so that \(E_{2,4}\) maps to \(\tfrac{i}{2}(X_2 Z_3 Y_4 -Y_2 Z_3 X_4)\), which we also denote as \(\tfrac{i}{2}(\overline{X_2 Y_4} -\overline{Y_2 X_4})\). Then we have

\[\begin{split}E_{k,\ell} & \mapsto \hat{E}_{k,\ell} = \tfrac{i}{2}(\overline{X_kY_\ell}-\overline{Y_kX_\ell}),\\ F_{k,\ell} & \mapsto \hat{F}_{k,\ell} = \tfrac{i}{2}(\overline{X_kX_\ell}+\overline{Y_kY_\ell}),\\ D_{j} & \mapsto \hat{D}_{j} = \tfrac{i}{2}(\mathbb{I}-Z_j).\end{split}\]

The fact that we need to use \(\overline{X_kY_\ell}\) instead of \(X_kY_\ell\) is a consequence of mapping fermions onto qubits via the Jordan-Wigner transformation. Depending on the application, the relative signs between operators in this mapping need to be evaluated with extra care.

Real rotation matrices

It is common for the orbital rotation matrix implemented by BasisRotation to be real-valued and thus orthogonal. The generators \(E_{k,k+1}\) generate the Lie algebra \(\mathfrak{so}(N)\), which means that the Givens rotations \(T_k\) are sufficient to factorize the full rotation, and only SingleExcitation gates are needed in the quantum circuit. A small exception occurs for orthogonal matrices that are not special orthogonal (unit determinant), i.e., that have determinant \(-1\). For those, the sign of one row or column of the matrix can be inverted, corresponding to a phase flip gate PauliZ in the circuit. The new matrix then has a unit determinant and can be implemented exclusively with SingleExcitation gates.