MoPyRegtest 0.4.0__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.0 → MoPyRegtest-0.5.0}/LICENSE +1 -1
- {MoPyRegtest-0.4.0 → MoPyRegtest-0.5.0/MoPyRegtest.egg-info}/PKG-INFO +12 -5
- {MoPyRegtest-0.4.0 → MoPyRegtest-0.5.0}/MoPyRegtest.egg-info/SOURCES.txt +2 -1
- {MoPyRegtest-0.4.0/MoPyRegtest.egg-info → MoPyRegtest-0.5.0}/PKG-INFO +12 -5
- {MoPyRegtest-0.4.0 → MoPyRegtest-0.5.0}/README.md +11 -4
- {MoPyRegtest-0.4.0 → MoPyRegtest-0.5.0}/mopyregtest/cli.py +9 -3
- {MoPyRegtest-0.4.0 → MoPyRegtest-0.5.0}/mopyregtest/generator.py +4 -2
- {MoPyRegtest-0.4.0 → MoPyRegtest-0.5.0}/mopyregtest/metrics.py +12 -0
- {MoPyRegtest-0.4.0 → MoPyRegtest-0.5.0}/mopyregtest/modelicaregressiontest.py +208 -17
- {MoPyRegtest-0.4.0 → MoPyRegtest-0.5.0}/setup.py +1 -1
- {MoPyRegtest-0.4.0 → MoPyRegtest-0.5.0}/tests/test_cli.py +38 -0
- MoPyRegtest-0.5.0/tests/test_compare_results.py +102 -0
- MoPyRegtest-0.4.0/tests/test_compare_results.py → MoPyRegtest-0.5.0/tests/test_unify_timestamps.py +1 -1
- {MoPyRegtest-0.4.0 → MoPyRegtest-0.5.0}/MoPyRegtest.egg-info/dependency_links.txt +0 -0
- {MoPyRegtest-0.4.0 → MoPyRegtest-0.5.0}/MoPyRegtest.egg-info/entry_points.txt +0 -0
- {MoPyRegtest-0.4.0 → MoPyRegtest-0.5.0}/MoPyRegtest.egg-info/requires.txt +0 -0
- {MoPyRegtest-0.4.0 → MoPyRegtest-0.5.0}/MoPyRegtest.egg-info/top_level.txt +0 -0
- {MoPyRegtest-0.4.0 → MoPyRegtest-0.5.0}/mopyregtest/__init__.py +0 -0
- {MoPyRegtest-0.4.0 → MoPyRegtest-0.5.0}/mopyregtest/templates/omc/model_import.mos.template +0 -0
- {MoPyRegtest-0.4.0 → MoPyRegtest-0.5.0}/mopyregtest/templates/omc/model_simulate.mos.template +0 -0
- {MoPyRegtest-0.4.0 → MoPyRegtest-0.5.0}/mopyregtest/utils.py +0 -0
- {MoPyRegtest-0.4.0 → MoPyRegtest-0.5.0}/setup.cfg +0 -0
- {MoPyRegtest-0.4.0 → MoPyRegtest-0.5.0}/tests/test_metrics.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
|
|
@@ -16,8 +16,15 @@ Requires-Dist: pandas
|
|
|
16
16
|
|
|
17
17
|
# MoPyRegtest: A Python enabled simple regression testing framework for Modelica models
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
[](https://github.com/pstelzig/MoPyRegtest/tree/master/LICENSE)
|
|
21
|
+
[](https://github.com/pstelzig/MoPyRegtest/issues)
|
|
22
|
+
|
|
23
|
+
**Project status**
|
|
24
|
+
[](https://github.com/pstelzig/MoPyRegtest/actions/workflows/job-unit-tests.yml)
|
|
25
|
+
[](https://github.com/pstelzig/MoPyRegtest/actions/workflows/job-examples.yml)
|
|
26
|
+
[](https://github.com/pstelzig/MoPyRegtest/actions/workflows/job-example-for-other-repo.yml)
|
|
27
|
+
[](https://pypi.org/project/MoPyRegtest/)
|
|
21
28
|
|
|
22
29
|
Scope of this project is to
|
|
23
30
|
* provide a simple regression testing framework for Modelica models
|
|
@@ -76,7 +83,7 @@ has a detailed explanation on how to automatically generate tests.
|
|
|
76
83
|
## Prerequisites
|
|
77
84
|
To use MoPyRegtest you need to have
|
|
78
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/),
|
|
79
|
-
* 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
|
|
80
87
|
* the OpenModelica compiler executable `omc` must be accessible via the `PATH` variable.
|
|
81
88
|
|
|
82
89
|
## Installation using pip3
|
|
@@ -127,7 +134,7 @@ knows where to find `mopyregtest` as installed by pip. To find out the location,
|
|
|
127
134
|
not confirm to proceed. The uninstallation will tell you which files pip would remove upon uninstalling MoPyRegtest,
|
|
128
135
|
including the `mopyregtest` executable (or `mopyregtest.exe` under Windows) and its location.
|
|
129
136
|
|
|
130
|
-
```
|
|
137
|
+
```
|
|
131
138
|
Found existing installation: MoPyRegtest 0.4.0rc1
|
|
132
139
|
Uninstalling MoPyRegtest-0.4.0rc1:
|
|
133
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
|
|
@@ -16,8 +16,15 @@ Requires-Dist: pandas
|
|
|
16
16
|
|
|
17
17
|
# MoPyRegtest: A Python enabled simple regression testing framework for Modelica models
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
[](https://github.com/pstelzig/MoPyRegtest/tree/master/LICENSE)
|
|
21
|
+
[](https://github.com/pstelzig/MoPyRegtest/issues)
|
|
22
|
+
|
|
23
|
+
**Project status**
|
|
24
|
+
[](https://github.com/pstelzig/MoPyRegtest/actions/workflows/job-unit-tests.yml)
|
|
25
|
+
[](https://github.com/pstelzig/MoPyRegtest/actions/workflows/job-examples.yml)
|
|
26
|
+
[](https://github.com/pstelzig/MoPyRegtest/actions/workflows/job-example-for-other-repo.yml)
|
|
27
|
+
[](https://pypi.org/project/MoPyRegtest/)
|
|
21
28
|
|
|
22
29
|
Scope of this project is to
|
|
23
30
|
* provide a simple regression testing framework for Modelica models
|
|
@@ -76,7 +83,7 @@ has a detailed explanation on how to automatically generate tests.
|
|
|
76
83
|
## Prerequisites
|
|
77
84
|
To use MoPyRegtest you need to have
|
|
78
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/),
|
|
79
|
-
* 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
|
|
80
87
|
* the OpenModelica compiler executable `omc` must be accessible via the `PATH` variable.
|
|
81
88
|
|
|
82
89
|
## Installation using pip3
|
|
@@ -127,7 +134,7 @@ knows where to find `mopyregtest` as installed by pip. To find out the location,
|
|
|
127
134
|
not confirm to proceed. The uninstallation will tell you which files pip would remove upon uninstalling MoPyRegtest,
|
|
128
135
|
including the `mopyregtest` executable (or `mopyregtest.exe` under Windows) and its location.
|
|
129
136
|
|
|
130
|
-
```
|
|
137
|
+
```
|
|
131
138
|
Found existing installation: MoPyRegtest 0.4.0rc1
|
|
132
139
|
Uninstalling MoPyRegtest-0.4.0rc1:
|
|
133
140
|
Would remove:
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
# MoPyRegtest: A Python enabled simple regression testing framework for Modelica models
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[](https://github.com/pstelzig/MoPyRegtest/tree/master/LICENSE)
|
|
5
|
+
[](https://github.com/pstelzig/MoPyRegtest/issues)
|
|
6
|
+
|
|
7
|
+
**Project status**
|
|
8
|
+
[](https://github.com/pstelzig/MoPyRegtest/actions/workflows/job-unit-tests.yml)
|
|
9
|
+
[](https://github.com/pstelzig/MoPyRegtest/actions/workflows/job-examples.yml)
|
|
10
|
+
[](https://github.com/pstelzig/MoPyRegtest/actions/workflows/job-example-for-other-repo.yml)
|
|
11
|
+
[](https://pypi.org/project/MoPyRegtest/)
|
|
5
12
|
|
|
6
13
|
Scope of this project is to
|
|
7
14
|
* provide a simple regression testing framework for Modelica models
|
|
@@ -60,7 +67,7 @@ has a detailed explanation on how to automatically generate tests.
|
|
|
60
67
|
## Prerequisites
|
|
61
68
|
To use MoPyRegtest you need to have
|
|
62
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/),
|
|
63
|
-
* 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
|
|
64
71
|
* the OpenModelica compiler executable `omc` must be accessible via the `PATH` variable.
|
|
65
72
|
|
|
66
73
|
## Installation using pip3
|
|
@@ -111,7 +118,7 @@ knows where to find `mopyregtest` as installed by pip. To find out the location,
|
|
|
111
118
|
not confirm to proceed. The uninstallation will tell you which files pip would remove upon uninstalling MoPyRegtest,
|
|
112
119
|
including the `mopyregtest` executable (or `mopyregtest.exe` under Windows) and its location.
|
|
113
120
|
|
|
114
|
-
```
|
|
121
|
+
```
|
|
115
122
|
Found existing installation: MoPyRegtest 0.4.0rc1
|
|
116
123
|
Uninstalling MoPyRegtest-0.4.0rc1:
|
|
117
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,38 +242,73 @@ 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
|
-------
|
|
248
250
|
out : None
|
|
249
251
|
"""
|
|
250
252
|
ref_data = pd.read_csv(filepath_or_buffer=reference_result, delimiter=',')
|
|
251
|
-
|
|
253
|
+
sim_data = pd.read_csv(filepath_or_buffer=simulation_result, delimiter=',')
|
|
252
254
|
|
|
253
255
|
if unify_timestamps:
|
|
254
|
-
data_ext = RegressionTest._unify_timestamps([ref_data,
|
|
256
|
+
data_ext = RegressionTest._unify_timestamps([ref_data, sim_data], fill_in_method)
|
|
255
257
|
ref_data = data_ext[0]
|
|
256
|
-
|
|
258
|
+
sim_data = data_ext[1]
|
|
257
259
|
|
|
258
260
|
# Determine common columns by comparing column headers
|
|
259
|
-
common_cols = set(ref_data.columns).intersection(set(
|
|
261
|
+
common_cols = set(ref_data.columns).intersection(set(sim_data.columns))
|
|
260
262
|
|
|
261
263
|
if not validated_cols:
|
|
262
264
|
validated_cols = common_cols
|
|
263
265
|
|
|
266
|
+
# Check if validated_cols is meaningful
|
|
267
|
+
validated_cols = set(validated_cols)
|
|
268
|
+
if "time" in validated_cols:
|
|
269
|
+
validated_cols.remove("time") # Ignore time column
|
|
270
|
+
|
|
271
|
+
if not validated_cols.issubset(set(ref_data.columns)):
|
|
272
|
+
missing_cols = validated_cols.difference(set(ref_data.columns))
|
|
273
|
+
raise ValueError(f"The reference data {reference_result} does not contain all entries of validated_cols. "
|
|
274
|
+
f"Missing: {missing_cols}")
|
|
275
|
+
|
|
276
|
+
if not validated_cols.issubset(set(sim_data.columns)):
|
|
277
|
+
missing_cols = validated_cols.difference(set(sim_data.columns))
|
|
278
|
+
raise ValueError(f"The simulation data {simulation_result} does not contain all entries of validated_cols."
|
|
279
|
+
f"Missing: {missing_cols}")
|
|
280
|
+
|
|
281
|
+
if len(validated_cols) == 0:
|
|
282
|
+
raise ValueError(f"validated_cols must contain at least one common variable in "
|
|
283
|
+
f"reference {reference_result} and simulation result {simulation_result}")
|
|
284
|
+
|
|
285
|
+
failed_cols = {}
|
|
264
286
|
for c in validated_cols:
|
|
265
287
|
print("Comparing column \"{}\"".format(c))
|
|
266
|
-
delta = metric(ref_data[["time", c]].values,
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
288
|
+
delta = metric(ref_data[["time", c]].values, sim_data[["time", c]].values)
|
|
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
|
|
297
|
+
|
|
298
|
+
if failed_cols:
|
|
299
|
+
if write_comparison:
|
|
300
|
+
RegressionTest._write_csv_comparison(reference_result, simulation_result,
|
|
301
|
+
failed_cols, fill_in_method)
|
|
302
|
+
|
|
303
|
+
raise AssertionError(
|
|
304
|
+
f"Values of results {simulation_result} and {reference_result} are different in columns "
|
|
305
|
+
f"{list(failed_cols.keys())} by more than {tol}. ")
|
|
271
306
|
|
|
272
307
|
return
|
|
273
308
|
|
|
274
309
|
def compare_result(self, reference_result, tol=1e-7, validated_cols=[],
|
|
275
310
|
metric=metrics.norm_infty_dist,
|
|
276
|
-
unify_timestamps=True, fill_in_method="ffill"):
|
|
311
|
+
unify_timestamps=True, fill_in_method="ffill", write_comparison=True):
|
|
277
312
|
"""
|
|
278
313
|
Executes simulation and then compares the obtained result and the reference result along the
|
|
279
314
|
validated columns. Throws an exception (AssertionError) if the deviation is larger or equal to tol.
|
|
@@ -286,15 +321,29 @@ class RegressionTest:
|
|
|
286
321
|
Absolute tolerance up to which deviation in the comparison metric is accepted
|
|
287
322
|
validated_cols : list
|
|
288
323
|
List of variable names (from the file header) in the reference .csv file that are used in the regression test
|
|
324
|
+
Important: All entries of validated_cols must be present in both the reference result and the actual result.
|
|
289
325
|
metric : Callable
|
|
290
326
|
Metric-like function that is used to compute the distance between the reference result and the actual result
|
|
291
|
-
produced by the simulation.
|
|
292
|
-
|
|
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)
|
|
332
|
+
|
|
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).
|
|
293
337
|
|
|
294
|
-
|
|
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]|`
|
|
295
344
|
|
|
296
345
|
where :math:`r_\text{ref}, r_\text{act} \in \mathbb{R}^N` denote the reference and the actual result
|
|
297
|
-
with timestamps :math:`
|
|
346
|
+
with timestamps :math:`t_i, i \in 1,\ldots,N`. Note that the timestamps of both results are unified using
|
|
298
347
|
the method _unify_timestamps.
|
|
299
348
|
|
|
300
349
|
This default function is implemented in
|
|
@@ -305,6 +354,12 @@ class RegressionTest:
|
|
|
305
354
|
|
|
306
355
|
metric=lambda r_ref, r_act: np.linalg.norm(r_ref[:, 1] - r_act[:, 1], ord=np.inf)
|
|
307
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
|
+
|
|
308
363
|
unify_timestamps : bool
|
|
309
364
|
Boolean controlling whether the timestamp unification shall be called in compare_result before evaluating
|
|
310
365
|
the metric. Default=True.
|
|
@@ -321,6 +376,11 @@ class RegressionTest:
|
|
|
321
376
|
pandas.DataFrame.fillna and "interpol" uses linear interpolation
|
|
322
377
|
as in pandas.DataFrame.interpol
|
|
323
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
|
+
|
|
324
384
|
Returns
|
|
325
385
|
-------
|
|
326
386
|
out : None
|
|
@@ -334,7 +394,7 @@ class RegressionTest:
|
|
|
334
394
|
|
|
335
395
|
RegressionTest.compare_csv_files(reference_result, simulation_result, tol, validated_cols,
|
|
336
396
|
metric,
|
|
337
|
-
unify_timestamps, fill_in_method)
|
|
397
|
+
unify_timestamps, fill_in_method, write_comparison)
|
|
338
398
|
|
|
339
399
|
return
|
|
340
400
|
|
|
@@ -441,4 +501,135 @@ class RegressionTest:
|
|
|
441
501
|
# Run the simulation script and append the output of the OpenModelica Compiler (omc) to omc_output
|
|
442
502
|
os.system(tool_executable + " {} >> {}".format(model_simulate_mos, tool_output))
|
|
443
503
|
|
|
444
|
-
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
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
import pathlib
|
|
3
|
+
import os
|
|
4
|
+
import mopyregtest
|
|
5
|
+
|
|
6
|
+
this_folder = pathlib.Path(__file__).absolute().parent
|
|
7
|
+
|
|
8
|
+
class TestCompareResults(unittest.TestCase):
|
|
9
|
+
def test_time_col_ignored(self):
|
|
10
|
+
"""
|
|
11
|
+
Validates that time as a validated column is ignored in the result comparison
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
self.assertRaises(ValueError, mopyregtest.RegressionTest.compare_csv_files,
|
|
15
|
+
reference_result="../examples/test_user_defined_metrics/references/Sine_res.csv",
|
|
16
|
+
simulation_result="../examples/test_user_defined_metrics/references/Sine_res.csv",
|
|
17
|
+
validated_cols=["time"])
|
|
18
|
+
|
|
19
|
+
def test_disjoint_cols(self):
|
|
20
|
+
"""
|
|
21
|
+
Validate that test of two CSV result files that have no common result variable besides time fails
|
|
22
|
+
"""
|
|
23
|
+
self.assertRaises(ValueError, mopyregtest.RegressionTest.compare_csv_files,
|
|
24
|
+
reference_result="../examples/test_Modelica_Electrical_Analog_Examples/references/Modelica.Electrical.Analog.Examples.CharacteristicIdealDiodes_res.csv",
|
|
25
|
+
simulation_result="../examples/test_user_defined_metrics/references/Sine_res.csv")
|
|
26
|
+
return
|
|
27
|
+
|
|
28
|
+
def test_validated_cols_not_contained1(self):
|
|
29
|
+
"""
|
|
30
|
+
Validate that comparison fails if not all elements of validated cols are contained in both reference and actual
|
|
31
|
+
result.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
self.assertRaises(ValueError, mopyregtest.RegressionTest.compare_csv_files,
|
|
35
|
+
reference_result="../examples/test_user_defined_metrics/references/Sine_res.csv",
|
|
36
|
+
simulation_result="../examples/test_user_defined_metrics/references/SineNoisy_res.csv",
|
|
37
|
+
validated_cols=["y", "not_present_var"])
|
|
38
|
+
return
|
|
39
|
+
|
|
40
|
+
def test_validated_cols_not_contained2(self):
|
|
41
|
+
"""
|
|
42
|
+
Validate that comparison fails if not all elements of validated cols are contained in both reference and actual
|
|
43
|
+
result. Case: Column not contained in reference_result.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
self.assertRaises(ValueError, mopyregtest.RegressionTest.compare_csv_files,
|
|
47
|
+
reference_result="../examples/test_user_defined_metrics/references/Sine_res.csv",
|
|
48
|
+
simulation_result="../examples/test_user_defined_metrics/references/SineNoisy_res.csv",
|
|
49
|
+
validated_cols=["y", "uniformNoise.y"])
|
|
50
|
+
return
|
|
51
|
+
|
|
52
|
+
def test_validated_cols_not_contained3(self):
|
|
53
|
+
"""
|
|
54
|
+
Validate that comparison fails if not all elements of validated cols are contained in both reference and actual
|
|
55
|
+
result. Case: Column not contained in simulation_result.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
self.assertRaises(ValueError, mopyregtest.RegressionTest.compare_csv_files,
|
|
59
|
+
reference_result="../examples/test_user_defined_metrics/references/SineNoisy_res.csv",
|
|
60
|
+
simulation_result="../examples/test_user_defined_metrics/references/Sine_res.csv",
|
|
61
|
+
validated_cols=["y", "uniformNoise.y"])
|
|
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
|
MoPyRegtest-0.4.0/tests/test_compare_results.py → MoPyRegtest-0.5.0/tests/test_unify_timestamps.py
RENAMED
|
@@ -2,7 +2,7 @@ import unittest
|
|
|
2
2
|
import mopyregtest
|
|
3
3
|
import pandas as pd
|
|
4
4
|
|
|
5
|
-
class
|
|
5
|
+
class TestUnifyTimestamps(unittest.TestCase):
|
|
6
6
|
def test_unify_timestamps_ffill(self):
|
|
7
7
|
res1 = pd.DataFrame(data=[[0.0, 1.0, 2.0], [0.5, 2.0, 4.0], [0.75, 3.0, 6.0], [1.0, 4.0, 8.0]],
|
|
8
8
|
columns=["time", "quant1", "quant2"])
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{MoPyRegtest-0.4.0 → MoPyRegtest-0.5.0}/mopyregtest/templates/omc/model_simulate.mos.template
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|