import copy


def get_object_state(obj, ignore_attributes=()):
  """Returns a dictionary with the state of the attributes of an object.

  Note that this is not general. For example, it will throw an error for classes
  that define a __slots__ field (like namedtuples).

  Args:
    obj: a Python object
    ignore_attributes: list of attributes to ignore when getting the object
      state

  Returns:
    state: a dictionary representation of the object state.
  """
  state = {}
  for k, v in obj.__dict__.items():
    if k not in ignore_attributes:
      state[k] = copy.deepcopy(v)
  for k in ignore_attributes:
    if not hasattr(obj, k):
      raise ValueError("Ignored attribute `%s` does not exist in object." % k)
  return state