Twirl

Twirl is a function that twirls an operator. That is, it implements a superoperator like the following one:

$$X \mapsto \int_{U(d)} (U \otimes U)X(U \otimes U)^\dagger \, dU,$$

where integration is performed with respect to Haar measure on the unitary group. Multipartite twirling can also be performed, as can some other related twirls (in particular, twirling over the real orthogonal group, isotropic twirling, and Pauli twirling). The output of this function is always sparse.

Syntax

 * TX = Twirl(X)
 * TX = Twirl(X,TYPE)
 * TX = Twirl(X,TYPE,P)

Argument descriptions

 * X: A square operator to have its twirl computed.
 * TYPE (optional, by default 'werner'): A string indicating what type of twirl should be performed. Can equal one of the following four values:
 * If TYPE = 'werner' then the twirl performed is:$$X \mapsto \int_{U(d)} (U \otimes U)X(U \otimes U)^\dagger \, dU,$$where integration is performed with respect to Haar measure over the group of unitary matrices. Can also perform the natural multipartite generalization of the above integral (see the optional parameter P</tt>).
 * If TYPE = 'isotropic'</tt> then the twirl performed is:$$X \mapsto \int_{U(d)} (U \otimes \overline{U})X(U \otimes \overline{U})^\dagger \, dU,$$where integration is performed with respect to Haar measure over the group of unitary matrices.
 * If TYPE = 'real'</tt> then the twirl performed is:$$X \mapsto \int_{O(d)} (O \otimes O)X(O \otimes O)^\dagger \, dO,$$where integration is performed with respect to Haar measure over the group of real orthogonal matrices. Can also perform the natural multipartite generalization of the above integral (see the optional parameter P</tt>).
 * If TYPE = 'pauli'</tt> then the twirl performed is:$$X \mapsto \frac{1}{4^q}\sum_{\text{Paulis } Q}(Q \otimes Q)X(Q \otimes Q)^\dagger,$$where $X \in M_{2^q} \otimes M_{2^q} \cong M_{4^q}$ for some $q \geq 1$.
 * P</tt> (optional, by default 2</tt>): The number of parties that X</tt> acts on. That is, $X \in M_n^{\otimes P}$ for some $n$. Must equal 2</tt> if TYPE = 'isotropic'</tt> or if TYPE = 'pauli'</tt>.

Werner twirling
Werner twirling a quantum state always results in a Werner state. More specifically, in the bipartite case we have the simple formula

$$\displaystyle\int_{U(d)} (U \otimes U)X(U \otimes U)^\dagger \, dU = \frac{\mathrm{Tr}\big( P_S X \big)}{\binom{d+1}{2}}P_S + \frac{\mathrm{Tr}\big(P_A X\big)}{\binom{d}{2}}P_A,$$

where $P_S$ is the projection onto the symmetric subspace and $P_A$ is the projection onto the antisymmetric subspace. We can see this fact numerically as follows:

Multipartite Werner twirling does not have such a simple formula. Nonetheless, the following code demonstrates the effect of twirling a 3-qubit state X</tt> using the Twirl</tt> function versus approximately twirling it by generating many Haar-uniform random unitary matrices.

Isotropic twirling
Isotropic twirling a quantum state always results in an isotropic state. More specifically, if $|\psi_+\rangle$ is the standard maximally-entangled pure state then we have

$$\displaystyle\int_{U(d)} (U \otimes \overline{U})X(U \otimes \overline{U})^\dagger \, dU = \big( \langle\psi_+|X|\psi_+\rangle \big)|\psi_+\rangle\langle\psi_+| + \frac{\mathrm{Tr}\big((I - |\psi_+\rangle\langle\psi_+|) X\big)}{d^2-1}(I - |\psi_+\rangle\langle\psi_+|).$$

We can see this fact numerically as follows:

Real orthogonal twirling
Twirling a bipartite quantum state by real orthogonal matrices always results in a linear combination of an isotropic state and a Werner state (equivalently, a state in the 3-dimensional space spanned by the projection onto the symmetric subspace, the projection onto the antisymmetric subspace, and the standard maximally-entangled pure state). More specifically, the following formula holds:

$$\displaystyle\int_{O(d)} (O \otimes O)X(O \otimes O)^\dagger \, dO = \big( \langle\psi_+|X|\psi_+\rangle \big)|\psi_+\rangle\langle\psi_+| + \frac{\mathrm{Tr}\big(P_A X\big)}{\binom{d}{2}}P_A + \frac{\mathrm{Tr}\big( (P_S-|\psi_+\rangle\langle\psi_+|) X \big)}{\binom{d+1}{2}-1}(P_S - |\psi_+\rangle\langle\psi_+|).$$

The following code generates the real orthogonal twirl of a random state in two different ways: first by using the Twirl function, and then by constructing 1000000 random (according to Haar measure) orthogonal matrices and averaging the value of $(O \otimes O)X(O \otimes O)^\dagger$ over them:

Real orthogonal twirling of a multipartite state does not have such a simple closed-form formula, but it always results in a linear combination of the $p!$ operators that permute the $p$ tensor factors and all of their partial transpositions. The following code generates the real orthogonal twirl of a random 3-qubit state:

Pauli twirl of a channel
A more common way to think of Pauli twirling is as the mapping that sends a superoperator $\Phi : M_{2^q} \rightarrow M_{2^q}$ to the superoperator $\Phi_P : M_{2^q} \rightarrow M_{2^q}$ defined as follows:
 * $$\Phi_P(X) := \frac{1}{4^q}\sum_{\text{Paulis } Q} Q\Phi(Q^\dagger XQ)Q^\dagger.$$

Applying the Twirl</tt> function to the Choi matrix of $\Phi$ implements this Pauli twirl on that channel: