[Scilab-users] xcos_simulate()

classic Classic list List threaded Threaded
6 messages Options
johan64 johan64
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] xcos_simulate()

Hi,

 

My xcos model becomes quite large and takes time to compile. In order to launch batches and optimisation process, it seems possible to compile the model juste one time.

However, I meet the same difficulties as described in this post :

 

<a href="http://mailinglists.scilab.org/xcos-xcos-simulate-scs-m-1-or-xcos-simulate-scs-m-4-td4031207.html#a4031274&quot;&gt;http://mailinglists.scilab.org/xcos-xcos-simulate-scs-m-1-or-xcos-simulate-scs-m-4-td4031207.html#a4031274">http://mailinglists.scilab.org/xcos-xcos-simulate-scs-m-1-or-xcos-simulate-scs-m-4-td4031207.html#a4031274">http://mailinglists.scilab.org/xcos-xcos-simulate-scs-m-1-or-xcos-simulate-scs-m-4-td4031207.html#a4031274

 

Indeed, the following script...

  ___________________________________

loadXcosLibs;

importXcosDiagram("C:\Users\johan\OneDrive\Micro entreprise\Technique\Kayak guide\Modélisation\Scilab\optimisation"+"\modèle physique et commande simple_10_opti.zcos");

tic();

xcos_simulate(scs_m, 4);

disp("méthode 2",toc());

 

tic();

%cpr = xcos_compile(scs_m);

disp( "Durée compilation",toc());

 

tic();

xcos_simulate(scs_m,1)

disp( "méthode 1",toc());

  ___________________________________

 

...gives the following results :

 ___________________________________

"scicos_simulate step 1"

   50.813412 s

 

  "scicos_simulate step 2"

   57.440604 s

 

  "xcos_simulate(scs_m, 4) méthode 2"

   58.808546 s

 

  "Compilation duration"

   55.615238 s

 

  "xcos_simulate(scs_m,1) méthode 1"

   61.133700 s

 ______________________________


It seems the compilation step is done in all these cases.

 

Thank you for your time and for your help


Johan


note 1 : when the final time of the simulation is set from 20s to 200s, the execution time increases about 15s

 

note 2 : according to the windows task manager, CPUs seem to be used about 30% during compilation and about 100% during simulation which takes few seconds


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
johan64 johan64
Reply | Threaded
Open this post in threaded view
|

Re: xcos_simulate()

Hi,

I am sorry, there is a mistake in my first post. Please, don't care about
the script described in italic.

My need is to compile my xcos diagram one time, simulate, then change
context parameters and run other simulations (in order to perform parametric
optimization on a large xcos model with many parameters and about 10-15
state variables).

I did some research and tests. To sum up :

1/xcos_simulate(scs_m,needcompile) : According to the Scilab Help,
needcompil is "DEPRECATED". Therefore, compilation is needed each times.

//////////////////////////////
2/scicos_simulate(scs_m,Info). I tried the PID optimization example method.
https://wiki.scilab.org/Xcos/Examples/PID
<https://wiki.scilab.org/Xcos/Examples/PID>  

Execute my model with
///Lancement de la simulation
disp("lancement")
 tic();
Info=scicos_simulate(scs_m,list())  
disp( "Durée simulation1",toc());  
tic();
Info=scicos_simulate(scs_m,Info)
 disp( "Durée simulation2",toc())/

Gives

/"lancement"    
"Durée simulation1"     83.604448    
"Durée simulation2"     81.738820/
Therefore, I win just 2 seconds with this method

/////////////////////////////////////////////////////
3/scicosim(); It seems to be the holy grail.
/
disp("lancement")
tic();
cpr=xcos_simulate(scs_m,4)
//cpr = xcos_compile(scs_m);
disp( "Simulation time 1 =",toc());
//Exploitation des données de compilation
state0=cpr.state; // cpr variable came from the compilation
sim=cpr.sim;
//Paramètre de simulation
tf=111;
atol=1.e-6;
rtol=1.e-6;
ttol=1.e-10;
deltat=tf;
scale=0;
solver=0;
hmax=0.1;

tol=[atol,rtol,ttol,deltat,scale,solver,hmax];

//Enregistrement des résultats
//save(pathu_result);

tic();
// initialisation
[state,t]=scicosim(state0,0,tf,sim,'start',tol);
// run
[state,t]=scicosim(state,t,tf,sim,'run',tol)
//end
[state,t]=scicosim(state,t,tf,sim,'finish',tol);
disp("Simulation time 2"+" = ",toc());
/
Gives
/
"Simulation time 1 ="

   83.815849

  "Simulation time 2 = "

   0.9816021
