Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Parameters
----------
Work: :obj:`dict`
:ref:`(example)`
calc_in: obj: numpy structured array
Rows from the :ref:`history array`
for processing
"""
calc_type = Work['tag']
self.calc_iter[calc_type] += 1
# calc_stats stores timing and summary info for this Calc (sim or gen)
calc_id = next(self._calc_id_counter)
timer = Timer()
try:
logger.debug("Running {}".format(calc_type_strings[calc_type]))
calc = self._run_calc[calc_type]
with timer:
logger.debug("Calling calc {}".format(calc_type))
# Worker creates own sim_dir only if sim work performed.
if calc_type == EVAL_SIM_TAG and self.loc_stack:
with self.loc_stack.loc(calc_type):
out = calc(calc_in, Work['persis_info'], Work['libE_info'])
elif calc_type == EVAL_SIM_TAG and not self.loc_stack:
self.loc_stack = Worker._make_sim_worker_dir(self.sim_specs, self.workerID)
with self.loc_stack.loc(calc_type):
out = calc(calc_in, Work['persis_info'], Work['libE_info'])
def libE_tcp_start_team(manager, nworkers, workers,
ip, port, authkey, launchf):
"Launch nworkers workers that attach back to a managers server."
worker_procs = []
specs = {'manager_ip': ip, 'manager_port': port, 'authkey': authkey}
with Timer() as timer:
for w in range(1, nworkers+1):
logger.info("Manager is launching worker {}".format(w))
if workers is not None:
specs['worker_ip'] = workers[w-1]
specs['tunnel_port'] = 0x71BE
specs['workerID'] = w
worker_procs.append(launchf(specs))
logger.info("Manager is awaiting {} workers".format(nworkers))
wcomms = manager.await_workers(nworkers)
logger.info("Manager connected to {} workers ({} s)".
format(nworkers, timer.elapsed))
return worker_procs, wcomms
def libE_tcp_start_team(manager, nworkers, workers,
ip, port, authkey, launchf):
"Launch nworkers workers that attach back to a managers server."
worker_procs = []
specs = {'manager_ip': ip, 'manager_port': port, 'authkey': authkey}
with Timer() as timer:
for w in range(1, nworkers+1):
logger.info("Manager is launching worker {}".format(w))
if workers is not None:
specs['worker_ip'] = workers[w-1]
specs['tunnel_port'] = 0x71BE
specs['workerID'] = w
worker_procs.append(launchf(specs))
logger.info("Manager is awaiting {} workers".format(nworkers))
wcomms = manager.await_workers(nworkers)
logger.info("Manager connected to {} workers ({} s)".
format(nworkers, timer.elapsed))
return worker_procs, wcomms
"""Stop the timer."""
self.tend = time.time()
self.timing = False
self.tcum += (self.tend-self.tstart)
def __enter__(self):
"""Enter a timing context."""
self.start()
return self
def __exit__(self, etype, value, traceback):
"""Exit a timing context."""
self.stop()
class JobTimer(Timer):
"""Timer class used in job controller jobs."""
def __str__(self):
"""Return a string representation of the timer."""
return ("JobTime: {0:.2f} JStart: {1} JEnd: {2}".
format(self.total, self.date_start, self.date_end))
def __init__(self, hist, libE_specs, alloc_specs,
sim_specs, gen_specs, exit_criteria,
wcomms=[]):
"""Initialize the manager."""
timer = Timer()
timer.start()
self.hist = hist
self.libE_specs = libE_specs
self.alloc_specs = alloc_specs
self.sim_specs = sim_specs
self.gen_specs = gen_specs
self.exit_criteria = exit_criteria
self.elapsed = lambda: timer.elapsed
self.wcomms = wcomms
self.W = np.zeros(len(self.wcomms), dtype=Manager.worker_dtype)
self.W['worker_id'] = np.arange(len(self.wcomms)) + 1
self.term_tests = \
[(2, 'elapsed_wallclock_time', self.term_test_wallclock),
(1, 'sim_max', self.term_test_sim_max),
(1, 'gen_max', self.term_test_gen_max),
(1, 'stop_val', self.term_test_stop_val)]