Difference between revisions of "ONELAB scripting syntax"

From ONELAB
Jump to: navigation, search
(Principe général)
(Conditional statements)
 
(47 intermediate revisions by the same user not shown)
Line 1: Line 1:
=== Principe général ===
+
ONELAB can be used to combine virtually any solver or data treatment code to build metamodels of relatively high complexities.
 +
A metamodel named ''model'' is constructed by defining clients and parameters in a file named ''model.ol'' with the syntax described below.
 +
A metamodel file contains only ONELAB statements.
  
L'utilisation de ONELAB n'est cependant pas limitée aux codes '''encapsulés'''.  
+
Native ONELAB clients (i.e. the mesh generator Gmsh and GetDP) need no interfacing and need only be declared in the metamodel.  
N'importe quel autre programme de calcul scientifique peut également utiliser ONELAB, mais cette fois-ci au travers d'une interface.  
+
For all other clients, ONELAB interfacing is based on the preprocessor principle.
On appelle ces clients des clients '''interfacés'''.
+
The natural input files of the clients are instrumented by the user (i.e. augmented with ONELAB commands).
 +
The name of the instrumented file is the name of the original file to which the ".ol" extension is added
 +
(e.g. an instrumented ''name.ext'' file will be named ''name.ext.ol'').
 +
Instrumented files are preprocessed, i.e. parsed by ONELAB to generate a valid input file for the client, just before its execution begins.
  
La syntaxe d'interfaçage se base sur le principe du [http://fr.wikipedia.org/wiki/Préprocesseur préprocesseur].
+
ONELAB commands in instrumented files must be enclosed between
Le préprocesseur ONELAB effectue des inclusions/exclusions conditionnelles de lignes de code et des substitutions de valeurs pour délivrer en sortie un fichier d'entrée valide pour le client.
+
OL.block
Etant donné que l'interface ONELAB est générique, càd qu'elle est identique pour tous les clients interfacés, toutes ces opérations sont réalisées sans jamais interpréter le code du client qui est considéré comme une suite de caractères sans signification.
+
    ...
 +
OL.endblock
 +
tags, or start with the
 +
OL.line
 +
tag. Comment lines in instrumented files start with "#".
  
Pour donner un exemple très simple, supposons qu'un client ''XYZ'' utilise un fichier d'entrée de type ''model.xyz'' contenant:
+
== Clients ==
<nowiki>
 
...
 
B = C + 2*0.005 + D
 
...
 
</nowiki>
 
et que la valeur 0.005 soit celle d'un paramètre L=0.005 l'on veut mettre en commun avec un autre client via le serveur ONELAB.
 
L'interfaçage ONELAB se fera en définissant un fichier ''model.xyz.ol'' contenant
 
<nowiki>
 
OL.parameter L.number(0.005,Parameters/1Geometry,Length);
 
...
 
B = C + 2*OL.getValue(L) + D
 
...
 
</nowiki>
 
La commande ''OL.parameter'' définit le paramètre ''Parameters/1Geometry/L'' sur le serveur ONELAB
 
et lui attribue la valeur par défaut 0.005 et le label "Length".
 
Lors de la conversion du fichier ''model.xyz.ol'', le préprocesseur repère les commandes ONELAB grâce au tag ''OL.'',
 
les traite et génère en sortie un fichier ''model.xyz'' syntaxiquement correct pour le client ''XYZ'',
 
à savoir dans ce cas-ci
 
<nowiki>
 
...
 
B = C + 2*0.004 + D
 
...
 
</nowiki>
 
si la valeur du paramètre ''L'' sur le serveur ONELAB est, au moment de la génération, 0.004 et non la valeur par défaut.
 
  
Il faut également enregistrer le solveur ''XYZ'' comme client auprès du server ONELAB.
+
;''name''.register(interfaced|encapsulated{, ''pathname''});
Cela se fait par la création d'un fichier ''model.ol'' contenant
+
:register the client ''name'' as an interfaced or native (encapsulated) client. The second argument is the executable name (full pathname or any alias that would be defined on your system).
<nowiki>
+
;''name''.commandLine(''pathname'')
OL.client XYZ.register(interfaced);
+
:defines the pathname to the client executable, if it was not given as second argument in the ''register'' statement.  
OL.client XYZ/InputFiles.Set(model.sif.ol);
+
;''name''.in(''file'',...)
</nowiki>
+
:comma-separated list of input files. Their presence is checked before execution. File with a ''.ol'' extension are converted before execution.
 +
