Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 11 additions & 15 deletions flume/base_classes/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,22 @@ def __init__(

return

def reset_analysis_flags(self, it_counter):
def reset_analysis_flags(self):
"""
Resets all of the analysis flags for all analyses within the system to be False. This is done when variable values are updated, as all systems must be analyzed again to propagate chanes in design variable values.
Resets all of the analysis flags for all analyses within the system to be False. This is done when variable values are updated, as all systems must be analyzed again to propagate changes in design variable values.
"""

# If it_counter is zero, skip this setp
if it_counter == 0:
pass
else:
# Loop through each top-level analysis, resetting each analysis in the stack
for top_level in self.top_level_analysis_list:
# Loop through each top-level analysis, resetting each analysis in the stack
for top_level in self.top_level_analysis_list:

# If the stack does not exist, make it
if not hasattr(top_level, "stack"):
# Assemble the stack
top_level.stack = top_level._make_stack()
# If the stack does not exist, make it
if not hasattr(top_level, "stack"):
# Assemble the stack
top_level.stack = top_level._make_stack()

# Loop through each object within the current top-level's analysis stack and set the analyzed attribute to be False
for analysis in top_level.stack:
analysis.analyzed = False
# Loop through each object within the current top-level's analysis stack and set the analyzed attribute to be False
for analysis in top_level.stack:
analysis.analyzed = False

return

Expand Down
8 changes: 3 additions & 5 deletions flume/interfaces/paropt_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,20 +201,18 @@ def getVarsAndBounds(self, x, lb, ub):

return

def set_system_variables(self, x, it_counter):
def set_system_variables(self, x):
"""
Sets the variable values for the analysis objects contained within the System.

Parameters
----------
x : ParOptVec
Design variable vector at the current iteration
it_counter : int
Current iteration for the optimization
"""

# Since system variables are being set, all analysis objects must be recomputed
self.flume_sys.reset_analysis_flags(it_counter)
self.flume_sys.reset_analysis_flags()

# Loop through the design variables for the system and set for their components
for var in self.flume_sys.design_vars_info:
Expand Down Expand Up @@ -279,7 +277,7 @@ def evalObjCon(self, x):
)

# Set the variable values for the various analyses
self.set_system_variables(x, self.it_counter)
self.set_system_variables(x)

# Perform the analysis for the objective function
self.flume_sys.obj_analysis.analyze(debug_print=False)
Expand Down
15 changes: 5 additions & 10 deletions flume/interfaces/pyoptsparse_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,18 @@ def user_update(it_number):
# Initialize the iteration counter
self.it_counter = 0

def _set_system_variables(self, xdict: dict, it_counter: int):
def _set_system_variables(self, xdict: dict):
"""
Private method that is used to set the design variables values provided in the input dictionary into the various Flume Analysis objects.

Parameters
----------
xdict : dict
Dictionary that specifies the current design point for the optimization problem. The keys are the global variable names, and the values are the numeric values for the design variables in the System
it_counter : int
Iteration number for the optimization
"""

# Since system variables are being set, all analysis objects must be recomputed
self.flume_sys.reset_analysis_flags(it_counter)
self.flume_sys.reset_analysis_flags()

# Loop through the design variables for the system and set the values for their components
for var in self.flume_sys.design_vars_info:
Expand Down Expand Up @@ -122,7 +120,7 @@ def _objconfun(self, xdict: dict):
)

# Set the variable values for the various analyses
self._set_system_variables(xdict, self.it_counter)
self._set_system_variables(xdict)

# Perform the analysis for the objective function
self.flume_sys.obj_analysis.analyze(debug_print=False)
Expand Down Expand Up @@ -250,10 +248,6 @@ def _objconGradFun(self, xdict: dict, funcs: dict):
.deriv
)

# Apply the scaling, if necessary
if rhs != 0.0:
gradc_i /= abs(rhs)

# Assign the gradient value into the grad_vals dictionary
if i > 0:
current = grad_vals[con_name][var]
Expand Down Expand Up @@ -359,7 +353,7 @@ def _addConGroups(self, optProb: Optimization):
scale = 1.0
else:
scale = 1 / abs(rhs_val)
bound_val = np.sign(rhs_val)
bound_val = rhs_val

# Greater than inequality constraints
if direction == "geq":
Expand Down Expand Up @@ -577,6 +571,7 @@ def _update_options_output_directory(self, optimizer: str, opt: Optimizer):
options["Summary file"] = os.path.join(
self.flume_sys.log_prefix, "SNOPT_summary.out"
)
options["Verify level"] = 3
elif optimizer.lower() == "ipopt":
options = opt.getOptions()
options["output_file"] = os.path.join(
Expand Down
6 changes: 3 additions & 3 deletions flume/interfaces/scipy_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,13 @@ def _get_dv_bounds(self, x):

return bounds

def _set_system_variables(self, x, it_counter):
def _set_system_variables(self, x):
"""
Sets the variable values for the analysis objects contained within the system.
"""

# Since system variables are being set, all analysis objects must be recomputed
self.flume_sys.reset_analysis_flags(it_counter - 1)
self.flume_sys.reset_analysis_flags()

# Loop through the design variables for the system and set for their components
for var in self.flume_sys.design_vars_info:
Expand Down Expand Up @@ -229,7 +229,7 @@ def _objective_func(self, x, method):
)

# Set the variable values for the various analyses
self._set_system_variables(x, self.it_counter)
self._set_system_variables(x)

# Perform the analysis for the objective function
self.flume_sys.obj_analysis.analyze(debug_print=False)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "flume-smdo"
version = "1.0.5"
version = "1.0.6"
description = "A framework for performing forward and derivative analyses for systems following directed acylic graph structure."
readme = "README.md"
authors = [{ name = "Cameron Smith", email = "csmith763@gatech.edu" }]
Expand Down
4 changes: 3 additions & 1 deletion tests/test_paropt_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ def optimize_system(self, n_p: int, maxit: int = 100):
self.positions.set_var_values(variables={"theta": theta0, "phi": phi0})

# Optimize the problem with ParOpt's TR method
x, fstar, con_star = interface.optimize_system(algorithm="tr")
x, fstar, con_star, opt = interface.optimize_system(
algorithm="tr", check_gradients=False
)

# Check that the potential energy at the final point matches the expected value
obj_val = fstar
Expand Down
4 changes: 2 additions & 2 deletions tests/test_pyoptsparse_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def setUp(self):

# Declare the constraint
sys.declare_constraints(
global_con_name={"con.g": {"direction": "leq", "rhs": 1.0}}
global_con_name={"con.g": {"direction": "geq", "rhs": -2.0}}
)

# Store the system as an attribute
Expand Down Expand Up @@ -165,7 +165,7 @@ def test_optimization_pyoptsparse_slsqp(self):
x = np.concatenate((sol.xStar["dvs.x_dv"], sol.xStar["dvs.y_dv"]))

# Set the expected optimal values
xstar = np.array([0.786, 0.618])
xstar = np.array([1.0, 1.0])

# Check that the values match
np.testing.assert_allclose(
Expand Down
Loading