foxes 1.2.1__py3-none-any.whl → 1.2.2__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.
Potentially problematic release.
This version of foxes might be problematic. Click here for more details.
- foxes/input/yaml/__init__.py +1 -1
- foxes/input/yaml/dict.py +191 -95
- {foxes-1.2.1.dist-info → foxes-1.2.2.dist-info}/METADATA +1 -1
- {foxes-1.2.1.dist-info → foxes-1.2.2.dist-info}/RECORD +8 -8
- {foxes-1.2.1.dist-info → foxes-1.2.2.dist-info}/LICENSE +0 -0
- {foxes-1.2.1.dist-info → foxes-1.2.2.dist-info}/WHEEL +0 -0
- {foxes-1.2.1.dist-info → foxes-1.2.2.dist-info}/entry_points.txt +0 -0
- {foxes-1.2.1.dist-info → foxes-1.2.2.dist-info}/top_level.txt +0 -0
foxes/input/yaml/__init__.py
CHANGED
foxes/input/yaml/dict.py
CHANGED
|
@@ -141,11 +141,176 @@ def read_dict(
|
|
|
141
141
|
return algo, engine
|
|
142
142
|
|
|
143
143
|
|
|
144
|
+
def get_output_obj(
|
|
145
|
+
ocls,
|
|
146
|
+
odict,
|
|
147
|
+
algo,
|
|
148
|
+
farm_results=None,
|
|
149
|
+
point_results=None,
|
|
150
|
+
base_class=Output,
|
|
151
|
+
extra_sig={},
|
|
152
|
+
):
|
|
153
|
+
"""
|
|
154
|
+
Create the output object
|
|
155
|
+
|
|
156
|
+
Parameters
|
|
157
|
+
----------
|
|
158
|
+
ocls: str
|
|
159
|
+
Name of the output class
|
|
160
|
+
odict: dict
|
|
161
|
+
The output dict
|
|
162
|
+
algo: foxes.core.Algorithm
|
|
163
|
+
The algorithm
|
|
164
|
+
farm_results: xarray.Dataset, optional
|
|
165
|
+
The farm results
|
|
166
|
+
point_results: xarray.Dataset, optional
|
|
167
|
+
The point results
|
|
168
|
+
base_class: object
|
|
169
|
+
The output's base class
|
|
170
|
+
extra_sig: dict
|
|
171
|
+
Extra function signature check, sets
|
|
172
|
+
arguments (key) with data (value)
|
|
173
|
+
|
|
174
|
+
Returns
|
|
175
|
+
-------
|
|
176
|
+
obj: object or None
|
|
177
|
+
The output object
|
|
178
|
+
|
|
179
|
+
:group: input.yaml
|
|
180
|
+
|
|
181
|
+
"""
|
|
182
|
+
cls = new_cls(base_class, ocls)
|
|
183
|
+
prs = list(signature(cls.__init__).parameters.keys())
|
|
184
|
+
if "algo" in prs:
|
|
185
|
+
assert algo is not None, f"Output of type '{ocls}' requires algo"
|
|
186
|
+
odict["algo"] = algo
|
|
187
|
+
if "farm" in prs:
|
|
188
|
+
odict["farm"] = algo.farm
|
|
189
|
+
if "farm_results" in prs:
|
|
190
|
+
if farm_results is None:
|
|
191
|
+
print(f"No farm results; skipping output {ocls}")
|
|
192
|
+
return None
|
|
193
|
+
odict["farm_results"] = farm_results
|
|
194
|
+
if "point_results" in prs:
|
|
195
|
+
odict["point_results"] = point_results
|
|
196
|
+
for k, v in extra_sig.items():
|
|
197
|
+
if k in prs:
|
|
198
|
+
odict[k] = v
|
|
199
|
+
|
|
200
|
+
return cls(**odict)
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def _get_object(rlabels, d):
|
|
204
|
+
"""Helper function for object extraction"""
|
|
205
|
+
d = d.replace("]", "")
|
|
206
|
+
i0 = d.find("[")
|
|
207
|
+
if i0 > 0:
|
|
208
|
+
inds = tuple([int(x) for x in d[i0 + 1 :].split(",")])
|
|
209
|
+
return rlabels[d[:i0]][inds]
|
|
210
|
+
else:
|
|
211
|
+
return rlabels[d]
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def run_obj_function(
|
|
215
|
+
obj,
|
|
216
|
+
fdict,
|
|
217
|
+
algo,
|
|
218
|
+
rlabels,
|
|
219
|
+
verbosity=None,
|
|
220
|
+
):
|
|
221
|
+
"""
|
|
222
|
+
Runs a function of an object
|
|
223
|
+
|
|
224
|
+
Parameters
|
|
225
|
+
----------
|
|
226
|
+
obj: object
|
|
227
|
+
The object
|
|
228
|
+
fdict: dict
|
|
229
|
+
The function call dict
|
|
230
|
+
algo: foxes.core.Algorithm
|
|
231
|
+
The algorithm
|
|
232
|
+
rlabels: dict
|
|
233
|
+
Storage for result variables
|
|
234
|
+
verbosity: int, optional
|
|
235
|
+
The verbosity level, 0 = silent
|
|
236
|
+
|
|
237
|
+
Returns
|
|
238
|
+
-------
|
|
239
|
+
results: object
|
|
240
|
+
The returns of the function
|
|
241
|
+
|
|
242
|
+
:group: input.yaml
|
|
243
|
+
|
|
244
|
+
"""
|
|
245
|
+
|
|
246
|
+
def _print(*args, level=1, **kwargs):
|
|
247
|
+
if verbosity is None or verbosity >= level:
|
|
248
|
+
print(*args, **kwargs)
|
|
249
|
+
|
|
250
|
+
fname = fdict.pop_item("function")
|
|
251
|
+
_print(f" - {fname}")
|
|
252
|
+
plt_show = fdict.pop("plt_show", False)
|
|
253
|
+
plt_close = fdict.pop("plt_close", False)
|
|
254
|
+
rlbs = fdict.pop("result_labels", None)
|
|
255
|
+
|
|
256
|
+
# grab function:
|
|
257
|
+
ocls = type(obj).__name__
|
|
258
|
+
assert hasattr(obj, fname), f"Output of type '{ocls}': Function '{fname}' not found"
|
|
259
|
+
f = getattr(obj, fname)
|
|
260
|
+
|
|
261
|
+
# add required input data objects:
|
|
262
|
+
prs = list(signature(f).parameters.keys())
|
|
263
|
+
if "algo" in prs:
|
|
264
|
+
fdict["algo"] = algo
|
|
265
|
+
if "farm" in prs:
|
|
266
|
+
fdict["farm"] = algo.farm
|
|
267
|
+
|
|
268
|
+
# replace result labels by objects:
|
|
269
|
+
for k, d in fdict.items():
|
|
270
|
+
if isinstance(d, str) and d[0] == "$":
|
|
271
|
+
fdict[k] = _get_object(rlabels, d)
|
|
272
|
+
|
|
273
|
+
# run function:
|
|
274
|
+
args = fdict.pop("args", tuple())
|
|
275
|
+
results = f(*args, **fdict)
|
|
276
|
+
|
|
277
|
+
# pyplot shortcuts:
|
|
278
|
+
if plt_show:
|
|
279
|
+
plt.show()
|
|
280
|
+
if plt_close:
|
|
281
|
+
results = None
|
|
282
|
+
plt.close()
|
|
283
|
+
|
|
284
|
+
# store results under result labels:
|
|
285
|
+
if rlbs is not None:
|
|
286
|
+
|
|
287
|
+
def _set_label(rlabels, k, r):
|
|
288
|
+
if k not in ["", "none", "None", "_", "__"]:
|
|
289
|
+
assert (
|
|
290
|
+
k[0] == "$"
|
|
291
|
+
), f"Output {i} of type '{ocls}', function '{fname}': result labels must start with '$', got '{k}'"
|
|
292
|
+
assert (
|
|
293
|
+
"[" not in k and "]" not in k and "," not in k
|
|
294
|
+
), f"Output {i} of type '{ocls}', function '{fname}': result labels cannot contain '[' or ']' or comma, got '{k}'"
|
|
295
|
+
_print(f" result label {k}: {type(r).__name__}")
|
|
296
|
+
rlabels[k] = r
|
|
297
|
+
|
|
298
|
+
if isinstance(rlbs, (list, tuple)):
|
|
299
|
+
for i, k in enumerate(rlbs):
|
|
300
|
+
_set_label(rlabels, k, results[i])
|
|
301
|
+
else:
|
|
302
|
+
_set_label(rlabels, rlbs, results)
|
|
303
|
+
|
|
304
|
+
return results
|
|
305
|
+
|
|
306
|
+
|
|
144
307
|
def run_outputs(
|
|
145
308
|
idict,
|
|
146
309
|
algo=None,
|
|
147
310
|
farm_results=None,
|
|
148
311
|
point_results=None,
|
|
312
|
+
extra_sig={},
|
|
313
|
+
ret_rlabels=False,
|
|
149
314
|
verbosity=None,
|
|
150
315
|
):
|
|
151
316
|
"""
|
|
@@ -161,9 +326,13 @@ def run_outputs(
|
|
|
161
326
|
The farm results
|
|
162
327
|
point_results: xarray.Dataset, optional
|
|
163
328
|
The point results
|
|
329
|
+
extra_sig: dict
|
|
330
|
+
Extra function signature check, sets
|
|
331
|
+
arguments (key) with data (value)
|
|
332
|
+
ret_rlabels: bool
|
|
333
|
+
Flag for returning results variables
|
|
164
334
|
verbosity: int, optional
|
|
165
|
-
|
|
166
|
-
settings from idict
|
|
335
|
+
The verbosity level, 0 = silent
|
|
167
336
|
|
|
168
337
|
Returns
|
|
169
338
|
-------
|
|
@@ -171,6 +340,8 @@ def run_outputs(
|
|
|
171
340
|
For each output enty, a tuple (dict, results),
|
|
172
341
|
where results is a tuple that represents one
|
|
173
342
|
entry per function call
|
|
343
|
+
rlabels: dict, optional
|
|
344
|
+
The results variables
|
|
174
345
|
|
|
175
346
|
:group: input.yaml
|
|
176
347
|
|
|
@@ -181,6 +352,7 @@ def run_outputs(
|
|
|
181
352
|
print(*args, **kwargs)
|
|
182
353
|
|
|
183
354
|
out = []
|
|
355
|
+
rlabels = Dict(name="result_labels")
|
|
184
356
|
if "outputs" in idict:
|
|
185
357
|
_print("Running outputs")
|
|
186
358
|
odicts = [
|
|
@@ -188,124 +360,48 @@ def run_outputs(
|
|
|
188
360
|
for i, odict in enumerate(idict["outputs"])
|
|
189
361
|
]
|
|
190
362
|
|
|
191
|
-
rlabels = Dict(name="result_labels")
|
|
192
|
-
|
|
193
|
-
def _get_object(rlabels, d):
|
|
194
|
-
d = d.replace("]", "")
|
|
195
|
-
i0 = d.find("[")
|
|
196
|
-
if i0 > 0:
|
|
197
|
-
inds = tuple([int(x) for x in d[i0 + 1 :].split(",")])
|
|
198
|
-
return rlabels[d[:i0]][inds]
|
|
199
|
-
else:
|
|
200
|
-
return rlabels[d]
|
|
201
|
-
|
|
202
363
|
for i, d in enumerate(odicts):
|
|
203
|
-
|
|
204
364
|
if "output_type" in d:
|
|
205
365
|
ocls = d.pop_item("output_type")
|
|
206
366
|
_print(f" Output {i}: {ocls}")
|
|
207
367
|
d0 = dict(output_type=ocls)
|
|
208
368
|
d0.update(d)
|
|
369
|
+
|
|
209
370
|
flist = [
|
|
210
|
-
Dict(f, name=f"{d.name}.function{
|
|
211
|
-
for
|
|
371
|
+
Dict(f, name=f"{d.name}.function{j}")
|
|
372
|
+
for j, f in enumerate(d.pop_item("functions"))
|
|
212
373
|
]
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
if "farm" in prs:
|
|
221
|
-
d["farm"] = algo.farm
|
|
222
|
-
if "farm_results" in prs:
|
|
223
|
-
if farm_results is None:
|
|
224
|
-
print(f"No farm results; skipping output {ocls}")
|
|
225
|
-
for fdict in flist:
|
|
226
|
-
out += (d0, None)
|
|
227
|
-
continue
|
|
228
|
-
d["farm_results"] = farm_results
|
|
229
|
-
if "point_results" in prs:
|
|
230
|
-
d["point_results"] = point_results
|
|
231
|
-
o = cls(**d)
|
|
374
|
+
|
|
375
|
+
o = get_output_obj(
|
|
376
|
+
ocls, d, algo, farm_results, point_results, extra_sig=extra_sig
|
|
377
|
+
)
|
|
378
|
+
if o is None:
|
|
379
|
+
out.append((d0, None))
|
|
380
|
+
continue
|
|
232
381
|
|
|
233
382
|
elif "object" in d:
|
|
234
383
|
ocls = d.pop("object")
|
|
384
|
+
_print(f" Output {i}: Object {ocls}")
|
|
235
385
|
o = _get_object(rlabels, ocls)
|
|
236
386
|
d0 = dict(object=ocls)
|
|
237
387
|
d0.update(d)
|
|
238
388
|
flist = [
|
|
239
|
-
Dict(f, name=f"{d.name}.function{
|
|
240
|
-
for
|
|
389
|
+
Dict(f, name=f"{d.name}.function{j}")
|
|
390
|
+
for j, f in enumerate(d.pop_item("functions"))
|
|
241
391
|
]
|
|
242
392
|
|
|
243
393
|
else:
|
|
244
394
|
raise KeyError(
|
|
245
|
-
f"Output {i}
|
|
395
|
+
f"Output {i}: Please specify either 'output_type' or 'object'"
|
|
246
396
|
)
|
|
247
397
|
|
|
248
398
|
fres = []
|
|
249
399
|
for fdict in flist:
|
|
250
|
-
|
|
251
|
-
_print(f" - {fname}")
|
|
252
|
-
plt_show = fdict.pop("plt_show", False)
|
|
253
|
-
plt_close = fdict.pop("plt_close", False)
|
|
254
|
-
rlbs = fdict.pop("result_labels", None)
|
|
255
|
-
|
|
256
|
-
# grab function:
|
|
257
|
-
assert hasattr(
|
|
258
|
-
o, fname
|
|
259
|
-
), f"Output {i} of type '{ocls}': Function '{fname}' not found"
|
|
260
|
-
f = getattr(o, fname)
|
|
261
|
-
|
|
262
|
-
# add required input data objects:
|
|
263
|
-
prs = list(signature(f).parameters.keys())
|
|
264
|
-
if "algo" in prs:
|
|
265
|
-
fdict["algo"] = algo
|
|
266
|
-
if "farm" in prs:
|
|
267
|
-
fdict["farm"] = algo.farm
|
|
268
|
-
|
|
269
|
-
# replace result labels by objects:
|
|
270
|
-
for k, d in fdict.items():
|
|
271
|
-
if isinstance(d, str) and d[0] == "$":
|
|
272
|
-
fdict[k] = _get_object(rlabels, d)
|
|
273
|
-
|
|
274
|
-
# run function:
|
|
275
|
-
args = fdict.pop("args", tuple())
|
|
276
|
-
results = f(*args, **fdict)
|
|
277
|
-
|
|
278
|
-
# pyplot shortcuts:
|
|
279
|
-
if plt_show:
|
|
280
|
-
plt.show()
|
|
281
|
-
if plt_close:
|
|
282
|
-
results = None
|
|
283
|
-
plt.close()
|
|
284
|
-
|
|
285
|
-
# store results under result labels:
|
|
286
|
-
if rlbs is not None:
|
|
287
|
-
|
|
288
|
-
def _set_label(rlabels, k, r):
|
|
289
|
-
if k not in ["", "none", "None", "_", "__"]:
|
|
290
|
-
assert (
|
|
291
|
-
k[0] == "$"
|
|
292
|
-
), f"Output {i} of type '{ocls}', function '{fname}': result labels must start with '$', got '{k}'"
|
|
293
|
-
assert (
|
|
294
|
-
"[" not in k and "]" not in k and "," not in k
|
|
295
|
-
), f"Output {i} of type '{ocls}', function '{fname}': result labels cannot contain '[' or ']' or comma, got '{k}'"
|
|
296
|
-
_print(f" result label {k}: {type(r).__name__}")
|
|
297
|
-
rlabels[k] = r
|
|
298
|
-
|
|
299
|
-
if isinstance(rlbs, (list, tuple)):
|
|
300
|
-
for i, k in enumerate(rlbs):
|
|
301
|
-
_set_label(rlabels, k, results[i])
|
|
302
|
-
else:
|
|
303
|
-
_set_label(rlabels, rlbs, results)
|
|
304
|
-
|
|
400
|
+
results = run_obj_function(o, fdict, algo, rlabels, verbosity)
|
|
305
401
|
fres.append(results)
|
|
306
402
|
out.append((d0, fres))
|
|
307
403
|
|
|
308
|
-
return out
|
|
404
|
+
return out if not ret_rlabels else out, rlabels
|
|
309
405
|
|
|
310
406
|
|
|
311
407
|
def run_dict(idict, *args, verbosity=None, **kwargs):
|
|
@@ -371,7 +467,7 @@ def run_dict(idict, *args, verbosity=None, **kwargs):
|
|
|
371
467
|
out += (point_results,)
|
|
372
468
|
|
|
373
469
|
# run outputs:
|
|
374
|
-
out += (run_outputs(idict, algo, farm_results, point_results, verbosity),)
|
|
470
|
+
out += (run_outputs(idict, algo, farm_results, point_results, verbosity=verbosity),)
|
|
375
471
|
|
|
376
472
|
# shutdown engine, if created above:
|
|
377
473
|
if engine is not None:
|
|
@@ -120,8 +120,8 @@ foxes/input/states/states_table.py,sha256=-y0vYGQ_OVNQUPMgU99da2FVBDEUvNUMzHN0HH
|
|
|
120
120
|
foxes/input/states/create/__init__.py,sha256=Ocqzmr9SOefeAvGX5DgawsPXfNdGzWOZ2ssvtqEmtAo,134
|
|
121
121
|
foxes/input/states/create/random_abl_states.py,sha256=7KD1q8pF0IQcv-AYq6tqw7jEd3D3Q3xSqOoF5WxMReU,3411
|
|
122
122
|
foxes/input/states/create/random_timeseries.py,sha256=gJpaQ4nEXxOjI4hp3xjNcVbCsmZUm-brXUxoqDb63WE,1266
|
|
123
|
-
foxes/input/yaml/__init__.py,sha256=
|
|
124
|
-
foxes/input/yaml/dict.py,sha256=
|
|
123
|
+
foxes/input/yaml/__init__.py,sha256=1EIaXSaykZ3VnhXN_SgqnWkRLVkXsL_608_-f19Xk14,167
|
|
124
|
+
foxes/input/yaml/dict.py,sha256=yHkw_x81ZKQ7BlCaTchoTDDAeakfr_zNdtXZgLGZ-B8,13607
|
|
125
125
|
foxes/input/yaml/yaml.py,sha256=wVn6v-4g_Cz-MuNBJhVku9UXCIJrwd9fviLbvsokUcA,2704
|
|
126
126
|
foxes/input/yaml/windio/__init__.py,sha256=h5zp7VDWYq7K4GVX91CkoEABhpYSTisFWiw-0YAq3eU,196
|
|
127
127
|
foxes/input/yaml/windio/get_states.py,sha256=cl4ZMurwbUyZflaoC1TPdBc5VjS7s7zp4_FYp80hkX0,6081
|
|
@@ -301,9 +301,9 @@ tests/1_verification/flappy_0_6_2/row_Bastankhah_Crespo/flappy/run.py,sha256=nwI
|
|
|
301
301
|
tests/1_verification/flappy_0_6_2/row_Bastankhah_linear_centre/test_row_Bastankhah_linear_centre.py,sha256=a7CQS-_Mnz3NynaTv1OY1CZ10iAqa7E3YxmkbDtoshw,2590
|
|
302
302
|
tests/1_verification/flappy_0_6_2/row_Bastankhah_linear_centre/flappy/run.py,sha256=s6FbEdpiIdHYmdD8S85_NhLH-S3EOinXvw8RHmR2QOU,2122
|
|
303
303
|
tests/3_examples/test_examples.py,sha256=rS2Dz04ktbS6v3TRDr96AkWGypr5u49jihqbEmGFmRU,694
|
|
304
|
-
foxes-1.2.
|
|
305
|
-
foxes-1.2.
|
|
306
|
-
foxes-1.2.
|
|
307
|
-
foxes-1.2.
|
|
308
|
-
foxes-1.2.
|
|
309
|
-
foxes-1.2.
|
|
304
|
+
foxes-1.2.2.dist-info/LICENSE,sha256=bBCH6mYTPzSepk2s2UUZ3II_ZYXrn1bnSqB85-aZHxU,1071
|
|
305
|
+
foxes-1.2.2.dist-info/METADATA,sha256=7dg2z1b6a9XZFlQCJRKBJ4sSfOkDAP4GJSGR8RLp7MA,8629
|
|
306
|
+
foxes-1.2.2.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
|
307
|
+
foxes-1.2.2.dist-info/entry_points.txt,sha256=KuS44FRH5NnMw201A8Btr76eNRKr2UOoKHjejAsqKwE,123
|
|
308
|
+
foxes-1.2.2.dist-info/top_level.txt,sha256=G7oHApEz5nc-iP__XsPcvjYe_NyXGmKMUMPHi3C3x6I,26
|
|
309
|
+
foxes-1.2.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|