code: def load_solve_state_from_h5(nnp, filename):
      """Load solve state from h5 file
      This code is duplicated with solver.pyx, since solver.pyx only accept a string file
      as its filename input, not support ByteIO style input. But supporting ByteIO is
      important for high performance requirement.
      """
  
      class SolverState:
          def __init__(self):
              self.t = 0
              self.pstate = {}
  
      states = OrderedDict()
      with get_file_handle_load(nnp, filename, ".h5") as f:
          # File's key is `/{parameter-name}/{state-name}` and `/{parameter-name}/t`
          skeys = []
          pkeys = set()
  
          def _get_skeys(name, obj):
              if not isinstance(obj, h5py.Dataset):
                  # Group
                  return
              # state key
              skeys.append(name)
              # To preserve order of parameters
              index = obj.parent.attrs.get("index", None)
              pname = name[: name.rindex("/")]
              # parameter key
              pkeys.add((index, pname))
  
          # TODO Refactoring visit logic for efficient execution
          f.visititems(_get_skeys)
          for _, pkey in sorted(pkeys):
              state = SolverState()
              for skey in skeys:
                  if not skey.startswith(pkey):
                      continue
                  ds = f[skey]
                  if skey.endswith("/t"):
                      state.t = ds[...]
                  else:
                      sname = skey.split("/")[-1]
                      var = nn.Variable.from_numpy_array(ds[...])
                      state.pstate[sname] = var
              states[pkey] = state
      return states
  
imports: import contextlib
  import io
  import os
  import re
  import zipfile
  from collections import OrderedDict
  from functools import partial
  import google.protobuf.text_format
  import h5py
  import nnabla
  import numpy
  from nnabla.logger import logger
  from nnabla.utils import nnabla_pb2
  from nnabla.utils.nnp_format import nnp_version
label_desc: Use image node_id 7 for calling a global function with example usage: load_solve_state_from_h5(nnp, filename) and returns: states