;''name''.out(''file'',...)
 +
:comma separated list of output files. They are deleted before execution.
 +
;''name''.run(''options'')
 +
:the string ''options'' is interpreted (if it contains substitution statements) and appended to the commandline when calling the client.
 +
;''name''.active(0|1)
 +
:sets the client active or inactive. Inactive clients are not executed but remain registered.
 +
;''name''.up(''file'',''j'',''k'',''Parameter/Name'', ...)
 +
:tells ONELAB to extract the ''k''th numbers from the ''j''st line in the file ''file'', and to upload it as a new parameters named ''Parameter/Name''. If the line number ''j'' is "-1", the last line of the file is considered instead of the ''j''th. The group of four arguments can be repeated in one single "up" statement to upload several parameters.
 +
;''name''.merge(''file'', ...)
 +
:comma separated list of solution files interpretable by Gmsh (.pos, .msh, .geo, ...) to be merged after execution. 
 +
;''name''.check()
 +
:This optional statement forces the client to be checked immediately after its declaration so that parameters it declares can be used directly in the sequel of the metamodel definition.
  
=== Syntaxe détaillée ===
+
== Clients on remote hosts ==  
  
* Définition des clients
+
Clients can be run on remote hosts. For this, automatic <code>ssh</code> on the remote host without password should be authorized (Cf for instance [http://linuxproblem.org/art_9.html] to see how this can be done on linux systems). Most of the above syntax is unchanged. Client registration, however, requires additional information:
:;OL.client client_def; <client_def; ...>
 
::où '''client_def''' est une des commandes suivantes:
 
::;''name''.register(interfaced|encapsulated);
 
:::enregistre un client de type ''interfacé'' ou ''encapsulé" (obligatoire)
 
::;''name''.Path(''path'')
 
:::définit le path système de l'exécutable (interactif)
 
::;''name''/InputFiles.Set(''file'',...)
 
:::définit la liste des fichiers d'entrée (obligatoire)
 
::;''name''/OutputFiles.Set(''file'',...)
 
:::définit la liste des fichiers de sortie (facultatif)
 
::;''name''.PreLineOptions(''options'')
 
:::définit des options en ligne de commande à placer avant la liste des fichiers d'entrée (facultatif)
 
::;''name''.LineOptions('options'')
 
:::définit des options en ligne de commande à placer après la liste des fichiers d'entrée (facultatif)
 
::;''name''.Active(0|1)
 
:::définit si le client est appelé ou non lors de l'exécution (valeur par défaut:1)
 
  
* Définition des paramètres
+
;''name''.register(interfaced|encapsulated,{''pathname''}, ''remote_host'', ''remote_dir'');
:;OL.parameter param_def; <param_def; ...>
+
:register the client ''name'' as an interfaced or native (encapsulated) remote client. The second argument is the executable name (full pathname or any alias that would be defined on the remote host). The 3rd and 4th mandatory arguments define the remote host (e.g. username@host) and the remote directory (either a full path or a relative path from the home directory).
::où '''param_def''' est une des commandes suivantes:
 
::;''name''.number(Value,Path,ShortHelp)
 
::: définition d'un paramètre numérique
 
::;''name''.MinMax(Min,Max,Step)
 
:::attribution d'un range [''Min,Max''] à un paramètre numérique existant.
 
:::''Step'' définit l'incrément qui sera utilisé lors d'une éventuelle étude paramétrique sur cet intervalle.
 
::;''name''.string(Value,Path,ShortHelp)
 
:::définit un paramètre de type ''string''
 
  
* Branchements conditionnels
+
Moreover, lists of input and output files (i.e. the arguments of the ''in'' and ''out'' statements) need now specify whether each individual file in the list should be looked for on the local or on the remote host.
:'''OL.iftrue(''param'')'''
+
This is very simply and systematically done by writing "./filename" in the list whenever the file is to be looked for in the working directory on the local host,
::lignes de codes transférées si le paramètre "param'' est différent de 0 ou ""
+
and "filename" when it has to be looked for in the remote directory on the remote host.
:'''OL.else'''
 
::lignes de codes transférées si le paramètre "param'' est égal à 0 ""
 
:'''OL.endif'''
 
  
* Inclusion d'un fichier
+
The metamodel CRYO (See [[Elmer]]) uses remote clients.
:;OL.include(''file'')
 
::insère à cet endroit le résultat de la conversion du fichier ''file''
 
  
* Substitution de valeur
+
== Parameters ==
:;OL.getValue(''name'')
 
::insère à cet endroit la valeur du paramètre ''name'' sur le serveur ONELAB. Cette commande peut apparaître plusieurs fois sur une même ligne.
 
  
 +
;''name''.number(Value{,Path{,Label{,Range}}})
 +
:defines a ONELAB parameter of type ''number", with name ''Path/name'' and assign the value ''Value'' to it.  The prepended ''Path'' string allows sorting parameters hierarchically in the ONELAB window. ''Label'' is the display name in the ONELAB window. The ''Range'' is a string built on the model of "min:max:step" that indicate the minimum and maximum value of the parameter as well as an increment that will be used when looping on the parameter.
 +
;''name''.range(''Range'')
 +
:defines the range of the parameter if it was not given in the declaration.
 +
;''name''.string(Value,Path,ShortHelp)
 +
:defines a ONELAB parameter of type ''string", with name ''Path/name'' and assign the value ''Value'' to it.  ''Label'' is the display name in the ONELAB window.
 +
;''name''.setVisible(0|1)
 +
:sets the parameter ''name'' to be visible or not in the ONELAB window.
 +
;''name''.setReadOnly(0|1)
 +
:sets the parameter ''name'' to be read-only or not. Read-only parameters are depending parameters, i.e. parameters that depend on other parameters and whose value is set by the metamodel, not by the user. Even when visible, they cannot be modified in the ONELAB window.
 +
;''name''.addChoices(Value, ...)
 +
:add items to the list of possible choices for the parameter. The list of choices is used when ONELAB makes a loop on the parameter.
 +
;''name''.resetChoices()
 +
:resets the list of choices of the parameter ''name''.
 +
;''name''.valueLabels(Value, Label, ...)
 +
:adds items to the list of possible choices for a parameter of type "number", and associates a label with each choice. The labels appear in a small menu when clicking on the drop-down arrow besides the parameter in the ONELAB window. Several pairs "Value, Label" can be given comma-separated in one single "valueLabel" statement.
 +
;''name''.radioButton(Value{,Path,{Label}})
 +
:defines a parameter of type number with "0" and "1" as only possible choices. Radio button parameters are used for on/off or yes/no options. They appear as a tickbox in the ONELAB window.
  
=== Exemple ===
+
== Value substitution ==
  
Fichier d'entrée pour Gmsh
+
;OL.get(''name'')
 +
:insert here the value from the server of the parameter ''name''. This command may appear several time in the same line.
 +
;OL.eval(''string'')
 +
:after resolving "OL.get" statements, if any, the string is sent to the algebraic interpreter [[http://sscilib.sourceforge.net/ MathEx]] for evaluation. E.g. <code>OL.eval( floor((OL.get(A) + OL.get(B))/ 2))</code>, where "floor" is a built-in function of MathEx.
  
{{tutorial|elmerfem/CRYO/cryo.geo|height=22em}}
+
== Conditional statements ==
  
Définition des clients ONELAB
+
There are three conditional statements in ONELAB.
  
{{tutorial|elmerfem/CRYO/cryo.ol|height=22em}}
+
OL.iftrue(''param'') | OL.ifntrue(''param'') | OL.if(''expression'')
 +
...
 +
OL.else
 +
...
 +
OL.endif
  
Fichier d'entrée poyr ElmerFem
+
The "iftrue" statement is true if the parameter ''param'' is not 0 (number case) or not the empty string "" (string case).
 +
The "ifntrue" statement is true if the parameter ''param'' is 0 (number case) or the empty string "" (string case).
 +
In the "if" statement, expression is constructed on the model
  
{{tutorial|elmerfem/CRYO/cryo.sif.ol|height=22em}}
+
termA {< | > | == | <= | >=} termB
 +
 
 +
where termA and termB are interpreted if necessary. For instance:
 +
 
 +
OL.if( OL.get(This/Parameter) <= 10 )
 +
 
 +
== Miscellaneous ==
 +
 
 +
;OL.include(''file'')
 +
:insert here the result of the preprocessing of the file ''file''
 +
;OL.msg(''string'')
 +
:interpretes the string ''string'' and echoes the result to the terminal.
 +
 
 +
== Definition of ONELAB tags ==
 +
 
 +
By default, ONELAB commands are identified in instrumented files by the onelab tag "OL.",
 +
and comment lines, ignored by the preprocessor, start with the comment tag "#".
 +
Those tags can however be modified to accomodate various client syntaxes.
 +
The command
 +
onelab.tags(\,//);
 +
for instance, redefines the onelab tag as "\" and the comment tag as "//"
 +
 
 +
The commands
 +
onelab.tags(); onelab.tags(,); or onelab.tags(OL.,#);
 +
indifferently, restore the defaults values.  
 +
 
 +
Example:
 +
 
 +
#example of tag redefinition
 +
OL.include(filename)
 +
onelab.tags(\,//)
 +
\iftrue(PARAM)
 +
  do something
 +
  // we are using modified tags
 +
\endif
 +
onelab.tags()
 +
#default tags are restored
 +
Val = OL.get(PARAM)

Latest revision as of 13:21, 19 November 2012

ONELAB can be used to combine virtually any solver or data treatment code to build metamodels of relatively high complexities. A metamodel named model is constructed by defining clients and parameters in a file named model.ol with the syntax described below. A metamodel file contains only ONELAB statements.

Native ONELAB clients (i.e. the mesh generator Gmsh and GetDP) need no interfacing and need only be declared in the metamodel. For all other clients, ONELAB interfacing is based on the preprocessor principle. The natural input files of the clients are instrumented by the user (i.e. augmented with ONELAB commands). The name of the instrumented file is the name of the original file to which the ".ol" extension is added (e.g. an instrumented name.ext file will be named name.ext.ol). Instrumented files are preprocessed, i.e. parsed by ONELAB to generate a valid input file for the client, just before its execution begins.

ONELAB commands in instrumented files must be enclosed between

OL.block
   ...
OL.endblock

tags, or start with the

OL.line

tag. Comment lines in instrumented files start with "#".

Clients

name.register(interfaced|encapsulated{, pathname});
register the client name as an interfaced or native (encapsulated) client. The second argument is the executable name (full pathname or any alias that would be defined on your system).
name.commandLine(pathname)
defines the pathname to the client executable, if it was not given as second argument in the register statement.
name.in(file,...)
comma-separated list of input files. Their presence is checked before execution. File with a .ol extension are converted before execution.
name.out(file,...)
comma separated list of output files. They are deleted before execution.
name.run(options)
the string options is interpreted (if it contains substitution statements) and appended to the commandline when calling the client.
name.active(0|1)
sets the client active or inactive. Inactive clients are not executed but remain registered.
name.up(file,j,k,Parameter/Name, ...)
tells ONELAB to extract the kth numbers from the jst line in the file file, and to upload it as a new parameters named Parameter/Name. If the line number j is "-1", the last line of the file is considered instead of the jth. The group of four arguments can be repeated in one single "up" statement to upload several parameters.
name.merge(file, ...)
comma separated list of solution files interpretable by Gmsh (.pos, .msh, .geo, ...) to be merged after execution.
name.check()
This optional statement forces the client to be checked immediately after its declaration so that parameters it declares can be used directly in the sequel of the metamodel definition.

Clients on remote hosts

Clients can be run on remote hosts. For this, automatic ssh on the remote host without password should be authorized (Cf for instance [1] to see how this can be done on linux systems). Most of the above syntax is unchanged. Client registration, however, requires additional information:

name.register(interfaced|encapsulated,{pathname}, remote_host, remote_dir);
register the client name as an interfaced or native (encapsulated) remote client. The second argument is the executable name (full pathname or any alias that would be defined on the remote host). The 3rd and 4th mandatory arguments define the remote host (e.g. username@host) and the remote directory (either a full path or a relative path from the home directory).

Moreover, lists of input and output files (i.e. the arguments of the in and out statements) need now specify whether each individual file in the list should be looked for on the local or on the remote host. This is very simply and systematically done by writing "./filename" in the list whenever the file is to be looked for in the working directory on the local host, and "filename" when it has to be looked for in the remote directory on the remote host.

The metamodel CRYO (See Elmer) uses remote clients.

Parameters

name.number(Value{,Path{,Label{,Range}}})
defines a ONELAB parameter of type number", with name Path/name and assign the value Value to it. The prepended Path string allows sorting parameters hierarchically in the ONELAB window. Label is the display name in the ONELAB window. The Range is a string built on the model of "min:max:step" that indicate the minimum and maximum value of the parameter as well as an increment that will be used when looping on the parameter.
name.range(Range)
defines the range of the parameter if it was not given in the declaration.
name.string(Value,Path,ShortHelp)
defines a ONELAB parameter of type string", with name Path/name and assign the value Value to it. Label is the display name in the ONELAB window.
name.setVisible(0|1)
sets the parameter name to be visible or not in the ONELAB window.
name.setReadOnly(0|1)
sets the parameter name to be read-only or not. Read-only parameters are depending parameters, i.e. parameters that depend on other parameters and whose value is set by the metamodel, not by the user. Even when visible, they cannot be modified in the ONELAB window.
name.addChoices(Value, ...)
add items to the list of possible choices for the parameter. The list of choices is used when ONELAB makes a loop on the parameter.
name.resetChoices()
resets the list of choices of the parameter name.
name.valueLabels(Value, Label, ...)
adds items to the list of possible choices for a parameter of type "number", and associates a label with each choice. The labels appear in a small menu when clicking on the drop-down arrow besides the parameter in the ONELAB window. Several pairs "Value, Label" can be given comma-separated in one single "valueLabel" statement.
name.radioButton(Value{,Path,{Label}})
defines a parameter of type number with "0" and "1" as only possible choices. Radio button parameters are used for on/off or yes/no options. They appear as a tickbox in the ONELAB window.

Value substitution

OL.get(name)
insert here the value from the server of the parameter name. This command may appear several time in the same line.
OL.eval(string)
after resolving "OL.get" statements, if any, the string is sent to the algebraic interpreter [MathEx] for evaluation. E.g. OL.eval( floor((OL.get(A) + OL.get(B))/ 2)), where "floor" is a built-in function of MathEx.

Conditional statements

There are three conditional statements in ONELAB.

OL.iftrue(param) | OL.ifntrue(param) | OL.if(expression)
... 
OL.else 
... 
OL.endif

The "iftrue" statement is true if the parameter param is not 0 (number case) or not the empty string "" (string case). The "ifntrue" statement is true if the parameter param is 0 (number case) or the empty string "" (string case). In the "if" statement, expression is constructed on the model

termA {< | > | == | <= | >=} termB

where termA and termB are interpreted if necessary. For instance:

OL.if( OL.get(This/Parameter) <= 10 )

Miscellaneous

OL.include(file)
insert here the result of the preprocessing of the file file
OL.msg(string)
interpretes the string string and echoes the result to the terminal.

Definition of ONELAB tags

By default, ONELAB commands are identified in instrumented files by the onelab tag "OL.", and comment lines, ignored by the preprocessor, start with the comment tag "#". Those tags can however be modified to accomodate various client syntaxes. The command

onelab.tags(\,//);

for instance, redefines the onelab tag as "\" and the comment tag as "//"

The commands

onelab.tags(); onelab.tags(,); or onelab.tags(OL.,#);

indifferently, restore the defaults values.

Example:

#example of tag redefinition
OL.include(filename)
onelab.tags(\,//)
\iftrue(PARAM)
  do something
  // we are using modified tags
\endif
onelab.tags()
#default tags are restored
Val = OL.get(PARAM)