gemseo / algos

design_space module

Design space

A design space is used to represent the optimization’s unknowns, a.k.a. design variables. A DesignSpace describes this design space at a given state, in terms of names, sizes, types, bounds and current values of the design variables. Variables can easily be added to the DesignSpace using the DesignSpace.add_variable() method or removed using the DesignSpace.remove_variable() method. We can also filter the design variables using the DesignSpace.filter() method. Getters and setters are also available to get or set the value of a given variable property. Lastly, an instance of DesignSpace can be stored in a txt or HDF file.

Classes:

DesignSpace([hdf_file])

Class that describes the design space at a given state:

class gemseo.algos.design_space.DesignSpace(hdf_file=None)[source]

Bases: object

Class that describes the design space at a given state:

the names/sizes/types/bounds of the variables and the initial solution of the optimization problem

Constructor.

Attributes:

AVAILABLE_TYPES

DESIGN_SPACE_GROUP

FLOAT

INTEGER

LB_GROUP

MINIMAL_FIELDS

NAMES_GROUP

NAME_GROUP

SEP

SIZE_GROUP

TABLE_NAMES

TYPE_GROUP

UB_GROUP

VALUE_GROUP

VAR_TYPE_GROUP

Methods:

add_variable(name[, size, var_type, l_b, …])

Add a variable to the design space.

array_to_dict(x_array)

Split the current point into a dictionary with variables names.

check()

Check the state of the design space.

check_membership(x_vect[, variables_names])

Checks whether the input variables satisfy the design space requirements.

dict_to_array(x_dict[, all_vars, all_var_list])

Aggregate a point as dictionary into array.

export_hdf(file_path[, append])

Export to hdf file.

export_to_txt(output_file[, fields, header_char])

Exports the design space to a text file.

extend(other)

Extend the design space with another design space.

filter(keep_variables[, copy])

Filter the design space to keep a sublist of variables.

filter_dim(variable, keep_dimensions)

Filters the design space to keep a sublist of dimensions for a given variable.

get_active_bounds([x_vec, tol])

Determine which bound constraints of the current point are active.

get_current_x([variables_names])

Gets the current point in the design space.

get_current_x_dict()

Get the current point in the design space.

get_current_x_normalized()

Returns the current point normalized.

get_indexed_var_name(variable_name)

Return a list of the variables names with their indices such as.

get_indexed_variables_names()

Return a list of the variables names with their indices such as.

get_lower_bound(name)

Gets the lower bound of a variable.

get_lower_bounds([variables_names])

Generates an array of the variables’ lower bounds.

get_pretty_table([fields])

Builds a PrettyTable object from the design space data.

get_size(name)

Get the size of a variable Return None if the variable is not known.

get_type(name)

Get the type of a variable Return None if the variable is not known.

get_upper_bound(name)

Gets the upper bound of a variable.

get_upper_bounds([variables_names])

Generates an array of the variables’ upper bounds.

get_variables_indexes(variables_names)

Return the indexes of a design array corresponding to the variables names.

has_current_x()

Tests if current_x is defined.

import_hdf(file_path)

Imports design space from hdf file.

normalize_vect(x_vect[, minus_lb])

Normalizes a vector of the design space.

project_into_bounds(x_c[, normalized])

Projects x_c onto the bounds, using a simple coordinate wise approach.

read_from_txt(input_file[, header])

Parses a csv file to read the DesignSpace.

remove_variable(name)

Remove a variable (and bounds and types) from the design space.

round_vect(x_vect)

Rounds the vector where variables are of integer type.

set_current_variable(name, current_value)

Set the current value of a single variable.

set_current_x(current_x)

Set the current point.

set_lower_bound(name, lower_bound)

Set a new lower bound for variable name.

set_upper_bound(name, upper_bound)

Set a new upper bound for variable name.

to_complex()

Casts the current value to complex.

unnormalize_vect(x_vect[, minus_lb, no_check])

Unnormalizes a normalized vector of the design space.

AVAILABLE_TYPES = ['float', 'integer']
DESIGN_SPACE_GROUP = 'design_space'
FLOAT = 'float'
INTEGER = 'integer'
LB_GROUP = 'l_b'
MINIMAL_FIELDS = ['name', 'lower_bound', 'upper_bound']
NAMES_GROUP = 'names'
NAME_GROUP = 'name'
SEP = '!'
SIZE_GROUP = 'size'
TABLE_NAMES = ['name', 'lower_bound', 'value', 'upper_bound', 'type']
TYPE_GROUP = 'type'
UB_GROUP = 'u_b'
VALUE_GROUP = 'value'
VAR_TYPE_GROUP = 'var_type'
add_variable(name, size=1, var_type='float', l_b=None, u_b=None, value=None)[source]

Add a variable to the design space.

Parameters
  • name – param size: (Default value = 1)

  • var_type – Default value = FLOAT)

  • l_b – Default value = None)

  • u_b – Default value = None)

  • value – Default value = None)

  • size – (Default value = 1)

array_to_dict(x_array)[source]

Split the current point into a dictionary with variables names.

Parameters

x_array – x array to be converted to a dict of array

check()[source]

Check the state of the design space.

check_membership(x_vect, variables_names=None)[source]

Checks whether the input variables satisfy the design space requirements.

Parameters
  • x_vect (dict or array) – design variables

  • variables_names – names of the variables to be checked

dict_to_array(x_dict, all_vars=True, all_var_list=None)[source]

Aggregate a point as dictionary into array.

