code: def flatten_flax_to_haiku(
      collection: FlaxCollection,
  ) -> HaikuParamsOrState:
      """Flattens a Flax variable collection (e.g. params) to a Haiku dict."""
      out = {}
      for name, value in collection.items():
          if not isinstance(value, Mapping):
              if "~" not in out:
                  out["~"] = {}
              out["~"][name] = value
          else:
              _flatten_flax_to_haiku_inner(value, out, (name,))
      return out
  
imports: from collections.abc import Mapping, MutableMapping, Sequence
  from typing import Any, Union
  from haiku._src import typing
label_desc: Use image node_id 1 for calling a global function with example usage: flatten_flax_to_haiku(collection) and returns: out