Epistimio / hydra_orion_sweeper

Hydra Sweeper Plugin for Orion
7 stars 2 forks source link

Duration field of the optimization results not converted to string #33

Closed FrancoisPgm closed 5 months ago

FrancoisPgm commented 8 months ago

Hi, I'm trying to run the example code on a HPC cluster, with hydra-core 1.3.2 and orion 0.2.4, and I get the error : omegaconf.errors.UnsupportedValueType: Value 'timedelta' is not a supported primitive type

What happens is that in my case the results object passed to show_results in implementation.py has a duration field instead of a elapsed_time one, so it doesn't get converted to a string and messes up the OmegaConf.save.

I can easily work around this issue by adding the conversion in show_results, but maybe a cleaner solution would be to iterate over all fields of results and convert them regardless of their name.

Here is the full stack trace of the error :

ExperimentStats(trials_completed=10, best_trials_id='ac0a6ebdc34ad7ba4194627ff8fa324a', best_evaluation=0.6944100000000001, start_time=datetime.datetime(2023, 11, 24, 17, 4, 24, 419571), finish_time=datetime.datetime(2023, 11, 24, 17, 5, 29, 699210), duration=datetime.timedelta(seconds=65, microseconds=279639))
Traceback (most recent call last):
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/hydra/_internal/utils.py", line 220, in run_and_report
    return func()
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/hydra/_internal/utils.py", line 466, in <lambda>
    lambda: hydra.multirun(
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/hydra/_internal/hydra.py", line 162, in multirun
    ret = sweeper.sweep(arguments=task_overrides)
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/hydra_plugins/hydra_orion_sweeper/orion_sweeper.py", line 79, in sweep
    return self.sweeper.sweep(arguments)
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/hydra_plugins/hydra_orion_sweeper/implementation.py", line 510, in sweep
    raise e
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/hydra_plugins/hydra_orion_sweeper/implementation.py", line 507, in sweep
    self.optimize(self.client)
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/hydra_plugins/hydra_orion_sweeper/implementation.py", line 550, in optimize
    self.show_results()
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/hydra_plugins/hydra_orion_sweeper/implementation.py", line 628, in show_results
    OmegaConf.create(results),
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/omegaconf.py", line 178, in create
    return OmegaConf._create_impl(
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/omegaconf.py", line 900, in _create_impl
    format_and_raise(node=None, key=None, value=None, msg=str(e), cause=e)
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/_utils.py", line 819, in format_and_raise
    _raise(ex, cause)
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/_utils.py", line 797, in _raise
    raise ex.with_traceback(sys.exc_info()[2])  # set env var OC_CAUSE=1 for full trace
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/omegaconf.py", line 861, in _create_impl
    return DictConfig(
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/dictconfig.py", line 111, in __init__
    format_and_raise(node=None, key=key, value=None, cause=ex, msg=str(ex))
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/_utils.py", line 819, in format_and_raise
    _raise(ex, cause)
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/_utils.py", line 797, in _raise
    raise ex.with_traceback(sys.exc_info()[2])  # set env var OC_CAUSE=1 for full trace
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/dictconfig.py", line 109, in __init__
    self._set_value(content, flags=flags)
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/dictconfig.py", line 647, in _set_value
    raise e
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/dictconfig.py", line 644, in _set_value
    self._set_value_impl(value, flags)
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/dictconfig.py", line 690, in _set_value_impl
    self.__setitem__(k, v)
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/dictconfig.py", line 314, in __setitem__
    self._format_and_raise(key=key, value=value, cause=e)
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/base.py", line 231, in _format_and_raise
    format_and_raise(
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/_utils.py", line 819, in format_and_raise
    _raise(ex, cause)
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/_utils.py", line 797, in _raise
    raise ex.with_traceback(sys.exc_info()[2])  # set env var OC_CAUSE=1 for full trace
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/dictconfig.py", line 308, in __setitem__
    self.__set_impl(key=key, value=value)
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/dictconfig.py", line 318, in __set_impl
    self._set_item_impl(key, value)
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/basecontainer.py", line 620, in _set_item_impl
    self._wrap_value_and_set(key, value, target_type_hint)
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/basecontainer.py", line 636, in _wrap_value_and_set
    self._format_and_raise(key=key, value=val, cause=e)
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/base.py", line 231, in _format_and_raise
    format_and_raise(
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/_utils.py", line 899, in format_and_raise
    _raise(ex, cause)
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/_utils.py", line 797, in _raise
    raise ex.with_traceback(sys.exc_info()[2])  # set env var OC_CAUSE=1 for full trace
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/basecontainer.py", line 628, in _wrap_value_and_set
    wrapped = _maybe_wrap(
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/omegaconf.py", line 1105, in _maybe_wrap
    return _node_wrap(
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/omegaconf.py", line 1045, in _node_wrap
    node = AnyNode(value=value, key=key, parent=parent)
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/nodes.py", line 135, in __init__
    super().__init__(
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/nodes.py", line 29, in __init__
    self._set_value(value)  # lgtm [py/init-calls-subclass]
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/nodes.py", line 46, in _set_value
    self._val = self.validate_and_convert(value)
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/nodes.py", line 76, in validate_and_convert
    return self._validate_and_convert_impl(value)
  File "/scratch/fpaugam/test_orion_env/lib/python3.8/site-packages/omegaconf/nodes.py", line 154, in _validate_and_convert_impl
    raise UnsupportedValueType(
omegaconf.errors.UnsupportedValueType: Value 'timedelta' is not a supported primitive type
    full_key: duration
    object_type=dict
bouthilx commented 8 months ago

Thanks for reporting!

Looks like a backward compatibility issue. A fix is on it's way here: https://github.com/Epistimio/hydra_orion_sweeper/pull/34