design_space module
Define an object to hold variables and constraints.
- class DesignSpace(variables: list[Variable], constraints: list[Constraint])
Bases:
objectHold variables and constraints of an optimisation problem.
- constraints: list[Constraint]
- classmethod from_files(elements_names: Sequence[str], filepath_variables: Path, variables_names: Sequence[str], filepath_constraints: Path | None = None, constraints_names: Sequence[str] | None = None, delimiter: str = ',') Self
Generate design space from files.
- Parameters:
elements_names (Sequence[str]) – Name of the elements with variables and constraints.
filepath_variables (pathlib.Path) – Path to the
variables.csvfile.variables_names (Sequence[str]) – Name of the variables to create.
filepath_constraints (pathlib.Path | None, optional) – Path to the
constraints.csvfile. The default is None, in which case no constraint is created.constraints_names (Sequence[str] | None, optional) – Name of the constraints to create. The default is None, in which case no constraint is created.
delimiter (str, optional) – Delimiter in the files. The default is a commma.
- Return type:
Self
- compute_constraints(simulation_output: SimulationOutput) ndarray
Compute constraint violation for
simulation_output.
- to_files(basepath: Path, variables_filename: str | Path = PosixPath('variables'), constraints_filename: str | Path = PosixPath('constraints'), overwrite: bool = False, **to_csv_kw: Any) None
Save variables and constraints in files.
- Parameters:
basepath (pathlib.Path) – Folder where the files will be stored.
variables_filename (pathlib.Path | str, optional) – Name of the output files without extension.
constraints_filename (pathlib.Path | str, optional) – Name of the output files without extension.
overwrite (bool, optional) – To overwrite an existing file with the same name or not. The default is False.
to_csv_kw (dict[str, Any]) – Keyword arguments given to the pandas
to_csvmethod.
- _to_file(parameters: list[DesignSpaceParameter], filepath: Path, delimiter: str = ',', **to_csv_kw: Any) None
Save all the design space parameters in a compact file.
- Parameters:
parameters (list[DesignSpaceParameter]) – All the defined parameters.
filepath (pathlib.Path) – Where file will be stored.
delimiter (str) – Delimiter between two columns. The default is ‘,’.
to_csv_kw (dict[str, Any]) – Keyword arguments given to the pandas
to_csvmethod.
- _parameters_to_single_file_line(element_name: str, parameters: list[DesignSpaceParameter]) dict[str, float | None | tuple[float, float]]
Prepare a dict containing all info of a single element.
- Parameters:
element_name (str) – Name of the element, which will be inserted in the output dict.
parameters (list[DesignSpaceParameter]) – Parameters concerning the element, which
limits(x_0if appliable) will be inserted in the dict.
- Returns:
Contains all
VariableorConstraintinformation of the element.- Return type:
- _gather_dicts_by_key(parameters: list[DesignSpaceParameter], key: str) dict[str, list[DesignSpaceParameter]]
Gather parameters with the same
keyattribute value in lists.- Parameters:
parameters (list[DesignSpaceParameter]) – Objects to study.
key (str) – Name of the attribute against which
parametersshould be gathered.
- Returns:
Keys are all existing values of attribute
keyfromparameters. Values are lists ofDesignSpaceParameterwithkeyattribute equaling the dict key.- Return type:
dict[Any, list[DesignSpaceParameter]]
- _parameters_to_dict(parameters: list[DesignSpaceParameter], to_get: Sequence[str]) list[dict]
Convert several design space parameters to dict.
We use the
prepend_parameter_nameargument to prepend the name of eachparameter.nameto the name of the valuesto_get. This way, we avoid dictionaries sharing the same keys in the output list.- Parameters:
parameters (list[DesignSpaceParameter]) – Where
to_getwill be looked for.to_get (Sequence[str]) – Values to get.
- Returns:
Contains
to_getvalues in dictionaries for every parameter.- Return type:
- _from_file(parameter_class: type[Variable], filepath: Path, elements_names: Sequence[str], parameters_names: Sequence[str], delimiter: str = ',') list[Variable]
- _from_file(parameter_class: type[Constraint], filepath: Path, elements_names: Sequence[str], parameters_names: Sequence[str], delimiter: str = ',') list[Constraint]
Generate list of variables or constraints from a given
.csv.Todo
Add support for when all element do not have the same variables/constraints.
- Parameters:
parameter_class (type[Variable] | type[Constraint]) – Object which
from_pd_seriesmethod will be called.filepath (pathlib.Path) – Path to the
.csv.elements_names (Sequence[str]) – Name of the elements.
parameters_names (Sequence[str]) – Name of the parameters.
delimiter (str) – Delimiter in the
.csv.
- Returns:
List of variables or constraints.
- Return type: