code: def log_used_modules(
      used_modules: list[MethodInvocation],
      next_f: Callable[..., T],
      args: tuple[Any, ...],
      kwargs: dict[str, Any],
      context: hk.MethodContext,
  ) -> T:
      """Method interceptor that logs used modules to the given list."""
      if context.method_name in IGNORED_METHODS:
          return next_f(*args, **kwargs)
  
      idx = len(used_modules)
      used_modules.append(
          None
      )  # pytype: disable=container-type-mismatch
      out = next_f(*args, **kwargs)
      used_modules[idx] = MethodInvocation(
          module_details=ModuleDetails.of(
              context.module, context.method_name
          ),
          args_spec=to_spec(args),
          kwargs_spec=to_spec(kwargs),
          output_spec=to_spec(out),
          context=context,
          call_stack=get_call_stack(),
      )
      return out
  
imports: from collections.abc import Mapping, Sequence
  import dataclasses
  import functools
  import pprint
  from typing import Any, Callable, Optional, TypeVar, Union
  from haiku._src import base
  from haiku._src import data_structures
  from haiku._src import module
  from haiku._src import transform
  from haiku._src import utils
  import jax
  import jax.numpy
  import numpy
  import tabulate
label_desc: Use image node_id 3 for calling a global function with example usage: log_used_modules(used_modules, next_f, args, kwargs, context) and returns: out, next_f