code: def multitrait_ss(mt, h2, pi, rg=0, seed=None):
      r"""Generates spike & slab betas for simulation of two correlated phenotypes.
  
      Parameters
      ----------
      mt : :class:`.MatrixTable`
          :class:`.MatrixTable` for simulated phenotype.
      h2 : :obj:`list` or :class:`numpy.ndarray`
          Desired SNP-based heritability of simulated traits.
      pi : :obj:`list` or :class:`numpy.ndarray`
          List of proportion of SNPs: :math:`p_{TT}`, :math:`p_{TF}`, :math:`p_{FT}`
          :math:`p_{TT}` is the proportion of SNPs that are causal for both traits,
          :math:`p_{TF}` is the proportion of SNPs that are causal for trait 1 but not trait 2,
          :math:`p_{FT}` is the proportion of SNPs that are causal for trait 2 but not trait 1.
      rg : :obj:`float` or :obj:`int`
          Genetic correlation between traits.
      seed : :obj:`int`, optional
          Seed for random number generator. If `seed` is ``None``, `seed` is set randomly.
  
      Warning
      -------
      May give inaccurate results if chosen parameters make the covariance matrix
      not positive semi-definite. Covariance matrix is likely to not be positive
      semi-definite when :math:`p_{TT}` is small and rg is large.
  
      Returns
      -------
      mt : :class:`.MatrixTable`
          :class:`.MatrixTable` with simulated SNP effects as a row field of arrays.
      pi : :obj:`list` or :class:`numpy.ndarray`
          List of proportion of SNPs: :math:`p_{TT}`, :math:`p_{TF}`, :math:`p_{FT}`.
          Possibly altered if covariance matrix of traits was not positive semi-definite.
      rg : :obj:`list`
          Genetic correlation between traits, possibly altered from input `rg` if
          covariance matrix was not positive semi-definite.
      """
      assert (
          sum(pi) <= 1
      ), "probabilities of being causal must sum to be less than 1"
      ptt, ptf, pft, pff = pi[0], pi[1], pi[2], 1 - sum(pi)
      cov_matrix = np.asarray(
          [[1 / (ptt + ptf), rg / ptt], [rg / ptt, 1 / (ptt + pft)]]
      )
      M = mt.count_rows()
      # seed random state for replicability
      randstate = np.random.RandomState(int(seed))
      if np.any(np.linalg.eigvals(cov_matrix) < 0):
          print(
              "adjusting parameters to make covariance matrix positive semidefinite"
          )
          rg0, ptt0 = rg, ptt
          while np.any(
              np.linalg.eigvals(cov_matrix) < 0
          ):  # check positive semidefinite
              rg = round(0.99 * rg, 6)
              ptt = round(ptt + (pff) * 0.001, 6)
              cov_matrix = np.asarray(
                  [
                      [1 / (ptt + ptf), rg / ptt],
                      [rg / ptt, 1 / (ptt + pft)],
                  ]
              )
          pff0, pff = pff, 1 - sum([ptt, ptf, pft])
          print(
              f"rg: {rg0} -> {rg}\nptt: {ptt0} -> {ptt}\npff: {pff0} -> {pff}"
          )
          pi = [ptt, ptf, pft, pff]
      beta = randstate.multivariate_normal(
          mean=np.zeros(2),
          cov=cov_matrix,
          size=[
              int(M),
          ],
      )
      zeros = np.zeros(shape=int(M)).T
      beta_matrix = np.stack(
          (
              beta,
              np.asarray([beta[:, 0], zeros]).T,
              np.asarray([zeros, zeros]).T,
              np.asarray([zeros, beta[:, 1]]).T,
          ),
          axis=1,
      )
      idx = np.random.choice(
          a=[0, 1, 2, 3], size=int(M), p=[ptt, ptf, pft, pff]
      )
      betas = beta_matrix[range(int(M)), idx, :]
      betas[:, 0] *= (h2[0] / M) ** (1 / 2)
      betas[:, 1] *= (h2[1] / M) ** (1 / 2)
      df = pd.DataFrame([0] * M, columns=["beta"])
      tb = hl.Table.from_pandas(df)
      tb = tb.add_index().key_by("idx")
      tb = tb.annotate(
          beta=hl.literal(betas.tolist())[hl.int32(tb.idx)]
      )
      mt = mt.add_row_index()
      mt = mt.annotate_rows(beta=tb[mt.row_idx]["beta"])
      return mt, pi, [rg]
  
imports: import hail
  from hail.typecheck import typecheck, oneof, nullable
  from hail.expr.expressions import expr_float64, expr_int32, expr_array, expr_call
  from hail.matrixtable import MatrixTable
  from hail.table import Table
  from hail.utils.java import Env
  import numpy
  import pandas
  import scipy.stats
label_desc: Use image node_id 4 for calling a global function with example usage: multitrait_ss(mt, h2, pi, rg, seed) and returns: mt,  pi,  list