Skip to content

Commit

Permalink
Merge pull request #318 from sciris/rc1.4.0-psl-resourcelimit
Browse files Browse the repository at this point in the history
Rc1.4.0 psl resourcelimit
  • Loading branch information
cliffckerr committed Aug 15, 2022
2 parents 061777e + 6235434 commit 409271e
Show file tree
Hide file tree
Showing 12 changed files with 1,123 additions and 551 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ New functions and methods
#. ``sc.rmnans()`` and ``sc.fillnans()`` have been added as aliases of ``sc.sanitize()`` with default options.
#. ``sc.rmpath()`` removes both files and folders, with an optional interactive mode.
#. ``sc.ispath()`` is an alias for ``isinstance(obj, pathlib.Path)``.
#. ``sc.randsleep()`` sleeps for a nondeterministic period of time

Bugfixes
~~~~~~~~
Expand All @@ -29,19 +30,24 @@ Bugfixes
Improvements
~~~~~~~~~~~~
#. If a copy/deepcopy is not possible, ``sc.cp()``/``sc.dcp()`` now raise an exception by default (previously, they silenced it).
#. ``sc.timer()`` now has a ``plot()`` method.
#. ``sc.parallelize()`` now supports additional parallelization options, e.g. ``concurrent.futures``, and new ``maxcpu``/``maxmem`` arguments.
#. ``sc.daterange()`` now accepts ``datedelta`` arguments, e.g. ``sc.daterange('2022-02-22', weeks=2)``.
#. ``sc.sanitize()`` can now handle multidimensional arrays.
#. ``sc.savefig()`` by default now creates folders if they don't exist.
#. ``sc.sanitize()`` can now handle multidimensional arrays.
#. ``sc.loadmetadata()`` can now read metadata from JPG files.
#. ``sc.timer()`` now has a ``plot()`` method.
#. ``sc.checkmem()`` now returns a dictionary of sizes rather than print to screen.

Housekeeping
~~~~~~~~~~~~
#. Profiling and load balancing functions have beem moved from ``sc.sc_utils`` and ``sc.sc_parallel`` to a new submodule, ``sc.sc_profiling``.
#. Most ``DeprecationWarning``s have been changed to ``FutureWarning``s.
Regression information
~~~~~~~~~~~~~~~~~~~~~~
#. The default for ``sc.cp()`` and ``sc.dcp()`` changed from ``die=False`` to ``die=True``, which may cause previously caught exceptions to be uncaught. For previous behavior, use ``sc.dcp(..., die=False)``.
#. The argument ``maxload`` (in ``sc.loadbalancer()``, ``sc.parallelize()``, etc.) has been renamed ``maxcpu`` (for consistency with the new ``maxmem`` argument).
#. Previously ``sc.loadbalancer(maxload=None)`` was interpreted as a default load limit (0.8); ``None`` is now interpreted as no limit.


Version 1.3.3 (2022-01-16)
Expand Down
3 changes: 2 additions & 1 deletion sciris/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
from .sc_math import *
from .sc_odict import *
from .sc_dataframe import *
from .sc_parallel import *
from .sc_fileio import *
from .sc_profiling import *
from .sc_parallel import *
from .sc_asd import *
from .sc_plotting import *
from .sc_colors import *
33 changes: 32 additions & 1 deletion sciris/sc_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,7 @@ def toc(self, label=None, **kwargs):

return output


def start(self):
''' Alias for tic() '''
return self.tic()
Expand All @@ -786,6 +787,7 @@ def tt(self, *args, **kwargs):
''' Alias for toctic() '''
return self.toctic(*args, **kwargs)


def plot(self, fig=None, figkwargs=None, grid=True, **kwargs):
"""
Create a plot of Timer.timings
Expand Down Expand Up @@ -842,7 +844,7 @@ def plot(self, fig=None, figkwargs=None, grid=True, **kwargs):
#%% Other functions
###############################################################################

__all__ += ['elapsedtimestr', 'timedsleep']
__all__ += ['elapsedtimestr', 'timedsleep', 'randsleep']


def elapsedtimestr(pasttime, maxdays=5, minseconds=10, shortmonths=True):
Expand Down Expand Up @@ -996,3 +998,32 @@ def timedsleep(delay=None, start=None, verbose=True):
if verbose:
print(f'Warning, delay less than elapsed time ({delay:0.1f} vs. {elapsed:0.1f})')
return


def randsleep(delay=1.0, var=1.0, low=None, high=None):
'''
Sleep for a nondeterminate period of time (useful for desynchronizing tasks)
Args:
delay (float/list): average duration in seconds to sleep for; if a pair of values, treat as low and high
var (float): how much variability to have (default, 1.0, i.e. from 0 to 2*interval)
low (float): optionally define lower bound of sleep
high (float): optionally define upper bound of sleep
**Examples**::
sc.randsleep(1) # Sleep for 0-2 s (average 1.0)
sc.randsleep(2, 0.1) # Sleep for 1.8-2.2 s (average 2.0)
sc.randsleep([0.5, 1.5]) # Sleep for 0.5-1.5 s
sc.randsleeep(low=0.5, high=1.5) # Ditto
'''
if low is None or high is None:
if scu.isnumber(delay):
low = delay*(1-var)
high = delay*(1+var)
else:
low, high = delay[0], delay[1]

dur = np.random.uniform(low, high)
time.sleep(dur)

return dur

0 comments on commit 409271e

Please sign in to comment.