channels.partial_trace ====================== .. py:module:: channels.partial_trace .. autoapi-nested-parse:: Generates the partial trace of a matrix. Functions --------- .. autoapisummary:: channels.partial_trace.partial_trace Module Contents --------------- .. py:function:: partial_trace(input_mat, sys = None, dim = None) Compute the partial trace of a matrix :cite:`WikiPartialTr`. The *partial trace* is defined as .. math:: \left( \text{Tr} \otimes \mathbb{I}_{\mathcal{Y}} \right) \left(X \otimes Y \right) = \text{Tr}(X)Y where :math:`X \in \text{L}(\mathcal{X})` and :math:`Y \in \text{L}(\mathcal{Y})` are linear operators over complex Euclidean spaces :math:`\mathcal{X}` and :math:`\mathcal{Y}`. Gives the partial trace of the matrix X, where the dimensions of the (possibly more than 2) subsystems are given by the vector :code:`dim` and the subsystems to take the trace on are given by the scalar or vector :code:`sys`. .. rubric:: Examples Consider the following matrix .. math:: X = \begin{pmatrix} 1 & 2 & 3 & 4 \\ 5 & 6 & 7 & 8 \\ 9 & 10 & 11 & 12 \\ 13 & 14 & 15 & 16 \end{pmatrix}. Taking the partial trace over the second subsystem of :math:`X` yields the following matrix .. math:: X_{pt, 2} = \begin{pmatrix} 7 & 11 \\ 23 & 27 \end{pmatrix}. By default, the partial trace function in :code:`|toqito⟩` takes the trace of the second subsystem. .. jupyter-execute:: import numpy as np from toqito.channels import partial_trace test_input_mat = np.arange(1, 17).reshape(4, 4) partial_trace(test_input_mat) By specifying the :code:`sys = [0]` argument, we can perform the partial trace over the first subsystem (instead of the default second subsystem as done above). Performing the partial trace over the first subsystem yields the following matrix .. math:: X_{pt, 1} = \begin{pmatrix} 12 & 14 \\ 20 & 22 \end{pmatrix} .. jupyter-execute:: import numpy as np from toqito.channels import partial_trace test_input_mat = np.arange(1, 17).reshape(4, 4) partial_trace(test_input_mat, [0]) We can also specify both dimension and system size as :code:`list` arguments. Consider the following :math:`16`-by-:math:`16` matrix. .. jupyter-execute:: import numpy as np from toqito.channels import partial_trace test_input_mat = np.arange(1, 257).reshape(16, 16) test_input_mat We can take the partial trace on the first and third subsystems and assume that the size of each of the 4 systems is of dimension 2. .. jupyter-execute:: import numpy as np from toqito.channels import partial_trace partial_trace(test_input_mat, [0, 2], [2, 2, 2, 2]) .. rubric:: References .. bibliography:: :filter: docname in docnames :raises ValueError: If matrix dimension is not equal to the number of subsystems. :param input_mat: A square matrix. :param sys: Scalar or vector specifying the size of the subsystems. :param dim: Dimension of the subsystems. If :code:`None`, all dimensions are assumed to be equal. :return: The partial trace of matrix :code:`input_mat`.