Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ghost opened this issue Jul 30, 2024 · 4 comments
Closed

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

ghost opened this issue Jul 30, 2024 · 4 comments

Comments

@ghost
Copy link

ghost commented Jul 30, 2024

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.

@t-sommer
Copy link
Contributor

Can you provide steps to reproduce the problem?

@ghost
Copy link
Author

ghost commented Jul 30, 2024

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

@t-sommer
Copy link
Contributor

t-sommer commented Aug 2, 2024

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

@t-sommer
Copy link
Contributor

Closing in favor of #715.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant