# Buggy code
def __rmul__(self, other):
    """
    MULTIPLICATION with Qobj on RIGHT [ ex. 4*Qobj ]
    """
    if isinstance(other, Qobj):  # if both are quantum objects
        if self.shape[1] == other.shape[0] and self.dims[1] == other.dims[0]:
            out = Qobj()
            out.data = other.data * self.data
            out.dims = self.dims
            out.shape = [self.shape[0], other.shape[1]]
            out.type = _typecheck(out)
            out._isherm = out.isherm
            return out.tidyup() if qset.auto_tidyup else out

        else:
            raise TypeError("Incompatible Qobj shapes")

    if isinstance(other, (list, np.ndarray)):
        # if other is a list, do element-wise multiplication
        return np.array([item * self for item in other])

    if _checkeseries(other) == "eseries":
        return other.__mul__(self)

    if isinstance(other, (int, float, complex, np.int64)):
        out = Qobj(type=self.type)
        out.data = other * self.data
        out.dims = self.dims
        out.shape = self.shape
        if isinstance(other, (int, float, np.int64)):
            out._isherm = self._isherm
        else:
            out._isherm = out.isherm

        return out.tidyup() if qset.auto_tidyup else out

    else:
        raise TypeError("Incompatible object for multiplication")


# Traceback (TypeError)
rho_psi = operator_to_vector(Qobj(np.diag(np.array([0.9, 0.1], dtype=complex))))>>> E_psi = rho_psi.dag()
S = to_super(sigmax())
(E_psi * S) * rho_psi
Traceback (most recent call last):
File "<ipython-input-22-90cbfac2a43e>", line 1, in <module>
(E_psi * S) * rho_psi
File "qutip/qobj.py", line 416, in __mul__
raise TypeError("Incompatible Qobj shapes")
TypeError: Incompatible Qobj shapes

E_psi * (S * rho_psi)
Quantum object: dims = [[1], [1]], shape = [1, 1], type = oper, isherm = True
Qobj data =
[[ 0.18]]
E_psi
Quantum object: dims = [[1], [[2], [2]]], shape = [1, 4], type = bra
Qobj data =
[[ 0.9  0.   0.   0.1]]
rho_psi
Quantum object: dims = [[[2], [2]], [1]], shape = [4, 1], type = operator-vector
Qobj data =
[[ 0.9]
[ 0. ]
[ 0. ]
[ 0.1]]
S
Quantum object: dims = [[[2], [2]], [[2], [2]]], shape = [4, 4], type = super, isherm = True
Qobj data =
[[ 0.  0.  0.  1.]
[ 0.  0.  1.  0.]
[ 0.  1.  0.  0.]
[ 1.  0.  0.  0.]]

# Fixed code
def __rmul__(self, other):
    """
    MULTIPLICATION with Qobj on RIGHT [ ex. 4*Qobj ]
    """
    if isinstance(other, Qobj):  # if both are quantum objects
        if self.shape[1] == other.shape[0] and self.dims[1] == other.dims[0]:
            out = Qobj()
            out.data = other.data * self.data
            out.dims = self.dims
            out.shape = [self.shape[0], other.shape[1]]
            out._isherm = out.isherm
            return out.tidyup() if qset.auto_tidyup else out

        else:
            raise TypeError("Incompatible Qobj shapes")

    if isinstance(other, (list, np.ndarray)):
        # if other is a list, do element-wise multiplication
        return np.array([item * self for item in other])

    if _checkeseries(other) == "eseries":
        return other.__mul__(self)

    if isinstance(other, (int, float, complex, np.int64)):
        out = Qobj()
        out.data = other * self.data
        out.dims = self.dims
        out.shape = self.shape
        if isinstance(other, (int, float, np.int64)):
            out._isherm = self._isherm
        else:
            out._isherm = out.isherm

        return out.tidyup() if qset.auto_tidyup else out

    else:
        raise TypeError("Incompatible object for multiplication")