OMSimulator icon indicating copy to clipboard operation
OMSimulator copied to clipboard

Simple swap between ssv files

Open larsviktorlarsson opened this issue 11 months ago • 7 comments

I have an ssp with an ssd with links to ssv files in resources folder inside the ssp. If I want to swap one of the ssv:s to another one that is included in the ssp. For instance a command:

oms.swapResource("resources/ManoverOS_variant_0.ssv","resources/ManoverOS_variant_1.ssv") to swap from ManoverOS_variant_0.ssv to ManoverOS_variant_1.ssv in the currently active .ssd.

I have tried the addResource and deleteResource functions, but they seem to assume the new ssv file is provided outside the ssp.

The ssp as zip file: test_cases.zip

Note: The ssd "ManoverOS_tcv_1.ssd" is the same as "SystemStructure.ssd", but with swapped ssv references (made before packing the ssp, which is how I currently handle this problem).

larsviktorlarsson avatar Feb 11 '25 08:02 larsviktorlarsson

maybe currently supported, maybe will be supported with new API, to be checked @arun3688

lenaRB avatar Mar 03 '25 13:03 lenaRB

already supported, @arun3688 will provide the correct syntax and test the use-case

lenaRB avatar Apr 14 '25 12:04 lenaRB

@larsviktorlarsson The api to swap the ssv resources should be like this

oms_importFile("path to your.ssp");
-- delete only the references
oms_deleteResources("ManoverOS.ManoverOS:ManoverOS_variant_0.ssv")
-- switch with new references
oms_referenceResources("ManoverOS.ManoverOS:ManoverOS_variant_1.ssv")

There are some examples in the testsuite on how to swith references of ssv files, see below

https://github.com/OpenModelica/OMSimulator/blob/maintenance/v2.1/testsuite/simulation/referenceResources1.lua https://github.com/OpenModelica/OMSimulator/blob/maintenance/v2.1/testsuite/simulation/referenceResources2.lua

arun3688 avatar May 09 '25 14:05 arun3688

@larsviktorlarsson this functionality is now available in our new API in python in more simpler way, the use case on your example would be

from OMSimulator import SSP, CRef, Settings, SSV
model = SSP('path to your SSP')
model.swapSSVReference(CRef('ManoverOS'), 'resources/ManoverOS_variant_0.ssv"', 'resources/ManoverOS_variant_1.ssv')
model.list()

arun3688 avatar May 15 '25 07:05 arun3688

@larsviktorlarsson this functionality is now available in our new API in python in more simpler way, the use case on your example would be

from OMSimulator import SSP, CRef, Settings, SSV
model = SSP('path to your SSP')
model.swapSSVReference(CRef('ManoverOS'), 'resources/ManoverOS_variant_0.ssv"', 'resources/ManoverOS_variant_1.ssv')
model.list()

@arun3688 @lenaRB This looks like it will do exactly what I am looking for. Is this functionality available in the latest version available on pip?

larsviktorlarsson avatar May 30 '25 08:05 larsviktorlarsson

@larsviktorlarsson It is not available in the latest pip version, But this functionality is avaiable in the master, But in the current version of the pip you have to use the API in the following way

from OMSimulator import OMSimulator
oms = OMSimulator()
oms.importFile("path to your.ssp");
-- delete only the references
oms.deleteResources("ManoverOS.ManoverOS:ManoverOS_variant_0.ssv")
-- switch with new references
oms.referenceResources("ManoverOS.ManoverOS:ManoverOS_variant_1.ssv")

arun3688 avatar May 30 '25 12:05 arun3688

@larsviktorlarsson can you test this functionality so that the issue can be closed?

robha67 avatar Nov 26 '25 13:11 robha67

@larsviktorlarsson ping

robha67 avatar Jan 07 '26 13:01 robha67

@arun3688 Thank you for the input, I have installed OMS 3.0 and will try this as soon as possible.

larsviktorlarsson avatar Jan 08 '26 08:01 larsviktorlarsson

@arun3688 I have now tested and it works as expected! One question, would it not be possible to swap ssv file reference after instantiation? e.g: model = SSP('path to your SSP') instantiated_model = model.instantiate() instantiated_model.swapSSVReference(CRef('ManoverOS'), 'resources/ManoverOS_variant_0.ssv"', 'resources/ManoverOS_variant_1.ssv')

In our test framework, the instantiation is a bottleneck for overall execution times when looping simulations, so it would help a lot if the model was only instantiated once instead of 4 times (if we have 4 different parameter sets to loop through).

larsviktorlarsson avatar Jan 09 '26 13:01 larsviktorlarsson

@larsviktorlarsson right now it is not possible, i will discuss with lennart and see if we can add the support in the instantiated model

arun3688 avatar Jan 09 '26 15:01 arun3688

@larsviktorlarsson I discussed the possiblity of allowing of swapping of ssv file after instantiation with @lochel and we decided not to do that, as we see some complication it will create in our design and we will skip it as of now

arun3688 avatar Jan 13 '26 13:01 arun3688

@arun3688 Ok I understand, makes sense. Thanks for looking into it

larsviktorlarsson avatar Jan 13 '26 13:01 larsviktorlarsson