code: def load_var_collection(
      file: Union[str, IO[BinaryIO]],
      vc: VarCollection,
      renamer: Optional[Renamer] = None,
  ):
      """Loads values of all variables in the given variables collection from file.
  
      Values loaded from file will replace old values in the variables collection.
      If variable exists in the file, but does not exist in the variables collection it will be ignored.
      If variable exists in the variables collection, but not found in the file then exception will be raised.
  
      Args:
          file: filename or python file handle of the input file.
          vc: variables collection which will be loaded from file.
          renamer: optional renamer to pre-process variables names from the file being read.
  
      Raises:
          ValueError: if variable from variables collection is not found in the input file.
      """
      renamer = renamer or (lambda x: x)
      do_close = isinstance(file, str)
      if do_close:
          file = open(file, "rb")
      data = np.load(file, allow_pickle=False)
      name_index = {
          renamer(k): str(i) for i, k in enumerate(data["names"])
      }
      var_names = collections.defaultdict(list)
      var_values = {}
      for k, v in vc.items():
          if isinstance(v, TrainRef):
              v = v.ref
          var_names[id(v)].append(k)
          var_values[id(v)] = v
      misses = []
      used_vars = set()
      for var_id, names in var_names.items():
          v = var_values[var_id]
          for name in names:
              index = name_index.get(name)
              if index is not None:
                  used_vars.add(name)
                  try:
                      v.assign(jn.array(data[index]))
                  except AssertionError as e:
                      raise AssertionError(
                          f"Error when restoring variable {name}: {str(e)}"
                      ) from None
                  break
          else:
              misses += names
      if misses:
          not_used = set(name_index.keys()) - used_vars
          raise ValueError(
              f"Missing value for variables currently in the model: {misses}. "
              f"The following variables on disk were not used, "
              f"maybe the missing variable was renamed from one of these: {not_used}."
          )
      if do_close:
          file.close()
  
file_path: objax/objax/io/ops.py
imports: import collections
  import os
  from typing import IO, BinaryIO, Union, Optional
  import jax.numpy
  import numpy
  from objax.util import Renamer
  from objax.variable import TrainRef, VarCollection
label_desc: Use image node_id 1 for calling a global function with example usage: load_var_collection(file, vc, renamer) without return types