interface problem Yade-Matlab

Asked by Alessandro Crema

Hi everybody!!

I need to interface a Yade script with a Matlab one.

In particular i need to optimize some coefficients of my YADE model through a particle swarm optimization function in Matlab.
So i search a way to run the matlab function, in order that it will be able to send some inputs and run automatically a Yade model and than, though its outputs, return in matlab and so on, until the optimization is reached.

I search everywhere some example or some useful command but i don't find nothing..

Someone has already had a problem like this?

Thanks in advance

Alessandro

Question information

Language:
English Edit question
Status:
Answered
For:
Yade Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Robert Caulk (rcaulk) said :
#1

Hello,

I have not seen anyone try to do this. Probably because python-numpy can do nearly everything matlab can do, and yade's interface runs through python.

My first question is, which optimization function are you trying to use in matlab? It is possible there is a comparable one in python which would make your life very easy. For example, here is a PSO for python [1]. My second question is, which parameters are you trying

As far as I see, you have two options. The first option is to port your matlab code over to python and add it as a function within the yade script. This way you can run the yade simulation followed by your optimization, which will modify certain parameters, then you can reload the yade simulation to some virgin state and loop until you want to stop. All within the same script.

The second option is to use a bash or python script to manipulate yade and matlab externally. First the script would execute yade. Inside yade it would read txt files for its parameters and write its output to txt files. Then the bash script would move to executing matlab, which would also read the txt files output by yade and write its output parameters to a txt file for yade.

Cheers,

Robert

[1]https://pypi.python.org/pypi/pyswarm/

Revision history for this message
Alessandro Crema (alessandroale) said :
#2

Hi Robert,
Thank you for the answer!
Yesterday i found the pyswarm in python and i trying to use it! In my problem i have 7 parameters, about the mechanical properties of a body, and in output i have 2 paramenters, which are the shear strength and the compressive strength.
I want to optimize those parameters in order to specialize as more as possible the model of the material that i obtain, for other following tests.
Is correct for you to assume as target function the sum of the difference of the two strength with respect the target values?
About instead the second option that you propose, which bash can i use in this case?
thanks in advance
Alessandro

Revision history for this message
Robert Caulk (rcaulk) said :
#3

Hello Alessandro,

>Is correct for you to assume as target function the sum of the difference of the two strength with respect the target values?

I am unfamiliar with particle swarm optimization, but I am assuming the "target function" is the one you are interested in minimizing? In my experience with optimization, you want the function you are minimizing to be a norm (of your choosing), not a sum. Sounds like you want to minimize the norm of the residual, which is generally a safe bet.

>About instead the second option that you propose, which bash can i use in this case? thanks in advance

Hmm I am not sure I understand. I am just describing a shell script written in bash. These are scripts executed through the terminal that control your computer. For example, "yadedaily test.py" is bash language that we use to execute our yade scripts. We can put that command in a script called script.sh. If you execute "sh script.sh" in the terminal, it will run the commands contained within the script. I am assuming matlab has non-gui access, maybe it is "matlab test.m"? So the script would look something like:

while (some logic); do
    yadedaily testYade.py # reads values from in.txt and prints values to out.txt
    matlab testMat.py # reads values from out.txt and prints values to in.txt
    # change logic if residual < tolerance?
end

Maybe this is not the best way to go about it. Just an idea.

Cheers,

Robert

Revision history for this message
Bruno Chareyre (bruno-chareyre) said :
#4

Hi,
Along the "txt interface" line, there is no real need to use bash.
It is possible to run a command like "matlab test.mat" from inside a python script [1], e.g. os.system("some_command with args"). In fact the same command exists in C++ if needed: system("matlab test.mat").
I would thus push python here, no need to add a third language.
Bruno

[1] https://stackoverflow.com/questions/89228/calling-an-external-command-in-python

Can you help with this problem?

Provide an answer of your own, or ask Alessandro Crema for more information if necessary.

To post a message you must log in.