4 from hep_ipython_tools
import calculation_queue, calculation, information, calculation_list
10 Handler class to start processes in an IPython notebook in a convenient way.
11 From this whole framework you should not need to create any instances by yourself but rather use the
12 given ipython handler for this.
14 Create a handler object in the beginning of your NB and use the two methods `process()`
15 and `process_parameter_space()` to turn parameters or a parameter creator function into a Calculation.
16 Do not create calculations on you own::
18 from tracking.validation.ipython_handler import handler
20 calculation = handler.process(parameters)
26 Each created log file gets registered and deleted if there are more than 20 log files present
27 or if the get_log function of the process is called (the log is saved elsewhere).
28 As the log files are saved to /tmp you have probably not to care about deleting them.
40 def process(self, result_queue=None, **kwargs):
42 Turn a parameter set into a Calculation that you can start, stop or whatever you want.
45 result_queue: The CalculationQueue you want to use. Without giving
46 this as a parameter the function creates one for you. Create
47 one on your own with the function create_queue.
50 if result_queue
is None:
54 calculation.append(result_queue=result_queue, log_file_name=self.
next_log_file_name(), parameters=
None, **kwargs)
60 Create a list of calculations by combining all parameters with all parameters you provide and
61 feeding the tuple into the parameter_creator_function.
62 If the kwargs_creator_function has a parameter named queue, the function feeds the corresponding
63 created queue into the parameter_creator_function.
64 The parameter_creator_function must return a dictionary for every combination of parameters it gets,
65 which will be used to construct a process out of it.
66 See ipython_handler_basf2/ipython_handler for an example.
68 Please note that a list of calculations acts the same as a single calculation you would get from
69 the process function. You can handle 10 calculations the same way you would handle a single one.
71 The kwargs_creator_function can transform the incoming parameters into different ones. To make this
72 more clear, the resulting dictionary created by the kwargs_creator_function is called kwargs.
73 These are the ones, that will be used to create a calculation process, so they must be compatible to the
74 calculation you chose (namely compatible with the append function of the _calculation_type).
77 kwargs_creator_function: A function with as many input parameters
78 as parameters you provide. If the function has an additional
79 queue parameter it is fed with the corresponding queue for this
81 parameter_lists: As many lists as you want. Every list is one
82 parameter. If you do not want a specific parameter
83 constellation to occur, you can return None in your
84 parameter_creator_function for this combination.
88 def kwargs_creator_function(par_1, par_2, par_3, queue):
89 kwargs = {... f(par_1) ... g(par_2) ... h(par_3)}
93 calculations = handler.process_parameter_space(kwargs_creator_function,
94 par_1=[1, 2, 3], par_2=["x", "y", "z"], par_3=[3, 4, 5])
96 The calculations will be created with the kwargs arguments.
99 all_kwargs, all_queues, all_parameters = calculation_list.create_all_calculations(kwargs_creator_function,
104 for kwargs, q, parameters
in zip(all_kwargs, all_queues, all_parameters):
106 parameters=parameters, **kwargs)
112 Return the name of the next log file.
113 If there are more than 20 log files present,
114 start deleting the oldest ones.
116 next_log_file = tempfile.mkstemp()
120 f = first_log_file[0]
121 log_file_name = first_log_file[1]
125 os.unlink(log_file_name)
128 return next_log_file[1]
133 Create a Calculation queue. You need to do this if you want to pass it to your modules
134 and write to it while processing the events.