Several analysis simultaneous

Hello !
I am currently performing sensitivity study and wanted to know if it is possible to launch severeal analysis at the same time for the same model. In detail here is what I’d like :

  • instance 1 AnyBody : parameter k1
  • Open the same main in another AnyBody processus for a second instance : parameter k2
  • etc…

So, my question is will changes at the instance n affect instance n-1 , n-2 and so on ?

Thank you for your advices on how to conduct such studies !
Lauranne

Hi Lauranne

I have been in the same situation many times. My solution have been to launch the AnyBody console application from external programs like Matlab or Python.

That way, you can start many simulations at the same time (provided you have a licence that allows for this). If you do it right they will not interfere with each other. However, it can be tedious work to setup Matlab or python programs to handle all of this. So I have created a small library (called AnyPyTools) that makes this very easy to do from python.

For example. To do a parameter study of the pedal arm length on the Bike2D example, would look like this.


from anypytools.abcutils import AnyPyProcess
from matplotlib.pyplot import plot, show

pedel_arm_length = [0.06,0.08,0.1,0.12,0.14,0.16]

app = AnyPyProcess(num_processes = 4)
loadmacro = ['load "BikeModel2D.main.any"']
mainmacro = ['operation Main.RunApplication', 'run']
parameters = [ ('Main.BikeParameters.PedalArmLength', pedel_arm_length  )]
outputs = ['Main.Study.Output.MaxMuscleActivity']
result = app.start_param_job(loadmacro, mainmacro, parameters, outputs)

for max_activity in result['Main.Study.Output.MaxMuscleActivity']:
    plot(max_activity, hold = True)
show()

The code above runs 4 AnyBody instances simultaneously and collects the MaxMuscleActivity variable from each of the instances.

You can see the figure it generates here:
https://dl.dropbox.com/u/1683635/param.png

If you are interested I can share the library with you.

It may also be that the guys at AnyBodyTechnology have a simpler idea to accomplish the same.

See you
Morten

Hi Morten,
Thanks for your reply !

Your solution seems really interesting for me and, yes, I would be very interested in sharing your library ! :slight_smile: Of what I understood in your code, you specify output in your python code ; is there any advantage compared with output from anybody (like an outuput .txt file) ?

In fact, I looked at such a solution by using visual basic since I don’t know python language. So you absolutely answer to my question : yes I can launch an instance, change a parameter and launch a new instance, without affecting the first instance.

Let me now develop further my idea : I was able to launch 3 instances at the same time. Then, what I wanted was to automatically launch a new instance when one of the first 3 ended. I looked on “waitformultipleobjects” but was not able to conclude. Do you think it could be any solution with python language ? I’m pretty sure matlab is not a good way since you have to freeze matlab to all time check if thread is still active.

Thank you very much for your time and help !
Lauranne

Hi Lauranne

Your solution seems really interesting for me and, yes, I would be very interested in sharing your library ! :slight_smile: Of what I understood in your code, you specify output in your python code ; is there any advantage compared with output from anybody (like an outuput .txt file) ?

There is basically not much difference. I have previously used AnyOutputFiles and collected the output using Matlab. The disadvantage with the output files is that you need to add the necessary classes to your anybody model. Thus, you need change your model and you need to write some specific code to collect the output. The python program I wrote uses a different trick to make AnyBody report the content of a variable. You can try it your self in the GUI. Right click a variable in the model tree in AnyBody and select "Dump all". Then the content is written in the console output.

Let me now develop further my idea : I was able to launch 3 instances at the same time. Then, what I wanted was to automatically launch a new instance when one of the first 3 ended. I looked on "waitformultipleobjects" but was not able to conclude.

When you launch the anybody console applications with a set of macro commands you have to add an 'exit' as the last macro command, otherwise it will not exit. Also if the simulations somehow fail then the instance will newer stop. So adding some timeout in Visual basic may solve that problem.

Do you think it could be any solution with python language

Well that is actually what my python library does behind the scenes. You specify how many simultaneous processes you want. In the example the number was set to four. So when one of the four finishes a new is automatically started. Generally, the optimal number of simultaneous process is a little under the number cores in the PC. You can also do something like that in Matlab, but it is a little less flexible, which is probably why you thought Matlab would not work.

