Skip to content

Negative wall_time exceptionΒ #3808

@fontanf

Description

@fontanf

Summary

We got an exception because of a negative wall clock time.

Steps to reproduce the issue

The exception happens from time to time but we are not able to reproduce it.

Error Message

.venv/lib/python3.11/site-packages/pyomo/contrib/solver/common/base.py:685: in solve
    results: Results = super().solve(model)
                       ^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.11/site-packages/pyomo/contrib/solver/solvers/knitro/base.py:96: in solve
    results.timing_info.wall_time = (tock - tick).total_seconds()
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.venv/lib/python3.11/site-packages/pyomo/common/config.py:2481: in __setattr__
    ConfigDict.__setitem__(self, name, value)
.venv/lib/python3.11/site-packages/pyomo/common/config.py:2443: in __setitem__
    cfg.set_value(val)
.venv/lib/python3.11/site-packages/pyomo/common/config.py:2001: in set_value
    self._setter(value)
.venv/lib/python3.11/site-packages/pyomo/common/config.py:1998: in _setter
    self._data = self._cast(value)
                 ^^^^^^^^^^^^^^^^^
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <pyomo.common.config.UninitializedConfigValue object at 0x7bd28cf95c40>
value = -0.216743

    def _cast(self, value):
        if value is None:
            return value
        if self._domain is not None:
            try:
                if value is not NOTSET:
                    return self._domain(value)
                else:
                    return self._domain()
            except:
                err = sys.exc_info()[1]
                if hasattr(self._domain, '__name__'):
                    _dom = self._domain.__name__
                else:
                    _dom = type(self._domain)
>               raise ValueError(
                    "invalid value for configuration '%s':\n"
                    "\tFailed casting %s\n\tto %s\n\tError: %s"
                    % (self.name(True), value, _dom, err)
                )
E               ValueError: invalid value for configuration 'timing_info.wall_time':
E               	Failed casting -0.216743
E               	to NonNegativeFloat
E               	Error: Expected non-negative float, but received -0.216743

.venv/lib/python3.11/site-packages/pyomo/common/config.py:1658: ValueError

Information on your system

Pyomo version: 6.9.5
Python version: 3.11
Operating system: Linux
How Pyomo was installed (PyPI, conda, source): pip
Solver (if applicable): Knitro

Additional information

It seems to me that the issue comes from using datetime.datetime.now(datetime.timezone.utc) to get the current time, while this is not guaranteed to be monotonic. I suspect these calls should be replaced by time.monotonic() https://docs.python.org/3/library/time.html#time.monotonic or time.perf_counter() https://docs.python.org/3/library/time.html#time.perf_counter

datetime.now is used at multiple other locations in Pyomo https://github.com/search?q=repo%3APyomo%2Fpyomo%20%22datetime.now%22&type=code

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions