Skip to content

External software component

external_software_component

Classes

ExternalSoftwareComponent

ExternalSoftwareComponent(
    load_case: LoadCase | None = None,
    material_grammar_file: Path | str = "",
    material: Material | None = None,
    check_subprocess: bool = False,
)

Bases: BaseComponent

A component to execute an external software.

Initialize self. See help(type(self)) for accurate signature.

Parameters:

  • load_case (LoadCase | None, default: None ) –

    The description is missing.

  • material_grammar_file (Path | str, default: '' ) –

    The description is missing.

  • material (Material | None, default: None ) –

    The description is missing.

  • check_subprocess (bool, default: False ) –

    The description is missing.

Source code in src\vimseo\core\components\external_software_component.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
def __init__(
    self,
    load_case: LoadCase | None = None,
    material_grammar_file: Path | str = "",
    material: Material | None = None,
    check_subprocess: bool = False,
) -> None:
    super().__init__(load_case, material_grammar_file, material, check_subprocess)

    self.output_grammar.update_from_data({self._ERROR_CODE_NAME: 0})
    self.output_grammar.required_names.add(self._ERROR_CODE_NAME)

    self._job_executor = JobExecutor("")
    self._attached_files = []
Attributes
USE_JOB_DIRECTORY class-attribute
USE_JOB_DIRECTORY: bool = False

Whether to create a job directory.

n_cpus property
n_cpus

The number of CPUs used to run the external software.

Methods:
add_attached_files
add_attached_files(
    files_to_attach: list[str, Path],
) -> None

Add files to be copied to job directory.

Parameters:

  • files_to_attach (list[str, Path]) –

    A list of files to be copied to the job directory.

Returns:

Source code in src\vimseo\core\components\external_software_component.py
174
175
176
177
178
179
180
181
182
183
def add_attached_files(self, files_to_attach: list[str, Path]) -> None:
    """Add files to be copied to job directory.

    Args:
        files_to_attach: A list of files to be copied to the job directory.

    Returns:
    """
    for f in files_to_attach:
        self._attached_files.append(f)
execute
execute(
    input_data: StrKeyMapping = READ_ONLY_EMPTY_DICT,
) -> DisciplineData

Execute the discipline, i.e. compute output data from input data.

If :attr:.virtual_execution is True, this method returns the :attr:.default_output_data. Otherwise, it calls the :meth:._run method performing the true execution and returns the corresponding output data. This :meth:._run method must be implemented in subclasses.

Parameters:

  • input_data (StrKeyMapping, default: READ_ONLY_EMPTY_DICT ) –

    The input data. Complete this dictionary with the :attr:.default_input_data.

Returns:

  • DisciplineData –

    The input and output data.

Source code in src\vimseo\core\gemseo_discipline_wrapper.py
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
def execute(
    self,
    input_data: StrKeyMapping = READ_ONLY_EMPTY_DICT,
) -> DisciplineData:

    if self.EXTRA_INPUT_GRAMMAR_CHECK:
        from vimseo.core.base_integrated_model import IntegratedModel

        all_input_names = list(input_data.keys()) + list(
            self.default_input_data.keys()
        )

        if (isinstance(self, (IntegratedModel))) and not set(
            all_input_names
        ).issubset(set(self.input_grammar.names)):
            extra_inputs = list(
                set(all_input_names) - set(self.input_grammar.names)
            )
            msg = (
                f"Input {extra_inputs} are not defined in the input grammar."
                f"Input grammar names are {list(self.input_grammar.names)}."
            )
            raise KeyError(msg)

    result = super().execute(input_data)

    # Fail loudly when an input was supplied by the caller but did not make
    # it through to the model (e.g. a dtype/shape the grammar quietly
    # rejects), which GEMSEO otherwise silently reverts to the default.
    # Scoped to the model boundary and to this discipline's *own* declared
    # inputs: in a coupled process (calibration, MDA, workflow) a sub-model
    # is handed the whole shared data dict -- sibling inputs and its own
    # fed-back outputs included -- none of which it is meant to validate.
    if input_data:
        from vimseo.core.base_integrated_model import IntegratedModel

        if isinstance(self, IntegratedModel):
            applied_data = self.get_input_data(with_namespaces=True)
            applied_names = set(applied_data)
            for name, passed in input_data.items():
                grammar_name = _resolve_input_name(name, applied_names)
                if grammar_name is None:
                    continue
                applied = applied_data[grammar_name]
                if not _input_applied(applied, passed):
                    msg = (
                        f"'{name}' was provided but not applied (dtype/shape "
                        f"mismatch?): passed {passed!r}, used {applied!r}."
                    )
                    raise ValueError(msg)

    return result
post_run
post_run(input_data, output_data)

Post-run operations.

Source code in src\vimseo\core\components\external_software_component.py
84
85
def post_run(self, input_data, output_data):
    """Post-run operations."""
pre_run
pre_run(input_data)

Pre-run operations.

Source code in src\vimseo\core\components\external_software_component.py
81
82
def pre_run(self, input_data):
    """Pre-run operations."""
set_job_executor
set_job_executor(job_executor: JobExecutor)

Set the job executor.

Parameters:

Source code in src\vimseo\core\components\external_software_component.py
124
125
126
127
128
129
130
def set_job_executor(self, job_executor: JobExecutor):
    """Set the job executor.

    Args:
        job_executor: The job executor.
    """
    self._job_executor = job_executor
write_input_files
write_input_files(input_data)

Write the input files for the external software.

Source code in src\vimseo\core\components\external_software_component.py
78
79
def write_input_files(self, input_data):
    """Write the input files for the external software."""