Code Monkey home page Code Monkey logo

otfmi's Issues

A otfmi function cannot evaluate a sample

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:

return self.simulate_sample(list_value_input, n_cpus=n_cpus, **kwargs)

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.

Get listed on the FMI tools page https://fmi-standard.org/tools/ and provide compatibility information

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!

Confusing error message

Issue description

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'

Potential solution

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.