Skip to content

Conversation

@syntron
Copy link
Contributor

@syntron syntron commented Jun 25, 2025

[ModelicaSystem] split simulate() into two methods

(1) create ModelicasystemCmd instance - simulate_cmd()
(2) run it - simulate()

reason:

  • use the instances of ModelicaSystemCmd to run the executeable with different settings as often as needed

@syntron syntron force-pushed the ModelicaSystem_simulate branch from b57bd0c to 3ee7f7d Compare June 28, 2025 19:26
Copy link
Member

@adeas31 adeas31 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't understand what this change is doing. Maybe you can add a simple usage as test.

@syntron
Copy link
Contributor Author

syntron commented Jul 1, 2025

@adeas31 splitting simulate into two parts allows to define the command to run the executable without running it. Thus, several runs can be defined and later be executed using the same executable. See PR #312; it also contains an example as unittest where this is used.

The example runs a DoE including structural and non-structural parameters. While any combination of non-structural parameters can be run using the same executable, any change of a structural parameter needs a rebuild of the executable. The new class - ModelicaSystemDoE - prepares all runs of the DoE (builing the model executable if needed) and then executes them in parallel.

This also relates to issue #230

@syntron syntron force-pushed the ModelicaSystem_simulate branch from 3ee7f7d to b57c7e3 Compare July 2, 2025 19:59
syntron added 2 commits July 7, 2025 19:13
(1) create ModelicasystemCmd instance - simulate_cmd()
(2) run it - simulate()
@syntron syntron force-pushed the ModelicaSystem_simulate branch from b57c7e3 to f108094 Compare July 7, 2025 17:15
@adeas31
Copy link
Member

adeas31 commented Jul 8, 2025

Still confused. I see that simulate sets _result_file which will not be set if I just use simulate_cmd. For example,

mod = OMPython.ModelicaSystem(....)
mod_sim_cmd = mod.simulate_cmd(....)
mod_sim_cmd.run()
mod_sim_cmd.args_set(.....)
mod_sim_cmd.run()

The above pseudo code will not set _result_file of ModelicaSystem class, right? Am I missing something?

@syntron
Copy link
Contributor Author

syntron commented Jul 8, 2025

@adeas31 your analyses is completly correct!

simulate_cmd() is within this PR only the preparation; the functionality of simulate() is splitted into two parts:

(1) prepare all such that a simulation can be run => simulate_cmd() which gets the result file as argument (required!)
(2) run the simulation within ModelicaSystem => simulate() using simulate_cmd()

In the current state, nothing changes; however, if you would like to run a bigger DoE, this allows to define one model within ModelicaSystem (define & build the executable) and then use simulate_cmd() to create serveral instances (containers) which allow to run a simulation using the executable with different settings (changing non-structural parameters).

The result file is not fixed within simulate_cmd() but provided as parameters such that it is possible to define a bunch of simulations in a first step and then run these in a loop / in several threads. This is shown by ModelicaSystemDoE (see PR #312 and especially the defined test). Here, the filenames of the results are also tracked such that all result data can later be read using getSolution() as it allows to provide a result filename.

Additional to the result file, it must also be ensured that the csv file used as input for the executable does not use the same filename. This is done by PR #313 - here, the csv filename can also be provided. Within ModelicaSystemDoE, it is defined based on the used name for the result file.

Regarding the pyseudo code, you have to define the result file to use:

mod = OMPython.ModelicaSystem(....)

# run 1
mod_sim_cmd = mod.simulate_cmd(result_file=result_file1, ....)
mod_sim_cmd.args_set(.....)
mod_sim_cmd.run()

# run 2
mod_sim_cmd = mod.simulate_cmd(result_file=result_file2, ....)
mod_sim_cmd.args_set(.....)
mod_sim_cmd.run()

@adeas31 adeas31 enabled auto-merge (squash) July 9, 2025 08:52
@adeas31 adeas31 merged commit 797eb84 into OpenModelica:master Jul 9, 2025
5 checks passed
@syntron syntron deleted the ModelicaSystem_simulate branch July 9, 2025 18:32
@syntron syntron mentioned this pull request Sep 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants