File: t_features.py

package info (click to toggle)
openturns 1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 38,588 kB
  • ctags: 26,495
  • sloc: cpp: 144,032; python: 26,855; ansic: 7,868; sh: 419; makefile: 263; yacc: 123; lex: 44
file content (93 lines) | stat: -rwxr-xr-x 2,344 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
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
#! /usr/bin/env python

from __future__ import print_function
import os

width = 40

# check that python can load OpenTURNS module
print('1: Python module load'.ljust(width), end=' ')
try:
    import openturns as ot
    print('OK')
except:
    print('no')

# check that python can find the Viewer module
# If it fails, check that matplotlib package is installed
print('2: Viewer (matplotlib)'.ljust(width), end=' ')
try:
    import openturns.viewer
    print('OK')
except:
    print('no')

# check that OpenTURNS can run R
# It should produce a file named testDraw.png
print('3: drawing (R)'.ljust(width), end=' ')
try:
    graph = ot.Normal().drawPDF()
    fname = 'testDraw.png'
    try:
        graph.draw(fname)
        os.remove(fname)
    except:
        raise
    print('OK')
except:
    print('no')

# check that rot package is installed
print('4: linear model (R.rot)'.ljust(width), end=' ')
try:
    lm = ot.LinearModelFactory().build(
        ot.Normal(2).getSample(10), ot.Normal().getSample(10))
    print('OK')
except:
    print('no')

# check XML support
print('5: serialization (LibXML2)'.ljust(width), end=' ')
try:
    storageManager = ot.XMLStorageManager('myFile.xml')
    print('OK')
except:
    print('no')

# check that analytical function are available
print('6: analytical function (muParser)'.ljust(width), end=' ')
try:
    f = ot.NumericalMathFunction(['x1', 'x2'], ['y'], ['x1+x2'])
    print('OK')
except:
    print('no')

# check that hmat library was found
print('7: HMatrix (hmat-oss)'.ljust(width), end=' ')
try:
    # This is a little bit tricky because HMat 1.0 fails with 1x1 matrices
    ot.ResourceMap.SetAsUnsignedInteger(
        'TemporalNormalProcess-SamplingMethod', 1)
    vertices = [[0.0, 0.0, 0.0]]
    vertices.append([1.0, 0.0, 0.0])
    vertices.append([0.0, 1.0, 0.0])
    vertices.append([0.0, 0.0, 1.0])
    simplices = [[0, 1, 2, 3]]
    # Discard messages from HMat
    ot.Log.Show(0)
    process = ot.TemporalNormalProcess(
        ot.ExponentialModel(3), ot.Mesh(vertices, simplices))
    f = process.getRealization()
    print('OK')
except:
    print('no')

# check that nlopt library was found
print('8: optimization (NLopt)'.ljust(width), end=' ')
try:
    problem = ot.OptimizationProblem()
    algo = ot.SLSQP()
    algo.setProblem(problem)
    print('OK')
except:
    print('no')