[Salome Automation 1] Introduction to YACS Module
By Cyprien Rusu
Summary
Topics Covered
- Scripting Without Coding
- Nodes Run Independent Python
- Step-by-Step Debugging Unlocks
Full Transcript
[Music] hello guys sa from F all and today I'll
show you something pretty cool uh it's another module of salom that I didn't present up to now in my videos but this
is definitely very useful uh and this model is called yak and I'm surprised that it even works in the windows version so I'm using the windows version
right now it's the 8.3 it's it's not the latest um and the sex is working so what is this sex model and what does it do well here is the the small example that
I'll show you during the video so I'll start over from scratch and uh show you what what this is exactly but before I show you that uh let me explain a bit
what is yak so if you have done just a bit of U scripting like uh coding using script for example
python um you may have some very row notion of you know the way a script works so generally a script has an input
has an output and has a various kind of functions in between like for Loops uh a lot of things that you can use in order
to basically execute something so but when we think about script we think about coding and about writing all that
line by line and if you're not very familiar with coding over or with python it might sound like something well that's very difficult I need to Learn
Python I need to learn a lot of things well uh what this Yak modu is basically doing is that it's a graphical way to to
script and build some automation scripts uh that will do some useful things for you and because it's within salom it's a
salom module it will allow you also to to build some automation over the Salam modules so for example you can think about Cod Aster or the geom module the
mesh and you can think about uh using Yaks to create an automatic uh workflow that will generate a geometry According
to some parameter like a parametric uh geometry creator that will Mees it according to various different kind of parameters uh and that would generate
and calculate the results for you so basically some kind of automation of the whole simulation process uh so you can do that with Yak so I I will not show in
this video how to do this I might do uh another video later on this so make sure you subscribe to my channel and you like
that this video so I get enough you know motivation to to do a second one so this uh so let's start with this this simple scheme and I'll show you how it works
and when you have when you went through this process you will have a very clear view of how to use Y and how it can be useful for
you so let's start over with a new project so I'll just save and close Okay save and close this one okay let's
start a new one okay I have already new one uh and let's start the yak module so the yak module is here and thisx model at the beginning it
looks like there's nothing inside it's very unintuitive so you really have to to see it at Le one how it works to understand um so click on this button
create a new y uh Yak scheme okay and you get this this scheme so this scheme is this is a graph graphical viewer in which you you will
be able to visualize this the the automation that you built with Yak at the beginning it has nothing inside so it's it's pretty weird you can't do much
with that and the way to to to use it is to right click on it and add a node to it so it's called a node and there are various kind of nodes available in Yaks
they are uh you know input data node output data node uh no but to be frank the the most the the most useful node is
this one inline script node because this this is a node in which you can put a python script within it so you can basically put anything you want within this kind of
node um once you have this node click on that and you see that on the right here you have input panel so this input panel
will allow you to uh add some input and output uh Port so it's ports but what it means is it's variables basically and here you have the way you can input a
script into it so let's see how to to put some uh so this this python script here this script node will do a very
simple operation it will just give me um a double output variable so it will generate a variable called o1 that will take a certain value at the start so
this will be used to initialize my script um and once I selected the type of variable I want to to use into my script so this is a duble
variable uh so it means double Precision basically and this is a name so you can change your name by double clicking here uh and the way to assign or
initialize this variable is to click once into this window so it looks like nothing happened and that's where it's a bit difficult to the first time you
click one once and then you you click o1 you write o1 on your keyboard equal 2.0 and you see that now this value is
written you click and apply and this this means basically that this o1 value will be initialized to the value 2.0 and this is a python script so you can
really put anything um that you you would write into P into a python script in into this script uh window here
um okay so I have my first node and I can I can kind of recite the window but when you have only one node it's yeah it's a bit weird how it works uh
graphically uh now let's add a second node so click on the main scheme so it's important you know which scheme is selected if you select this one and you add a node it will add a
node within this one so you have to select this and let's add the this time a for Loop node so it's a different type of
node which will basically execute a loop so and you you can place another node within this one so let's let's uh create another another
node within this and I'll do I'll do the same thing that this one I'll create two input
variable which will be doubles and I I'm switching to this to Output ports and I will create also two output variable and you see that
graphically they are added here uh on the screen so you can see the inputs and the outputs so I'll change the name of that because this is the entry value I'll call that
E1 E2 and uh outputs well I'll call that S1 and
S2 because yeah I'm still using the French notation e is for Entre which means entry uh input and S is for sorty
which means output but anyway you understand this is input then this is the output and what I'll do here in this window here is that
I will calculate the value of S1 and S2 based on the input so S1 will be equal to E1 +
E2 and S2 will be equal to e um E1 minus E2 and let's let's just apply okay and now this is my script you see very
simple the outputs are linked to the inputs using a simple formula okay now let's create uh another node which
will contain the final output so again I'm clicking on the main
scheme I will go into inline script node again here and I will give it two double
inputs so depending on your script and the kind of object calculator make sure you have the right type of variable you know so in this case it's just very
simple variable so this will be a double and I'll call that also E1 and
E2 uh note that I have E1 E2 here and here but those two nodes are totally independent and that's also something
about uh Yak is that each of those nodes is computed into an independent python container so container is basically some kind of
uh you can think about it as a sealed box which contains its own python uh interpreter so you can think about this
note here is using python um you know it's using python I don't know 3.7 and this one will use Python 3.8 so it can use
different python distribution uh well it's not recom recommended obviously you should use the same but just to give you an example
that those are totally independent notes okay so once I have all of this I I forgot something for this for for Loop
click on it and go into the number of steps to define the execution to Five Steps right okay so now that I have
those those nodes the next um next step is to connect the those different variables and those nodes in between so
they can exchange data basically so I want to connect this first node output with the input of the for
Loop and how will I connect this I want to initialize the value of
um E2 W which is within this node to the in the first value of o1 here so I'll just dve and drop and click and you see you have a pass like that which is
created and this E1 value is not initialized yet you see when you see it's not initialized and I will
initialize it to the value of the index so the index is the current value uh of the loop so for example for the first
step of the loop index will be equal to zero or maybe one uh we'll see see and so go from uh from 0 to four for
from one to to five maybe I don't remember if it starts at zero or one uh anyway this this will be the initialized
value at every every Loop uh and I want to connect this output so this will be this
Loop will execute fully and then it will save um it will save those two values
into this node here and now I have generated my uh my
yak scheme so next save that so save your scheme so I'll call that
too1 one you see it's save under XML format so and it's independent from salom hdf file so you can create um
schemes like this and import them into other salom um you know files so if you have your own automation you can uh create that and import it and by the way
y also has some cataloges of built-in nodes or stuff like this so but this will be for later I'm not showing that
in the video um Okay so now it's time to execute and see what this script actually does and how it works so there
are two um two modes into yak and now I am in the script building mode which is the it's called I think Edition mode and
to go to the other mode you have to click on the small wheel uh to prepare the current edited scheme for run so you click on that and if you have a problem
into your scheme at this point you'll get some errors and telling you that something is not right um here I have no error it works so my script is ready to
be executed um so to execute it just click on the start or resume the scheme execution okay and now it's it executed
everything at once and it's it's actually so fast that you don't even saw what it did uh but if you look at here so here you can see basically
the contents of the variables for the different nodes and you have um you have each of the node the for Loop the the py script
8 py script zero Etc and you see the final value that I'm getting into E1 and E2 is six for E1 and two for E2 so those
are the calculated end value when my script is fully executed at the end now uh what if if you know there's a problem
in in within um within my script during the execution and I want to debug basically step by step to see what is
happening within uh this scheme so there is a Mode called Step bystep execution so you can switch to this set execution
step by step and if you start again you see that this time it will only execute uh one by one so you have to Rec click again to this to see what it does so
first step is to initialize this second step is to initialize the for Loop second step is okay it goes the index
takes the value one so if you go into here you see that um my E1 is equal to the index which is one so it goes from
one to five yeah doesn't start at zero the E2 is taken as two because it it's initialized as the output of this and
the outputs are calculated according to the equation that I defined here now I go to the next step it executes the
second uh the second Loop you see that the this is not executed yet it will only be executed at the end then there is the third step fourth
step five step and now this is the followup is executed and the then the the value is sent as an output and taken
as an input by this node here and you see that this is the final value I'm getting E1 is equal to 6 and E2 is equal to
2 and um yeah and now I think you have an idea for how ax works so this you could as I'm I told you at
the beginning you could po basically put anything within those uh scripts uh so you can think of for example this first node would basically create a geometry
for you so H how do you create a geometry with a script well you you have to look at my video I think I made a video about how to use a geome module
with python to generate uh a script so you have to use that to generate a script that will generate your geometry and then you paste it basically into
this um and you send it to a second Loop and this Loop will do something recursive so maybe I don't know um maybe calculating something for you like using
Code Aster to calculate something and and giving out some value outputs and this script at the end maybe would use par View to to postprocess the results
and give you some pictures of uh of your simulation but this is a bit too advanced for this video this is only introduction so I'll do u a more
advanced video later on so make sure you subscribe to the channel and thank you very much for watching I hope you enjoyed the video and this was useful for you and let me know if you have uh
want to know anything specific or you have some questions or you know leave them in the comments of the video let me know uh this is always some inspiration
for me for the next videos and uh it also helps me to to think what I can teach you in the next videos thank you very much uh for following the blog thanks
Loading video analysis...