code: def to_realimag(z):
      
      if isinstance(z, qt.Qobj):
          z = z.data
      if not is_hermitian(z):  # pragma no coverage
          raise ValueError("Need a hermitian matrix z")
      return spvstack([sphstack([z.real, z.imag]), sphstack([z.imag.T, z.real])]).tocsr().real
docs: Convert a complex hermitian matrix to a real valued doubled up representation, i.e., for
      ``Z = Z_r + 1j * Z_i`` return ``R(Z)``::
  
          R(Z) = [ Z_r   Z_i]
                 [-Z_i   Z_r]
  
      A complex hermitian matrix ``Z`` with elementwise real and imaginary parts
      ``Z = Z_r + 1j * Z_i`` can be
      isomorphically represented in doubled up form as::
  
          R(Z) = [ Z_r   Z_i]
                 [-Z_i   Z_r]
  
          R(X)*R(Y) = [ (X_r*Y_r-X_i*Y_i)    (X_r*Y_i + X_i*Y_r)]
                      [-(X_r*Y_i + X_i*Y_r)  (X_r*Y_r-X_i*Y_i)  ]
  
                    = R(X*Y).
  
      In particular, ``Z`` is complex positive (semi-)definite iff ``R(Z)`` is real positive
      (semi-)definite.
  
      :param (qutip.Qobj|scipy.sparse.base.spmatrix) z:  The operator representation matrix.
      :returns: R(Z) the doubled up representation.
      :rtype: scipy.sparse.csr_matrix