FMPy icon indicating copy to clipboard operation
FMPy copied to clipboard

Failed to instantiate FMU 3.0 version in tests/test_fmu_container.py

Open Kalash-byte opened this issue 1 year ago • 3 comments

If i try to run the default feedthrough.fmu file using create_fmu_container it is throwing an error with version FMI 3.0 even if i use my own fmu file 3.0 same error is being thrown. But for 2.0 it is working properly.

Kalash-byte avatar Jul 30 '24 05:07 Kalash-byte

Can you provide steps to reproduce the problem?

t-sommer avatar Jul 30 '24 07:07 t-sommer

import pytest from itertools import product from fmpy import simulate_fmu, plot_result,dump from fmpy.fmucontainer import create_fmu_container, Variable, Connection, Configuration, Component, DefaultExperiment from fmpy.util import compile_platform_binary from fmpy.validation import validate_fmu from fmpy.model_description import Unit, BaseUnit, SimpleType, DisplayUnit, Item

dump('Feedthrough.fmu')

@pytest.mark.parametrize('fmi_version, parallelDoStep', product([2, 3], [False, True])) def test_create_fmu_container(fmi_version, parallelDoStep):

if fmi_version == 2:
    real_type = 'Real'
    integer_type = 'Integer'
else:
    real_type = 'Float64'
    integer_type = 'Int32'

configuration = Configuration(
    fmiVersion=f'{fmi_version}.0',
    parallelDoStep=parallelDoStep,
    unitDefinitions=[
        Unit(name="rad/s", baseUnit=BaseUnit(rad=1, s=-1), displayUnits=[DisplayUnit(name='rpm', factor=9.549296585513721)]),
    ],
    typeDefinitions=[
        SimpleType(name='AngularVelocity', type=real_type, quantity='AngularVelocity', unit='rad/s',
                   displayUnit='rpm'),
        SimpleType(name='Option', type='Enumeration', items=[
            Item(name='Option 1', value=1, description="First option"),
            Item(name='Option 2', value=2, description="Second option")
        ])
    ],
    defaultExperiment=DefaultExperiment(
        startTime='0',
        stopTime='10',
        tolerance='1e-5',
        stepSize='1e-7'
    ),
    variables=[
        Variable(
            type=real_type,
            variability='continuous',
            causality='input',
            name='Float64_continuous_input',
            start='1.1',
            declaredType='AngularVelocity',
            mapping=[('instance1', 'Float64_continuous_input')]
        ),
        Variable(
            type=integer_type,
            variability='discrete',
            causality='input',
            name='Int32_input',
            start='2',
            mapping=[('instance1', 'Int32_input')]
        ),
        Variable(
            type='Boolean',
            variability='discrete',
            causality='input',
            name='Boolean_input',
            start='true',
            mapping=[('instance1', 'Boolean_input')]
        ),
        Variable(
            type='Enumeration',
            variability='discrete',
            causality='input',
            name='Enumeration_input',
            declaredType='Option',
            start='1',
            mapping=[('instance1', 'Enumeration_input')]
        ),
        Variable(
            type=real_type,
            initial='calculated',
            variability='continuous',
            causality='output',
            name='Float64_continuous_output',
            unit='rad/s',
            displayUnit='rpm',
            mapping=[('instance2', 'Float64_continuous_output')]
        ),
        Variable(
            type=integer_type,
            variability='discrete',
            causality='output',
            name='Int32_output',
            mapping=[('instance2', 'Int32_output')]
        ),
        Variable(
            type='Boolean',
            variability='discrete',
            causality='output',
            name='Boolean_output',
            mapping=[('instance2', 'Boolean_output')]
        ),
        Variable(
            type='Enumeration',
            variability='discrete',
            causality='output',
            declaredType='Option',
            name='Enumeration_output',
            mapping=[('instance2', 'Enumeration_output')]
        )
    ],
    components=[
        Component(
            filename='myenv\\fmu_references_2.0\\Feedthrough.fmu',
            name='instance1'
        ),
        Component(
            filename='myenv\\fmu_references_2.0\\Feedthrough.fmu',
            name='instance2'
        ),
    ],
    connections=[
        Connection('instance1', 'Float64_continuous_output', 'instance2', 'Float64_continuous_input'),
        Connection('instance1', 'Int32_output', 'instance2', 'Int32_input'),
        Connection('instance1', 'Boolean_output', 'instance2', 'Boolean_input'),
        Connection('instance1', 'Enumeration_output', 'instance2', 'Enumeration_input'),
        
    ]
)

if parallelDoStep:
    filename = f'FeedthroughParallel{fmi_version}.fmu'
else:
    filename = f'FeedthroughSynchronous{fmi_version}.fmu'

create_fmu_container(configuration, filename)
# dump(filename)
problems = validate_fmu(filename)

assert not problems

# test default start values

default_start_values = {
    'Float64_continuous_input': 1.1,
    'Boolean_input': True,
    'Int32_input': 2,
}

result = simulate_fmu(filename, output=default_start_values.keys(),
                      # debug_logging=True,
                      fmi_call_logger=print,
                      stop_time=1, output_interval=1)
plot_result(result)

test_create_fmu_container(2,True) This code is working fine but as soon i plug in 3.0 version fmu it doesn't work

ghost avatar Jul 30 '24 09:07 ghost

The FMU Container does currently not support nested FMI 3.0 FMUs. I will tag this as an enhancement request.

t-sommer avatar Aug 02 '24 08:08 t-sommer

Closing in favor of #715.

t-sommer avatar Nov 21 '24 09:11 t-sommer