Exemplo n.º 1
0
    def _add(self, other, qargs=None):
        """Return the QuantumChannel self + other.

        If ``qargs`` are specified the other channel will be added
        assuming it is the identity channel on all other subsystems.

        Args:
            other (QuantumChannel): a quantum channel.
            qargs (None or list): optional subsystems to add on
                                  (Default: None)

        Returns:
            QuantumChannel: the linear addition self + other as a SuperOp object.

        Raises:
            QiskitError: if other cannot be converted to a channel or
                         has incompatible dimensions.
        """
        # NOTE: this method must be overriden for subclasses
        # that don't have a linear matrix representation
        # ie Kraus and Stinespring

        if qargs is None:
            qargs = getattr(other, 'qargs', None)

        if not isinstance(other, self.__class__):
            other = self.__class__(other)

        self._validate_add_dims(other, qargs)
        other = ScalarOp._pad_with_identity(self, other, qargs)

        ret = copy.copy(self)
        ret._data = self._data + other._data
        return ret
Exemplo n.º 2
0
    def _add(self, other, qargs=None):
        """Return the operator self + other.

        If ``qargs`` are specified the other operator will be added
        assuming it is identity on all other subsystems.

        Args:
            other (Operator): an operator object.
            qargs (None or list): optional subsystems to add on
                                  (Default: None)

        Returns:
            Operator: the operator self + other.

        Raises:
            QiskitError: if other is not an operator, or has incompatible
                         dimensions.
        """
        # pylint: disable=cyclic-import
        from qiskit.quantum_info.operators.scalar_op import ScalarOp

        if qargs is None:
            qargs = getattr(other, 'qargs', None)

        if not isinstance(other, Operator):
            other = Operator(other)

        self._op_shape._validate_add(other._op_shape, qargs)
        other = ScalarOp._pad_with_identity(self, other, qargs)

        ret = copy.copy(self)
        ret._data = self.data + other.data
        return ret
Exemplo n.º 3
0
 def _add(self, other, qargs=None):
     # NOTE: this method must be overridden for subclasses
     # that don't have a linear matrix representation
     # ie Kraus and Stinespring
     if not isinstance(other, type(self)):
         other = type(self)(other)
     self._op_shape._validate_add(other._op_shape, qargs)
     other = ScalarOp._pad_with_identity(self, other, qargs)
     ret = copy.copy(self)
     ret._data = self._data + other._data
     return ret