code: def encode_from_state(v: Stateful) -> Any:
      return {
          "__kind__": Kind.Stateful,
          "class": fqname_for(v.__class__),
          "kwargs": encode(v.__dict__),
      }
  
imports: import textwrap
  from enum import Enum
  from functools import singledispatch, partial
  from pathlib import PurePath
  from pydoc import locate
  from typing import Any, NamedTuple, cast
  from toolz.dicttoolz import valmap
  from gluonts.core import fqname_for
  from gluonts.pydantic import BaseModel
label_desc: Use image node_id 2 for calling a global function with example usage: encode_from_state(v) and returns: dict