/

I win about 83 seconds!!!

Unfortunately, after running xcos_simulate one time, I don't find simple way
to change context parameters without launch xcos_simulate again (using
scs_m.props.context...) which wastes simulation time.
cpr.sim.rpar seems to contain block parameters but without symbolic
expression.

does anyone have an idea?

Thank you for your help






--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
johan64 johan64
Reply | Threaded
Open this post in threaded view
|

Re: xcos_simulate()

Hi,

Quick demonstration of the system :

https://youtu.be/_E3ElQalODI <https://youtu.be/_E3ElQalODI>  

I 've used the tool AnimaGIF. Because the sampling frequency of the scilab
model is 10Hz < 24 frames/sec
i've used slowmoVideo to interpolate "missing frames". This freeware uses
optical flow method.

It could be a good way to make fluent animation in addition to AnimaGIF.

Cordialy



--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Clément David-3 Clément David-3
Reply | Threaded
Open this post in threaded view
|

Re: xcos_simulate()

In reply to this post by johan64
Hi Johan,

First, sorry for the delay I tagged your mails to be read later but took some time to reach them 😊. Your last mail bumped the full conversation.

To better understand the simulation time, let me describe you what happens when you click play. After creating the schema you basically have a set of blocks with parameter values set at edition time and a set of links that connect blocks. Before simulation happens there is still work to do:
 1. As parameters can change the structure of blocks, we need to refresh/evaluate all blocks to set a parameters to the current values.
 2. A flatten copy is created to resolve inputs/outputs ports on subsystem
 3. The schedule of the graph is computed and a "compiled" cpr structure is created

On the simulation phase, you can only use this cpr structure to run ODE solvers on your system and produce results.

If you want to do multiple simulation of the same system changing only parameters *and* keeping the same diagram structure, I suggest you to use `Info = scicos_simulate(scs_m, Info)` where Info is defined as : Info = list(%tcur, %cpr, alreadyran, needstart, needcompile, %state0) . This seems not documented enough.

You can update parameters on Info(2) , the cpr, or Info(6) , the states, by yourself. This will remove all "compilation time" without using the internal scicosim  and let you change final time or filter parameters for example. For customers, we used this approach to do some optimization on filter coefficient.

Hope this will help you,
Regards,

Clément


-----Original Message-----
From: users <[hidden email]> On Behalf Of johan64
Sent: Sunday, February 28, 2021 12:56 PM
To: [hidden email]
Subject: Re: [Scilab-users] xcos_simulate()

Hi,

I am sorry, there is a mistake in my first post. Please, don't care about the script described in italic.

My need is to compile my xcos diagram one time, simulate, then change context parameters and run other simulations (in order to perform parametric optimization on a large xcos model with many parameters and about 10-15 state variables).

I did some research and tests. To sum up :

1/xcos_simulate(scs_m,needcompile) : According to the Scilab Help, needcompil is "DEPRECATED". Therefore, compilation is needed each times.

//////////////////////////////
2/scicos_simulate(scs_m,Info). I tried the PID optimization example method.
https://wiki.scilab.org/Xcos/Examples/PID
<https://wiki.scilab.org/Xcos/Examples/PID>  

Execute my model with
///Lancement de la simulation
disp("lancement")
 tic();
Info=scicos_simulate(scs_m,list())
disp( "Durée simulation1",toc());
tic();
Info=scicos_simulate(scs_m,Info)
 disp( "Durée simulation2",toc())/

Gives

/"lancement"    
"Durée simulation1"     83.604448    
"Durée simulation2"     81.738820/
Therefore, I win just 2 seconds with this method

/////////////////////////////////////////////////////
3/scicosim(); It seems to be the holy grail.
/
disp("lancement")
tic();
cpr=xcos_simulate(scs_m,4)
//cpr = xcos_compile(scs_m);
disp( "Simulation time 1 =",toc());
//Exploitation des données de compilation state0=cpr.state; // cpr variable came from the compilation sim=cpr.sim; //Paramètre de simulation tf=111; atol=1.e-6; rtol=1.e-6; ttol=1.e-10; deltat=tf; scale=0; solver=0; hmax=0.1;

tol=[atol,rtol,ttol,deltat,scale,solver,hmax];

//Enregistrement des résultats
//save(pathu_result);

