nextnanoevo.MetricExtractor module
- class nextnanoevo.MetricExtractor.Metric(input_length=1, output_length=1, extraction_function: callable | None = None)
Bases:
object
The class interfacing array of output datafiles and the metric array
- Parameters:
- input_lengthint
Number of input datafiles
- output_lengthint
length of the output array (1 for scalar, >1 for vector)
- extraction_functioncallable
The function to extract the metric from the datafiles
- Attributes:
- input_file_pathstr
The input file for the Nextnano simulation.
Methods
extract
(input_datafiles, *args, **kwargs)Computes the metric array from the input datafiles
Validates the metric definition
- extract(input_datafiles: list, *args, **kwargs)
Computes the metric array from the input datafiles
It is recommended (safer) to design extraction function without args and kwargs (use only if necessary)
- Parameters:
- input_datafileslist
List of datafiles to extract the metric from
- argslist
Additional arguments for the extraction function
- kwargsdict
Additional keyword arguments for the extraction function
- Returns:
- numpy.ndarray
The extracted metric array
- validate_metric()
Validates the metric definition
- Raises:
- ValueError
If the metric has less than one input or output
- nextnanoevo.MetricExtractor.default_extractor(dfiles)
Default extractor function for the metric. Gets the first value of the first variable in each datafile and returns their sum.
- nextnanoevo.MetricExtractor.default_manyobj_extractor(dfiles)
Extractor function example for manyobjective optimization. Returns an array contatining the first value of the first variable in each datafile.
- nextnanoevo.MetricExtractor.default_value_getter(dfile)
Gets first value of the first variable in the datafile. Use for default extraction function.
- nextnanoevo.MetricExtractor.len_of_output_object(obj: list)
Gets length of the output object (list, tuple or ndarray)
- nextnanoevo.MetricExtractor.sum_expand_vector_with_zeros_extractor(dfiles)
Dummy extractor function for the manyobjective optimization. Returns a vector of the lenfth of dfiles. The first element is the sum of the first values of the first variable in each datafile, and the rest are zeros.