mg-pso-gui 0.1.13__py3-none-any.whl → 0.1.16__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
mgpsogui/trace.json ADDED
@@ -0,0 +1,472 @@
1
+ {
2
+ "dir": "C:\\Users\\robertcordingly\\PycharmProjects\\pythonProject6",
3
+ "start": "2024-03-13 02:06:28.041821",
4
+ "min_rounds": 1,
5
+ "max_rounds": 2,
6
+ "iters": 20,
7
+ "ftol": "-inf",
8
+ "ftol_iter": 1,
9
+ "rtol": 0.001,
10
+ "rtol_iter": 1,
11
+ "n_threads": 10,
12
+ "n_particles": 10,
13
+ "n_steps": 2,
14
+ "steps": [
15
+ {
16
+ "param": [
17
+ {
18
+ "name": "soilOutLPS",
19
+ "bounds": [
20
+ 0.0,
21
+ 2.0
22
+ ]
23
+ },
24
+ {
25
+ "name": "lagInterflow",
26
+ "bounds": [
27
+ 10.0,
28
+ 80.0
29
+ ]
30
+ }
31
+ ],
32
+ "objfunc": [
33
+ {
34
+ "name": "ns",
35
+ "of": "ns",
36
+ "data": [
37
+ "obs_data02_14.csv/obs/orun[1]",
38
+ "output/csip_run/out/Outlet.csv/output/catchmentSimRunoff"
39
+ ]
40
+ }
41
+ ]
42
+ },
43
+ {
44
+ "param": [
45
+ {
46
+ "name": "flowRouteTA",
47
+ "bounds": [
48
+ 0.4,
49
+ 5.0
50
+ ]
51
+ },
52
+ {
53
+ "name": "soilMaxDPS",
54
+ "bounds": [
55
+ 0.0,
56
+ 5.0
57
+ ]
58
+ }
59
+ ],
60
+ "objfunc": [
61
+ {
62
+ "name": "ns",
63
+ "of": "ns",
64
+ "data": [
65
+ "obs_data02_14.csv/obs/orun[1]",
66
+ "output/csip_run/out/Outlet.csv/output/catchmentSimRunoff"
67
+ ]
68
+ }
69
+ ]
70
+ }
71
+ ],
72
+ "args": {
73
+ "param": [
74
+ {
75
+ "name": "startTime",
76
+ "value": "2002-01-01"
77
+ },
78
+ {
79
+ "name": "endTime",
80
+ "value": "2006-12-31"
81
+ },
82
+ {
83
+ "name": "dataStartTime",
84
+ "value": "2002-01-01"
85
+ },
86
+ {
87
+ "name": "dataEndTime",
88
+ "value": "2006-12-31"
89
+ },
90
+ {
91
+ "name": "cal_startTime",
92
+ "value": "2003-01-01"
93
+ },
94
+ {
95
+ "name": "cal_endTime",
96
+ "value": "2006-12-31"
97
+ },
98
+ {
99
+ "name": "parallelismThreads",
100
+ "value": "2"
101
+ },
102
+ {
103
+ "name": "flagLoadState",
104
+ "value": "true"
105
+ },
106
+ {
107
+ "name": "payload",
108
+ "value": "false"
109
+ },
110
+ {
111
+ "name": "project",
112
+ "value": "SFIR3"
113
+ }
114
+ ],
115
+ "url": "http://csip.engr.colostate.edu:8087/csip-oms/m/ages/0.3.0",
116
+ "files": {},
117
+ "step_param_names": [
118
+ "flowRouteTA",
119
+ "soilMaxDPS"
120
+ ],
121
+ "step_objfunc": [
122
+ {
123
+ "name": "ns",
124
+ "of": "ns",
125
+ "data": [
126
+ "obs_data02_14.csv/obs/orun[1]",
127
+ "output/csip_run/out/Outlet.csv/output/catchmentSimRunoff"
128
+ ]
129
+ }
130
+ ],
131
+ "calib_params": {
132
+ "soilOutLPS": 1.3852729993614596,
133
+ "lagInterflow": 56.51654153627339
134
+ },
135
+ "req_queue": "<queue.Queue at 0x2b66bfe9f40>",
136
+ "conf": {
137
+ "service_timeout": 400.0,
138
+ "http_retry": 5,
139
+ "http_allow_redirects": true,
140
+ "async_call": false,
141
+ "http_conn_timeout": 10,
142
+ "http_read_timeout": 400,
143
+ "particles_fail": 5
144
+ },
145
+ "rnd": 2,
146
+ "step": 2
147
+ },
148
+ "r1s1": {
149
+ "time": "2024-03-13 02:09:17.010187",
150
+ "best_costs": [
151
+ [
152
+ 0.4132185,
153
+ 0.41315801
154
+ ]
155
+ ],
156
+ "steps": [
157
+ {
158
+ "param": [
159
+ {
160
+ "name": "soilOutLPS",
161
+ "bounds": [
162
+ 0.0,
163
+ 2.0
164
+ ],
165
+ "value": 1.4232478417536503
166
+ },
167
+ {
168
+ "name": "lagInterflow",
169
+ "bounds": [
170
+ 10.0,
171
+ 80.0
172
+ ],
173
+ "value": 58.2004069813242
174
+ }
175
+ ],
176
+ "objfunc": [
177
+ {
178
+ "name": "ns",
179
+ "of": "ns",
180
+ "data": [
181
+ "obs_data02_14.csv/obs/orun[1]",
182
+ "output/csip_run/out/Outlet.csv/output/catchmentSimRunoff"
183
+ ]
184
+ }
185
+ ],
186
+ "cost": 0.4965635659744849
187
+ },
188
+ {
189
+ "param": [
190
+ {
191
+ "name": "flowRouteTA",
192
+ "bounds": [
193
+ 0.4,
194
+ 5.0
195
+ ]
196
+ },
197
+ {
198
+ "name": "soilMaxDPS",
199
+ "bounds": [
200
+ 0.0,
201
+ 5.0
202
+ ]
203
+ }
204
+ ],
205
+ "objfunc": [
206
+ {
207
+ "name": "ns",
208
+ "of": "ns",
209
+ "data": [
210
+ "obs_data02_14.csv/obs/orun[1]",
211
+ "output/csip_run/out/Outlet.csv/output/catchmentSimRunoff"
212
+ ]
213
+ }
214
+ ]
215
+ }
216
+ ]
217
+ },
218
+ "r1s2": {
219
+ "time": "2024-03-13 02:11:57.122093",
220
+ "best_costs": [
221
+ [
222
+ 0.4132185,
223
+ 0.41315801
224
+ ]
225
+ ],
226
+ "steps": [
227
+ {
228
+ "param": [
229
+ {
230
+ "name": "soilOutLPS",
231
+ "bounds": [
232
+ 0.0,
233
+ 2.0
234
+ ],
235
+ "value": 1.4232478417536503
236
+ },
237
+ {
238
+ "name": "lagInterflow",
239
+ "bounds": [
240
+ 10.0,
241
+ 80.0
242
+ ],
243
+ "value": 58.2004069813242
244
+ }
245
+ ],
246
+ "objfunc": [
247
+ {
248
+ "name": "ns",
249
+ "of": "ns",
250
+ "data": [
251
+ "obs_data02_14.csv/obs/orun[1]",
252
+ "output/csip_run/out/Outlet.csv/output/catchmentSimRunoff"
253
+ ]
254
+ }
255
+ ],
256
+ "cost": 0.4965635659744849
257
+ },
258
+ {
259
+ "param": [
260
+ {
261
+ "name": "flowRouteTA",
262
+ "bounds": [
263
+ 0.4,
264
+ 5.0
265
+ ],
266
+ "value": 1.9829062991388553
267
+ },
268
+ {
269
+ "name": "soilMaxDPS",
270
+ "bounds": [
271
+ 0.0,
272
+ 5.0
273
+ ],
274
+ "value": 2.569282303473601
275
+ }
276
+ ],
277
+ "objfunc": [
278
+ {
279
+ "name": "ns",
280
+ "of": "ns",
281
+ "data": [
282
+ "obs_data02_14.csv/obs/orun[1]",
283
+ "output/csip_run/out/Outlet.csv/output/catchmentSimRunoff"
284
+ ]
285
+ }
286
+ ],
287
+ "cost": 0.41587191865116957
288
+ }
289
+ ]
290
+ },
291
+ "r1": {
292
+ "time": "2024-03-13 02:11:57.122093",
293
+ "round_cost": 0.9124354846256545,
294
+ "best_costs": [
295
+ [
296
+ 0.4132185,
297
+ 0.41315801
298
+ ]
299
+ ],
300
+ "improvements": [
301
+ [
302
+ false,
303
+ false
304
+ ]
305
+ ]
306
+ },
307
+ "r2s1": {
308
+ "time": "2024-03-13 02:14:38.624493",
309
+ "best_costs": [
310
+ [
311
+ 0.4132185,
312
+ 0.41315801
313
+ ]
314
+ ],
315
+ "steps": [
316
+ {
317
+ "param": [
318
+ {
319
+ "name": "soilOutLPS",
320
+ "bounds": [
321
+ 0.0,
322
+ 2.0
323
+ ],
324
+ "value": 1.3852729993614596
325
+ },
326
+ {
327
+ "name": "lagInterflow",
328
+ "bounds": [
329
+ 10.0,
330
+ 80.0
331
+ ],
332
+ "value": 56.51654153627339
333
+ }
334
+ ],
335
+ "objfunc": [
336
+ {
337
+ "name": "ns",
338
+ "of": "ns",
339
+ "data": [
340
+ "obs_data02_14.csv/obs/orun[1]",
341
+ "output/csip_run/out/Outlet.csv/output/catchmentSimRunoff"
342
+ ]
343
+ }
344
+ ],
345
+ "cost": 0.41321849826662227
346
+ },
347
+ {
348
+ "param": [
349
+ {
350
+ "name": "flowRouteTA",
351
+ "bounds": [
352
+ 0.4,
353
+ 5.0
354
+ ],
355
+ "value": 1.9829062991388553
356
+ },
357
+ {
358
+ "name": "soilMaxDPS",
359
+ "bounds": [
360
+ 0.0,
361
+ 5.0
362
+ ],
363
+ "value": 2.569282303473601
364
+ }
365
+ ],
366
+ "objfunc": [
367
+ {
368
+ "name": "ns",
369
+ "of": "ns",
370
+ "data": [
371
+ "obs_data02_14.csv/obs/orun[1]",
372
+ "output/csip_run/out/Outlet.csv/output/catchmentSimRunoff"
373
+ ]
374
+ }
375
+ ],
376
+ "cost": 0.41587191865116957
377
+ }
378
+ ]
379
+ },
380
+ "r2s2": {
381
+ "time": "2024-03-13 02:17:21.403554",
382
+ "best_costs": [
383
+ [
384
+ 0.4132185,
385
+ 0.41315801
386
+ ]
387
+ ],
388
+ "steps": [
389
+ {
390
+ "param": [
391
+ {
392
+ "name": "soilOutLPS",
393
+ "bounds": [
394
+ 0.0,
395
+ 2.0
396
+ ],
397
+ "value": 1.3852729993614596
398
+ },
399
+ {
400
+ "name": "lagInterflow",
401
+ "bounds": [
402
+ 10.0,
403
+ 80.0
404
+ ],
405
+ "value": 56.51654153627339
406
+ }
407
+ ],
408
+ "objfunc": [
409
+ {
410
+ "name": "ns",
411
+ "of": "ns",
412
+ "data": [
413
+ "obs_data02_14.csv/obs/orun[1]",
414
+ "output/csip_run/out/Outlet.csv/output/catchmentSimRunoff"
415
+ ]
416
+ }
417
+ ],
418
+ "cost": 0.41321849826662227
419
+ },
420
+ {
421
+ "param": [
422
+ {
423
+ "name": "flowRouteTA",
424
+ "bounds": [
425
+ 0.4,
426
+ 5.0
427
+ ],
428
+ "value": 1.9512811039470743
429
+ },
430
+ {
431
+ "name": "soilMaxDPS",
432
+ "bounds": [
433
+ 0.0,
434
+ 5.0
435
+ ],
436
+ "value": 1.4271995521553167
437
+ }
438
+ ],
439
+ "objfunc": [
440
+ {
441
+ "name": "ns",
442
+ "of": "ns",
443
+ "data": [
444
+ "obs_data02_14.csv/obs/orun[1]",
445
+ "output/csip_run/out/Outlet.csv/output/catchmentSimRunoff"
446
+ ]
447
+ }
448
+ ],
449
+ "cost": 0.41315801069598224
450
+ }
451
+ ]
452
+ },
453
+ "r2": {
454
+ "time": "2024-03-13 02:17:21.403554",
455
+ "round_cost": 0.8263765089626045,
456
+ "best_costs": [
457
+ [
458
+ 0.4132185,
459
+ 0.41315801
460
+ ]
461
+ ],
462
+ "improvements": [
463
+ [
464
+ false,
465
+ false
466
+ ]
467
+ ]
468
+ },
469
+ "rounds": 2,
470
+ "end": "2024-03-13 02:17:21.901600",
471
+ "time": "0:10:53.346725"
472
+ }
@@ -9,52 +9,34 @@ def csip_worker(reqq: queue.Queue, thread_no: int, stop, full_trace,
9
9
  async_call = conf.get('async_call', True) # default is async
10
10
  save_resp = conf.get('save_response_to', None) # save response, set it to a folder if responses should be saved.
11
11
 
12
- print("client1")
13
-
14
12
  while not stop():
15
- print("client2")
16
13
 
17
14
  try:
18
15
  (rnd, step, iteration, particle, x, step_param_names, calib_params, objfunc, resq) = reqq.get(True, 0.5)
19
16
  # print(thread_no, particle)
20
-
21
- print("client3")
22
17
 
23
18
  c = Client(metainfo=metainfo)
24
19
 
25
- print("client4")
26
-
27
20
  # static params (from args)
28
21
  for param in arg_params:
29
22
  c.add_data(param['name'], param['value'])
30
23
 
31
- print("client5")
32
-
33
24
  # particle params (generated from steps)
34
25
  # for i, value in enumerate(x):
35
26
  for idx, value in enumerate(x[particle, :]):
36
27
  c.add_data(step_param_names[idx], value)
37
28
 
38
-
39
- print("client6")
40
-
41
29
  # other, previously calibrated params (other steps)
42
30
  for name, value in calib_params.items():
43
31
  c.add_data(name, value)
44
32
 
45
- print("client7")
46
-
47
33
  # objective function info
48
34
  for of in objfunc:
49
35
  c.add_cosu(of['name'], of['of'], of['data'])
50
36
  # c.add_data(of['name'], (of['data'][0], of['data'][1]))
51
37
 
52
- print("client8")
53
-
54
38
  print('.', end='', flush=True)
55
39
 
56
- print("client9")
57
-
58
40
  try:
59
41
  # print(c)
60
42
  if async_call:
@@ -62,47 +44,32 @@ def csip_worker(reqq: queue.Queue, thread_no: int, stop, full_trace,
62
44
  else:
63
45
  res = c.execute(url, files=files, conf=conf)
64
46
 
65
- print("client10")
66
-
67
47
  if res.is_failed():
68
48
  print(res)
69
49
 
70
- print("client11")
71
-
72
50
  if save_resp:
73
51
  res.save_to(os.path.join(save_resp, 'r{}s{}i{}p{}.json'.format(rnd, step, iteration, particle)))
74
-
75
- print("client12")
76
-
52
+
77
53
  # print(res)
78
54
  print('O', end='', flush=True)
79
55
 
80
- print("client13")
81
-
82
56
  cost = utils.calc_cost(res, objfunc)
83
57
 
84
- print("client14")
85
-
86
58
  if full_trace is not None:
87
59
  all_params = {}
88
60
  # for i, value in enumerate(x):
89
61
  for idx, value in enumerate(x[particle, :]):
90
62
  all_params[step_param_names[idx]] = value
91
-
92
- print("client15")
93
63
 
94
64
  for name, value in calib_params.items():
95
65
  all_params[name] = value
96
66
  full_trace.append((all_params, cost))
97
67
 
98
- print("client16")
99
-
100
68
  resq.put((particle, cost))
101
69
  except Exception as e:
102
70
  print(res)
103
71
  print(e)
104
-
105
- print("client17")
72
+
106
73
  reqq.task_done()
107
74
  except queue.Empty:
108
75
  continue
@@ -29,44 +29,30 @@ def eval_cost(x, iteration, step_param_names, step_objfunc, calib_params, req_qu
29
29
  step):
30
30
  particles = len(x[:, 0])
31
31
 
32
- print("c1")
33
-
34
32
  pfail_count = conf.get('particles_fail', 1) # Number of particles allowed to fail.
35
33
  pfail_retry = conf.get('particles_retry', 3) # retry number of times if more than allowed fail
36
34
 
37
- print("c2")
38
-
39
35
  while pfail_retry > 0:
40
36
  cost = np.ones(particles)
41
37
  res_queue = queue.Queue()
42
38
 
43
39
  print(' ', end='', flush=True)
44
40
 
45
- print("c3")
46
-
47
41
  # submit for processing
48
42
  # for i_particle, v in enumerate(x[:, 0]):
49
43
  for particle in range(particles):
50
44
  req_queue.put((rnd, step, iteration, particle, x, step_param_names, calib_params, step_objfunc, res_queue))
51
45
  # req_queue.put((i_particle, x[i_particle,:], step_param_names, calib_params, step_objfunc, res_queue))
52
46
 
53
- print("c4")
54
-
55
47
  # wait for the cost value to come back
56
48
  # for i, v in enumerate(x[:, 0]):
57
49
  for idx in range(particles):
58
- print("c4.1")
59
50
  (particle, p_cost) = res_queue.get()
60
51
  cost[particle] = p_cost
61
- print("c4.2")
62
52
  res_queue.task_done()
63
53
 
64
- print("c5")
65
-
66
54
  res_queue.join()
67
55
 
68
- print("c6")
69
-
70
56
  # replace the 'nan' cost values (failed/missing runs) with the mean of the
71
57
  # rest of the cost values, hence ignore it
72
58
 
@@ -74,24 +60,15 @@ def eval_cost(x, iteration, step_param_names, step_objfunc, calib_params, req_qu
74
60
  nan_idx = np.where(np.isnan(cost))
75
61
  failed_particles = len(nan_idx[0])
76
62
 
77
- print("c7")
78
-
79
63
  # leave the loop if fails acceptable
80
64
  if failed_particles <= pfail_count:
81
65
  break
82
66
 
83
- print("c8")
84
-
85
67
  print("Re-running particles, since ", failed_particles, ' out of ', particles, ' particles failed.')
86
68
  pfail_retry -= 1
87
69
 
88
- print("c9")
89
-
90
- print("c10")
91
-
92
70
  if pfail_retry == 0:
93
71
  print('Particle evaluation failed ', conf.get('particles_retry', 3), ' times. PSO stopped.')
94
- print("c11")
95
72
  return None
96
73
 
97
74
  # print("mean ", mean)
@@ -102,18 +79,6 @@ def eval_cost(x, iteration, step_param_names, step_objfunc, calib_params, req_qu
102
79
  print(flush=True)
103
80
  return cost
104
81
 
105
- # Simulator
106
- def global_best_sim(steps: Dict, rounds: Tuple, args: Dict, n_particles: int, iters: int, options: Dict,
107
- oh_strategy: Dict = None, n_threads: int = 4, rtol: float = 0.001, ftol: float = -np.inf,
108
- ftol_iter: int = 1, full_trace: List = None, rtol_iter: int = 1,
109
- conf: Dict = None, metainfo: Dict = None, cost_target: float = -np.inf, result_queue: Queue = None) -> Tuple:
110
- import time
111
- while True:
112
- print("WOW", flush=True)
113
- if result_queue is not None:
114
- result_queue.put('WOW')
115
- time.sleep(1)
116
-
117
82
  def global_best(steps: Dict, rounds: Tuple, args: Dict, n_particles: int, iters: int, options: Dict,
118
83
  oh_strategy: Dict = None, n_threads: int = 4, rtol: float = 0.001, ftol: float = -np.inf,
119
84
  ftol_iter: int = 1, full_trace: List = None, rtol_iter: int = 1,
@@ -275,16 +240,12 @@ def global_best(steps: Dict, rounds: Tuple, args: Dict, n_particles: int, iters:
275
240
 
276
241
  args['rnd'] = r + 1
277
242
  args['step'] = s + 1
278
-
279
- print("g1")
280
243
 
281
244
  # perform optimization
282
245
  cost, pos = optimizer[s].optimize(eval_cost, iters=step.get('iters', iters), **args)
283
246
  if cost is None:
284
247
  early_exit = True
285
248
  break
286
-
287
- print("g2")
288
249
 
289
250
  # capture the best cost
290
251
  # if cost < best_cost[s] and np.abs(cost - best_cost[s]) > rtol:
@@ -293,8 +254,6 @@ def global_best(steps: Dict, rounds: Tuple, args: Dict, n_particles: int, iters:
293
254
  no_improvement[s] = False
294
255
  utils.annotate_step(best_cost[s], pos, steps, s)
295
256
 
296
- print("g3")
297
-
298
257
  print('\n Step summary, best particle values: {} '.format(pos))
299
258
 
300
259
  if result_queue is not None:
@@ -306,24 +265,17 @@ def global_best(steps: Dict, rounds: Tuple, args: Dict, n_particles: int, iters:
306
265
  step_trace[key]['best_costs'] = best_cost
307
266
  step_trace[key]['steps'] = copy.deepcopy(steps)
308
267
 
309
- print("g4")
310
-
311
268
  if step_file is not None:
312
269
  with open(step_file, "w") as fo:
313
270
  json.dump(step_trace, fo)
314
271
 
315
- print("g5")
316
-
317
272
  # print(json.dumps(steps, sort_keys=False, indent=2))
318
273
 
319
274
  if early_exit:
320
- print("g6")
321
275
  step_trace['exit'] = '1'
322
276
  break
323
277
 
324
278
  round_cost = np.sum(best_cost)
325
-
326
- print("g7")
327
279
 
328
280
  # if no improvement in all steps, break out of rounds prematurely
329
281
  # but start checking only after min_rounds