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 (
Path) – Path to thevariables.csvfile.variables_names (
Sequence[str]) – Name of the variables to create.filepath_constraints (
Path|None, default:None) – Path to theconstraints.csvfile.constraints_names (
Sequence[str] |None, default:None) – Name of the constraints to create.delimiter (
str, default:',') – Delimiter in the files.
- Return type:
Self
- 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 (
Path) – Folder where the files will be stored.variables_filename (
str|Path, default:PosixPath('variables')) – Name of the output files without extension.constraints_filename (
str|Path, default:PosixPath('constraints')) – Name of the output files without extension.overwrite (
bool, default:False) – To overwrite an existing file with the same name or not. The default is False.to_csv_kw (
Any) – Keyword arguments given to the pandasto_csvmethod.
- Return type:
- _to_file(parameters, filepath, delimiter=',', **to_csv_kw)[source]
Save all the design space parameters in a compact file.
- _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, whichlimits(x_0if appliable) will be inserted in the dict.
- Return type:
- Returns:
Contains all
VariableorConstraintinformation of the element.
- _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])
- Return type:
None
- _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 whichparametersshould be gathered.
- Return type:
- Returns:
Keys are all existing values of attribute
keyfromparameters. Values are lists ofDesignSpaceParameterwithkeyattribute equaling the dict key.
- _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.
- _from_file(parameter_class, filepath, elements_names, parameters_names, delimiter=',')[source]
- Overloads:
parameter_class (type[Variable]), filepath (Path), elements_names (Sequence[str]), parameters_names (Sequence[str]), delimiter (str) → list[Variable]
parameter_class (type[Constraint]), filepath (Path), elements_names (Sequence[str]), parameters_names (Sequence[str]), delimiter (str) → list[Constraint]
- Parameters:
- Return type:
list[Variable] | 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:
- Returns:
List of variables or constraints.
- Return type:
list[Variable] | list[Constraint]