Setting simulation parameters with python leads to invalid model

thg
thg Altair Community Member
edited October 4 in Community Q&A

Hello,

I am currently trying to automate the creation of MBS models with the MotionView Python Interface.
Everything works quite good so far and I am able to define even complex models with just a python script.

However, once I try to set or access any parameter from the Model.simPara class, the model is not valid anymore and when trying to export the solver file I get the following error:

Syntax error...Math parser error evaluating run_name-value under Model-MotionSolve Simulation Options. [General]

This message appears regardless of the model and value I access or set.
Further, when setting the value it appears to set the value but also messes up some other parameter, that cannot be parsed later.. 

To be more precise:

  • I open a model that has not been modified and it runs
  • I execute on of the following commands and I get the error shown above
    # this actually sets the value to 10 and leads to the error >>> model.simPara.end_time = 10 >>> model.simPara.end_time  10.0 >>> model.simPara.setValue("end_time", 5) >>> model.simPara.end_time  5.0  # accessing the parameter also leads to the error >>> model.simPara.h0_max 1e-08 >>> model.simPara.getValue("h0_max") 1e-08 

Even executing the last command leads to an asterisk appearing behind the model in the project browser, which means there are unsaved changes.

The documentation gives an example how to set the parameters but that does not work.
https://2023.help.altair.com/2023/hwdesktop/hwx/topics/reference/mv/simulationparameters_python_class_simulationparameters_r.htm

Is there any other method for setting the simulation parameters with the python script?

Thanks you!

Best Regards
Tobias

