design_space module

Define an object to hold variables and constraints.

class DesignSpace(variables, constraints)[source]

Bases: object

Hold variables and constraints of an optimisation problem.

Parameters:
variables: list[Variable]
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 the variables.csv file.

  • variables_names (Sequence[str]) – Name of the variables to create.

  • filepath_constraints (Path | None, default: None) – Path to the constraints.csv file.

  • constraints_names (Sequence[str] | None, default: None) – Name of the constraints to create.

  • delimiter (str, default: ',') – Delimiter in the files.

Return type:

Self

compute_constraints(simulation_output)[source]

Compute constraint violation for simulation_output.

Parameters:

simulation_output (SimulationOutput)

Return type:

ndarray[tuple[Any, ...], dtype[double]]

__str__()[source]

Give nice output of the variables and constraints.

Return type:

str

_str_variables()[source]

Generate information on the variables that were created.

Return type:

str

_str_constraints()[source]

Generate information on the constraints that were created.

Return type:

str

to_pandas_dataframe()[source]

Convert list of variables to a pandas dataframe.

Return type:

DataFrame

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 pandas to_csv method.

Return type:

None

_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 (Path) – Where file will be stored.

  • delimiter (str, default: ',') – Delimiter between two columns. The default is ','.

  • to_csv_kw (Any) – Keyword arguments given to the pandas to_csv method.

Return type:

None

_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_0 if appliable) will be inserted in the dict.

Return type:

dict[str, float | None | tuple[float, float]]

Returns:

Contains all Variable or Constraint information 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:

int

__init__(variables, constraints)
Parameters:
Return type:

None

_gather_dicts_by_key(parameters, key)[source]

Gather parameters with the same key attribute value in lists.

Parameters:
  • parameters (list[DesignSpaceParameter]) – Objects to study.

  • key (str) – Name of the attribute against which parameters should be gathered.

Return type:

dict[str, list[DesignSpaceParameter]]

Returns:

Keys are all existing values of attribute key from parameters. Values are lists of DesignSpaceParameter with key attribute equaling the dict key.

_parameters_to_dict(parameters, to_get)[source]

Convert several design space parameters to dict.

We use the prepend_parameter_name argument to prepend the name of each parameter.name to the name of the values to_get. This way, we avoid dictionaries sharing the same keys in the output list.

Parameters:
Return type:

list[dict]

Returns:

Contains to_get values in dictionaries for every parameter.

_merge(dicts)[source]

Merge a list of dicts in a single dict.

Parameters:

dicts (list[dict])

Return type:

dict

_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:
  • parameter_class (type[Constraint] | type[Variable]) – Object which from_pd_series method will be called.

  • filepath (Path) – Path to the CSV.

  • elements_names (Sequence[str]) – Name of the elements.

  • parameters_names (Sequence[str]) – Name of the parameters.

  • delimiter (str, default: ',') – Delimiter in the CSV.

Returns:

List of variables or constraints.

Return type:

list[Variable] | list[Constraint]