File: t_YACSPhysicalModel_std.py

package info (click to toggle)
persalys 13.1.1%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 71,916 kB
  • sloc: xml: 496,859; cpp: 53,848; python: 3,435; sh: 332; makefile: 131; ansic: 14
file content (42 lines) | stat: -rwxr-xr-x 982 bytes parent folder | download
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
#! /usr/bin/env python

import openturns as ot
import openturns.testing as ott
import persalys


pyscript = "def _exec(x, y, p):\n    w, z = 3*x+4*y+p,x+y+p\n    return w, z\n"

model = persalys.YACSPhysicalModel("myPhysicalModel", [], [], pyscript)

X = [[1, 2, 4], [2, 3, 5], [6, 1, 3]]

Y_ref = [[15, 7], [23, 10], [25, 10]]

# full eval
f = model.getFunction()
Y = f(X)
print(Y)
ott.assert_almost_equal(Y, Y_ref)

# partial eval
f = model.getFunction(["w"])
Y = f(X)
print(Y)
ott.assert_almost_equal(Y, ot.Sample(Y_ref).getMarginal(0))

# script
myStudy = persalys.Study("myStudy")
myStudy.add(model)
script = myStudy.getPythonScript()
# print('script=', script)
exec(script)

# test for output variables order
pyscript = "def _exec(inp1):\n    aaa,bbb,ddd,ccc = 1.,2.,3.,inp1\n    return aaa,bbb,ddd,ccc\n"
model = persalys.YACSPhysicalModel("order", [], [], pyscript)
x = [8.0]
y_ref = [1.0, 2.0, 3.0, 8.0]
f = model.getFunction()
y = f(x)
# ott.assert_almost_equal(y, y_ref)