openturns / otfmi Goto Github PK
View Code? Open in Web Editor NEWFMI models manipulation module
Home Page: http://openturns.github.io/otfmi/master/
License: GNU Lesser General Public License v3.0
FMI models manipulation module
Home Page: http://openturns.github.io/otfmi/master/
License: GNU Lesser General Public License v3.0
Hello,
The link to FMI standard (https://fmi-standard.org/docs/3.0-dev/#definition-of-model-variables) is broken in the main page of the web documentation.
The following script fails :
import openturns as ot
import otfmi
import os
# Define probabilistic model.
E = ot.Beta(0.93, 3.2, 2.8e7, 4.8e7)
Fparam = ot.LogNormalMuSigma(3.0e4, 9000.0, 15000.0)
F = ot.ParametrizedDistribution(Fparam)
L = ot.Uniform(250.0, 260.0)
I = ot.Beta(2.5, 4.0, 310.0, 450.0)
# Create the Spearman correlation matrix of the input random vector
RS = ot.CorrelationMatrix(4)
RS[2,3] = -0.2
# Evaluate the correlation matrix of the Normal copula from RS
R = ot.NormalCopula.GetCorrelationFromSpearmanCorrelation(RS)
# Create the Normal copula parametrized by R
mycopula = ot.NormalCopula(R)
# Create the input probability distribution of dimension 4
inputDistribution = ot.ComposedDistribution([E, F, L, I], mycopula)
# Give a description of each component of the input distribution
inputDistribution.setDescription( ("E", "F", "L", "I") )
# Create the input random vector
inputRandomVector = ot.RandomVector(inputDistribution)
# FMU model
path = os.path.dirname(os.path.abspath(__file__))
path_fmu = os.path.join(path,"deviationpoutre-win64.fmu")
model_fmu = otfmi.FMUFunction(path_fmu, inputs_fmu=["E", "F", "L", "I"], outputs_fmu="y")
# One single point
X = inputDistribution.getMean()
print(X)
Y = model_fmu(X)
print(Y)
# Simple Monte-Carlo sampling
size = 10
sampleX = inputRandomVector.getSample(size)
print(sampleX)
sampleY = model_fmu(sampleX)
print(sampleY)
with the deviation.fmu file at:
https://github.com/openturns/otfmi/blob/master/otfmi/example/file/fmu/win64/deviation.fmu
It produces the error message:
TypeError: InvalidArgumentException : Output value for OpenTURNSFMUFunction._exec_sample() method is not a 2d-sequence object
This is because the actual output of pool.run is:
([array([15.76007131])], [array([12.98466089])], [array([18.23594914])], [array([7.42586189])], [array([12.31297981])], [array([13.38886067])], [array([24.85640079])], [array([12.18491227])], [array([9.01482853])], [array([13.38254173])])
This is a tuple, where each item is a list with one single item. Each single item is an array.
The bug is at:
Line 253 in 0b843e3
Obviously, the content of pool.run cannot be returned without post-processing.
The fixed code reads:
output = pool.run(list_kwargs, final=self.__final)
dataOutput = [x[0] for x in output]
return dataOutput
This makes the script work on my case, but I do not know if if works in general, e.g. when the output is multidimensional.
otfmi.fmi.get_name_variable
takes as argument a model which is either a Pyfmi object or a string.
A newcomer to OTFMI may write the following code (as it makes sense):
model = otfmi.FMUFunction(path_fmu, ...)
list_name = otfmi.fmi.get_name_variable(model)
The following error message appears (as model is an overlay of a FMUFunction, not a Pyfmi object):
Traceback (most recent call last):
File "/home/gerrer/Desktop/test_otfmi/pi_fail.py", line 15, in <module>
otfmi.fmi.get_name_variable(func)
File "/home/gerrer/anaconda3/envs/fmidsk/lib/python3.9/site-packages/otfmi/fmi.py", line 331, in get_name_variable
model = load_fmu(model)
File "/home/gerrer/anaconda3/envs/fmidsk/lib/python3.9/site-packages/otfmi/fmi.py", line 36, in load_fmu
return pyfmi.load_fmu(path_fmu, kind="CS", log_file_name=log_file_name)
File "src/pyfmi/fmi.pyx", line 8588, in pyfmi.fmi.load_fmu
File "/home/gerrer/anaconda3/envs/fmidsk/lib/python3.9/posixpath.py", line 90, in join
genericpath._check_arg_types('join', a, *p)
File "/home/gerrer/anaconda3/envs/fmidsk/lib/python3.9/genericpath.py", line 152, in _check_arg_types
raise TypeError(f'{funcname}() argument must be str, bytes, or '
TypeError: join() argument must be str, bytes, or os.PathLike object, not 'Function'
In otfmi/fmi.py, lines 465 : replace the type test performed by "try - except" with condition on the accessibility of a method by a real type test (is instance of pyfmi object or string) and clear error message if this is not the case.
see https://github.com/modelica/fmi-standard.org/blob/main/CONTRIBUTING.md#updating-the-tools-list
For the examplesURL you are encouraged to provide a link to a webpage or repo where you document how you tested your tool w.r.t to FMI support. So you could list that you tested the import with the reference FMUs. See e.g. https://github.com/altairengineering/fmus for an example
Thanks in advance!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.