Simple swap between ssv files
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).
maybe currently supported, maybe will be supported with new API, to be checked @arun3688
already supported, @arun3688 will provide the correct syntax and test the use-case
@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
@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()
@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 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")
@larsviktorlarsson can you test this functionality so that the issue can be closed?
@larsviktorlarsson ping
@arun3688 Thank you for the input, I have installed OMS 3.0 and will try this as soon as possible.
@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 right now it is not possible, i will discuss with lennart and see if we can add the support in the instantiated model
@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 Ok I understand, makes sense. Thanks for looking into it