Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
else:
commentstr = ''
reason += 'Trajectory %s%s -- Explored Parameters: %s' % \
(self._traj.v_name,
commentstr,
str(compat.listkeys(self._traj._explored_parameters)))
self._logger.info('Preparing sumatra record with reason: %s' % reason)
self._sumatra_reason = reason
self._loaded_sumatatra_project = load_project(self._sumatra_project)
if self._traj.f_contains('parameters', shortcuts=False):
param_dict = self._traj.parameters.f_to_dict(fast_access=False)
for param_name in compat.listkeys(param_dict):
param = param_dict[param_name]
if param.f_has_range():
param_dict[param_name] = param.f_get_range()
else:
param_dict[param_name] = param.f_get()
else:
param_dict = {}
relpath = os.path.relpath(sys.modules['__main__'].__file__, self._sumatra_project)
executable = PythonExecutable(path=sys.executable)
self._sumatra_record = self._loaded_sumatatra_project.new_record(
parameters=param_dict,
main_file=relpath,
executable=executable,
def _prepare_sumatra(self):
""" Prepares a sumatra record """
reason = self._sumatra_reason
if reason:
reason += ' -- '
if self._traj.v_comment:
commentstr = ' (`%s`)' % self._traj.v_comment
else:
commentstr = ''
reason += 'Trajectory %s%s -- Explored Parameters: %s' % \
(self._traj.v_name,
commentstr,
str(compat.listkeys(self._traj._explored_parameters)))
self._logger.info('Preparing sumatra record with reason: %s' % reason)
self._sumatra_reason = reason
self._loaded_sumatatra_project = load_project(self._sumatra_project)
if self._traj.f_contains('parameters', shortcuts=False):
param_dict = self._traj.parameters.f_to_dict(fast_access=False)
for param_name in compat.listkeys(param_dict):
param = param_dict[param_name]
if param.f_has_range():
param_dict[param_name] = param.f_get_range()
else:
param_dict[param_name] = param.f_get()
else:
param_dict = {}
if log_levels is None:
log_levels = kwargs.pop('log_levels', logging.INFO)
log_multiproc = kwargs.pop('log_multiproc', True)
if not isinstance(logger_names, (tuple, list)):
logger_names = [logger_names]
if not isinstance(log_levels, (tuple, list)):
log_levels = [log_levels]
if len(log_levels) == 1:
log_levels = [log_levels[0] for _ in logger_names]
# We don't want to manipulate the original dictionary
dictionary = copy.deepcopy(LOGGING_DICT)
prefixes = ['']
if not log_multiproc:
for key in compat.listkeys(dictionary):
if key.startswith('multiproc_'):
del dictionary[key]
else:
prefixes.append('multiproc_')
# Add all handlers to all loggers
for prefix in prefixes:
for handler_dict in dictionary[prefix + 'handlers'].values():
if 'filename' in handler_dict:
filename = os.path.join(log_folder, handler_dict['filename'])
filename = os.path.normpath(filename)
handler_dict['filename'] = filename
dictionary[prefix + 'loggers'] = {}
logger_dict = dictionary[prefix + 'loggers']
for idx, logger_name in enumerate(logger_names):
logger_dict[logger_name] = {
process_dict = {} # Dict containing all subprocees
# For the cap values, we lazily evaluate them
cpu_usage_func = lambda: self._estimate_cpu_utilization()
memory_usage_func = lambda: self._estimate_memory_utilization(process_dict)
swap_usage_func = lambda: psutil.swap_memory().percent
signal_cap = True # If True cap warning is emitted
max_signals = 10 # Maximum number of warnings, after that warnings are
# no longer signaled
# Signal start of progress calculation
self._show_progress(n - 1, total_runs)
while len(process_dict) > 0 or keep_running:
# First check if some processes did finish their job
for pid in compat.listkeys(process_dict):
proc = process_dict[pid]
# Delete the terminated processes
if not proc.is_alive():
proc.join()
del process_dict[pid]
del proc
# Check if caps are reached.
# Cap is only checked if there is at least one
# process working to prevent deadlock.
no_cap = True
if self._check_usage and self._ncores > len(process_dict) > 0:
for cap_name, cap_function, threshold in (
('CPU Cap', cpu_usage_func, self._cpu_cap),
('Memory Cap', memory_usage_func, self._memory_cap[0]),
:param split_name: DEQUE of names to get the next nodes.
:param recursive:
To also delete all children of a group node
:return: True if node was deleted, otherwise False
"""
# If the names list is empty, we have reached the node we want to delete.
if len(split_name) == 0:
if actual_node.v_is_group and actual_node.f_has_children():
if recursive:
for child in compat.listkeys(actual_node._children):
actual_node.f_remove_child(child, recursive=True)
else:
raise TypeError('Cannot remove group `%s` it contains children. Please '
'remove with `recursive=True`.' % actual_node.v_full_name)
self._delete_node(actual_node)
return True
# Otherwise get the next node by using the first name in the list
name = split_name.popleft()
if name in actual_node._links:
if len(split_name)>0:
raise RuntimeError('You cannot remove nodes while hopping over links!')
actual_node.f_remove_link(name)
else:
child = actual_node._children[name]
(self.v_full_name, str(compat.listkeys(self._data))))
else:
raise AttributeError('Your result `%s` is empty, cannot access data.' %
self.v_full_name)
result_list = []
for name in args:
if isinstance(name, int):
if name == 0:
name = self.v_name
else:
name = self.v_name + '_%d' % name
if not name in self._data:
if name == 'data' and len(self._data) == 1:
return self._data[compat.listkeys(self._data)[0]]
else:
raise AttributeError('`%s` is not part of your result `%s`.' %
(name, self.v_full_name))
result_list.append(self._data[name])
if len(args) == 1:
return result_list[0]
else:
return result_list