Automatic wrapper for executables with Graphical User Interface¶
The DiscFromExe wrapper¶
This section describes how to use DiscFromExe
.
The input and output template files can be edited using the dedicated GUI, see next section.
- class gemseo.wrappers.disc_from_exe.DiscFromExe(input_template, output_template, output_folder_basepath, executable_command, input_filename, output_filename, folders_iter=FoldersIter.NUMBERED, name=None, parse_outfile_method=Parsers.TEMPLATE_PARSER, write_input_file_method=None, parse_out_separator='=', use_shell=True)[source]
Generic wrapper for executables.
This
MDODiscipline
uses template files describing the input and output variables.The templates can be generated with a graphical user interface (GUI). by executing the module
template_grammar_editor
.An input template file is a JSON file formatted as
{ "a": GEMSEO_INPUT{a::1.0}, "b": GEMSEO_INPUT{b::2.0}, "c": GEMSEO_INPUT{c::3.0} }
where
"a"
is the name of an input, and1.0
is its default value. Similarly, an output template file is a JSON file formatted as{ "a": GEMSEO_OUTPUT{a::1.0}, "b": GEMSEO_OUTPUT{b::2.0}, "c": GEMSEO_OUTPUT{c::3.0} }
where
"a"
is the name of an output, and1.0
is its default value.The current limitations are
Only one input and one output template file, otherwise, inherit from this class and modify the parsers. Only limited input writing and output parser strategies are implemented. To change that, you can pass custom parsing and writing methods to the constructor.
The only limitation in the current file format is that it must be a plain text file and not a binary file. In this case, the way of interfacing it is to provide a specific parser to the
DiscFromExe
, with thewrite_input_file_method()
andparse_outfile_method()
arguments of the constructor.
- Parameters:
input_template (str) – The path to the input template file. The input locations in the file are marked by
GEMSEO_INPUT{input_name::1.0}
, whereinput_name
is the name of the input variable, and1.0
is its default value.output_template (str) – The path to the output template file. The output locations in the file are marked by
GEMSEO_OUTPUT{output_name::1.0}
, whereoutput_name
is the name of the output variable, and1.0
is its default value.output_folder_basepath (str) – The description is missing.
executable_command (str) – The command to run the executable. E.g.
python my_script.py -i input.txt -o output.txt
input_filename (str) – The name of the input file to be generated in the output folder. E.g.
"input.txt"
.output_filename (str) – The name of the output file to be generated in the output folder. E.g.
"output.txt"
.folders_iter (str | FoldersIter) –
The type of unique identifiers for the output folders. If
NUMBERED
, the generated output folders will bef"output_folder_basepath{i+1}"
, wherei
is the maximum value of the already existingf"output_folder_basepath{i}"
folders. Otherwise, a unique number based on the UUID function is generated. This last option shall be used if multiple MDO processes are run in the same work directory.By default it is set to NUMBERED.
name (str | None) – The name of the discipline. If None, use the class name.
parse_outfile_method (str | Parsers) –
The optional method that can be provided by the user to parse the output template file. If
None
, useparse_outfile()
. If theKEY_VALUE_PARSER
is used as output parser, specify the separator key.By default it is set to TEMPLATE_PARSER.
write_input_file_method (str | None) – The method to write the input data file. If
None
, usewrite_input_file()
.parse_out_separator (str) –
The separator used for the output parser.
By default it is set to “=”.
use_shell (bool) –
If
True
, run the command using the default shell. Otherwise, run directly the command.By default it is set to True.
- Raises:
TypeError – If the provided
write_input_file_method
is not callable.
- generate_uid()[source]
Generate a unique identifier for the execution directory.
Generate a unique identifier for the current execution. If the folders_iter strategy is
NUMBERED
, the successive iterations are named by an integer 1, 2, 3 etc. This is multiprocess safe. Otherwise, a unique number based on the UUID function is generated. This last option shall be used if multiple MDO processes are runned in the same workdir.- Returns:
An unique string identifier (either a number or a UUID).
- Return type:
- cache: AbstractCache | None
The cache containing one or several executions of the discipline according to the cache policy.
- data_processor: DataProcessor
A data processor to be used before the execution of the discipline.
- exec_for_lin: bool
Whether the last execution was due to a linearization.
- executable_command: str
The executable command.
- property folders_iter: FoldersIter
The names of the new execution directories.
- Raises:
ValueError – When the value is not a valid
FoldersIter
.
- input_filename: str
The name of the input file.
- input_grammar: BaseGrammar
The input grammar.
- input_template: str
The path to the input template file.
- jac: dict[str, dict[str, ndarray]]
{input:
matrix}}``.
- Type:
The Jacobians of the outputs wrt inputs of the form ``{output
- name: str
The name of the discipline.
- output_filename: str
The name of the output file.
- output_folder_basepath: str
The base path of the execution directories.
- output_grammar: BaseGrammar
The output grammar.
- output_template: str
The path to the output template file.
- parse_outfile: Callable[[Mapping[str, tuple[int]]], Sequence[str]]
The function used to parse the output template file.
- re_exec_policy: str
The policy to re-execute the same discipline.
- residual_variables: Mapping[str, str]
The output variables mapping to their inputs, to be considered as residuals; they shall be equal to zero.
- run_solves_residuals: bool
If True, the run method shall solve the residuals.
Inputs and outputs files template edition GUI¶
- class gemseo.wrappers.template_grammar_editor.QtTemplateEditor(in_sep='GEMSEO_INPUT', out_sep='GEMSEO_OUTPUT')[source]
- Parameters:
in_sep –
The separator name for the input tag.
By default it is set to “GEMSEO_INPUT”.
out_sep –
The separator name for the output tag.
By default it is set to “GEMSEO_OUTPUT”.
- add_action(name, status_tip, shortcut, connect)[source]
Add an action with a button and icon.
- Parameters:
name – The name of the action.
status_tip – The tip for the user to browse with the mouse.
shortcut – The keyboard shortcut (Ctrl+S) for instance.
connect – The method to call at trigger.
- highlight(sep, color='red')[source]
Highlight some text.
- Parameters:
sep – The regex that validates the text to highlight.
color –
The color to be used.
By default it is set to “red”.
- make_input()[source]
Make an input from the selected data.
- make_output()[source]
Make an output from the selected data.
- open_doc()[source]
Open the document for edition of the template.
- save_doc()[source]
Save the template to a file.
The following screenshots detail the steps to create the templates from the reference input file.

Open a reference input file¶

Select the input and press the Input button (Ctrl+I) to generate the template tag¶

Enter the input name¶

The GUI highlights the inputs that are tagged in the template¶

The user saves the input template (Ctrl+S)¶

Same for the outputs, shortcut (Ctrl+O)¶