design_space module
Define an object to hold variables and constraints.
- class DesignSpace(variables, constraints)[source]
Bases:
objectHold variables and constraints of an optimisation problem.
- Parameters:
constraints (
list[Constraint])
-
constraints:
list[Constraint]
- classmethod from_files(elements_names, filepath_variables, variables_names, filepath_constraints=None, constraints_names=None, delimiter=',')[source]
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)[source]
Compute constraint violation for
simulation_output.- Parameters:
simulation_output (
SimulationOutput)- Return type:
- to_files(basepath, variables_filename=PosixPath('variables'), constraints_filename=PosixPath('constraints'), overwrite=False, **to_csv_kw)[source]
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.
- Return type:
- _to_file(parameters, filepath, delimiter=',', **to_csv_kw)[source]
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.
- Return type:
- _parameters_to_single_file_line(element_name, parameters)[source]
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:
- _check_dimensions(parameters)[source]
Ensure that all elements have the same number of var or const.
- Parameters:
parameters (
list[Variable] |list[Constraint])- Return type:
- __init__(variables, constraints)
- Parameters:
constraints (
list[Constraint])
- _gather_dicts_by_key(parameters, key)[source]
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, to_get)[source]
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, filepath, elements_names, parameters_names, delimiter=',')[source]
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: