Parallel¶
Parallel
calculates the model and features of the
model for one specific set of model parameters.
Parallel
is the class that is run in parallel.
API Reference¶

class
uncertainpy.core.
Parallel
(model=None, features=None, logger_level=u'info')[source]¶ Calculates the model and features of the model for one set of model parameters. Is the class that is run in parallel.
Parameters:  model ({None, Model or Model subclass instance, model function}, optional) – Model to perform uncertainty quantification on. For requirements see Model.run. Default is None.
 features ({None, Features or Features subclass instance, list of feature functions}, optional) – Features to calculate from the model result. If None, no features are calculated. If list of feature functions, all will be calculated. Default is None.
 logger_level ({“info”, “debug”, “warning”, “error”, “critical”, None}, optional) – Set the threshold for the logging level. Logging messages less severe than this level is ignored. If None, no logging to file is performed Default logger level is “info”.
Variables:  model (uncertainpy.Parallel.model) –
 features (uncertainpy.Parallel.features) –
See also
uncertainpy.features.Features
,uncertainpy.models.Model
uncertainpy.models.Model.run
 Requirements for the model run function.

create_interpolations
(result)[source]¶ Create an interpolation.
Model or feature result s that have a varying number of time steps, are interpolated. Interpolation is only performed for one dimensional result. Zero dimensional result does not need to be interpolated, and support for interpolating two dimensional and above result have currently not been implemented. Adds a “interpolation” keyvalue pair to result.
Parameters: result (dict) – The model and feature results. The model and each feature each has a dictionary with the time values,
"time"
, and model/feature results,"values"
. An example:result = {model.name: {"values": array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), "time": array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])}, "feature1d": {"values": array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), "time": array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])}, "feature0d": {"values": 1, "time": np.nan}, "feature2d": {"values": array([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]), "time": array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])}, "feature_adaptive": {"values": array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), "time": array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])}, "feature_invalid": {"values": np.nan, "time": np.nan}}
Returns: result – If an interpolation has been created, those features/model have “interpolation” and the corresponding interpolation object added to each features/model dictionary. An example:
result = {self.model.name: {"values": array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), "time": array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])}, "feature1d": {"values": array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), "time": array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])}, "feature0d": {"values": 1, "time": np.nan}, "feature2d": {"values": array([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]), "time": array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])}, "feature_adaptive": {"values": array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), "time": array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), "interpolation": scipy interpolation object}, "feature_invalid": {"values": np.nan, "time": np.nan}}
Return type: dict
Notes
If either model or feature results are irregular, the results must be interpolated for Chaospy to be able to create the polynomial approximation. For 1D results this is done with scipy:
InterpolatedUnivariateSpline(time, U, k=3)
.

features
¶ Features to calculate from the model result.
Parameters: new_features ({None, Features or Features subclass instance, list of feature functions}) – Features to calculate from the model result. If None, no features are calculated. If list of feature functions, all will be calculated. Returns: features – Features to calculate from the model result. If None, no features are calculated. Return type: {None, Features object}

interpolation_1d
(result, feature)[source]¶ Create an interpolation for an 1D result.
Parameters: result (dict) – The model and feature results. The model and each feature each has a dictionary with the time values,
"time"
, and model/feature results,"values"
. An example:result = {model.name: {"values": array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), "time": array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])}, "feature1d": {"values": array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), "time": array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])}, "feature0d": {"values": 1, "time": np.nan}, "feature2d": {"values": array([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]), "time": array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])}, "feature_adaptive": {"values": array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), "time": array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])}, "feature_invalid": {"values": np.nan, "time": np.nan}}
Returns: interpolation – The result of the interpolation. If either the time or values contain None or numpy.nan, None is returned.
Return type: {scipy.interpolate.fitpack2.InterpolatedUnivariateSpline, None}
Raises: ValueError
– If the values of the feature are not 1D.ValueError
– If the time of the feature is not 1D.
Notes
The interpolation is performed using scipy:
InterpolatedUnivariateSpline(time, values, k=3)
.

model
¶ Model to perform uncertainty quantification on. For requirements see Model.run.
Parameters: new_model ({None, Model or Model subclass instance, model function}) – Model to perform uncertainty quantification on. Returns: model – Model to perform uncertainty quantification on. Return type: Model or Model subclass instance

run
(model_parameters)[source]¶ Run a model and calculate features from the model output, return the results.
The model is run and each feature of the model is calculated from the model output, time (time values) and values (model result). The results are interpolated if they are irregular, meaning they return a varying number of steps. An interpolation is created and added to results for the model/features that are irregular. Each instance of None is converted to
numpy.nan
.Parameters: model_parameters (dictionary) – All model parameters as a dictionary. These parameters are sent to model.run(). Returns: result – The model and feature results. The model and each feature each has a dictionary with the time values, "time"
, and model/feature results,"values"
. If an interpolation has been created, those features/model also has"interpolation"
added. An example:result = {self.model.name: {"values": array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), "time": array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])}, "feature1d": {"values": array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), "time": array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])}, "feature0d": {"values": 1, "time": np.nan}, "feature2d": {"values": array([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]]), "time": array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])}, "feature_adaptive": {"values": array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]), "time": array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]), "interpolation": scipy interpolation object}, "feature_invalid": {"values": np.nan, "time": np.nan}}
Return type: dictionary Notes
Time time and result values are calculated from the model. Then sent to model.postprocess, and the postprocessed result from model.postprocess is added to result. time and values are sent to features.preprocess and the preprocessed results is used to calculate each feature.
See also
uncertainpy.utils.utility.none_to_nan()
 Method for converting from None to NaN
uncertainpy.features.Features.preprocess()
 preprocessing model results before features are calculated
uncertainpy.models.Model.postprocess()
 posteprocessing of model results