gemseo / wrappers

Show inherited members

xls_discipline module

Excel based discipline.

class gemseo.wrappers.xls_discipline.XLSDiscipline(xls_file_path, name=None, macro_name='execute', copy_xls_at_setstate=False, recreate_book_at_run=False)[source]

Bases: MDODiscipline

Wraps an Excel workbook into a discipline.

Warning

As this wrapper relies on the xlwings library to handle macros and interprocess communication, it is only working under Windows and macOS.

Initialize xls file path and macro.

Inputs must be specified in the “Inputs” sheet, in the following format (A and B are the first two columns).

A

B

a

1

b

2

Where a is the name of the first input, and 1 is its default value b is the name of the second one, and 2 its default value.

There must be no empty lines between the inputs.

The number of rows is arbitrary, but they must be contiguous and start at line 1.

The same applies for the “Outputs” sheet (A and B are the first two columns).

A

B

c

3

Where c is the only output. They may be multiple.

If the file is a XLSM, a macro named “execute” must exist and will be called by the _run method before retrieving the outputs. The macro has no arguments, it takes its inputs in the Inputs sheet, and write the outputs to the “Outputs” sheet.

Alternatively, the user may provide a macro name to the constructor, or None if no macro shall be executed.

Parameters:
  • xls_file_path (Path | str) – The path to the Excel file. If the file is a XLSM, a macro named “execute” must exist and will be called by the _run() method before retrieving the outputs.

  • name (str | None) – The name of the discipline. If None, use the class name.

  • macro_name (str | None) –

    The name of the macro to be executed for a XLSM file. If None is provided, do not run a macro.

    By default it is set to “execute”.

  • copy_xls_at_setstate (bool) –

    If True, create a copy of the original Excel file for each of the pickled parallel processes. This option is required to be set to True for parallelization in Windows platforms.

    By default it is set to False.

  • recreate_book_at_run (bool) –

    Whether to rebuild the xls objects at each _run call.

    By default it is set to False.

Raises:

ImportError – If xlwings cannot be imported.

cache: AbstractCache | None

The cache containing one or several executions of the discipline according to the cache policy.

data_processor: DataProcessor

A tool to pre- and post-process discipline data.

exec_for_lin: bool

Whether the last execution was due to a linearization.

input_grammar: BaseGrammar

The input grammar.

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_grammar: BaseGrammar

The output grammar.

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.