:py:mod:`state_ops.pure_to_mixed` ================================= .. py:module:: state_ops.pure_to_mixed .. autoapi-nested-parse:: Pure to mixed operation. Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: state_ops.pure_to_mixed.pure_to_mixed .. py:function:: pure_to_mixed(phi) Convert a state vector or density matrix to a density matrix. .. rubric:: Examples It is possible to convert a pure state vector to a mixed state vector using the :code:`toqito` package. Consider the following Bell state .. math:: u = \frac{1}{\sqrt{2}} \left( |00 \rangle + |11 \rangle \right). The corresponding mixed state from :math:`u` is calculated as .. math:: \rho = u u^* = \frac{1}{2} \begin{pmatrix} 1 & 0 & 0 & 1 \\ 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 \\ 1 & 0 & 0 & 1 \end{pmatrix} Using :code:`toqito`, we can obtain this matrix as follows. >>> from toqito.states import bell >>> from toqito.state_ops import pure_to_mixed >>> phi = bell(0) >>> pure_to_mixed(phi) array([[0.5, 0. , 0. , 0.5], [0. , 0. , 0. , 0. ], [0. , 0. , 0. , 0. ], [0.5, 0. , 0. , 0.5]]) We can also give matrix inputs to the function in :code:`toqito`. >>> from toqito.states import bell >>> from toqito.state_ops import pure_to_mixed >>> phi = bell(0) * bell(0).conj().T >>> pure_to_mixed(phi) array([[0.5, 0. , 0. , 0.5], [0. , 0. , 0. , 0. ], [0. , 0. , 0. , 0. ], [0.5, 0. , 0. , 0.5]]) :raises ValueError: If matrix is not square. :param phi: A density matrix or a pure state vector. :return: density matrix representation of :code:`phi`, regardless of whether :code:`phi` is itself already a density matrix or if if is a pure state vector.