probabilistic-library 26.1.1rc5__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.
Files changed (22) hide show
  1. probabilistic_library-26.1.1rc5/PKG-INFO +46 -0
  2. probabilistic_library-26.1.1rc5/probabilistic_library/__init__.py +44 -0
  3. probabilistic_library-26.1.1rc5/probabilistic_library/bin/Deltares.Probabilistic.CWrapper.dll +0 -0
  4. probabilistic_library-26.1.1rc5/probabilistic_library/bin/__init__.py +24 -0
  5. probabilistic_library-26.1.1rc5/probabilistic_library/bin/libDeltares.Probabilistic.CWrapper.so +0 -0
  6. probabilistic_library-26.1.1rc5/probabilistic_library/interface.py +275 -0
  7. probabilistic_library-26.1.1rc5/probabilistic_library/logging.py +230 -0
  8. probabilistic_library-26.1.1rc5/probabilistic_library/project.py +1459 -0
  9. probabilistic_library-26.1.1rc5/probabilistic_library/reliability.py +1564 -0
  10. probabilistic_library-26.1.1rc5/probabilistic_library/sensitivity.py +450 -0
  11. probabilistic_library-26.1.1rc5/probabilistic_library/statistic.py +1866 -0
  12. probabilistic_library-26.1.1rc5/probabilistic_library/uncertainty.py +615 -0
  13. probabilistic_library-26.1.1rc5/probabilistic_library/utils.py +184 -0
  14. probabilistic_library-26.1.1rc5/probabilistic_library.egg-info/PKG-INFO +46 -0
  15. probabilistic_library-26.1.1rc5/probabilistic_library.egg-info/SOURCES.txt +20 -0
  16. probabilistic_library-26.1.1rc5/probabilistic_library.egg-info/dependency_links.txt +1 -0
  17. probabilistic_library-26.1.1rc5/probabilistic_library.egg-info/requires.txt +2 -0
  18. probabilistic_library-26.1.1rc5/probabilistic_library.egg-info/top_level.txt +1 -0
  19. probabilistic_library-26.1.1rc5/pyproject.toml +27 -0
  20. probabilistic_library-26.1.1rc5/readme.md +25 -0
  21. probabilistic_library-26.1.1rc5/setup.cfg +4 -0
  22. probabilistic_library-26.1.1rc5/setup.py +38 -0
