code: def concordance(
      left, right, *, _localize_global_statistics=True
  ) -> Tuple[List[List[int]], Table, Table]:
      """Calculate call concordance with another dataset.
  
      .. include:: ../_templates/req_tstring.rst
  
      .. include:: ../_templates/req_tvariant.rst
  
      .. include:: ../_templates/req_biallelic.rst
  
      .. include:: ../_templates/req_unphased_diploid_gt.rst
  
      Examples
      --------
  
      Compute concordance between two datasets and output the global concordance
      statistics and two tables with concordance computed per column key and per
      row key:
  
      >>> global_conc, cols_conc, rows_conc = hl.concordance(dataset, dataset2)
  
      Notes
      -----
  
      This method computes the genotype call concordance (from the entry
      field **GT**) between two biallelic variant datasets.  It requires
      unique sample IDs and performs an inner join on samples (only
      samples in both datasets will be considered). In addition, all genotype
      calls must be **diploid** and **unphased**.
  
      It performs an ordered zip join of the variants.  That means the
      variants of each dataset are sorted, with duplicate variants
      appearing in some random relative order, and then zipped together.
      When a variant appears a different number of times between the two
      datasets, the dataset with the fewer number of instances is padded
      with "no data".  For example, if a variant is only in one dataset,
      then each genotype is treated as "no data" in the other.
  
      This method returns a tuple of three objects: a nested list of
      list of int with global concordance summary statistics, a table
      with concordance statistics per column key, and a table with
      concordance statistics per row key.
  
      **Using the global summary result**
  
      The global summary is a list of list of int (conceptually a 5 by 5 matrix),
      where the indices have special meaning:
  
      0. No Data (missing variant or filtered entry)
      1. No Call (missing genotype call)
      2. Hom Ref
      3. Heterozygous
      4. Hom Var
  
      The first index is the state in the left dataset and the second index is
      the state in the right dataset. Typical uses of the summary list are shown
      below.
  
      >>> summary, samples, variants = hl.concordance(dataset, dataset2)
      >>> left_homref_right_homvar = summary[2][4]
      >>> left_het_right_missing = summary[3][1]
      >>> left_het_right_something_else = sum(summary[3][:]) - summary[3][3]
      >>> total_concordant = summary[2][2] + summary[3][3] + summary[4][4]
      >>> total_discordant = sum([sum(s[2:]) for s in summary[2:]]) - total_concordant
  
      **Using the table results**
  
      Table 1: Concordance statistics by column
  
      This table contains the column key field of `left`, and the following fields:
  
          - `n_discordant` (:py:data:`.tint64`) -- Count of discordant calls (see below for
            full definition).
          - `concordance` (:class:`.tarray` of :class:`.tarray` of :py:data:`.tint64`) --
            Array of concordance per state on left and right, matching the structure of
            the global summary defined above.
  
      Table 2: Concordance statistics by row
  
      This table contains the row key fields of `left`, and the following fields:
  
          - `n_discordant` (:py:data:`.tfloat64`) -- Count of discordant calls (see below for
            full definition).
          - `concordance` (:class:`.tarray` of :class:`.tarray` of :py:data:`.tint64`) --
            Array of concordance per state on left and right, matching the structure of the
            global summary defined above.
  
      In these tables, the column **n_discordant** is provided as a convenience,
      because this is often one of the most useful concordance statistics. This
      value is the number of genotypes which were called (homozygous reference,
      heterozygous, or homozygous variant) in both datasets, but where the call
      did not match between the two.
  
      The column `concordance` matches the structure of the global summmary,
      which is detailed above. Once again, the first index into this array is the
      state on the left, and the second index is the state on the right. For
      example, ``concordance[1][4]`` is the number of "no call" genotypes on the
      left that were called homozygous variant on the right.
  
      Parameters
      ----------
      left : :class:`.MatrixTable`
          First dataset to compare.
      right : :class:`.MatrixTable`
          Second dataset to compare.
  
      Returns
      -------
      (list of list of int, :class:`.Table`, :class:`.Table`)
          The global concordance statistics, a table with concordance statistics
          per column key, and a table with concordance statistics per row key.
  
      """
  
      require_col_key_str(left, "concordance, left")
      require_col_key_str(right, "concordance, right")
  
      left_sample_counter = left.aggregate_cols(
          hl.agg.counter(left.col_key[0])
      )
      right_sample_counter = right.aggregate_cols(
          hl.agg.counter(right.col_key[0])
      )
  
      left_bad = [
          f"{k!r}: {v}" for k, v in left_sample_counter.items() if v > 1
      ]
      right_bad = [
          f"{k!r}: {v}"
          for k, v in right_sample_counter.items()
          if v > 1
      ]
      if left_bad or right_bad:
          raise ValueError(
              f"Found duplicate sample IDs:\n"
              f"  left:  {', '.join(left_bad)}\n"
              f"  right: {', '.join(right_bad)}"
          )
  
      included = set(left_sample_counter.keys()).intersection(
          set(right_sample_counter.keys())
      )
  
      info(
          f"concordance: including {len(included)} shared samples "
          f"({len(left_sample_counter)} total on left, {len(right_sample_counter)} total on right)"
      )
  
      left = require_biallelic(left, "concordance, left")
      right = require_biallelic(right, "concordance, right")
  
      lit = hl.literal(included, dtype=hl.tset(hl.tstr))
      left = left.filter_cols(lit.contains(left.col_key[0]))
      right = right.filter_cols(lit.contains(right.col_key[0]))
  
      left = left.select_entries("GT").select_rows().select_cols()
      right = right.select_entries("GT").select_rows().select_cols()
  
      joined = hl.experimental.full_outer_join_mt(left, right)
  
      def get_idx(struct):
          return hl.if_else(
              hl.is_missing(struct),
              0,
              hl.coalesce(2 + struct.GT.n_alt_alleles(), 1),
          )
  
      aggr = hl.agg.counter(
          get_idx(joined.left_entry) + 5 * get_idx(joined.right_entry)
      )
  
      def concordance_array(counter):
          return hl.range(0, 5).map(
              lambda i: hl.range(0, 5).map(
                  lambda j: counter.get(i + 5 * j, 0)
              )
          )
  
      discordant_indices = set()
      for i in range(5):
          for j in range(5):
              if i > 1 and j > 1 and i != j:
                  discordant_indices.add(i + 5 * j)
  
      def n_discordant(counter):
          return hl.sum(
              hl.array(counter)
              .filter(
                  lambda tup: hl.literal(discordant_indices).contains(
                      tup[0]
                  )
              )
              .map(lambda tup: tup[1])
          )
  
      glob = joined.aggregate_entries(
          concordance_array(aggr), _localize=_localize_global_statistics
      )
      if _localize_global_statistics:
          total_conc = [x[1:] for x in glob[1:]]
          on_diag = sum(
              total_conc[i][i] for i in range(len(total_conc))
          )
          total_obs = sum(sum(x) for x in total_conc)
          pct = (
              on_diag / total_obs * 100
              if total_obs > 0
              else float("nan")
          )
          info(f"concordance: total concordance {pct:.2f}%")
  
      per_variant = joined.annotate_rows(concordance=aggr)
      per_variant = per_variant.select_rows(
          concordance=concordance_array(per_variant.concordance),
          n_discordant=n_discordant(per_variant.concordance),
      )
      per_sample = joined.annotate_cols(concordance=aggr)
      per_sample = per_sample.select_cols(
          concordance=concordance_array(per_sample.concordance),
          n_discordant=n_discordant(per_sample.concordance),
      )
  
      return glob, per_sample.cols(), per_variant.rows()
  
imports: import abc
  import logging
  import hail
  from collections import Counter
  import os
  from shlex import quote
  from typing import Dict, Tuple, List, Optional, Union
  from hailtop import pip_version
  from hailtop.utils import async_to_blocking
  import hailtop.batch_client
  from hailtop.config import get_deploy_config
  from hailtop import yamlx
  from hail.backend.service_backend import ServiceBackend
  from hail.typecheck import typecheck, oneof, anytype, nullable, numeric
  from hail.expr.expressions.expression_typecheck import expr_float64
  from hail.utils import FatalError
  from hail.utils.java import Env, info, warning
  from hail.utils.misc import divide_null, guess_cloud_spark_provider, new_temp_file
  from hail.matrixtable import MatrixTable
  from hail.table import Table
  from hail.ir import TableToTableApply
  from .misc import require_biallelic, require_row_key_variant, require_col_key_str, require_table_key_variant, require_alleles_field
label_desc: Use image node_id 3 for calling a global function with example usage: concordance(left, right) and returns: glob,  per_sample,  per_variant, hl, hl, hl