Parameters
  • x_dict – point as dictionary

  • all_vars – if True, all variables shall be in x_dict

  • all_var_list – list of whole set of variables, if None, use self.variables_names

export_hdf(file_path, append=False)[source]

Export to hdf file.

Parameters
  • file_path – path to file to write

  • append – if True, appends the data in the file

export_to_txt(output_file, fields=None, header_char='', **table_options)[source]

Exports the design space to a text file.

Parameters
  • output_file – output file path

  • fields – list of fields to export, by default all

extend(other)[source]

Extend the design space with another design space.

Parameters

other (DesignSpace) – design space to be appended

filter(keep_variables, copy=False)[source]

Filter the design space to keep a sublist of variables.

Parameters
  • keep_variables (str of list(str)) – the list of variables to keep

  • copy (bool) – if True then a copy of the design space is filtered, otherwise the design space itself is filtered

Returns

the filtered design space (or a copy)

Return type

DesignSpace

filter_dim(variable, keep_dimensions)[source]

Filters the design space to keep a sublist of dimensions for a given variable.

Parameters
  • variable – the variable

  • keep_dimensions – the list of dimension to keep

get_active_bounds(x_vec=None, tol=1e-08)[source]

Determine which bound constraints of the current point are active.

Parameters
  • x_vec – the point at which we check the bounds

  • tol – tolerance of comparison of a scalar with a bound (Default value = 1e-8)

get_current_x(variables_names=None)[source]

Gets the current point in the design space.

Parameters

variables_names (list(str)) – names of the required variables, optional

Returns

the x vector as array

Return type

ndarray

get_current_x_dict()[source]

Get the current point in the design space.

Returns

the x vector as a dict, keys are the variable names values are the variable vales as np array

get_current_x_normalized()[source]

Returns the current point normalized.

Returns

the x vector as array normalized by the bounds

get_indexed_var_name(variable_name)[source]

Return a list of the variables names with their indices such as.

[x!0,x!1,y,z!0,z!1]

Parameters

variable_name (str) – name of the variable

Returns

names of the variable components

Return type

list(str)

get_indexed_variables_names()[source]

Return a list of the variables names with their indices such as.

[x!0,x!1,y,z!0,z!1]

Returns

names of all the variables components

Return type

list(str)

get_lower_bound(name)[source]

Gets the lower bound of a variable.

Parameters

name – variable name

Returns

variable lower bound (possibly infinite)

get_lower_bounds(variables_names=None)[source]

Generates an array of the variables’ lower bounds.

Parameters

variables_names – names of the variables of which the lower bounds are required

get_pretty_table(fields=None)[source]

Builds a PrettyTable object from the design space data.

Parameters

fields – list of fields to export, by default all

Returns

the pretty table object

get_size(name)[source]

Get the size of a variable Return None if the variable is not known.

Parameters

name – name of the variable

get_type(name)[source]

Get the type of a variable Return None if the variable is not known.

Parameters

name – name of the variable

get_upper_bound(name)[source]

Gets the upper bound of a variable.

Parameters

name – variable name

Returns

variable upper bound (possibly infinite)

get_upper_bounds(variables_names=None)[source]

Generates an array of the variables’ upper bounds.

Parameters

variables_names – names of the variables of which the upper bounds are required

get_variables_indexes(variables_names)[source]

Return the indexes of a design array corresponding to the variables names.

Parameters

variables_names (list(str)) – names of the variables

Returns

indexes of a design array corresponding to the variables names

Return type

ndarray

has_current_x()[source]

Tests if current_x is defined.

Returns

True if current_x is defined

import_hdf(file_path)[source]

Imports design space from hdf file.

Parameters

file_path

normalize_vect(x_vect, minus_lb=True)[source]

Normalizes a vector of the design space. Unbounded variables are not normalized.

Parameters
  • x_vect (ndarray) – design variables

  • minus_lb – if True, remove lower bounds at normalization

Returns

normalized vector

project_into_bounds(x_c, normalized=False)[source]

Projects x_c onto the bounds, using a simple coordinate wise approach.

Parameters
  • normalized (bool) – if True then the vector is assumed to be normalized

  • x_c – x vector (np array)

Returns

projected x_c

static read_from_txt(input_file, header=None)[source]

Parses a csv file to read the DesignSpace.

Parameters
  • input_file – returns: s: the design space

  • header – fields list, or by default, read in the file

Returns

the design space

remove_variable(name)[source]

Remove a variable (and bounds and types) from the design space.

Parameters

name – name of the variable to remove

round_vect(x_vect)[source]

Rounds the vector where variables are of integer type.

Parameters

x_vect – design variables to round

set_current_variable(name, current_value)[source]

Set the current value of a single variable.

Parameters
  • name – name of the variable

  • current_value – current value of the variable

set_current_x(current_x)[source]

Set the current point.

Parameters

current_x – the current design vector

set_lower_bound(name, lower_bound)[source]

Set a new lower bound for variable name.

Parameters
  • name – name of the variable

  • lower_bound – lower bound

set_upper_bound(name, upper_bound)[source]

Set a new upper bound for variable name.

Parameters
  • name – name of the variable

  • upper_bound – upper bound

to_complex()[source]

Casts the current value to complex.

unnormalize_vect(x_vect, minus_lb=True, no_check=False)[source]

Unnormalizes a normalized vector of the design space.

Parameters
  • x_vect (ndarray) – design variables

  • minus_lb – if True, remove lower bounds at normalization

  • no_check – if True, don’t check that values are in [0,1]

Returns

normalized vector