Conditions | 7 |
Total Lines | 66 |
Lines | 0 |
Ratio | 0 % |
Changes | 35 | ||
Bugs | 10 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | |||
98 | def create_submit(queue_id,**kwargs): |
||
99 | queue_name = queue_id |
||
100 | num_tasks = 1 |
||
101 | if 'num_tasks' in kwargs: |
||
102 | num_tasks = kwargs['num_tasks'] |
||
103 | |||
104 | tpn = tasks_per_node(queue_id) |
||
105 | queue_tpn = tpn |
||
106 | if 'tasks_per_node' in kwargs: |
||
107 | tpn = min(tpn,kwargs['tasks_per_node']) |
||
108 | |||
109 | nc = node_config(queue_id) |
||
110 | qc = available_tasks(queue_id) |
||
111 | |||
112 | if qc['max tasks'] > 0: |
||
113 | num_tasks = min(num_tasks,qc['max tasks']) |
||
114 | |||
115 | num_threads_per_task = nc['max thread'] |
||
116 | if 'num_threads_per_task' in kwargs: |
||
117 | num_threads_per_task = kwargs['num_threads_per_task'] |
||
118 | num_threads_per_task = min(num_threads_per_task,int(math.ceil(float(nc['max thread'])/float(tpn)))) |
||
119 | |||
120 | my_name = kwargs.get('my_name', "myclusterjob") |
||
121 | my_output = kwargs.get('my_output', "myclusterjob.out") |
||
122 | my_script = kwargs.get('my_script', None) |
||
123 | if 'mycluster-' in my_script: |
||
124 | my_script = get_data(my_script) |
||
125 | |||
126 | user_email = kwargs.get('user_email', None) |
||
127 | project_name = kwargs.get('project_name', 'default') |
||
128 | |||
129 | wall_clock = kwargs.get('wall_clock', '12:00') |
||
130 | if ':' not in wall_clock: |
||
131 | wall_clock = wall_clock + ':00' |
||
132 | |||
133 | num_nodes = int(math.ceil(float(num_tasks)/float(tpn))) |
||
134 | |||
135 | num_queue_slots = num_nodes*queue_tpn |
||
136 | |||
137 | no_syscribe = kwargs.get('no_syscribe', False) |
||
138 | |||
139 | record_job = not no_syscribe |
||
140 | |||
141 | openmpi_args = kwargs.get('openmpi_args', "-bysocket -bind-to-socket") |
||
142 | |||
143 | qos = kwargs.get('qos', None) |
||
144 | |||
145 | template = load_template('lsf.jinja') |
||
146 | |||
147 | script_str = template.render(my_name = my_name, |
||
148 | my_script = my_script, |
||
149 | my_output = my_output, |
||
150 | user_email = user_email, |
||
151 | queue_name = queue_name, |
||
152 | num_queue_slots = num_queue_slots, |
||
153 | num_tasks = num_tasks, |
||
154 | tpn = tpn, |
||
155 | num_threads_per_task = num_threads_per_task, |
||
156 | num_nodes = num_nodes, |
||
157 | project_name = project_name, |
||
158 | wall_clock = wall_clock, |
||
159 | record_job = record_job, |
||
160 | openmpi_args = openmpi_args, |
||
161 | qos = qos) |
||
162 | |||
163 | return script_str |
||
164 | |||
234 |