You can find the library hosted on GitHub (search for AnyPyTools), and it is easy to setup if you are familiar with python. However, if haven't used python before it can be a bit confusing to everything working. For that, I have a portable python distribution which have all the right packages pre-installed. It works out of the box without any installation required. Send me an email (mel@m-tech.aau.dk) and I can give you a link

Thanks,
Morten

Hi Morten

You can try it your self in the GUI. Right click a variable in the model tree in AnyBody and select "Dump all". Then the content is written in the console output.

I was able to right click >*Dump all. But then ? What exactly do you call "console output" ? And how to get variables for matlab analysis for example ?

When you launch the anybody console applications with a set of macro commands you have to add an 'exit' as the last macro command

In fact I did, and even 2 exits to also exit the cmd.exe and not only the anybodyconsol.exe. But I think my problem appears before the end of analysis because I get a message error as soon as the first 3 instances are launched. I tried adding timeout but did not solved the problem. Maybe should I specify I used VisualBasic for Application, coupled with excel ; do you think it could explain my problems ? Maybe some limitations linked with that ?

I'll e-mail you for your portable python distribution, thanks a lot ! :slight_smile:

Lauranne

Hi Lauranne,

I am not sure if this has already been resolved.

If you right click a varaible in the ModelTree and select dump all the value will be printed into the “console window” where you would normally see the error messages, model runtime info etc.

What kind of error message do you get ?

Best regards
Søren

Hi

I would like to try doing this to run more than one MotionAndParameterOptimization and InverseDynamicsModel at a time. I have over 600 trails to process, and it will take forever to run them in serial. So this would be great to run them in parallel.

Each of the trails has a unique C3D file, and unique initial conditions, So basically there is a separate GaitFullBody model main program file in a folder (call it Trail Specific Folder) for each trail. This main program points to other files, in the Trail Specific Folder, and to other files in other folders. All of these program files are common to all trails. It is only the main file code that is unique.

Could you please give some steps for how I can set up the programming using Python. Ive never used Python, before so can you please add some detail to the steps.

Also is there any other updates to the advice in this string?

Sincerely thanks
Damon

Hi Damon

The advice I gave Lauranne in this thread was mostly for parameter studies. That is, running the same model with many different parameters.

However, I also have some python code for running many different trials, and my trick is pretty much like your solution. I have many main-files which each load their own trial specific data file as well as subject specific file. I also a few other tricks, that makes it very easy to add new trials without editing any anyscript files. I often use this approach to run models with 500 or more trials.

The python libraries I wrote handles all the trouble of loading the files and scheduling them for processing. You can find the source files here:
https://github.com/AnyBody-Research-Group/AnyPyTools

The python code will look something like this:


from anypytools.abcutils import AnyPyProcess
folder = os.getcwd()

app = AnyPyProcess(basepath = folder,
                   subdir_search=  '.*main\.any',
                   num_processes = 10)

app.start_batch_job(['load "Kinematics.main.any"', 
                     'operation Main.RunMotionAndParameterOptimizationSequence',
                     'run',
                     'exit'])
                     
app.start_batch_job(['load "InversDynamics.main.any"', 
                     'operation  Main.InverseDynamicAnalysisSequence',
                     'run',
                     'exit'])

It may be a little hard to setup if you have no experience with Python, and I don’t know if the AnyBodyTech support can help you with this.

Otherwise, try to write to my University email account (mel@m-tech.aau.dk). Then maybe I can help you a little more.

/Morten

Hi Damon,
As mention by Morten, I used his code to change many different input parameters to launche several analysis.

I finally do not use the python code because it appeared pretty hard to adapt all of my previous work made with Matlab. So I developped same kind of scripts than what Morten did, but less complex since I did not need all of his functions. Basically I use the “Matlabpool” to launch works in parallel and call the AnybodyCon.exe via the “dos” function.

Do not hesitate to contact me (lauranne.sins@gmail.com) if you think it could be a solution for you and that you feel better than with python.

Lauranne