idaholab / raven

RAVEN is a flexible and multi-purpose probabilistic risk analysis, validation and uncertainty quantification, parameter optimization, model reduction and data knowledge-discovering framework.
https://raven.inl.gov/
Apache License 2.0
216 stars 132 forks source link

[DEFECT] MultivariateNormal distribution class errors out when being loaded from a pickle file #2253

Closed j-bryan closed 6 months ago

j-bryan commented 6 months ago

Thank you for the defect report

Defect Description

The ravenframework.Distributions.MultivariateNormal class pickles successfully and appears to unpickle successfully. However, some attributes of its parent class NDimensionalDistributions like workingDir are not saved on pickling, so calling the getInitParams method of MultivariateNormal causes the unpickled distribution to error our with an AttributeError.

This bug affects the ravenframework.TSA.VARMA class.

Steps to Reproduce

The following short script reproduces the error. I ran this from the raven base directory.

import os
import pickle
import numpy as np
from ravenframework.Distributions import MultivariateNormal

# Initialize a MultivariateNormal distribution object
dist = MultivariateNormal()
dist.method = 'pca'
dist.dimension = 2
dist.rank = 2
dist.mu = np.zeros(2)
dist.covariance = np.eye(2).ravel()
dist.workingDir = os.getcwd()  # must be set or errors on pickling
dist.initializeDistribution()

# Pickle and unpickle the object
pk = pickle.dumps(dist)
dist2 = pickle.loads(pk)

# fails with "AttributeError: 'MultivariateNormal' object has no attribute 'workingDir'"
dist2.getInitParams()

Expected Behavior

All attributes set and stored by the parent class should also be recovered when pickling the child class. This should enable all class methods to execute properly after unpickling.

Screenshots and Input Files

See "Steps to Reproduce" for a minimum working example. The output of that example on my machine is shown in the included screenshot.

Screenshot 2024-01-26 at 1 53 17 PM

OS

MacOS

OS Version

14.3

Dependency Manager

CONDA

For Change Control Board: Issue Review

For Change Control Board: Issue Closure