-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
47 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# (C) Copyright 2023 European Centre for Medium-Range Weather Forecasts. | ||
# This software is licensed under the terms of the Apache Licence Version 2.0 | ||
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
# In applying this licence, ECMWF does not waive the privileges and immunities | ||
# granted to it by virtue of its status as an intergovernmental organisation | ||
# nor does it submit to any jurisdiction. | ||
|
||
import logging | ||
import time | ||
|
||
from climetlab.utils.humanize import seconds | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
class Stepper: | ||
def __init__(self, step, lead_time): | ||
self.step = step | ||
self.lead_time = lead_time | ||
self.start = time.time() | ||
self.last = self.start | ||
self.num_steps = lead_time // step | ||
LOG.info("Starting inference for %s steps (%sh).", self.num_steps, lead_time) | ||
|
||
def __enter__(self): | ||
return self | ||
|
||
def __call__(self, i, step): | ||
now = time.time() | ||
elapsed = now - self.start | ||
speed = (i + 1) / elapsed | ||
eta = (self.num_steps - i) / speed | ||
LOG.info( | ||
"Done %s out of %s in %s (%sh), ETA: %s.", | ||
i + 1, | ||
self.num_steps, | ||
seconds(now - self.last), | ||
step, | ||
seconds(eta), | ||
) | ||
self.last = now | ||
|
||
def __exit__(self, *args): | ||
elapsed = time.time() - self.start | ||
LOG.info("Elapsed: %s.", seconds(elapsed)) | ||
LOG.info("Average: %s per step.", seconds(elapsed / self.num_steps)) |