database module¶
A database of function calls and design variables¶
-
class
gemseo.algos.database.
Database
(input_hdf_file=None)[source]¶ Bases:
object
Class to store evaluations of functions, such as DOE or optimization histories
Avoids multiple calls of the same functions, useful when simulations are costly
It is also used to store inputs and retrieve them for optimization graphical post processing and plots generation
Can be serialized to HDF5 for portability and cold post processing
Constructor
-
GRAD_TAG
= '@'¶
-
ITER_TAG
= 'Iter'¶
-
KEYSSEPARATOR
= '__KEYSSEPARATOR__'¶
-
clean_from_iterate
(iterate)[source]¶ Delete the iterates after a given iterate number
- Parameters
iterate – the iterate number
-
contains_dataname
(data_name, skip_grad=False)[source]¶ Tests if history has a value named data_name stored
- Parameters
data_name – the name of the data
skip_grad – do not account for gradient names
- Returns
True if data_name is in self
-
contains_x
(x_vect)[source]¶ Tests if history has a design variables x stored
- Parameters
x_vect – the design variables to test
- Returns
True if x_vect is in self
-
export_hdf
(file_path='optimization_history.h5', append=False)[source]¶ Export optimization history to hdf file.
- Parameters
file_path – path to file to write (Default value = ‘optimization_history.h5’)
append – if True, appends the data in the file (Default value = False)
-
export_to_ggobi
(functions=None, file_path='opt_hist.xml', design_variables_names=None)[source]¶ Export history to xml file format for ggobi tool
- Parameters
functions – Default value = None)
file_path – Default value = “opt_hist.xml”)
design_variables_names – Default value = None)
-
filter
(data_list_to_keep)[source]¶ Keeps only the values in the data list :param data_list_to_keep: the list of data names to keep
-
get
(x_vect, default=None)[source]¶ Return the value for key if key is in the dictionary, else default.
-
get_all_data_names
(skip_grad=True, skip_iter=False)[source]¶ Return data variables (design, functions, gradient, … Gradient variables can be skipped
- Parameters
skip_grad – do not list gradient names (Default value = True)
skip_iter – do not add Iter in the list
- Returns
the list of data names in the database
-
get_complete_history
(functions=None, add_missing_tag=False, missing_tag='NA', all_iterations=False, stacked_data=None)[source]¶ Return complete history of optimization: design variables, functions, gradients.
- Parameters
functions – functions names to get (Default value = None)
add_missing_tag – add “missing_tag” when data is not available for this iteration (Default value = False)
missing_tag – the missing tag to add (Default value = ‘NA’)
all_iterations – if True, points called at several iterations will be duplicated in the history (each duplicate corresponding to a different calling index); otherwise each point will appear only once (with the latest calling index) (Default value = False)
stacked_data – list of names corresponding to data stored as lists. For example the iterations indexes are stored in a list. Other examples of stacked data may be penalization parameters or trust region radii. (Default value = None)
- Returns
function history and x history as lists
-
get_f_of_x
(fname, x_vect, dist_tol=0.0)[source]¶ If x in self, get associated “fname” value, if it exists
- Parameters
fname – the function name
x_vect – the design variables
- Returns
the values associated to x with name fname
-
get_func_grad_history
(funcname, x_hist=False)[source]¶ Return gradient values history Can also return history of design variables
- Parameters
funcname – the function name
x_hist – if True, returns variables history as well (Default value = False)
- Returns
the jacobian history list
-
get_func_history
(funcname, x_hist=False)[source]¶ Return function values history. Can also return history of design variables
- Parameters
funcname – the function name
x_hist – if True, returns variables history as well (Default value = False)
- Returns
the function history list
-
get_history_array
(functions=None, design_variables_names=None, add_missing_tag=False, missing_tag='NA', add_dv=True, all_iterations=False, stacked_data=None)[source]¶ Return history of optimization process
- Parameters
functions – functions names to export (Default value = None)
design_variables_names – names of the design variables (Default value = None)
missing_tag – missing tag to add (Default value = ‘NA’)
add_dv – if True, adds the design variables to the returned array (Default value = True)
add_missing_tag – add “missing_tag” when data is not available for this iteration (Default value = False)
missing_tag – the missing tag to add (Default value = ‘NA’)
all_iterations – if True, points called at several iterations will be duplicated in the history (each duplicate corresponding to a different calling index); otherwise each point will appear only once (with the latest calling index) (Default value = False)
stacked_data – list of names corresponding to data stored as lists. For example the iterations indexes are stored in a list. Other examples of stacked data may be penalization parameters or trust region radii. (Default value = None)
- Returns
function history and x history as lists
-
get_index_of
(x_vect)[source]¶ Returns the index of a particular x :param x_vect: x numpy array :returns: the index of x_vect, or throws a key error
-
get_x_by_iter
(iteration)[source]¶ Return design variables at a specified iteration
- Parameters
iteration – the iteration number
- Returns
the numpy array of x at iteration
-
import_from_opendace
(database_file)[source]¶ Reads an opendace xml database
- Parameters
database_file – the path to the database file
-
import_hdf
(filename='optimization_history.h5')[source]¶ Imports a database from hdf file
- Parameters
filename – Default value = ‘optimization_history.h5’)
-
is_func_grad_history_empty
(funcname)[source]¶ Check if history is empty
- Parameters
funcname – the function name
- Returns
True if history is empty
-
missing_value_tag
= 'NA'¶
-
pop
(k[, d]) → v, remove specified key and return the corresponding[source]¶ value. If key is not found, d is returned if given, otherwise KeyError is raised
-
static
set_dv_names
(n_dv)[source]¶ Create a list of default design variables names
- Parameters
n_dv – number of design variables in problem
- Returns
a list of design variables names
-
-
class
gemseo.algos.database.
HashableNdarray
(wrapped, tight=False)[source]¶ Bases:
object
HashableNdarray wrapper for ndarray objects.
Instances of ndarray are not HashableNdarray, meaning they cannot be added to sets, nor used as keys in dictionaries. This is by design - ndarray objects are mutable, and therefore cannot reliably implement the __hash__() method.
The HashableNdarray class allows a way around this limitation. It implements the required methods for HashableNdarray objects in terms of an encapsulated ndarray object. This can be either a copied instance (which is safer) or the original object (which requires the user to be careful enough not to modify it).
Creates a new HashableNdarray object encapsulating an ndarray.
:param wrapped:The wrapped ndarray. :param tight: If True, a copy of the input ndaray is created.