qiskit/quantum_info/operators/channel/choi.py
def compose(self, other, qargs=None, front=False):
        """Return the composition channel self∘other.

        Args:
            other (QuantumChannel): a quantum channel.
            qargs (list): a list of subsystem positions to compose other on.
            front (bool): If False compose in standard order other(self(input))
                          otherwise compose in reverse order self(other(input))
                          [default: False]

        Returns:
            Choi: The composition channel as a Choi object.

        Raises:
            QiskitError: if other cannot be converted to a channel or
            has incompatible dimensions.
        """
        if qargs is not None:
            return Choi(
                SuperOp(self).compose(other, qargs=qargs, front=front))

        # Convert to Choi matrix
        if not isinstance(other, Choi):
            other = Choi(other)
        # Check dimensions match up
        if front and self._input_dim != other._output_dim:
            raise QiskitError(
                'input_dim of self must match output_dim of other')
        if not front and self._output_dim != other._input_dim:
            raise QiskitError(
                'input_dim of other must match output_dim of self')

        if front:
            first = np.reshape(other._data, other._bipartite_shape)
            second = np.reshape(self._data, self._bipartite_shape)
            input_dim = other._input_dim
            input_dims = other.input_dims()
            output_dim = self._output_dim
            output_dims = self.output_dims()
        else:
            first = np.reshape(self._data, self._bipartite_shape)
            second = np.reshape(other._data, other._bipartite_shape)
            input_dim = self._input_dim
            input_dims = self.input_dims()
            output_dim = other._output_dim
            output_dims = other.output_dims()

        # Contract Choi matrices for composition
        data = np.reshape(
            np.einsum('iAjB,AkBl->ikjl', first, second),
            (input_dim * output_dim, input_dim * output_dim))
        return Choi(data, input_dims, output_dims)
def compose(self, other, qargs=None, front=False):
        """Return the composition channel self∘other.

        Args:
            other (QuantumChannel): a quantum channel.
            qargs (list): a list of subsystem positions to compose other on.
            front (bool): If False compose in standard order other(self(input))
                          otherwise compose in reverse order self(other(input))
                          [default: False]

        Returns:
            Choi: The composition channel as a Choi object.

        Raises:
            QiskitError: if other cannot be converted to a channel or
            has incompatible dimensions.
        """
        if qargs is not None:
            return Choi(
                SuperOp(self).compose(other, qargs=qargs, front=front))

        # Convert to Choi matrix
        if not isinstance(other, Choi):
            other = Choi(other)
        # Check dimensions match up
        if front and self._input_dim != other._output_dim:
            raise QiskitError(
                'input_dim of self must match output_dim of other')
        if not front and self._output_dim != other._input_dim:
            raise QiskitError(
                'input_dim of other must match output_dim of self')

        if front:
            first = np.reshape(other._data, other._bipartite_shape)
            second = np.reshape(self._data, self._bipartite_shape)
            input_dim = other._input_dim
            input_dims = other.input_dims()
            output_dim = self._output_dim
            output_dims = self.output_dims()
        else:
            first = np.reshape(self._data, self._bipartite_shape)
            second = np.reshape(other._data, other._bipartite_shape)
            input_dim = self._input_dim
            input_dims = self.input_dims()
            output_dim = other._output_dim
            output_dims = other.output_dims()

        # Contract Choi matrices for composition
        data = np.reshape(
            np.einsum('iAjB,AkBl->ikjl', first, second),
            (input_dim * output_dim, input_dim * output_dim))
        return Choi(data, input_dims, output_dims)
def compose ( self , other , qargs = None , front = False ) : if qargs is not None : return Choi ( SuperOp ( self ) . compose ( other , qargs = qargs , front = front ) ) # Convert to Choi matrix if not isinstance ( other , Choi ) : other = Choi ( other ) # Check dimensions match up if front and self . _input_dim != other . _output_dim : raise QiskitError ( 'input_dim of self must match output_dim of other' ) if not front and self . _output_dim != other . _input_dim : raise QiskitError ( 'input_dim of other must match output_dim of self' ) if front : first = np . reshape ( other . _data , other . _bipartite_shape ) second = np . reshape ( self . _data , self . _bipartite_shape ) input_dim = other . _input_dim input_dims = other . input_dims ( ) output_dim = self . _output_dim output_dims = self . output_dims ( ) else : first = np . reshape ( self . _data , self . _bipartite_shape ) second = np . reshape ( other . _data , other . _bipartite_shape ) input_dim = self . _input_dim input_dims = self . input_dims ( ) output_dim = other . _output_dim output_dims = other . output_dims ( ) # Contract Choi matrices for composition data = np . reshape ( np . einsum ( 'iAjB,AkBl->ikjl' , first , second ) , ( input_dim * output_dim , input_dim * output_dim ) ) return Choi ( data , input_dims , output_dims )
Return the composition channel self∘other.

        Args:
            other (QuantumChannel): a quantum channel.
            qargs (list): a list of subsystem positions to compose other on.
            front (bool): If False compose in standard order other(self(input))
                          otherwise compose in reverse order self(other(input))
                          [default: False]

        Returns:
            Choi: The composition channel as a Choi object.

        Raises:
            QiskitError: if other cannot be converted to a channel or
            has incompatible dimensions.
Return the composition channel self∘other .