tic();
// initialisation
[state,t]=scicosim(state0,0,tf,sim,'start',tol);
// run
[state,t]=scicosim(state,t,tf,sim,'run',tol)
//end
[state,t]=scicosim(state,t,tf,sim,'finish',tol);
disp("Simulation time 2"+" = ",toc());
/
Gives
/
"Simulation time 1 ="

   83.815849

  "Simulation time 2 = "

   0.9816021
/

I win about 83 seconds!!!

Unfortunately, after running xcos_simulate one time, I don't find simple way to change context parameters without launch xcos_simulate again (using
scs_m.props.context...) which wastes simulation time.
cpr.sim.rpar seems to contain block parameters but without symbolic expression.

does anyone have an idea?

Thank you for your help






--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Clément David-3 Clément David-3
Reply | Threaded
Open this post in threaded view
|

Re: xcos_simulate()

In reply to this post by johan64

Hi (again Johan),

 

For your information, we track/fix issue on big models by testing them in internal workbench. If you have simulation issue, we can add your model on this non-opensource set to try to improve the compilation time for it. Don’t hesitate to mail it to me (might be a partial or without parameter knowledge).

 

Regards,

 

Clément

 

From: users <[hidden email]> On Behalf Of Johan Lafitte
Sent: Wednesday, February 10, 2021 6:41 PM
To: [hidden email]
Subject: [Scilab-users] xcos_simulate()

 

Hi,

 

My xcos model becomes quite large and takes time to compile. In order to launch batches and optimisation process, it seems possible to compile the model juste one time.

However, I meet the same difficulties as described in this post :

 

<a href="http://mailinglists.scilab.org/xcos-xcos-simulate-scs-m-1-or-xcos-simulate-scs-m-4-td4031207.html#a4031274&quot;&gt;http://mailinglists.scilab.org/xcos-xcos-simulate-scs-m-1-or-xcos-simulate-scs-m-4-td4031207.html#a4031274">http://mailinglists.scilab.org/xcos-xcos-simulate-scs-m-1-or-xcos-simulate-scs-m-4-td4031207.html#a4031274">http://mailinglists.scilab.org/xcos-xcos-simulate-scs-m-1-or-xcos-simulate-scs-m-4-td4031207.html#a4031274

 

Indeed, the following script...

  ___________________________________

loadXcosLibs;

importXcosDiagram("C:\Users\johan\OneDrive\Micro entreprise\Technique\Kayak guide\Modélisation\Scilab\optimisation"+"\modèle physique et commande simple_10_opti.zcos");

tic();

xcos_simulate(scs_m, 4);

disp("méthode 2",toc());

 

tic();

%cpr = xcos_compile(scs_m);

disp( "Durée compilation",toc());

 

tic();

xcos_simulate(scs_m,1)

disp( "méthode 1",toc());

  ___________________________________

 

...gives the following results :

 ___________________________________

"scicos_simulate step 1"

   50.813412 s

 

  "scicos_simulate step 2"

   57.440604 s

 

  "xcos_simulate(scs_m, 4) méthode 2"

   58.808546 s

 

  "Compilation duration"

   55.615238 s

 

  "xcos_simulate(scs_m,1) méthode 1"

   61.133700 s

 ______________________________

 

It seems the compilation step is done in all these cases.

 

Thank you for your time and for your help

 

Johan

 

note 1 : when the final time of the simulation is set from 20s to 200s, the execution time increases about 15s

 

note 2 : according to the windows task manager, CPUs seem to be used about 30% during compilation and about 100% during simulation which takes few seconds


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
johan64 johan64
Reply | Threaded
Open this post in threaded view
|

Re: xcos_simulate()

Hi Clement,

Thank you for you answer. I 've tried the  scicos_simulate function again.
In this test initial conditions and inputs are set to 0. Normally, in this
case, state variables don't consume simulation time but I have no tools to
watch out  its activity.

1/ I've succeed in changing parameters between the two simulation. OK

2/The simulation time is not improve in the second execution (using "Info")
whereas nothing was changed. Maybe it is not a compilation problem?

I prefer contact you by email and sent you the model and make a sum up after
on this mailing list.

Thank you for your time.

///Lancement de la simulation
    disp("lancement")
    tic();
    Info=scicos_simulate(scs_m,list())
    disp("Durée de simulation = ",toc());
    //Affichage
    exec(pwd()+"\Scénarios"+"\Postraitement_commande simple.sce",-1);
pause
xdel(winsid())
//Lancement de la simulation 2
    tic();
    Info=scicos_simulate(scs_m,Info)
    disp( "Durée simulation2",toc())
    //Affichage
    exec(pwd()+"\Scénarios"+"\Postraitement_commande simple.sce",-1);/



--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users