/
tests.txt
130 lines (100 loc) · 8.5 KB
/
tests.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# -*- coding: utf-8 -*-
# Additional tests besides those in the ModelicaRes documentation
.. testsetup::
>>> decimals = 8
>>> import numpy as np
>>> np.set_printoptions(precision=decimals)
# Don't use np.round or built-in round; they're inconsistent in the
# number of decimal places between versions of Python and even the floats
# they're passed.
>>> def round(value):
... FMT = '%' + '.%if' % decimals
... try:
... return [round(v) for v in value]
... except TypeError:
... return float(FMT % value)
>>> from modelicares import *
# Tests on modelicares.exps
# -------------------------
>>> modelica_str(False)
'false'
# modelicares.simres.SimRes methods
# ---------------------------------
>>> sim = SimRes('examples/ChuaCircuit.mat')
>>> sim['C1.v'].value() # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
Traceback (most recent call last):
...
ValueError: The variable is not a constant. Use values() instead of value().
>>> sim['C1.vv'].values() # doctest: +ELLIPSIS
Traceback (most recent call last):
...
LookupError: C1.vv is not a valid variable name.
<BLANKLINE>
Did you mean one of these?
C1.v
C1.p.v
C1.n.v
# modelicares.simres.SimRes properties
# ------------------------------------
>>> sim = SimRes('examples/ChuaCircuit/1/dsres.mat')
>>> sim['Nr.Ga'].description == ''
True
>>> sim['Nr.Ga'].unit
'S'
# modelicares.linres.LinResList methods
# -------------------------------------
>>> lins = LinResList('examples/PID/*/')
>>> lins.sort()
>>> lins.dirname # doctest: +ELLIPSIS
['.../examples/PID/1', '.../examples/PID/2']
>>> lins.append('examples/PID.mat')
>>> print(lins) # doctest: +ELLIPSIS
List of linearization results (LinRes instances) from the following files
in the .../examples directory:
PID/1/dslin.mat
PID/2/dslin.mat
PID.mat
# modelicares.exps
# ----------------
>>> d = ParamDict({'a': 1, 'b.c': np.array([2, 3]), 'b.d': False,
... 'b.e': '"hello"', 'b.f': None})
>>> l = list(str(d)) # (a=1, b(c={2, 3}, e="hello", d=false))
>>> l.sort()
>>> l
[' ', ' ', ' ', ' ', '"', '"', '(', '(', ')', ')', ',', ',', ',', ',', '1', '2', '3', '=', '=', '=', '=', 'a', 'a', 'b', 'c', 'd', 'e', 'e', 'e', 'f', 'h', 'l', 'l', 'l', 'o', 's', '{', '}']
>>> experiments = gen_experiments(
... ['Modelica.Electrical.Analog.Examples.ChuaCircuit'],
... {'L.L': [16, 18, 20], 'C2.C': [80, 100, 120]},
... design=doe.ofat)
>>> sorted([experiment.model + str(sorted(list(str(experiment.params))))
... for experiment in experiments])
["Modelica.Electrical.Analog.Examples.ChuaCircuit[' ', '(', '(', '(', ')', ')', ')', ',', '0', '0', '1', '1', '2', '6', '=', '=', 'C', 'C', 'L', 'L']", "Modelica.Electrical.Analog.Examples.ChuaCircuit[' ', '(', '(', '(', ')', ')', ')', ',', '0', '0', '2', '2', '8', '=', '=', 'C', 'C', 'L', 'L']", "Modelica.Electrical.Analog.Examples.ChuaCircuit[' ', '(', '(', '(', ')', ')', ')', ',', '0', '1', '1', '2', '2', '6', '=', '=', 'C', 'C', 'L', 'L']", "Modelica.Electrical.Analog.Examples.ChuaCircuit[' ', '(', '(', '(', ')', ')', ')', ',', '0', '1', '2', '6', '8', '=', '=', 'C', 'C', 'L', 'L']", "Modelica.Electrical.Analog.Examples.ChuaCircuit[' ', '(', '(', '(', ')', ')', ')', ',', '0', '1', '2', '8', '8', '=', '=', 'C', 'C', 'L', 'L']"]
>>> experiments = gen_experiments(
... ['Modelica.Electrical.Analog.Examples.ChuaCircuit'],
... {'L.L': [16, 18, 20], 'C2.C': [80, 100, 120]},
... design=doe.fullfact)
>>> sorted([experiment.model + str(sorted(list(str(experiment.params))))
... for experiment in experiments])
["Modelica.Electrical.Analog.Examples.ChuaCircuit[' ', '(', '(', '(', ')', ')', ')', ',', '0', '0', '0', '1', '2', '2', '=', '=', 'C', 'C', 'L', 'L']", "Modelica.Electrical.Analog.Examples.ChuaCircuit[' ', '(', '(', '(', ')', ')', ')', ',', '0', '0', '1', '1', '2', '6', '=', '=', 'C', 'C', 'L', 'L']", "Modelica.Electrical.Analog.Examples.ChuaCircuit[' ', '(', '(', '(', ')', ')', ')', ',', '0', '0', '1', '1', '2', '8', '=', '=', 'C', 'C', 'L', 'L']", "Modelica.Electrical.Analog.Examples.ChuaCircuit[' ', '(', '(', '(', ')', ')', ')', ',', '0', '0', '1', '2', '2', '2', '=', '=', 'C', 'C', 'L', 'L']", "Modelica.Electrical.Analog.Examples.ChuaCircuit[' ', '(', '(', '(', ')', ')', ')', ',', '0', '0', '2', '2', '8', '=', '=', 'C', 'C', 'L', 'L']", "Modelica.Electrical.Analog.Examples.ChuaCircuit[' ', '(', '(', '(', ')', ')', ')', ',', '0', '1', '1', '2', '2', '6', '=', '=', 'C', 'C', 'L', 'L']", "Modelica.Electrical.Analog.Examples.ChuaCircuit[' ', '(', '(', '(', ')', ')', ')', ',', '0', '1', '1', '2', '2', '8', '=', '=', 'C', 'C', 'L', 'L']", "Modelica.Electrical.Analog.Examples.ChuaCircuit[' ', '(', '(', '(', ')', ')', ')', ',', '0', '1', '2', '6', '8', '=', '=', 'C', 'C', 'L', 'L']", "Modelica.Electrical.Analog.Examples.ChuaCircuit[' ', '(', '(', '(', ')', ')', ')', ',', '0', '1', '2', '8', '8', '=', '=', 'C', 'C', 'L', 'L']"]
>>> experiments = gen_experiments(
... ['Modelica.Electrical.Analog.Examples.ChuaCircuit']*3,
... {'L.L': [16, 18, 20], 'C2.C': [80, 100, 120]},
... design=doe.aslisted)
>>> sorted([experiment.model + str(sorted(list(str(experiment.params))))
... for experiment in experiments])
["Modelica.Electrical.Analog.Examples.ChuaCircuit[' ', '(', '(', '(', ')', ')', ')', ',', '0', '0', '1', '1', '2', '8', '=', '=', 'C', 'C', 'L', 'L']", "Modelica.Electrical.Analog.Examples.ChuaCircuit[' ', '(', '(', '(', ')', ')', ')', ',', '0', '0', '1', '2', '2', '2', '=', '=', 'C', 'C', 'L', 'L']", "Modelica.Electrical.Analog.Examples.ChuaCircuit[' ', '(', '(', '(', ')', ')', ')', ',', '0', '1', '2', '6', '8', '=', '=', 'C', 'C', 'L', 'L']"]
>>> models = ['Modelica.Mechanics.MultiBody.Examples.Systems.RobotR3.oneAxis']
>>> params = dict(axis=dict(motor=dict(i_max=[5, 15],
... Ra=dict(R=[200, 300]))))
>>> sorted([experiment.model + str(sorted(list(str(experiment.params))))
... for experiment in gen_experiments(models, params)])
["Modelica.Mechanics.MultiBody.Examples.Systems.RobotR3.oneAxis[' ', '(', '(', '(', '(', ')', ')', ')', ')', ',', '0', '0', '1', '2', '5', '=', '=', 'R', 'R', '_', 'a', 'a', 'a', 'i', 'i', 'm', 'm', 'o', 'o', 'r', 's', 't', 'x', 'x']", "Modelica.Mechanics.MultiBody.Examples.Systems.RobotR3.oneAxis[' ', '(', '(', '(', '(', ')', ')', ')', ')', ',', '0', '0', '1', '3', '5', '=', '=', 'R', 'R', '_', 'a', 'a', 'a', 'i', 'i', 'm', 'm', 'o', 'o', 'r', 's', 't', 'x', 'x']", "Modelica.Mechanics.MultiBody.Examples.Systems.RobotR3.oneAxis[' ', '(', '(', '(', '(', ')', ')', ')', ')', ',', '0', '0', '2', '5', '=', '=', 'R', 'R', '_', 'a', 'a', 'a', 'i', 'i', 'm', 'm', 'o', 'o', 'r', 's', 't', 'x', 'x']", "Modelica.Mechanics.MultiBody.Examples.Systems.RobotR3.oneAxis[' ', '(', '(', '(', '(', ')', ')', ')', ')', ',', '0', '0', '3', '5', '=', '=', 'R', 'R', '_', 'a', 'a', 'a', 'i', 'i', 'm', 'm', 'o', 'o', 'r', 's', 't', 'x', 'x']"]
>>> models = ['Modelica.Mechanics.MultiBody.Examples.Systems.RobotR3.oneAxis']
>>> params = dict(axis=dict(motor=dict(i_max=[5, 15],
... Ra=dict(R=[200, 300]))))
>>> sorted([experiment.model + str(sorted(list(str(experiment.params))))
... for experiment in gen_experiments(models, params)])
["Modelica.Mechanics.MultiBody.Examples.Systems.RobotR3.oneAxis[' ', '(', '(', '(', '(', ')', ')', ')', ')', ',', '0', '0', '1', '2', '5', '=', '=', 'R', 'R', '_', 'a', 'a', 'a', 'i', 'i', 'm', 'm', 'o', 'o', 'r', 's', 't', 'x', 'x']", "Modelica.Mechanics.MultiBody.Examples.Systems.RobotR3.oneAxis[' ', '(', '(', '(', '(', ')', ')', ')', ')', ',', '0', '0', '1', '3', '5', '=', '=', 'R', 'R', '_', 'a', 'a', 'a', 'i', 'i', 'm', 'm', 'o', 'o', 'r', 's', 't', 'x', 'x']", "Modelica.Mechanics.MultiBody.Examples.Systems.RobotR3.oneAxis[' ', '(', '(', '(', '(', ')', ')', ')', ')', ',', '0', '0', '2', '5', '=', '=', 'R', 'R', '_', 'a', 'a', 'a', 'i', 'i', 'm', 'm', 'o', 'o', 'r', 's', 't', 'x', 'x']", "Modelica.Mechanics.MultiBody.Examples.Systems.RobotR3.oneAxis[' ', '(', '(', '(', '(', ')', ')', ')', ')', ',', '0', '0', '3', '5', '=', '=', 'R', 'R', '_', 'a', 'a', 'a', 'i', 'i', 'm', 'm', 'o', 'o', 'r', 's', 't', 'x', 'x']"]
>>> sorted([sorted(list(experiment.params.items()))
... for experiment in gen_experiments(models, params)])
[[('axis.motor.Ra.R', 200), ('axis.motor.i_max', 5)], [('axis.motor.Ra.R', 200), ('axis.motor.i_max', 15)], [('axis.motor.Ra.R', 300), ('axis.motor.i_max', 5)], [('axis.motor.Ra.R', 300), ('axis.motor.i_max', 15)]]