@@ -0,0 +1,46 @@
1
+ Metadata-Version: 2.4
2
+ Name: probabilistic_library
3
+ Version: 26.1.1rc5
4
+ Summary: Package which provides probabilistic methods
5
+ Author: Deltares
6
+ Author-email: Deltares <d-prob-support@deltares.nl>
7
+ License: LGPL-3.0
8
+ Project-URL: Homepage, https://deltares.github.io/ProbabilisticLibrary/
9
+ Project-URL: Documentation, https://github.com/Deltares/ProbabilisticLibrary/tree/master/doc
10
+ Project-URL: Repository, https://github.com/Deltares/ProbabilisticLibrary
11
+ Project-URL: issues, https://github.com/Deltares/ProbabilisticLibrary/issues
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Development Status :: 5 - Production/Stable
15
+ Requires-Python: >=3.11
16
+ Description-Content-Type: text/markdown
17
+ Requires-Dist: numpy
18
+ Requires-Dist: matplotlib
19
+ Dynamic: author
20
+ Dynamic: requires-python
21
+
22
+ [![Python 3.11](https://img.shields.io/badge/Python-3.11-blue.svg)](https://www.python.org/downloads/release/python-31110/)
23
+ [![C++][c++-image]][c++standard]
24
+ [![docs2](https://github.com/Deltares/ProbabilisticLibrary/actions/workflows/docs.yml/badge.svg)](https://github.com/Deltares/ProbabilisticLibrary/actions/workflows/docs.yml)
25
+
26
+ [c++-image]: https://img.shields.io/badge/C++-20-blue.svg?style=flat&logo=c%2B%2B
27
+ [c++standard]: https://isocpp.org/std/the-standard
28
+
29
+ # Probabilistic Library
30
+
31
+ This is the Probabilistic Library of Deltares.
32
+ The library provides a set of routines that enable reliability, uncertainty, and sensitivity analyses.
33
+
34
+ ## Scientific background
35
+
36
+ The scientific background of the library can be found here:
37
+ [scientific_background.pdf](https://github.com/Deltares/ProbabilisticLibrary/releases/download/25.3.1/scientific_background.pdf)
38
+
39
+ ## Python wrapper
40
+
41
+ A description of the Python classes is given here:
42
+ [API documentation](https://deltares.github.io/ProbabilisticLibrary/probabilistic_library.html)
43
+
44
+ ## Tutorials
45
+
46
+ See the [Tutorials](https://github.com/Deltares/ProbabilisticLibrary/blob/master/sources/Deltares.Probabilistic.PWrapper.Notebooks/gallery/gallery.md) for several demonstrations and instructions on how to use the Probabilistic Library.
@@ -0,0 +1,44 @@
1
+ # Copyright (C) Stichting Deltares. All rights reserved.
2
+ #
3
+ # This file is part of the Probabilistic Library.
4
+ #
5
+ # The Probabilistic Library is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+ # All names, logos, and references to "Deltares" are registered trademarks of
19
+ # Stichting Deltares and remain full property of Stichting Deltares at all times.
20
+ # All rights reserved.
21
+ #
22
+ """The Probabilistic Library provides functionality to perform reliability, uncertainty and sensitivity analyses via a
23
+ `probabilistic_library.project.ReliabilityProject`, `probabilistic_library.project.UncertaintyProject` or
24
+ `probabilistic_library.project.SensitivityProject`.
25
+
26
+ Using an externally defined model as a python script, the Probabilistic Library derives input and output values. They will be
27
+ provided to the user as `probabilistic_library.statistic.Stochast`s, so that the user can provide uncertainty to them. Correlations
28
+ are provided via a `probabilistic_library.statistic.CorrelationMatrix`.
29
+
30
+ When running an analysis, the result is a `probabilistic_library.reliability.DesignPoint`, `probabilistic_library.uncertainty.UncertaintyResult`
31
+ or `probabilistic_library.sensitivity.SensitivityResult`.
32
+ """
33
+
34
+ __version__ = "26.1.1-rc5"
35
+
36
+ from .interface import *
37
+ from .logging import *
38
+ from .statistic import *
39
+ from .reliability import *
40
+ from .uncertainty import *
41
+ from .sensitivity import *
42
+ from .project import *
43
+
44
+
@@ -0,0 +1,24 @@
1
+ # Copyright (C) Stichting Deltares. All rights reserved.
2
+ #
3
+ # This file is part of the Probabilistic Library.
4
+ #
5
+ # The Probabilistic Library is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+ # All names, logos, and references to "Deltares" are registered trademarks of
19
+ # Stichting Deltares and remain full property of Stichting Deltares at all times.
20
+ # All rights reserved.
21
+ #
22
+
23
+ __version__ = "26.1.1-rc5"
24
+
@@ -0,0 +1,275 @@
1
+ # Copyright (C) Stichting Deltares. All rights reserved.
2
+ #
3
+ # This file is part of the Probabilistic Library.
4
+ #
5
+ # The Probabilistic Library is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+ # All names, logos, and references to "Deltares" are registered trademarks of
19
+ # Stichting Deltares and remain full property of Stichting Deltares at all times.
20
+ # All rights reserved.
21
+ #
22
+ from ast import Pass
23
+ import ctypes
24
+ import sys
25
+ import os
26
+ import time
27
+
28
+ from pathlib import Path
29
+ from ctypes import cdll
30
+
31
+ CALLBACK = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.POINTER(ctypes.c_double), ctypes.c_int, ctypes.POINTER(ctypes.c_double))
32
+ MULTIPLE_CALLBACK = ctypes.CFUNCTYPE(ctypes.c_void_p, ctypes.c_int, ctypes.POINTER(ctypes.POINTER(ctypes.c_double)), ctypes.c_int, ctypes.POINTER(ctypes.POINTER(ctypes.c_double)))
33
+ EMPTY_CALLBACK = ctypes.CFUNCTYPE(ctypes.c_void_p)
34
+
35
+ def _print_error(message):
36
+ print('error: ' + str(message), flush = True)
37
+
38
+ def LoadLibrary(lib_full_path):
39
+ global lib
40
+ lib = None
41
+ if os.path.isfile(lib_full_path):
42
+ try:
43
+ lib = cdll.LoadLibrary(lib_full_path)
44
+ except:
45
+ message = sys.exc_info()[0]
46
+ _print_error(message)
47
+ raise
48
+ if lib == None:
49
+ print("ERROR: Could not find " + lib_full_path)
50
+
51
+ def IsLibraryLoaded():
52
+ return 'lib' in globals() and not lib is None
53
+
54
+ def LoadDefaultLibrary():
55
+ dir_path = os.path.dirname(os.path.realpath(__file__))
56
+ if (sys.platform.startswith("linux")):
57
+ lib_file = 'libDeltares.Probabilistic.CWrapper.so'
58
+ else:
59
+ lib_file = 'Deltares.Probabilistic.CWrapper.dll'
60
+ lib_full_path = os.path.join(dir_path, 'bin', lib_file);
61
+ LoadLibrary(lib_full_path)
62
+
63
+ def AddLibrary(add_lib_full_path):
64
+ if not IsLibraryLoaded():
65
+ LoadDefaultLibrary()
66
+
67
+ if os.path.isfile(add_lib_full_path):
68
+ try:
69
+ lib.AddLibrary(bytes(add_lib_full_path, 'utf-8'))
70
+ except:
71
+ message = sys.exc_info()[0]
72
+ _print_error(message)
73
+ raise
74
+
75
+
76
+ def Create(object_type):
77
+ try:
78
+ object_type_b = bytes(object_type, 'utf-8')
79
+ lib.Create.restype = ctypes.c_int
80
+ return lib.Create(object_type_b)
81
+ except:
82
+ message = sys.exc_info()[0]
83
+ _print_error(message)
84
+ raise
85
+
86
+ def Destroy(id_):
87
+ lib.Destroy(ctypes.c_int(id_))
88
+
89
+ def Exit():
90
+ lib.Exit()
91
+
92
+ def GetValue(id_, property_):
93
+ lib.GetValue.restype = ctypes.c_double
94
+ return lib.GetValue(ctypes.c_int(id_), bytes(property_, 'utf-8'))
95
+
96
+ def SetValue(id_, property_, value_):
97
+ lib.SetValue(ctypes.c_int(id_), bytes(property_, 'utf-8'), ctypes.c_double(value_))
98
+
99
+ def GetIntValue(id_, property_):
100
+ lib.GetIntValue.restype = ctypes.c_int
101
+ return lib.GetIntValue(ctypes.c_int(id_), bytes(property_, 'utf-8'))
102
+
103
+ def SetIntValue(id_, property_, value_):
104
+ lib.SetIntValue(ctypes.c_int(id_), bytes(property_, 'utf-8'), ctypes.c_int(value_))
105
+
106
+ def GetIdValue(id_, property_):
107
+ lib.GetIdValue.restype = ctypes.c_int
108
+ return lib.GetIdValue(ctypes.c_int(id_), bytes(property_, 'utf-8'))
109
+
110
+ def GetIntArgValue(id_, arg_, property_):
111
+ lib.GetIntArgValue.restype = ctypes.c_double
112
+ return lib.GetIntArgValue(ctypes.c_int(id_), ctypes.c_int(arg_), bytes(property_, 'utf-8'))
113
+
114
+ def SetIntArgValue(id_, arg_, property_, value_):
115
+ lib.SetIntArgValue(ctypes.c_int(id_), ctypes.c_int(arg_), bytes(property_, 'utf-8'), ctypes.c_double(value_))
116
+
117
+ def GetBoolValue(id_, property_):
118
+ lib.GetBoolValue.restype = ctypes.c_bool
119
+ return lib.GetBoolValue(ctypes.c_int(id_), bytes(property_, 'utf-8'))
120
+
121
+ def SetBoolValue(id_, property_, value_):
122
+ lib.SetBoolValue(ctypes.c_int(id_), bytes(property_, 'utf-8'), ctypes.c_bool(value_))
123
+
124
+ def GetStringValue(id_, property_):
125
+
126
+ lib.GetStringLength.restype = ctypes.c_int
127
+ size = lib.GetStringLength(ctypes.c_int(id_), bytes(property_, 'utf-8'))
128
+
129
+ result = ctypes.create_string_buffer(size+1)
130
+ lib.GetStringValue.restype = ctypes.c_void_p
131
+ lib.GetStringValue(ctypes.c_int(id_), bytes(property_, 'utf-8'), result, ctypes.c_size_t(ctypes.sizeof(result)))
132
+ result_str = result.value.decode()
133
+ return result_str
134
+
135
+ def GetIndexedStringValue(id_, property_, index_):
136
+
137
+ lib.GetIndexedStringLength.restype = ctypes.c_int
138
+ size = lib.GetIndexedStringLength(ctypes.c_int(id_), bytes(property_, 'utf-8'), ctypes.c_int(index_))
139
+
140
+ result = ctypes.create_string_buffer(size+1)
141
+ lib.GetIndexedStringValue.restype = ctypes.c_void_p
142
+ lib.GetIndexedStringValue(ctypes.c_int(id_), bytes(property_, 'utf-8'), ctypes.c_int(index_), result, ctypes.c_size_t(ctypes.sizeof(result)))
143
+ result_str = result.value.decode()
144
+ return result_str
145
+
146
+ def SetStringValue(id_, property_, value_):
147
+ lib.SetStringValue(ctypes.c_int(id_), bytes(property_, 'utf-8'), bytes(value_, 'utf-8'))
148
+
149
+ def FillArrayValue(id_, property_, values_, size):
150
+ lib.FillArrayValue(ctypes.c_int(id_), bytes(property_, 'utf-8'), values_, ctypes.c_uint(size))
151
+
152
+ def SetArrayValue(id_, property_, values_):
153
+ cvalues = (ctypes.c_double * len(values_))(*values_)
154
+ lib.SetArrayValue(ctypes.c_int(id_), bytes(property_, 'utf-8'), ctypes.POINTER(ctypes.c_double)(cvalues), ctypes.c_uint(len(values_)))
155
+
156
+ def GetArgValues(id_, property_, values_, output_values_):
157
+ cvalues = (ctypes.c_double * len(values_))(*values_)
158
+ lib.GetArgValues.restype = ctypes.c_void_p
159
+ lib.GetArgValues(ctypes.c_int(id_), bytes(property_, 'utf-8'), ctypes.POINTER(ctypes.c_double)(cvalues), ctypes.c_uint(len(values_)), output_values_)
160
+
161
+ def GetArrayValue(id_, property_):
162
+
163
+ count_property = property_ + '_count'
164
+ count = GetIntValue(id_, count_property)
165
+
166
+ lib.GetIndexedValue.restype = ctypes.c_double
167
+
168
+ values = []
169
+ for i in range(count):
170
+ value = lib.GetIndexedValue(ctypes.c_int(id_), bytes(property_, 'utf-8'), ctypes.c_int(i))
171
+ values.append(value)
172
+
173
+ return values
174
+
175
+ def GetArrayIntValue(id_, property_):
176
+
177
+ count_property = property_ + '_count'
178
+ count = GetIntValue(id_, count_property)
179
+
180
+ lib.GetIndexedIntValue.restype = ctypes.c_int
181
+
182
+ values = []
183
+ for i in range(count):
184
+ value = lib.GetIndexedIntValue(ctypes.c_int(id_), bytes(property_, 'utf-8'), ctypes.c_int(i))
185
+ values.append(value)
186
+
187
+ return values
188
+
189
+ def GetArrayIdValue(id_, property_):
190
+
191
+ count_property = property_ + '_count'
192
+ count = GetIntValue(id_, count_property)
193
+
194
+ lib.GetIndexedIdValue.restype = ctypes.c_int
195
+
196
+ values = []
197
+ for i in range(count):
198
+ value = lib.GetIndexedIdValue(ctypes.c_int(id_), bytes(property_, 'utf-8'), ctypes.c_int(i))
199
+ values.append(value)
200
+
201
+ return values
202
+
203
+ def GetArrayStringValue(id_, property_):
204
+
205
+ count_property = property_ + '_count'
206
+ count = GetIntValue(id_, count_property)
207
+
208
+ values = []
209
+ for i in range(count):
210
+ value = GetIndexedStringValue(id_, property_, i)
211
+ values.append(value)
212
+
213
+ return values
214
+
215
+ def SetArrayIntValue(id_, property_, values_):
216
+ cvalues = (ctypes.c_int * len(values_))(*values_)
217
+ lib.SetArrayIntValue(ctypes.c_int(id_), bytes(property_, 'utf-8'), ctypes.POINTER(ctypes.c_int)(cvalues), ctypes.c_uint(len(values_)))
218
+
219
+ def GetArgValue(id_, property_, arg_):
220
+ lib.GetArgValue.restype = ctypes.c_double
221
+ return lib.GetArgValue(ctypes.c_int(id_), bytes(property_, 'utf-8'), ctypes.c_double(arg_))
222
+
223
+ def SetArgValue(id_, property_, arg_, value_):
224
+ lib.SetArgValue(ctypes.c_int(id_), bytes(property_, 'utf-8'), ctypes.c_double(arg_), ctypes.c_double(value_))
225
+
226
+ def GetIndexedValue(id_, property_, index_):
227
+ lib.GetIndexedValue.restype = ctypes.c_double
228
+ return lib.GetIndexedValue(ctypes.c_int(id_), bytes(property_, 'utf-8'), ctypes.c_int(index_))
229
+
230
+ def SetIndexedValue(id_, property_, index_, value_):
231
+ lib.SetIndexedValue(ctypes.c_int(id_), bytes(property_, 'utf-8'), ctypes.c_int(index_), ctypes.c_double(value_))
232
+
233
+ def GetIndexedIndexedValue(id_, property_, index1_, index2_):
234
+ lib.GetIndexedIndexedValue.restype = ctypes.c_double
235
+ return lib.GetIndexedIndexedValue(ctypes.c_int(id_), bytes(property_, 'utf-8'), ctypes.c_int(index1_), ctypes.c_int(index2_))
236
+
237
+ def SetIndexedIndexedValue(id_, property_, index1_, index2_, value_):
238
+ lib.SetIndexedIndexedValue(ctypes.c_int(id_), bytes(property_, 'utf-8'), ctypes.c_int(index1_), ctypes.c_int(index2_), ctypes.c_double(value_))
239
+
240
+ def SetIndexedIndexedIntValue(id_, property_, index1_, index2_, value_):
241
+ lib.SetIndexedIndexedIntValue(ctypes.c_int(id_), bytes(property_, 'utf-8'), ctypes.c_int(index1_), ctypes.c_int(index2_), ctypes.c_int(value_))
242
+
243
+ def SetCallBack(id_, property_, callBack_):
244
+ try:
245
+ lib.SetCallBack(ctypes.c_int(id_), bytes(property_, 'utf-8'), callBack_)
246
+ except:
247
+ message = sys.exc_info()[0]
248
+ _print_error(message)
249
+ raise
250
+
251
+ def SetMultipleCallBack(id_, property_, callBack_):
252
+ try:
253
+ lib.SetMultipleCallBack(ctypes.c_int(id_), bytes(property_, 'utf-8'), callBack_)
254
+ except:
255
+ message = sys.exc_info()[0]
256
+ print('error: ' + str(message), flush = True)
257
+ raise
258
+
259
+ def SetEmptyCallBack(id_, property_, callBack_):
260
+ try:
261
+ lib.SetEmptyCallBack(ctypes.c_int(id_), bytes(property_, 'utf-8'), callBack_)
262
+ except:
263
+ message = sys.exc_info()[0]
264
+ _print_error(message)
265
+ raise
266
+
267
+ def GetCallBack(id_, property_):
268
+ try:
269
+ return lib.GetCallBack(ctypes.c_int(id_), bytes(property_, 'utf-8'))
270
+ except:
271
+ message = sys.exc_info()[0]
272
+ _print_error(message)
273
+ raise
274
+ def Execute(id_, method_):
275
+ lib.Execute(ctypes.c_int(id_), bytes(method_, 'utf-8'))
@@ -0,0 +1,230 @@
1
+ # Copyright (C) Stichting Deltares. All rights reserved.
2
+ #
3
+ # This file is part of the Probabilistic Library.
4
+ #
5
+ # The Probabilistic Library is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU Lesser General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU Lesser General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU Lesser General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+ # All names, logos, and references to "Deltares" are registered trademarks of
19
+ # Stichting Deltares and remain full property of Stichting Deltares at all times.
20
+ # All rights reserved.
21
+ #
22
+ from __future__ import annotations
23
+ from math import isnan
24
+ from enum import Enum
25
+
26
+ from .utils import FrozenObject, FrozenList, PrintUtils
27
+ from . import interface
28
+
29
+ if not interface.IsLibraryLoaded():
30
+ interface.LoadDefaultLibrary()
31
+
32
+ class MessageType(Enum):
33
+ """Enumeration which defines the severity of a message."""
34
+ debug = 'debug'
35
+ info = 'info'
36
+ warning = 'warning'
37
+ error = 'error'
38
+ def __str__(self):
39
+ return str(self.value)
40
+
41
+ class Message(FrozenObject):
42
+ """Defines a message, which will be presented to the user.
43
+ A message may be the result of a validation request or an informative message of an algorithm"""
44
+
45
+ def __init__(self, id = None):
46
+ if id == None:
47
+ self._id = interface.Create('message')
48
+ else:
49
+ self._id = id
50
+ super()._freeze()
51
+
52
+ @classmethod
53
+ def from_message(cls, message_type, message_text):
54
+ message = cls()
55
+ interface.SetStringValue(message._id, 'type', str(message_type))
56
+ interface.SetStringValue(message._id, 'text', message_text)
57
+ return message
58
+
59
+ def __del__(self):
60
+ interface.Destroy(self._id)
61
+
62
+ def __str__(self):
63
+ if self.subject == "":
64
+ return str(self.type) + ': ' + self.text
65
+ else:
66
+ return str(self.type) + ': ' + self.subject + ' => ' + self.text
67
+
68
+ def __dir__(self):
69
+ return ['type',
70
+ 'subject',
71
+ 'text',
72
+ 'print']
73
+
74
+ @property
75
+ def type(self) -> MessageType:
76
+ """Gets the message type, which indicates the severity of the message"""
77
+ return MessageType[interface.GetStringValue(self._id, 'type')]
78
+
79
+ @property
80
+ def subject(self) -> str:
81
+ """Gets the subject, the object to which the message applies"""
82
+ return interface.GetStringValue(self._id, 'subject')
83
+
84
+ @property
85
+ def text(self) -> str:
86
+ """Gets the message text"""
87
+ return interface.GetStringValue(self._id, 'text')
88
+
89
+ def print(self):
90
+ """Prints the message"""
91
+ text = str(self)
92
+ if len(text) > 0:
93
+ text = text[0].capitalize() + text[1:]
94
+ print(text)
95
+
96
+ class ValidationReport(FrozenObject):
97
+ """Result of a validation analysis, consists of a number of validation messages"""
98
+
99
+ def __init__(self, id = None):
100
+ if id == None:
101
+ self._id = interface.Create('validation_report')
102
+ else:
103
+ self._id = id
104
+ self._messages = None
105
+ super()._freeze()
106
+
107
+ def __del__(self):
108
+ interface.Destroy(self._id)
109
+
110
+ def __dir__(self):
111
+ return ['is_valid',
112
+ 'messages',
113
+ 'print']
114
+
115
+ def is_valid(self) -> bool:
116
+ """Indicates whether this validation report should be interpreted as valid or non-valid"""
117
+ return interface.GetBoolValue(self._id, 'is_valid')
118
+
119
+ @property
120
+ def messages(self) -> FrozenList[Message]:
121
+ """List of all validation messages"""
122
+ if self._messages is None:
123
+ message_ids = interface.GetArrayIdValue(self._id, 'messages')
124
+ messages = []
125
+ for message_id in message_ids:
126
+ message = Message(message_id)
127
+ messages.append(message)
128
+ self._messages = FrozenList(messages)
129
+ return self._messages
130
+
131
+ def print(self):
132
+ """Prints all validation messages or an indication in case of no validation messages"""
133
+ if len(self.messages) == 0:
134
+ print('ok')
135
+ else:
136
+ for message in self.messages:
137
+ message.print()
138
+
139
+
140
+ class Evaluation(FrozenObject):
141
+ """Registers a sample and execution results of a model"""
142
+
143
+ def __init__(self, id = None):
144
+ if id == None:
145
+ self._id = interface.Create('evaluation')
146
+ else:
147
+ self._id = id
148
+ self._input_values = None
149
+ self._output_values = None
150
+ super()._freeze()
151
+
152
+ def __del__(self):
153
+ interface.Destroy(self._id)
154
+
155
+ def __dir__(self):
156
+ return ['iteration',
157
+ 'quantile',
158
+ 'z',
159
+ 'beta',
160
+ 'weight',
161
+ 'input_values',
162
+ 'output_values',
163
+ 'print']
164
+
165
+ @property
166
+ def iteration(self) -> int:
167
+ """Iteration index in a reliability, uncertainty or sensitivity algorithm"""
168
+ return interface.GetIntValue(self._id, 'iteration')
169
+
170
+ @property
171
+ def quantile(self) -> float:
172
+ """Quantile to which the sample belongs in an uncertainty algorithm"""
173
+ return interface.GetValue(self._id, 'quantile')
174
+
175
+ @property
176
+ def z(self) -> float:
177
+ """Z-value, indicating failure or non-failure, used by a reliability algorithm"""
178
+ return interface.GetValue(self._id, 'z')
179
+
180
+ @property
181
+ def beta(self) -> float:
182
+ """Distance of the sample to the origin in u-space"""
183
+ return interface.GetValue(self._id, 'beta')
184
+
185
+ @property
186
+ def weight(self) -> float:
187
+ """Weight of the sample in the reliability or uncertainty algorithm"""
188
+ return interface.GetValue(self._id, 'weight')
189
+
190
+ @property
191
+ def input_values(self) -> FrozenList[float]:
192
+ """List of input values for the model"""
193
+ if self._input_values is None:
194
+ input_values = interface.GetArrayValue(self._id, 'input_values')
195
+ self._input_values = FrozenList(input_values)
196
+ return self._input_values
197
+
198
+ @property
199
+ def output_values(self) -> FrozenList[float]:
200
+ """List of output values produced by the model"""
201
+ if self._output_values is None:
202
+ output_values = interface.GetArrayValue(self._id, 'output_values')
203
+ self._output_values = FrozenList(output_values)
204
+ return self._output_values
205
+
206
+ def print(self, decimals = 4):
207
+ """Prints the evaluation
208
+
209
+ Parameters
210
+ ----------
211
+ decimals : int, optional.
212
+ The number of decimals to print"""
213
+
214
+ self._print(0, decimals)
215
+
216
+ def _print(self, indent, decimals = 4):
217
+ pre = PrintUtils.get_space_from_indent(indent)
218
+ input_values = ', '.join([f'{v:.{decimals}g}' for v in self.input_values])
219
+ output_values = ', '.join([f'{v:.{decimals}g}' for v in self.output_values])
220
+ if not isnan(self.quantile):
221
+ pre = pre + f'quantile {self.quantile:.{decimals}g}: '
222
+ if isnan(self.z) and len(self.output_values) == 0:
223
+ print(pre + f'[{input_values}]')
224
+ elif isnan(self.z) and len(self.output_values) > 0:
225
+ print(pre + f'[{input_values}] -> [{output_values}]')
226
+ elif not isnan(self.z) and len(self.output_values) == 0:
227
+ print(pre + f'[{input_values}] -> {self.z:.{decimals}g}')
228
+ elif not isnan(self.z) and len(self.output_values) > 0:
229
+ print(pre + f'[{input_values}] -> [{output_values}] -> {self.z:.{decimals}g}')
230
+