9 from funcsigs
import signature
11 from inspect
import signature
14from hep_ipython_tools
import calculation_queue
17def create_all_calculations(parameter_creator_function, **calculation_lists):
19 Create all calculations.
22 parameter_names_in_list = calculation_lists.keys()
23 parameter_values_in_list = calculation_lists.values()
25 every_parameter_combination = create_every_parameter_combination(parameter_names_in_list,
26 parameter_values_in_list)
28 all_queues = [calculation_queue.CalculationQueue() for _
in every_parameter_combination]
30 def add_queue_if_needed(c_queue, param_combination):
31 param_combination_copy = param_combination.copy()
32 args = signature(parameter_creator_function).parameters
34 param_combination_copy.update({
"queue": c_queue})
36 return param_combination_copy
38 every_parameter_combination_with_queue = [add_queue_if_needed(c_queue, parameters)
for
39 c_queue, parameters
in zip(all_queues, every_parameter_combination)]
41 def call_creator(param_combination):
42 calculation_kwargs = parameter_creator_function(**param_combination)
43 return calculation_kwargs
45 all_calculation_kwargs = map(call_creator, every_parameter_combination_with_queue)
46 return all_calculation_kwargs, all_queues, every_parameter_combination
49def create_every_parameter_combination(parameter_names, parameter_values):
51 Combine all parameter values with all other parameter values
and form dictionaries
with the correct
55 parameter_names: A list of names of the parameters.
56 parameter_values: A list of lists
with parameter values. Each list stands
57 for one parameter (so the len of parameter_names must be the len of
61 A list of dictionaries, each a single combination of parameters.
64 assert len(parameter_names) == len(parameter_values)
66 every_parameter_combination = itertools.product(*parameter_values)
67 every_parameter_combination_with_names = [
68 {parameter_name: value
for parameter_name, value
in zip(
69 parameter_names, values)}
for values
in every_parameter_combination]
70 return every_parameter_combination_with_names