OpenModelica / OMSimulator

The OpenModelica FMI & SSP-based co-simulation environment.
Other
71 stars 50 forks source link

importSnapshot in Python bindings not implemented #1209

Open sturmk opened 1 year ago

sturmk commented 1 year ago

Description

Despite being contained in the documentation, "oms.importSnapshot" is not available in the Python bindings for OMSimulator.

Steps to reproduce the behavior

#!/usr/bin/env python3
import OMSimulator as oms
[...]
status = oms.importSnapshot('root', snapshot)

AttributeError: module 'OMSimulator' has no attribute 'importSnapshot'

Expected behavior

A call to the underlying C-function which executes importSnapshot should happen.

arun3688 commented 1 year ago

@sturmk The API is indeed available, You are using older version of OMSimulator, please update OMSimulator package if you are using pip otherwise update from github master, see the example in the testsuite https://github.com/OpenModelica/OMSimulator/blob/master/testsuite/simulation/snapshot.py

sturmk commented 1 year ago

@arun3688

#!/usr/bin/env python3
import OMSimulator as oms
oms.version

'OMSimulator v2.1.1.post190-gcfb740c-linux'

arun3688 commented 1 year ago

@sturmk can you post your ful python script

sturmk commented 1 year ago

@arun3688 it's not about the script. even typing oms.imp in an interactive python session and using TAB-completion only yields oms.importFile(. Looking into the source, neither NewAPI.py, nor OMSimulator.py contain a definition for importSnapshot.

arun3688 commented 1 year ago

@sturmk with the new API format i think you need to create the model or system instances and use the API, see the example here https://github.com/OpenModelica/OMSimulator/blob/master/testsuite/simulation/equationPair.py, But could you adapt your example with the old style and see it works example snapshot.py

sturmk commented 1 year ago

@arun3688 That's why I created this issue. I use it exactly like the example you mention. The Python3 interpreter is not aware of any existence of "importSnapshot" because it is not defined in OMSimulator.py nor NewAPI.py. I'm not the most advanced Python scripter, but I'll try to fix it and send a PR when done.

arun3688 commented 1 year ago

@sturmk The API is already available otherwise our testsuite will not work, The API is added in the file capi.py in OMSimulatorPython folder