26
26
27
27
def print_daemon_log ():
28
28
home = os .environ ['HOME' ]
29
- print "Output of 'cat {}/.aiida/daemon/log/aiida_daemon .log':" .format (home )
29
+ print "Output of 'cat {}/.aiida/daemon/log/celery .log':" .format (home )
30
30
try :
31
31
print subprocess .check_output (
32
- ["cat" , "{}/.aiida/daemon/log/aiida_daemon .log" .format (home )],
32
+ ["cat" , "{}/.aiida/daemon/log/celery .log" .format (home )],
33
33
stderr = subprocess .STDOUT ,
34
34
)
35
35
except subprocess .CalledProcessError as e :
@@ -98,6 +98,65 @@ def validate_workchains(expected_results):
98
98
99
99
return valid
100
100
101
+ def validate_cached (cached_calcs ):
102
+ """
103
+ Check that the calculations with created with caching are indeed cached.
104
+ """
105
+ return all (
106
+ '_aiida_cached_from' in calc .extras () and
107
+ calc .get_hash () == calc .get_extra ('_aiida_hash' )
108
+ for calc in cached_calcs
109
+ )
110
+
111
+ def create_calculation (code , counter , inputval , use_cache = False ):
112
+ parameters = ParameterData (dict = {'value' : inputval })
113
+ template = ParameterData (dict = {
114
+ ## The following line adds a significant sleep time.
115
+ ## I set it to 1 second to speed up tests
116
+ ## I keep it to a non-zero value because I want
117
+ ## To test the case when AiiDA finds some calcs
118
+ ## in a queued state
119
+ #'cmdline_params': ["{}".format(counter % 3)], # Sleep time
120
+ 'cmdline_params' : ["1" ],
121
+ 'input_file_template' : "{value}" , # File just contains the value to double
122
+ 'input_file_name' : 'value_to_double.txt' ,
123
+ 'output_file_name' : 'output.txt' ,
124
+ 'retrieve_temporary_files' : ['triple_value.tmp' ]
125
+ })
126
+ calc = code .new_calc ()
127
+ calc .set_max_wallclock_seconds (5 * 60 ) # 5 min
128
+ calc .set_resources ({"num_machines" : 1 })
129
+ calc .set_withmpi (False )
130
+ calc .set_parser_name ('simpleplugins.templatereplacer.test.doubler' )
131
+
132
+ calc .use_parameters (parameters )
133
+ calc .use_template (template )
134
+ calc .store_all (use_cache = use_cache )
135
+ expected_result = {
136
+ 'value' : 2 * inputval ,
137
+ 'retrieved_temporary_files' : {
138
+ 'triple_value.tmp' : str (inputval * 3 )
139
+ }
140
+ }
141
+ print "[{}] created calculation {}, pk={}" .format (
142
+ counter , calc .uuid , calc .dbnode .pk )
143
+ return calc , expected_result
144
+
145
+ def submit_calculation (code , counter , inputval ):
146
+ calc , expected_result = create_calculation (
147
+ code = code , counter = counter , inputval = inputval
148
+ )
149
+ calc .submit ()
150
+ print "[{}] calculation submitted." .format (counter )
151
+ return calc , expected_result
152
+
153
+ def create_cache_calc (code , counter , inputval ):
154
+ calc , expected_result = create_calculation (
155
+ code = code , counter = counter , inputval = inputval , use_cache = True
156
+ )
157
+ print "[{}] created cached calculation." .format (counter )
158
+ return calc , expected_result
159
+
101
160
def main ():
102
161
103
162
# Submitting the Calculations
@@ -106,39 +165,10 @@ def main():
106
165
expected_results_calculations = {}
107
166
for counter in range (1 , number_calculations + 1 ):
108
167
inputval = counter
109
- parameters = ParameterData (dict = {'value' : inputval })
110
- template = ParameterData (dict = {
111
- ## The following line adds a significant sleep time.
112
- ## I set it to 1 second to speed up tests
113
- ## I keep it to a non-zero value because I want
114
- ## To test the case when AiiDA finds some calcs
115
- ## in a queued state
116
- #'cmdline_params': ["{}".format(counter % 3)], # Sleep time
117
- 'cmdline_params' : ["1" ],
118
- 'input_file_template' : "{value}" , # File just contains the value to double
119
- 'input_file_name' : 'value_to_double.txt' ,
120
- 'output_file_name' : 'output.txt' ,
121
- 'retrieve_temporary_files' : ['triple_value.tmp' ]
122
- })
123
- calc = code .new_calc ()
124
- calc .set_max_wallclock_seconds (5 * 60 ) # 5 min
125
- calc .set_resources ({"num_machines" : 1 })
126
- calc .set_withmpi (False )
127
- calc .set_parser_name ('simpleplugins.templatereplacer.test.doubler' )
128
-
129
- calc .use_parameters (parameters )
130
- calc .use_template (template )
131
- calc .store_all ()
132
- print "[{}] created calculation {}, pk={}" .format (
133
- counter , calc .uuid , calc .dbnode .pk )
134
- expected_results_calculations [calc .pk ] = {
135
- 'value' : inputval * 2 ,
136
- 'retrieved_temporary_files' : {
137
- 'triple_value.tmp' : str (inputval * 3 )
138
- }
139
- }
140
- calc .submit ()
141
- print "[{}] calculation submitted." .format (counter )
168
+ calc , expected_result = submit_calculation (
169
+ code = code , counter = counter , inputval = inputval
170
+ )
171
+ expected_results_calculations [calc .pk ] = expected_result
142
172
143
173
# Submitting the Workchains
144
174
print "Submitting {} workchains to the daemon" .format (number_workchains )
@@ -158,7 +188,7 @@ def main():
158
188
exited_with_timeout = True
159
189
while time .time () - start_time < timeout_secs :
160
190
time .sleep (15 ) # Wait a few seconds
161
-
191
+
162
192
# Print some debug info, both for debugging reasons and to avoid
163
193
# that the test machine is shut down because there is no output
164
194
@@ -168,7 +198,7 @@ def main():
168
198
print "Output of 'verdi calculation list -a':"
169
199
try :
170
200
print subprocess .check_output (
171
- ["verdi" , "calculation" , "list" , "-a" ],
201
+ ["verdi" , "calculation" , "list" , "-a" ],
172
202
stderr = subprocess .STDOUT ,
173
203
)
174
204
except subprocess .CalledProcessError as e :
@@ -177,7 +207,7 @@ def main():
177
207
print "Output of 'verdi work list':"
178
208
try :
179
209
print subprocess .check_output (
180
- ['verdi' , 'work' , 'list' ],
210
+ ['verdi' , 'work' , 'list' ],
181
211
stderr = subprocess .STDOUT ,
182
212
)
183
213
except subprocess .CalledProcessError as e :
@@ -186,7 +216,7 @@ def main():
186
216
print "Output of 'verdi daemon status':"
187
217
try :
188
218
print subprocess .check_output (
189
- ["verdi" , "daemon" , "status" ],
219
+ ["verdi" , "daemon" , "status" ],
190
220
stderr = subprocess .STDOUT ,
191
221
)
192
222
except subprocess .CalledProcessError as e :
@@ -204,8 +234,18 @@ def main():
204
234
timeout_secs )
205
235
sys .exit (2 )
206
236
else :
237
+ # create cached calculations -- these should be FINISHED immediately
238
+ cached_calcs = []
239
+ for counter in range (1 , number_calculations + 1 ):
240
+ inputval = counter
241
+ calc , expected_result = create_cache_calc (
242
+ code = code , counter = counter , inputval = inputval
243
+ )
244
+ cached_calcs .append (calc )
245
+ expected_results_calculations [calc .pk ] = expected_result
207
246
if (validate_calculations (expected_results_calculations )
208
- and validate_workchains (expected_results_workchains )):
247
+ and validate_workchains (expected_results_workchains )
248
+ and validate_cached (cached_calcs )):
209
249
print_daemon_log ()
210
250
print ""
211
251
print "OK, all calculations have the expected parsed result"
0 commit comments