Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide Pysmo warnings in tests #1428

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions idaes/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ def _new_idaes_config_block():
"properties",
"reactions",
"ui",
"surrogate",
]
),
domain=set,
Expand All @@ -515,6 +516,7 @@ def _new_idaes_config_block():
"control_volume",
"properties",
"reactions",
"surrogate",
]
),
domain=set,
Expand Down
5 changes: 1 addition & 4 deletions idaes/core/base/flowsheet_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ def __init__(self):
self.visualize = self._visualize_null
self.installed = False
else:
# FIXME the explicit submodule import is needed because the idaes_ui doesn't import its fv submodule
# otherwise, you get "AttributeError: module 'idaes_ui' has no 'fv' attribute"
import idaes_ui.fv

import idaes_ui
self.visualize = idaes_ui.fv.visualize
self.installed = True

Expand Down
49 changes: 23 additions & 26 deletions idaes/core/surrogate/pysmo/kriging.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@

# Imports from IDAES namespace
from idaes.core.surrogate.pysmo.sampling import FeatureScaling as fs
from idaes.logger import getIdaesLogger

# Logging
_log = getIdaesLogger(__name__, tag="surrogate")


def set_log_level(level):
"""Set logging level for the default logger in this module."""
_log.setLevel(level)


class MyBounds(object):
Expand Down Expand Up @@ -145,11 +154,7 @@ def __init__(
if (
os.path.exists(fname) and overwrite is True
): # Explicit overwrite done by user
print(
"Warning:",
fname,
"already exists; previous file will be overwritten.\n",
)
_log.warning(f"'{fname}' already exists; previous file will be overwritten")
self.filename = fname
elif os.path.exists(fname) and overwrite is False: # User is not overwriting
self.filename = (
Expand All @@ -158,12 +163,8 @@ def __init__(
+ pd.Timestamp.today().strftime("%m-%d-%y_%H%M%S")
+ ".pickle"
)
print(
"Warning:",
fname,
'already exists; results will be saved to "',
self.filename,
'".\n',
_log.warning(
f"'{fname}' already exists; results will be saved to {self.filename}"
)
# self.filename = 'solution.pickle'
elif os.path.exists(fname) is False:
Expand Down Expand Up @@ -314,9 +315,9 @@ def kriging_sd(cov_inv, y_mu, ns):
# sigma_sq = np.matmul(y_mu.transpose(), np.matmul(cov_inv, y_mu)) / ns
return sigma_sq

@staticmethod
def print_fun(x, f, accepted):
print("at minimum %.4f accepted %d" % (f, int(accepted)))
# @staticmethod
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented code

# def print_fun(x, f, accepted):
# print("at minimum %.4f accepted %d" % (f, int(accepted)))

def objective_function(self, var_vector, x, y, p):
"""
Expand Down Expand Up @@ -421,7 +422,7 @@ def parameter_optimization(self, p):
bounds = tuple(bounds)

if self.num_grads:
print("Optimizing kriging parameters using L-BFGS-B algorithm...")
_log.info("Optimizing kriging parameters using L-BFGS-B algorithm...")
other_args = (self.x_data_scaled, self.y_data, p)
# opt_results = opt.minimize(self.objective_function, initial_value, args=other_args, method='L-BFGS-B', jac=self.numerical_gradient, bounds=bounds, options={'gtol': 1e-7}) #, 'disp': True})
opt_results1 = opt.minimize(
Expand All @@ -447,7 +448,7 @@ def parameter_optimization(self, p):
else:
opt_results = opt_results2
else:
print("Optimizing Kriging parameters using Basinhopping algorithm...")
_log.info("Optimizing Kriging parameters using Basinhopping algorithm...")
other_args = {
"args": (self.x_data_scaled, self.y_data, p),
"bounds": bounds,
Expand All @@ -466,7 +467,8 @@ def parameter_optimization(self, p):

def optimal_parameter_evaluation(self, var_vector, p):
"""
The optimal_parameter_evaluation method evaluates the values of all the parameters of the final Kriging model.
The optimal_parameter_evaluation method evaluates the values of all the parameters
of the final Kriging model.
For an input set of Kriging parameters var_vector and p, it:

(1) Generates the covariance matrix by calling covariance_matrix_generator
Expand Down Expand Up @@ -501,13 +503,8 @@ def optimal_parameter_evaluation(self, var_vector, p):
mean = self.kriging_mean(cov_inv, self.y_data)
y_mu = self.y_mu_calculation(self.y_data, mean)
variance = self.kriging_sd(cov_inv, y_mu, ns)
print(
"\nFinal results\n================\nTheta:",
theta,
"\nMean:",
mean,
"\nRegularization parameter:",
reg_param,
_log.info(
f"results: theta={theta} mean={mean} regularization-parameter={reg_param}"
)
return theta, reg_param, mean, variance, cov_mat, cov_inv, y_mu

Expand Down Expand Up @@ -738,9 +735,9 @@ def pickle_save(self, solutions):
try:
filehandler = open(self.filename, "wb")
pickle.dump(solutions, filehandler)
print("\nResults saved in ", str(self.filename))
_log.info(f"results saved in '{self.filename}'")
except:
raise IOError("File could not be saved.")
raise IOError(f"File '{self.filename}' could not be saved.")

@staticmethod
def pickle_load(solution_file):
Expand Down
Loading
Loading