def stable_hash(x):
    """A hash of `x` that is stable across program runs.
  
  Background:
  As of Python 3, `hash()` is given a fresh seed every time the interpret
  starts; hash codes are not stable without setting the env var
  `PYTHONHASHSEED`.

  Can we just simply adjust for the seed programmatically?
  Note that while it is possible to get the hash seed at runtime:
   * https://stackoverflow.com/questions/41088635/extract-hash-seed-in-unit-testing
  Python doesn't use the seed in an easily-inverted way:
   * https://github.com/python/cpython/blob/630c8df5cf126594f8c1c4579c1888ca80a29d59/Python/pyhash.c#L237

  Thus for stability (and even light portability), we leverage Python
  serialization to provide a key for `x`.
  """
    try:
        import cloudpickle as pkl
    except ImportError:
        import pickle as pkl
    key = pkl.dumps(x)
    import hashlib
    return int(hashlib.md5(key).hexdigest(), 16)
