MoPyRegtest 0.4.1__tar.gz → 0.5.0__tar.gz
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.
- {MoPyRegtest-0.4.1 → MoPyRegtest-0.5.0}/LICENSE +1 -1
- {MoPyRegtest-0.4.1 → MoPyRegtest-0.5.0/MoPyRegtest.egg-info}/PKG-INFO +3 -3
- {MoPyRegtest-0.4.1/MoPyRegtest.egg-info → MoPyRegtest-0.5.0}/PKG-INFO +3 -3
- {MoPyRegtest-0.4.1 → MoPyRegtest-0.5.0}/README.md +2 -2
- {MoPyRegtest-0.4.1 → MoPyRegtest-0.5.0}/mopyregtest/cli.py +9 -3
- {MoPyRegtest-0.4.1 → MoPyRegtest-0.5.0}/mopyregtest/generator.py +4 -2
- {MoPyRegtest-0.4.1 → MoPyRegtest-0.5.0}/mopyregtest/metrics.py +12 -0
- {MoPyRegtest-0.4.1 → MoPyRegtest-0.5.0}/mopyregtest/modelicaregressiontest.py +178 -11
- {MoPyRegtest-0.4.1 → MoPyRegtest-0.5.0}/setup.py +1 -1
- {MoPyRegtest-0.4.1 → MoPyRegtest-0.5.0}/tests/test_cli.py +38 -0
- {MoPyRegtest-0.4.1 → MoPyRegtest-0.5.0}/tests/test_compare_results.py +44 -0
- {MoPyRegtest-0.4.1 → MoPyRegtest-0.5.0}/MoPyRegtest.egg-info/SOURCES.txt +0 -0
- {MoPyRegtest-0.4.1 → MoPyRegtest-0.5.0}/MoPyRegtest.egg-info/dependency_links.txt +0 -0
- {MoPyRegtest-0.4.1 → MoPyRegtest-0.5.0}/MoPyRegtest.egg-info/entry_points.txt +0 -0
- {MoPyRegtest-0.4.1 → MoPyRegtest-0.5.0}/MoPyRegtest.egg-info/requires.txt +0 -0
- {MoPyRegtest-0.4.1 → MoPyRegtest-0.5.0}/MoPyRegtest.egg-info/top_level.txt +0 -0
- {MoPyRegtest-0.4.1 → MoPyRegtest-0.5.0}/mopyregtest/__init__.py +0 -0
- {MoPyRegtest-0.4.1 → MoPyRegtest-0.5.0}/mopyregtest/templates/omc/model_import.mos.template +0 -0
- {MoPyRegtest-0.4.1 → MoPyRegtest-0.5.0}/mopyregtest/templates/omc/model_simulate.mos.template +0 -0
- {MoPyRegtest-0.4.1 → MoPyRegtest-0.5.0}/mopyregtest/utils.py +0 -0
- {MoPyRegtest-0.4.1 → MoPyRegtest-0.5.0}/setup.cfg +0 -0
- {MoPyRegtest-0.4.1 → MoPyRegtest-0.5.0}/tests/test_metrics.py +0 -0
- {MoPyRegtest-0.4.1 → MoPyRegtest-0.5.0}/tests/test_unify_timestamps.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2019--2024 Philipp Emanuel Stelzig
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: MoPyRegtest
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: A Python enabled simple regression testing framework for Modelica models
|
|
5
5
|
Home-page: https://github.com/pstelzig/mopyregtest
|
|
6
6
|
Author: Philipp Emanuel Stelzig
|
|
@@ -83,7 +83,7 @@ has a detailed explanation on how to automatically generate tests.
|
|
|
83
83
|
## Prerequisites
|
|
84
84
|
To use MoPyRegtest you need to have
|
|
85
85
|
* a [Python 3](https://www.python.org/) distribution including the modules [`unittest`](https://docs.python.org/3/library/unittest.html), [`numpy`](https://numpy.org/) and [`pandas`](https://pandas.pydata.org/),
|
|
86
|
-
* a working [OpenModelica](https://www.openmodelica.org/) installation (version 1.13.0 or later, works also for latest 1.
|
|
86
|
+
* a working [OpenModelica](https://www.openmodelica.org/) installation (version 1.13.0 or later, works also for latest 1.22), and
|
|
87
87
|
* the OpenModelica compiler executable `omc` must be accessible via the `PATH` variable.
|
|
88
88
|
|
|
89
89
|
## Installation using pip3
|
|
@@ -134,7 +134,7 @@ knows where to find `mopyregtest` as installed by pip. To find out the location,
|
|
|
134
134
|
not confirm to proceed. The uninstallation will tell you which files pip would remove upon uninstalling MoPyRegtest,
|
|
135
135
|
including the `mopyregtest` executable (or `mopyregtest.exe` under Windows) and its location.
|
|
136
136
|
|
|
137
|
-
```
|
|
137
|
+
```
|
|
138
138
|
Found existing installation: MoPyRegtest 0.4.0rc1
|
|
139
139
|
Uninstalling MoPyRegtest-0.4.0rc1:
|
|
140
140
|
Would remove:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: MoPyRegtest
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: A Python enabled simple regression testing framework for Modelica models
|
|
5
5
|
Home-page: https://github.com/pstelzig/mopyregtest
|
|
6
6
|
Author: Philipp Emanuel Stelzig
|
|
@@ -83,7 +83,7 @@ has a detailed explanation on how to automatically generate tests.
|
|
|
83
83
|
## Prerequisites
|
|
84
84
|
To use MoPyRegtest you need to have
|
|
85
85
|
* a [Python 3](https://www.python.org/) distribution including the modules [`unittest`](https://docs.python.org/3/library/unittest.html), [`numpy`](https://numpy.org/) and [`pandas`](https://pandas.pydata.org/),
|
|
86
|
-
* a working [OpenModelica](https://www.openmodelica.org/) installation (version 1.13.0 or later, works also for latest 1.
|
|
86
|
+
* a working [OpenModelica](https://www.openmodelica.org/) installation (version 1.13.0 or later, works also for latest 1.22), and
|
|
87
87
|
* the OpenModelica compiler executable `omc` must be accessible via the `PATH` variable.
|
|
88
88
|
|
|
89
89
|
## Installation using pip3
|
|
@@ -134,7 +134,7 @@ knows where to find `mopyregtest` as installed by pip. To find out the location,
|
|
|
134
134
|
not confirm to proceed. The uninstallation will tell you which files pip would remove upon uninstalling MoPyRegtest,
|
|
135
135
|
including the `mopyregtest` executable (or `mopyregtest.exe` under Windows) and its location.
|
|
136
136
|
|
|
137
|
-
```
|
|
137
|
+
```
|
|
138
138
|
Found existing installation: MoPyRegtest 0.4.0rc1
|
|
139
139
|
Uninstalling MoPyRegtest-0.4.0rc1:
|
|
140
140
|
Would remove:
|
|
@@ -67,7 +67,7 @@ has a detailed explanation on how to automatically generate tests.
|
|
|
67
67
|
## Prerequisites
|
|
68
68
|
To use MoPyRegtest you need to have
|
|
69
69
|
* a [Python 3](https://www.python.org/) distribution including the modules [`unittest`](https://docs.python.org/3/library/unittest.html), [`numpy`](https://numpy.org/) and [`pandas`](https://pandas.pydata.org/),
|
|
70
|
-
* a working [OpenModelica](https://www.openmodelica.org/) installation (version 1.13.0 or later, works also for latest 1.
|
|
70
|
+
* a working [OpenModelica](https://www.openmodelica.org/) installation (version 1.13.0 or later, works also for latest 1.22), and
|
|
71
71
|
* the OpenModelica compiler executable `omc` must be accessible via the `PATH` variable.
|
|
72
72
|
|
|
73
73
|
## Installation using pip3
|
|
@@ -118,7 +118,7 @@ knows where to find `mopyregtest` as installed by pip. To find out the location,
|
|
|
118
118
|
not confirm to proceed. The uninstallation will tell you which files pip would remove upon uninstalling MoPyRegtest,
|
|
119
119
|
including the `mopyregtest` executable (or `mopyregtest.exe` under Windows) and its location.
|
|
120
120
|
|
|
121
|
-
```
|
|
121
|
+
```
|
|
122
122
|
Found existing installation: MoPyRegtest 0.4.0rc1
|
|
123
123
|
Uninstalling MoPyRegtest-0.4.0rc1:
|
|
124
124
|
Would remove:
|
|
@@ -22,6 +22,8 @@ def metric_str_to_func(m: str):
|
|
|
22
22
|
return metrics.Lp_dist
|
|
23
23
|
elif m == "Linfty_dist":
|
|
24
24
|
return metrics.Linfty_dist
|
|
25
|
+
elif m == "abs_dist_ptwise":
|
|
26
|
+
return metrics.abs_dist_ptwise
|
|
25
27
|
else:
|
|
26
28
|
raise ValueError("Invalid value for metric")
|
|
27
29
|
|
|
@@ -91,7 +93,8 @@ def parse_args(cmd_args):
|
|
|
91
93
|
help="Metric to be used. Choose here from predefined values. "
|
|
92
94
|
"For user-defined metrics please consider creating the tests with a dedicated script. "
|
|
93
95
|
"If omitted, the default is norm_infty_dist",
|
|
94
|
-
choices=["norm_p_dist", "norm_infty_dist", "Lp_dist", "Linfty_dist"
|
|
96
|
+
choices=["norm_p_dist", "norm_infty_dist", "Lp_dist", "Linfty_dist", "abs_dist_ptwise"],
|
|
97
|
+
default="norm_infty_dist")
|
|
95
98
|
generate_parser.add_argument("--tol", type=float,
|
|
96
99
|
help="Absolute tolerance up to which deviation in the comparison metric is accepted",
|
|
97
100
|
default=1e-7)
|
|
@@ -109,7 +112,7 @@ def parse_args(cmd_args):
|
|
|
109
112
|
compare_parser.add_argument("--metric", type=str,
|
|
110
113
|
help="Metric to be used. Choose here from predefined values. "
|
|
111
114
|
"For user-defined metrics please consider creating the tests with a dedicated script.",
|
|
112
|
-
choices=["norm_p_dist", "norm_infty_dist", "Lp_dist", "Linfty_dist"],
|
|
115
|
+
choices=["norm_p_dist", "norm_infty_dist", "Lp_dist", "Linfty_dist", "abs_dist_ptwise"],
|
|
113
116
|
default="norm_infty_dist")
|
|
114
117
|
compare_parser.add_argument("--validated-cols", type=str,
|
|
115
118
|
help="Comma separated list like <var name 1>,<var name 2>. "
|
|
@@ -127,4 +130,7 @@ def parse_args(cmd_args):
|
|
|
127
130
|
|
|
128
131
|
|
|
129
132
|
def main():
|
|
130
|
-
|
|
133
|
+
if len(sys.argv) <= 1:
|
|
134
|
+
parse_args(["--help"])
|
|
135
|
+
else:
|
|
136
|
+
parse_args(sys.argv[1:])
|
|
@@ -97,7 +97,7 @@ if __name__ == '__main__':
|
|
|
97
97
|
metric : function or str
|
|
98
98
|
Metric to be used in result comparison. Important: If the metric is given as a funtion, one must use one
|
|
99
99
|
of the predefined metrics, i.e. mopyregtest.metrics.norm_p_dist, mopyregtest.metrics.norm_infty_dist,
|
|
100
|
-
mopyregtest.metrics.Lp_dist or mopyregtest.metrics.
|
|
100
|
+
mopyregtest.metrics.Lp_dist, mopyregtest.metrics.Linfty_dist, or mopyregtest.metrics.abs_dist_ptwise.
|
|
101
101
|
|
|
102
102
|
If a user-defined metric shall be used, the code must be passed as a string!
|
|
103
103
|
tol : float
|
|
@@ -123,7 +123,9 @@ if __name__ == '__main__':
|
|
|
123
123
|
self.modelica_version = modelica_version
|
|
124
124
|
self.dependencies = dependencies
|
|
125
125
|
if (callable(metric) and
|
|
126
|
-
metric in [metrics.norm_p_dist, metrics.norm_infty_dist,
|
|
126
|
+
metric in [metrics.norm_p_dist, metrics.norm_infty_dist,
|
|
127
|
+
metrics.Lp_dist, metrics.Linfty_dist,
|
|
128
|
+
metrics.abs_dist_ptwise]):
|
|
127
129
|
self.metric = f"mopyregtest.metrics.{metric.__name__}"
|
|
128
130
|
elif type(metric) == str:
|
|
129
131
|
self.metric = metric
|
|
@@ -109,3 +109,15 @@ def Linfty_dist(f1, f2):
|
|
|
109
109
|
_check_comparability(f1, f2)
|
|
110
110
|
|
|
111
111
|
return Linfty_norm(np.vstack((f1[:, 0], f2[:, 1] - f1[:, 1])).transpose())
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def func_ptwise(f1, f2, dist: callable):
|
|
115
|
+
_check_comparability(f1, f2)
|
|
116
|
+
|
|
117
|
+
delta = np.vstack((f1[:, 0], np.vectorize(dist)(f2[:, 1] - f1[:, 1]))).transpose()
|
|
118
|
+
|
|
119
|
+
return delta
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def abs_dist_ptwise(f1, f2):
|
|
123
|
+
return func_ptwise(f1, f2, np.abs)
|
|
@@ -219,7 +219,7 @@ class RegressionTest:
|
|
|
219
219
|
@staticmethod
|
|
220
220
|
def compare_csv_files(reference_result, simulation_result, tol=1e-7, validated_cols=[],
|
|
221
221
|
metric=metrics.norm_infty_dist,
|
|
222
|
-
unify_timestamps=True, fill_in_method="ffill"):
|
|
222
|
+
unify_timestamps=True, fill_in_method="ffill", write_comparison=True):
|
|
223
223
|
"""
|
|
224
224
|
Compares two CSV files from Modelica simulation runs, one as a reference result, the other one as the actual
|
|
225
225
|
simulation result.
|
|
@@ -242,6 +242,8 @@ class RegressionTest:
|
|
|
242
242
|
See doc string of RegressionTest.compare_result
|
|
243
243
|
fill_in_method : str
|
|
244
244
|
See doc string of RegressionTest.compare_result
|
|
245
|
+
write_comparison : bool
|
|
246
|
+
See doc string of RegressionTest.compare_result
|
|
245
247
|
|
|
246
248
|
Returns
|
|
247
249
|
-------
|
|
@@ -284,19 +286,29 @@ class RegressionTest:
|
|
|
284
286
|
for c in validated_cols:
|
|
285
287
|
print("Comparing column \"{}\"".format(c))
|
|
286
288
|
delta = metric(ref_data[["time", c]].values, sim_data[["time", c]].values)
|
|
287
|
-
|
|
288
|
-
|
|
289
|
+
|
|
290
|
+
if type(delta) is np.ndarray:
|
|
291
|
+
if np.any(delta[:, 1] >= tol):
|
|
292
|
+
delta_gt_tol = np.where(delta >= tol, delta, 0.0)
|
|
293
|
+
failed_cols[c] = pd.DataFrame(data=delta_gt_tol, columns=["time", "delta"])
|
|
294
|
+
else:
|
|
295
|
+
if np.abs(delta) >= tol:
|
|
296
|
+
failed_cols[c] = delta
|
|
289
297
|
|
|
290
298
|
if failed_cols:
|
|
299
|
+
if write_comparison:
|
|
300
|
+
RegressionTest._write_csv_comparison(reference_result, simulation_result,
|
|
301
|
+
failed_cols, fill_in_method)
|
|
302
|
+
|
|
291
303
|
raise AssertionError(
|
|
292
304
|
f"Values of results {simulation_result} and {reference_result} are different in columns "
|
|
293
|
-
f"{failed_cols.keys()} by more than {tol}.
|
|
305
|
+
f"{list(failed_cols.keys())} by more than {tol}. ")
|
|
294
306
|
|
|
295
307
|
return
|
|
296
308
|
|
|
297
309
|
def compare_result(self, reference_result, tol=1e-7, validated_cols=[],
|
|
298
310
|
metric=metrics.norm_infty_dist,
|
|
299
|
-
unify_timestamps=True, fill_in_method="ffill"):
|
|
311
|
+
unify_timestamps=True, fill_in_method="ffill", write_comparison=True):
|
|
300
312
|
"""
|
|
301
313
|
Executes simulation and then compares the obtained result and the reference result along the
|
|
302
314
|
validated columns. Throws an exception (AssertionError) if the deviation is larger or equal to tol.
|
|
@@ -312,13 +324,26 @@ class RegressionTest:
|
|
|
312
324
|
Important: All entries of validated_cols must be present in both the reference result and the actual result.
|
|
313
325
|
metric : Callable
|
|
314
326
|
Metric-like function that is used to compute the distance between the reference result and the actual result
|
|
315
|
-
produced by the simulation.
|
|
316
|
-
|
|
327
|
+
produced by the simulation.
|
|
328
|
+
|
|
329
|
+
The return value of the metric function MUST either be
|
|
330
|
+
|
|
331
|
+
a nonnegative scalar value (i.e. a time-wise nonlocalized deviation)
|
|
317
332
|
|
|
318
|
-
|
|
333
|
+
or
|
|
334
|
+
|
|
335
|
+
an np.ndarray of shape (N,2) containing a timeseries of localized deviations between r_ref and r_act
|
|
336
|
+
(i.e. a time-wise localized metric evaluation).
|
|
337
|
+
|
|
338
|
+
The timestamps in a returned timeseries do not need to match those of r_ref or of r_act. Timestamp
|
|
339
|
+
unification will be used when plotting localized deviations.
|
|
340
|
+
|
|
341
|
+
Default is the infinity-norm on the difference between reference result and actual result.
|
|
342
|
+
|
|
343
|
+
:math:`\| r_\text{ref} - r_\text{act} \|_{\infty} = \max_{i \in 1,\ldots,N} |r_\text{ref}[t_i] - r_\text{act}[t_i]|`
|
|
319
344
|
|
|
320
345
|
where :math:`r_\text{ref}, r_\text{act} \in \mathbb{R}^N` denote the reference and the actual result
|
|
321
|
-
with timestamps :math:`
|
|
346
|
+
with timestamps :math:`t_i, i \in 1,\ldots,N`. Note that the timestamps of both results are unified using
|
|
322
347
|
the method _unify_timestamps.
|
|
323
348
|
|
|
324
349
|
This default function is implemented in
|
|
@@ -329,6 +354,12 @@ class RegressionTest:
|
|
|
329
354
|
|
|
330
355
|
metric=lambda r_ref, r_act: np.linalg.norm(r_ref[:, 1] - r_act[:, 1], ord=np.inf)
|
|
331
356
|
|
|
357
|
+
A default implementation of a metric returning a timeseries of deviations would be
|
|
358
|
+
|
|
359
|
+
metric=mopyregtest.metrics.abs_dist_ptwise
|
|
360
|
+
|
|
361
|
+
which is simply :math:`\Big\{ (t_i, |r_\text{ref}[t_i] - r_\text{act}[t_i]| : i \in 1,\ldots,N \Big\}`
|
|
362
|
+
|
|
332
363
|
unify_timestamps : bool
|
|
333
364
|
Boolean controlling whether the timestamp unification shall be called in compare_result before evaluating
|
|
334
365
|
the metric. Default=True.
|
|
@@ -345,6 +376,11 @@ class RegressionTest:
|
|
|
345
376
|
pandas.DataFrame.fillna and "interpol" uses linear interpolation
|
|
346
377
|
as in pandas.DataFrame.interpol
|
|
347
378
|
|
|
379
|
+
write_comparison : bool
|
|
380
|
+
If there are result comparisons that have failed, this will trigger writing a comparison csv file to the
|
|
381
|
+
folder where the actual simulation result is found and be called <simulation_result_name_root>_compare.csv.
|
|
382
|
+
Default=True.
|
|
383
|
+
|
|
348
384
|
Returns
|
|
349
385
|
-------
|
|
350
386
|
out : None
|
|
@@ -358,7 +394,7 @@ class RegressionTest:
|
|
|
358
394
|
|
|
359
395
|
RegressionTest.compare_csv_files(reference_result, simulation_result, tol, validated_cols,
|
|
360
396
|
metric,
|
|
361
|
-
unify_timestamps, fill_in_method)
|
|
397
|
+
unify_timestamps, fill_in_method, write_comparison)
|
|
362
398
|
|
|
363
399
|
return
|
|
364
400
|
|
|
@@ -465,4 +501,135 @@ class RegressionTest:
|
|
|
465
501
|
# Run the simulation script and append the output of the OpenModelica Compiler (omc) to omc_output
|
|
466
502
|
os.system(tool_executable + " {} >> {}".format(model_simulate_mos, tool_output))
|
|
467
503
|
|
|
468
|
-
return
|
|
504
|
+
return
|
|
505
|
+
|
|
506
|
+
@staticmethod
|
|
507
|
+
def _write_csv_comparison(reference_result, simulation_result, failed_cols, fill_in_method="ffill",
|
|
508
|
+
comparison_fname=""):
|
|
509
|
+
"""
|
|
510
|
+
Writes a comparison CSV file from the result comparison of reference_result and actual simulation result,
|
|
511
|
+
which includes also the results for the failed variable columns in the output. Note that to have results in
|
|
512
|
+
one common CSV files, the timestamps must be identical. The output CSV file has a
|
|
513
|
+
format like:
|
|
514
|
+
|
|
515
|
+
root
|
|
516
|
+
|
|
|
517
|
+
+ -- reference
|
|
518
|
+
|
|
|
519
|
+
+...
|
|
520
|
+
+ -- actual
|
|
521
|
+
|
|
|
522
|
+
+...
|
|
523
|
+
+ -- failed
|
|
524
|
+
|
|
|
525
|
+
+ var_failed_0
|
|
526
|
+
|
|
|
527
|
+
+ reference
|
|
528
|
+
|
|
|
529
|
+
+ actual
|
|
530
|
+
|
|
|
531
|
+
+ [delta_nonloc|delta_greater_tol]
|
|
532
|
+
|
|
|
533
|
+
+ var_failed_1
|
|
534
|
+
|
|
|
535
|
+
+ reference
|
|
536
|
+
|
|
|
537
|
+
+ actual
|
|
538
|
+
|
|
|
539
|
+
+ [delta_nonloc|delta_greater_tol]
|
|
540
|
+
|
|
541
|
+
In case of the metric used in the comparison returning a scalar value, the deviation is a constant
|
|
542
|
+
(because it cannot be localized), and is called delta_nonloc.
|
|
543
|
+
|
|
544
|
+
In case of metric returning a timeseries, it contains the part of the timeseries where the error exceeds the
|
|
545
|
+
tolerance, and is called delta_greater_tol.
|
|
546
|
+
|
|
547
|
+
Parameters
|
|
548
|
+
----------
|
|
549
|
+
reference_result : str
|
|
550
|
+
Path to a reference .csv file
|
|
551
|
+
simulation_result : str
|
|
552
|
+
Path to a simulation result .csv file
|
|
553
|
+
failed_cols : dict
|
|
554
|
+
A dictionary mapping the name of the column for which comparison between r_ref and r_act failed to the
|
|
555
|
+
deviation delta. This delta MUST FOR ALL COLUMNS have the same type, which can either be
|
|
556
|
+
|
|
557
|
+
a nonnegative real value
|
|
558
|
+
|
|
559
|
+
or
|
|
560
|
+
|
|
561
|
+
a pandas DataFrame with columns ["time", "delta"].
|
|
562
|
+
fill_in_method : str
|
|
563
|
+
See doc string of RegressionTest.compare_result
|
|
564
|
+
comparison_fname : str
|
|
565
|
+
Path to where the output shall be written. If not specified, the output filename
|
|
566
|
+
is <path/to/simulation_result/simulation_result_name_root>_compare.csv
|
|
567
|
+
|
|
568
|
+
Returns
|
|
569
|
+
-------
|
|
570
|
+
out : None
|
|
571
|
+
"""
|
|
572
|
+
|
|
573
|
+
if not comparison_fname:
|
|
574
|
+
comparison_fname = (pathlib.Path(simulation_result).absolute().parent /
|
|
575
|
+
f"{pathlib.Path(simulation_result).stem}_comparison.csv")
|
|
576
|
+
|
|
577
|
+
ref_data = pd.read_csv(filepath_or_buffer=reference_result, delimiter=',')
|
|
578
|
+
sim_data = pd.read_csv(filepath_or_buffer=simulation_result, delimiter=',')
|
|
579
|
+
|
|
580
|
+
# Determine if the delta in failed_cols between actual and reference is a (nonlocal) scalar or a timeseries
|
|
581
|
+
is_scalar = True
|
|
582
|
+
for v in failed_cols.values():
|
|
583
|
+
if type(v) is pd.DataFrame:
|
|
584
|
+
is_scalar = False
|
|
585
|
+
break
|
|
586
|
+
|
|
587
|
+
# Timestamps must be unified to have both results side by side
|
|
588
|
+
if is_scalar: # Only unify ref_data and sim_data, make delta a constant timeseries
|
|
589
|
+
data_ext = RegressionTest._unify_timestamps([ref_data, sim_data], fill_in_method)
|
|
590
|
+
ref_data_ext = data_ext[0]
|
|
591
|
+
sim_data_ext = data_ext[1]
|
|
592
|
+
|
|
593
|
+
timestamps_ext = sim_data_ext["time"].values
|
|
594
|
+
failed_cols_ext = {}
|
|
595
|
+
for c in failed_cols.keys():
|
|
596
|
+
delta_ext = failed_cols[c]*np.ones(shape=timestamps_ext.shape)
|
|
597
|
+
failed_cols_ext[c] = pd.DataFrame(data=np.vstack((timestamps_ext, delta_ext)).transpose(),
|
|
598
|
+
columns=["time", "delta"])
|
|
599
|
+
else: # Unify ref_data, sim_data and all delta timeseries
|
|
600
|
+
failed_keys = list(failed_cols.keys())
|
|
601
|
+
data_ext = RegressionTest._unify_timestamps([ref_data, sim_data] + list(failed_cols.values()))
|
|
602
|
+
ref_data_ext = data_ext[0]
|
|
603
|
+
sim_data_ext = data_ext[1]
|
|
604
|
+
|
|
605
|
+
failed_cols_ext = {}
|
|
606
|
+
for i in range(0, len(failed_keys)):
|
|
607
|
+
failed_cols_ext[failed_keys[i]] = data_ext[2+i]
|
|
608
|
+
|
|
609
|
+
# Extract the columns for time and the failed comparisons
|
|
610
|
+
time_data = sim_data_ext["time"]
|
|
611
|
+
ref_data_ext.drop(columns=["time"], inplace=True)
|
|
612
|
+
sim_data_ext.drop(columns=["time"], inplace=True)
|
|
613
|
+
for c in failed_cols_ext.keys():
|
|
614
|
+
failed_cols_ext[c].drop(columns=["time"], inplace=True)
|
|
615
|
+
|
|
616
|
+
failed_tseries = pd.DataFrame()
|
|
617
|
+
for c in failed_cols_ext.keys():
|
|
618
|
+
c_ref = ref_data_ext[c]
|
|
619
|
+
c_ref.name = f"failed.{c}.reference"
|
|
620
|
+
c_act = sim_data_ext[c]
|
|
621
|
+
c_act.name = f"failed.{c}.actual"
|
|
622
|
+
c_delta = failed_cols_ext[c]["delta"]
|
|
623
|
+
if is_scalar:
|
|
624
|
+
c_delta.name = f"failed.{c}.delta_nonloc"
|
|
625
|
+
else:
|
|
626
|
+
c_delta.name = f"failed.{c}.delta_greater_tol"
|
|
627
|
+
failed_tseries = pd.concat([failed_tseries, c_ref, c_act, c_delta], axis=1)
|
|
628
|
+
|
|
629
|
+
# Concatenate results and prepend result headers
|
|
630
|
+
ref_data_ext.columns = [f"reference.{c}" for c in ref_data_ext.columns]
|
|
631
|
+
sim_data_ext.columns = [f"actual.{c}" for c in sim_data_ext.columns]
|
|
632
|
+
comparison_csv = pd.concat([time_data, ref_data_ext, sim_data_ext, failed_tseries], axis=1)
|
|
633
|
+
comparison_csv.to_csv(comparison_fname, sep=",")
|
|
634
|
+
|
|
635
|
+
return
|
|
@@ -8,7 +8,7 @@ with open("README.md") as fh:
|
|
|
8
8
|
|
|
9
9
|
setuptools.setup(
|
|
10
10
|
name="MoPyRegtest",
|
|
11
|
-
version="0.
|
|
11
|
+
version="0.5.0",
|
|
12
12
|
author="Philipp Emanuel Stelzig",
|
|
13
13
|
description="A Python enabled simple regression testing framework for Modelica models",
|
|
14
14
|
long_description=long_description,
|
|
@@ -35,6 +35,24 @@ class TestCli(unittest.TestCase):
|
|
|
35
35
|
|
|
36
36
|
return
|
|
37
37
|
|
|
38
|
+
def test_generate3(self):
|
|
39
|
+
"""
|
|
40
|
+
Testing for optional arguments in CLI: mopyregtest generate
|
|
41
|
+
"""
|
|
42
|
+
cmd_args = ["generate",
|
|
43
|
+
"--metric=abs_dist_ptwise",
|
|
44
|
+
"--tol=1.2e-5",
|
|
45
|
+
"--references=Modelica.Blocks.Sources.Sine:{}".format(
|
|
46
|
+
this_folder / "../examples/test_user_defined_metrics/references/SineNoisy_res.csv"),
|
|
47
|
+
str(this_folder / "../examples/generate_tests/gen_tests3"),
|
|
48
|
+
"BlocksAbsDistPtwise_from_cli",
|
|
49
|
+
"~/.openmodelica/libraries/Modelica 4.0.0+maint.om/",
|
|
50
|
+
"Modelica.Blocks.Sources.Sine"]
|
|
51
|
+
|
|
52
|
+
cli.parse_args(cmd_args)
|
|
53
|
+
|
|
54
|
+
return
|
|
55
|
+
|
|
38
56
|
def test_compare1(self):
|
|
39
57
|
"""
|
|
40
58
|
Testing for default arguments in CLI: mopyregtest compare
|
|
@@ -74,6 +92,8 @@ class TestCli(unittest.TestCase):
|
|
|
74
92
|
str(this_folder / "../examples/test_user_defined_metrics/references/Sine_res.csv")]
|
|
75
93
|
|
|
76
94
|
self.assertRaises(AssertionError, cli.parse_args, cmd_args=cmd_args)
|
|
95
|
+
self.assertTrue(
|
|
96
|
+
(this_folder / "../examples/test_user_defined_metrics/references/Sine_res_comparison.csv").exists())
|
|
77
97
|
|
|
78
98
|
return
|
|
79
99
|
|
|
@@ -91,3 +111,21 @@ class TestCli(unittest.TestCase):
|
|
|
91
111
|
cli.parse_args(cmd_args)
|
|
92
112
|
|
|
93
113
|
return
|
|
114
|
+
|
|
115
|
+
def test_compare5(self):
|
|
116
|
+
"""
|
|
117
|
+
Testing for new metric argument abs_dist_ptwise in CLI: mopyregtest compare
|
|
118
|
+
"""
|
|
119
|
+
cmd_args = ["compare",
|
|
120
|
+
"--metric=abs_dist_ptwise",
|
|
121
|
+
"--tol=2.5e-4",
|
|
122
|
+
"--validated-cols=y",
|
|
123
|
+
"--fill-in-method=interpolate",
|
|
124
|
+
str(this_folder / "../examples/test_user_defined_metrics/references/SineNoisy_res.csv"),
|
|
125
|
+
str(this_folder / "../examples/test_user_defined_metrics/references/Sine_res.csv")]
|
|
126
|
+
|
|
127
|
+
self.assertRaises(AssertionError, cli.parse_args, cmd_args=cmd_args)
|
|
128
|
+
self.assertTrue(
|
|
129
|
+
(this_folder / "../examples/test_user_defined_metrics/references/Sine_res_comparison.csv").exists())
|
|
130
|
+
|
|
131
|
+
return
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import unittest
|
|
2
|
+
import pathlib
|
|
3
|
+
import os
|
|
2
4
|
import mopyregtest
|
|
3
5
|
|
|
6
|
+
this_folder = pathlib.Path(__file__).absolute().parent
|
|
7
|
+
|
|
4
8
|
class TestCompareResults(unittest.TestCase):
|
|
5
9
|
def test_time_col_ignored(self):
|
|
6
10
|
"""
|
|
@@ -56,3 +60,43 @@ class TestCompareResults(unittest.TestCase):
|
|
|
56
60
|
simulation_result="../examples/test_user_defined_metrics/references/Sine_res.csv",
|
|
57
61
|
validated_cols=["y", "uniformNoise.y"])
|
|
58
62
|
return
|
|
63
|
+
|
|
64
|
+
def test_write_comparison_timeseries1(self):
|
|
65
|
+
"""
|
|
66
|
+
Validate that writing a comparison timeseries on failed tests can be switched off using the write_comparison
|
|
67
|
+
argument.
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
compar_file_path = (this_folder / "../examples/test_user_defined_metrics/references/Sine_res_comparison.csv")
|
|
71
|
+
|
|
72
|
+
if compar_file_path.exists():
|
|
73
|
+
os.remove(compar_file_path)
|
|
74
|
+
|
|
75
|
+
self.assertRaises(AssertionError, mopyregtest.RegressionTest.compare_csv_files,
|
|
76
|
+
reference_result="../examples/test_user_defined_metrics/references/SineNoisy_res.csv",
|
|
77
|
+
simulation_result="../examples/test_user_defined_metrics/references/Sine_res.csv",
|
|
78
|
+
tol=1e-5,
|
|
79
|
+
validated_cols=["y"],
|
|
80
|
+
write_comparison=False)
|
|
81
|
+
self.assertFalse(compar_file_path.exists())
|
|
82
|
+
|
|
83
|
+
return
|
|
84
|
+
|
|
85
|
+
def test_write_comparison_timeseries2(self):
|
|
86
|
+
"""
|
|
87
|
+
Validate that a comparison timeseries is written on a failed test by default.
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
compar_file_path = (this_folder / "../examples/test_user_defined_metrics/references/Sine_res_comparison.csv")
|
|
91
|
+
|
|
92
|
+
if compar_file_path.exists():
|
|
93
|
+
os.remove(compar_file_path)
|
|
94
|
+
|
|
95
|
+
self.assertRaises(AssertionError, mopyregtest.RegressionTest.compare_csv_files,
|
|
96
|
+
reference_result="../examples/test_user_defined_metrics/references/SineNoisy_res.csv",
|
|
97
|
+
simulation_result="../examples/test_user_defined_metrics/references/Sine_res.csv",
|
|
98
|
+
tol=1e-5,
|
|
99
|
+
validated_cols=["y"])
|
|
100
|
+
self.assertTrue(compar_file_path.exists())
|
|
101
|
+
|
|
102
|
+
return
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{MoPyRegtest-0.4.1 → MoPyRegtest-0.5.0}/mopyregtest/templates/omc/model_simulate.mos.template
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|