OMSimulator icon indicating copy to clipboard operation
OMSimulator copied to clipboard

importSnapshot in Python bindings not implemented

Open sturmk opened this issue 1 year ago • 7 comments

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.

sturmk avatar Feb 28 '23 14:02 sturmk

@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

arun3688 avatar Feb 28 '23 15:02 arun3688

@arun3688

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

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

sturmk avatar Feb 28 '23 15:02 sturmk

@sturmk can you post your ful python script

arun3688 avatar Feb 28 '23 15:02 arun3688

@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.

sturmk avatar Feb 28 '23 15:02 sturmk

@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

arun3688 avatar Feb 28 '23 15:02 arun3688

@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.

sturmk avatar Feb 28 '23 16:02 sturmk

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

arun3688 avatar Feb 28 '23 19:02 arun3688