code: def _to_haiku_state(variables: FlaxVariables) -> hk.State:
      """Converts a nested Flax collection to a Haiku state dict."""
      state = {}
      for collection_name, collection in variables.items():
          flat_collection = utils.flatten_flax_to_haiku(collection)
          for mod_name, name, value in hkds.traverse(flat_collection):
              mod_name = f"{collection_name}/{mod_name}"
              if mod_name not in state:
                  state[mod_name] = {}
              state[mod_name][name] = value
      return state
  
file_path: dm-haiku/haiku/_src/flax/transform_flax.py
imports: from collections.abc import Mapping
  from typing import Any, Callable
  import flax.errors
  import flax.linen
  from haiku._src import base
  from haiku._src import filtering
  from haiku._src import lift
  from haiku._src import transform
  from haiku._src import typing
  from haiku._src.flax import utils
label_desc: Use image node_id 2 for calling a global function with example usage: _to_haiku_state(variables) and returns: state