Input parameters from a file

Asked by Gonzalo Tancredi

I am interested in running a set of simulations with a different set of initial conditions.
It would be useful to have a different input file and run the same python script with the different input files.

I tried the example on
https://answers.launchpad.net/esys-particle/+question/115759

But it does not work.
It says
   from columnParams import *
ImportError: No module named columnParams

Could anyone give an example of how to run an script where the input parameters are read from a file?
Any running example would be useful. I can use it as a model for other scripts.

Gonzalo

Question information

Language:
English Edit question
Status:
Solved
For:
ESyS-Particle Edit question
Assignee:
No assignee Edit question
Solved by:
Dion Weatherley
Solved:
Last query:
Last reply:
Revision history for this message
Launchpad Janitor (janitor) said :
#1

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
Dion Weatherley (d-weatherley) said :
#2

This question needs to be answered.

Revision history for this message
Launchpad Janitor (janitor) said :
#3

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
Dion Weatherley (d-weatherley) said :
#4

This question still needs to be answered

Revision history for this message
Best Dion Weatherley (d-weatherley) said :
#5

Hi Gonzalo,

There are a number of ways to read input files in simulation scripts. I'll describe one of the simplest ways to do it:

To start, you need to create a python script to store the values of your input parameters (e.g. myParameters.py). In that script simply define your input parameters and their values, something like this:

#myParameters.py:
minRadius = 0.2
maxRadius = 1.0
stiffness = 1000.0
gravity = 9.81

Next, you need to modify your simulation script to "import" this python file. To do that, add the following to your simulation script, near the start of the script:

from myParameters import *

Once you have done that, you can simply use the parameters like variables in your simulation script e.g.

sim.createInteractionGroup (
     GravityPrms (
         name = "gravity",
         acceleration = Vec3(0.0, -1.0*gravity, 0.0)
      )
)

To run different simulations using different parameter values, you need to copy the myParameters.py script and your simulation script into an empty directory then edit myParameters.py to set new values for your input parameters. After that execute the simulation and it should use the new values.

I hope this helps.

Cheers,

Dion.

Revision history for this message
Gonzalo Tancredi (gonzalo) said :
#6

Thanks Dion Weatherley, that solved my question.

Revision history for this message
Gonzalo Tancredi (gonzalo) said :
#7

Hi Dion

Thank you for your answer.

I will try it.

Cheers

Gonzalo