toqito.perms.permutation_operator¶
-
toqito.perms.
permutation_operator
(dim: list[int] | int, perm: list[int], inv_perm: bool = False, is_sparse: bool = False) → np.ndarray[source]¶ Produce a unitary operator that permutes subsystems.
Generates a unitary operator that permutes the order of subsystems according to the permutation vector
perm
, where the \(i^{th}\) subsystem has dimensiondim[i]
.If
inv_perm
= True, it implements the inverse permutation ofperm
. The permutation operator return is full isis_sparse
isFalse
and sparse ifis_sparse
isTrue
.Examples
The permutation operator obtained with dimension \(d = 2\) is equivalent to the standard swap operator on two qubits
\[\begin{split}P_{2, [2, 1]} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}\end{split}\]Using
toqito
, this can be achieved in the following manner.>>> from toqito.perms import permutation_operator >>> permutation_operator(2, [2, 1]) [[1., 0., 0., 0.], [0., 0., 1., 0.], [0., 1., 0., 0.], [0., 0., 0., 1.]]
Parameters: - dim – The dimensions of the subsystems to be permuted.
- perm – A permutation vector.
- inv_perm – Boolean dictating if
perm
is inverse or not. - is_sparse – Boolean indicating if return is sparse or not.
Returns: Permutation operator of dimension
dim
.