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=DirectoryNamingMethod.NUMBERED, name=None, parse_outfile_method=Parser.TEMPLATE, write_input_file_method=None, parse_out_separator='=', use_shell=True, clean_after_execution=False)[source]
Specific 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.For security reasons, the executable is executed via the Python subprocess library with no shell. If a shell is needed, you may override this in a derived class.
Initialize self. See help(type(self)) for accurate signature.
- Parameters:
input_template (str | Path) – 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 | Path) – 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 | Path) – The base path of the execution directories.
executable_command (str) – The command to run the executable. E.g.
python my_script.py -i input.txt -o output.txt
input_filename (str | Path) – The name of the input file to be generated in the output folder. E.g.
"input.txt"
.output_filename (str | Path) – The name of the output file to be generated in the output folder. E.g.
"output.txt"
.folders_iter (DirectoryNamingMethod) –
The method to create the execution directories.
By default it is set to “NUMBERED”.
name (str | None) – The name of the discipline. If
None
, use the class name.parse_outfile_method (Parser | OutputParser) –
The optional method that can be provided by the user to parse the output template file. If the
KEY_VALUE
is used as output parser, the user may specify the separator key.By default it is set to “TEMPLATE”.
write_input_file_method (InputWriter | None) – The method to write the input data file. If
None
, usewrite_input_file()
.parse_out_separator (str) –
The separator used for the
KEY_VALUE
output parser.By default it is set to “=”.
use_shell (bool) –
This argument is ignored and will be removed, the shell is not used.
By default it is set to True.
clean_after_execution (bool) –
Whether to clean the last created directory after execution.
By default it is set to False.
- Raises:
TypeError – If the provided
parse_outfile_method
is not callable. If the providedwrite_input_file_method
is not callable.
- 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.
- property executable_command
The executable command.
- input_filename: str
The name of the input file.
- input_grammar: BaseGrammar
The input grammar.
- input_template: Path
The path to the input template file.
- jac: MutableMapping[str, MutableMapping[str, ndarray | csr_array | JacobianOperator]]
The Jacobians of the outputs wrt inputs.
The structure is
{output: {input: matrix}}
.
- name: str
The name of the discipline.
- output_filename: str
The name of the output file.
- output_grammar: BaseGrammar
The output grammar.
- output_template: Path
The path to the output template file.
- parse_outfile: OutputParser
The function used to parse the output template file.
- re_exec_policy: ReExecutionPolicy
The policy to re-execute the same discipline.
- residual_variables: dict[str, str]
The output variables mapping to their inputs, to be considered as residuals; they shall be equal to zero.
- run_solves_residuals: bool
Whether the run method shall solve the residuals.
- write_input_file: InputWriter
The function used to write the input template file.
Inputs and outputs files template edition GUI¶
Warning
This feature requires the GEMSEO template editor GUI plugin.
The following screenshots detail the steps to create the templates from the reference input file.