Answers

  • GTT Adam
    GTT Adam
    Altair Employee
    edited September 30

    Hi Tobias,

    When you execute the changes to the end time in the Python Window, does the error appear?

    I checked in version 2024 (so far) and the following 2 lines execute as intended:

    mod = mview.getModel() 
    mod.simPara.end_time = 10

    image

    It is possible that the 2023 help you are referencing conflicts with the 2022.3 version you are currently using. There may be syntax changes between the two, so I would recommend updating to the most recent release and trying again.

     

    Hope this helps!

    Adam Reid

  • thg
    thg Altair Community Member
    edited September 30

    Hi Tobias,

    When you execute the changes to the end time in the Python Window, does the error appear?

    I checked in version 2024 (so far) and the following 2 lines execute as intended:

    mod = mview.getModel() 
    mod.simPara.end_time = 10

    image

    It is possible that the 2023 help you are referencing conflicts with the 2022.3 version you are currently using. There may be syntax changes between the two, so I would recommend updating to the most recent release and trying again.

     

    Hope this helps!

    Adam Reid

    Dear Adam Reid,

    thank you very much for your answer.

    If I check the model before executing mod.simPara.end_time everything seems to be okay according to the message log. After executing, the end_time is set properly but I get an error in the model check. See the following screenshots.

    Before executing:
    image

    After Executing (note the message log):
    image

    I experienced this behaviour in the 2022.3, 2023 and the latest 2024.1 release.

    I did some further investigations this morning and it seems that the problematic parameter is mod.simPara.run_name
    This parameter does really not seem to exist when accessing the mod.simPara for the first time. However, I can set it to 1 and then the model check does not show errors anymore. See the python window below:
    image

    This is a very dirty workaround since now each file of the run is named "1".
    When trying to set the mod.simPara.run_name as a string, the error in the model check appears again.

    I attached the python file of a simple bouncing ball model. Maybe you can have a look if you get the same error.

    Thank you!

    Best Regards
    Tobias

  • GTT Adam
    GTT Adam
    Altair Employee
    edited October 1
    thg said:

    Dear Adam Reid,

    thank you very much for your answer.

    If I check the model before executing mod.simPara.end_time everything seems to be okay according to the message log. After executing, the end_time is set properly but I get an error in the model check. See the following screenshots.

    Before executing:
    image

    After Executing (note the message log):
    image

    I experienced this behaviour in the 2022.3, 2023 and the latest 2024.1 release.

    I did some further investigations this morning and it seems that the problematic parameter is mod.simPara.run_name
    This parameter does really not seem to exist when accessing the mod.simPara for the first time. However, I can set it to 1 and then the model check does not show errors anymore. See the python window below:
    image

    This is a very dirty workaround since now each file of the run is named "1".
    When trying to set the mod.simPara.run_name as a string, the error in the model check appears again.

    I attached the python file of a simple bouncing ball model. Maybe you can have a look if you get the same error.

    Thank you!

    Best Regards
    Tobias

    Hi Tobias,

    Oddly enough, the Sedan_1.MDL example model from the Vehicle Tools Extension I used to test this syntax out does not produce the same error. Can you please test a different model to see if this is isolated to your model only?

     

    Hope this helps!

    Adam Reid

  • thg
    thg Altair Community Member
    edited October 2

    Hi Tobias,

    Oddly enough, the Sedan_1.MDL example model from the Vehicle Tools Extension I used to test this syntax out does not produce the same error. Can you please test a different model to see if this is isolated to your model only?

     

    Hope this helps!

    Adam Reid

    Dear Adam Reid,

    thanks for checking!

    I tried several models (that I created from scratch) and they all suffer from the same behaviour.

    There is another thing I found out in that regard. I created the model from the python script provided earlier and saved some versions of it:

    1. before executing any simPara command: bounce_before.mdl
      • the file does not show any parameters regarding the analysis
      • the Model Check is OK and the simulation runs
    2. before executing any simPara command but setting the end time manually via the entity editor: bounce_before_gui.mdl
      • the file only includes the changed parameter
      • Model Check is OK and simulation runs
    3. after executing any simPara assignment or method: bounce_after.mdl
      • the file contains a lot of lines with all simulation parameters, one of which is  
        *SetString( DS_MotionSolve_Simopts.run_name,       Error Evaluating )
      • Model Check gives the error shown above
    4. after manually replacing Error Evaluating with the "bounce" in the mdl-file: bounce_after_mod.mdl
      • after opening that file: Model Check is OK and the simulation runs

    It feels that there is something strange going on with the Python Interface since the simPara commands do not really reflect the behaviour of the gui command.
    It also seems that the run_name parameter is interpreted as a math expression. That may be why it is not possible to provide a string with the Python Interface.

    I hope this helps tracking down the error.

    Best Regards and many thanks for your attention to that matter!
    Tobias

  • GTT Adam
    GTT Adam
    Altair Employee
    edited October 4
    thg said:

    Dear Adam Reid,

    thanks for checking!

    I tried several models (that I created from scratch) and they all suffer from the same behaviour.

    There is another thing I found out in that regard. I created the model from the python script provided earlier and saved some versions of it:

    1. before executing any simPara command: bounce_before.mdl
      • the file does not show any parameters regarding the analysis
      • the Model Check is OK and the simulation runs
    2. before executing any simPara command but setting the end time manually via the entity editor: bounce_before_gui.mdl
      • the file only includes the changed parameter
      • Model Check is OK and simulation runs
    3. after executing any simPara assignment or method: bounce_after.mdl
      • the file contains a lot of lines with all simulation parameters, one of which is  
        *SetString( DS_MotionSolve_Simopts.run_name,       Error Evaluating )
      • Model Check gives the error shown above
    4. after manually replacing Error Evaluating with the "bounce" in the mdl-file: bounce_after_mod.mdl
      • after opening that file: Model Check is OK and the simulation runs

    It feels that there is something strange going on with the Python Interface since the simPara commands do not really reflect the behaviour of the gui command.
    It also seems that the run_name parameter is interpreted as a math expression. That may be why it is not possible to provide a string with the Python Interface.

    I hope this helps tracking down the error.

    Best Regards and many thanks for your attention to that matter!
    Tobias

    Hi Tobias,

    You are correct: the Run name error does exist after setting the parameter. Modifications only appear to work if doubles are used and not strings. I will create a ticket for development to see if this can be fixed.

     

    Hope this helps!

    Adam Reid