本文整理汇总了Python中sfepy.base.base.Struct.dump_names方法的典型用法代码示例。如果您正苦于以下问题:Python Struct.dump_names方法的具体用法?Python Struct.dump_names怎么用?Python Struct.dump_names使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfepy.base.base.Struct
的用法示例。
在下文中一共展示了Struct.dump_names方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: call
# 需要导入模块: from sfepy.base.base import Struct [as 别名]
# 或者: from sfepy.base.base.Struct import dump_names [as 别名]
def call( self, ret_all = False ):
problem = self.problem
opts = self.app_options
coef_info = getattr( self.conf, opts.coefs )
compute_names = set(get_default(opts.compute_only, coef_info.keys()))
compute_names = ['c.' + key for key in compute_names]
is_store_filenames = coef_info.pop('filenames', None) is not None
try:
compute_names.remove('c.filenames')
except:
pass
dependencies = {}
save_names = {}
dump_names = {}
def store_filenames( app ):
if not '(not_set)' in app.get_save_name_base():
save_names[app.name] = app.get_save_name_base()
if not '(not_set)' in app.get_dump_name_base():
dump_names[app.name] = app.get_dump_name_base()
# Some coefficients can require other coefficients - resolve their
# order here.
req_info = self.conf.get(opts.requirements, {})
info = copy(coef_info)
info.update(req_info)
all_deps = set(compute_names)
sorted_names = []
for coef_name in compute_names:
cargs = coef_info[coef_name[2:]]
requires = cargs.get('requires', [])
deps = insert_sub_reqs(copy(requires), [], info)
all_deps.update(deps)
aux = [key for key in deps if key.startswith('c.')] + [coef_name]
sorted_names.extend(aux)
sorted_coef_names = []
for name in sorted_names:
if name[2:] not in sorted_coef_names:
sorted_coef_names.append(name[2:])
coefs = Struct()
for coef_name in sorted_coef_names:
cargs = coef_info[coef_name]
output('computing %s...' % coef_name)
requires = cargs.get('requires', [])
requirements = [name for name in requires if not
name.startswith('c.')]
self.compute_requirements(requirements, dependencies,
store_filenames)
for name in requires:
if name.startswith('c.'):
dependencies[name] = getattr(coefs, name[2:])
mini_app = MiniAppBase.any_from_conf( coef_name, problem, cargs )
problem.clear_equations()
# Pass only the direct dependencies, not the indirect ones.
data = {}
for key in requires:
data[key] = dependencies[key]
val = mini_app(self.volume, data=data)
setattr(coefs, coef_name, val)
output( '...done' )
# remove "auxiliary" coefs
for coef_name in sorted_coef_names:
cstat = coef_info[coef_name].get('status', 'main')
if cstat == 'auxiliary':
delattr(coefs, coef_name)
# Store filenames of all requirements as a "coefficient".
if is_store_filenames:
coefs.save_names = save_names
coefs.dump_names = dump_names
if opts.coefs_info is not None:
coefs.info = opts.coefs_info
if ret_all:
return coefs, dependencies
else:
return coefs
示例2: call
# 需要导入模块: from sfepy.base.base import Struct [as 别名]
# 或者: from sfepy.base.base.Struct import dump_names [as 别名]
def call(self, ret_all=False):
problem = self.problem
opts = self.app_options
# Some coefficients can require other coefficients - resolve their
# order here.
req_info = getattr(self.conf, opts.requirements, {})
coef_info = getattr(self.conf, opts.coefs, {})
is_store_filenames = coef_info.pop('filenames', None) is not None
sorted_names = self.get_sorted_dependencies(req_info, coef_info,
opts.compute_only)
use_multiprocessing = _use_multiprocessing\
and getattr(self.conf.options, 'multiprocessing', True)\
and len(sorted_names) > 2
coefs = Struct()
if use_multiprocessing:
manager = multiprocessing.Manager()
dependencies = manager.dict()
sd_names = manager.dict()
numdeps = manager.list()
remaining = manager.Value('i', len(sorted_names))
tasks = multiprocessing.Queue()
lock = multiprocessing.Lock()
# calculate namber of dependencies and inverse map
inverse_deps = {}
for ii, name in enumerate(sorted_names):
if name.startswith('c.'):
reqs = coef_info[name[2:]].get('requires', [])
else:
reqs = req_info[name].get('requires', [])
numdeps.append(len(reqs))
if len(reqs) > 0:
for req in reqs:
if req in inverse_deps:
inverse_deps[req].append((ii, name))
else:
inverse_deps[req] = [(ii, name)]
for ii, name in enumerate(sorted_names):
if numdeps[ii] == 0:
tasks.put(name)
num_workers = multiprocessing.cpu_count()
workers = []
for ii in xrange(num_workers):
args = (tasks, lock, remaining, numdeps, inverse_deps,
problem, opts, self.volume, self.post_process_hook,
req_info, coef_info, sd_names, dependencies)
w = multiprocessing.Process(target=self.calculate_req_multi,
args=args)
w.start()
workers.append(w)
# block until all workes are terminated
for w in workers:
w.join()
else: # no mlutiprocessing
dependencies = {}
sd_names = {}
for name in sorted_names:
val = self.calculate_req(problem, opts,
self.volume, self.post_process_hook,
name, req_info, coef_info,
sd_names, dependencies)
dependencies[name] = val
coefs = Struct()
deps = {}
for name in dependencies.keys():
data = dependencies[name]
if name.startswith('c.'):
coef_name = name[2:]
cstat = coef_info[coef_name].get('status', 'main')
# remove "auxiliary" coefs
if not cstat == 'auxiliary':
setattr(coefs, coef_name, data)
else:
deps[name] = data
# Store filenames of all requirements as a "coefficient".
if is_store_filenames:
save_names = {}
dump_names = {}
for name in sd_names.keys():
val = sd_names[name]
if name.startswith('s.'):
save_names[name[2:]] = val
elif name.startswith('d.'):
dump_names[name[2:]] = val
coefs.save_names = save_names
coefs.dump_names = dump_names
if opts.coefs_info is not None:
coefs.info = opts.coefs_info
#.........这里部分代码省略.........
示例3: call
# 需要导入模块: from sfepy.base.base import Struct [as 别名]
# 或者: from sfepy.base.base.Struct import dump_names [as 别名]
def call( self, ret_all = False ):
problem = self.problem
opts = self.app_options
coef_info = getattr( self.conf, opts.coefs )
is_store_filenames = coef_info.pop('filenames', None) is not None
dependencies = {}
save_names = {}
dump_names = {}
def store_filenames( app ):
if not '(not_set)' in app.get_save_name_base():
save_names[app.name] = app.get_save_name_base()
if not '(not_set)' in app.get_dump_name_base():
dump_names[app.name] = app.get_dump_name_base()
def _get_parents(req_list):
out = []
for req_name in req_list:
aux = req_name.split('.')
if len(aux) == 2:
out.append(aux[1])
return out
# Some coefficients can require other coefficients - resolve theirorder
# here.
graph = {}
for coef_name, cargs in coef_info.iteritems():
if not coef_name in graph:
graph[coef_name] = [0]
requires = cargs.get('requires', [])
for parent in _get_parents(requires):
graph[coef_name].append(parent)
requires.remove('c.' + parent)
sorted_coef_names = sort_by_dependency(deepcopy(graph))
## print graph
## print sorted_coef_names
coefs = Struct()
for coef_name in sorted_coef_names:
cargs = coef_info[coef_name]
output( 'computing %s...' % coef_name )
requires = cargs.get( 'requires', [] )
self.compute_requirements( requires, dependencies, store_filenames )
mini_app = MiniAppBase.any_from_conf( coef_name, problem, cargs )
if len(graph[coef_name]) > 1:
for name in graph[coef_name][1:]:
key = 'c.' + name
requires.append(key)
dependencies[key] = getattr(coefs, name)
problem.clear_equations()
# Pass only the direct dependencies, not the indirect ones.
data = {}
for key in requires:
data[key] = dependencies[key]
val = mini_app(self.volume, data=data)
setattr( coefs, coef_name, val )
output( '...done' )
# remove "auxiliary" coefs
for coef_name in sorted_coef_names:
cstat = coef_info[coef_name].get('status', 'main')
if cstat == 'auxiliary':
delattr(coefs, coef_name)
# Store filenames of all requirements as a "coefficient".
if is_store_filenames:
coefs.save_names = save_names
coefs.dump_names = dump_names
if ret_all:
return coefs, dependencies
else:
return coefs
示例4: call
# 需要导入模块: from sfepy.base.base import Struct [as 别名]
# 或者: from sfepy.base.base.Struct import dump_names [as 别名]
#.........这里部分代码省略.........
# calculate number of dependencies and inverse map
inverse_deps = {}
for ii, name in enumerate(sorted_names):
if name.startswith('c.'):
reqs = coef_info[name[2:]].get('requires', [])
else:
reqs = req_info[name].get('requires', [])
numdeps.append(len(reqs))
if len(reqs) > 0:
for req in reqs:
if req in inverse_deps:
inverse_deps[req].append((ii, name))
else:
inverse_deps[req] = [(ii, name)]
for ii, name in enumerate(sorted_names):
if numdeps[ii] == 0:
tasks.put(name)
workers = []
for ii in range(num_workers):
args = (tasks, lock, remaining, numdeps, inverse_deps,
problem, opts, self.post_process_hook, req_info,
coef_info, sd_names, dependencies, self.micro_coors,
time_tag, micro_chunk_tab, str(ii + 1))
w = multiproc.Process(target=self.calculate_req_multi,
args=args)
w.start()
workers.append(w)
# block until all workes are terminated
for w in workers:
w.join()
if is_micro_coors:
dependencies = self.dechunk_reqs_coefs(dependencies,
len(micro_chunk_tab))
coef_info = coef_info_orig
else: # no mlutiprocessing
dependencies = {}
sd_names = {}
sorted_names = self.get_sorted_dependencies(req_info, coef_info,
opts.compute_only)
for name in sorted_names:
if not name.startswith('c.'):
if is_micro_coors:
req_info[name]['store_idxs'] = ([jj\
for jj in self.app_options.store_micro_idxs], 0)
val = self.calculate_req(problem, opts, self.post_process_hook,
name, req_info, coef_info, sd_names,
dependencies, self.micro_coors,
time_tag)
dependencies[name] = val
coefs = Struct()
deps = {}
for name in dependencies.keys():
data = dependencies[name]
if name.startswith('c.'):
coef_name = name[2:]
cstat = coef_info[coef_name].get('status', 'main')
# remove "auxiliary" coefs
if not cstat == 'auxiliary':
setattr(coefs, coef_name, data)
else:
deps[name] = data
# Store filenames of all requirements as a "coefficient".
if is_store_filenames:
for name in sd_names.keys():
if '|multiprocessing_' in name:
mname = rm_multi(name)
if mname in sd_names:
sd_names[mname] += sd_names[name]
else:
sd_names[mname] = sd_names[name]
del(sd_names[name])
save_names = {}
dump_names = {}
for name in sd_names.keys():
val = sd_names[name]
if name.startswith('s.'):
save_names[name[2:]] = val
elif name.startswith('d.'):
dump_names[name[2:]] = val
coefs.save_names = save_names
coefs.dump_names = dump_names
if opts.coefs_info is not None:
coefs.info = opts.coefs_info
if ret_all:
return coefs, deps
else:
return coefs