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
23 changes: 18 additions & 5 deletions mphys/network/remote_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,18 @@ def _add_objectives_from_baseline_model(self, output_dict):
)
self.derivative_coloring_num += 1

def _lower_bound_used(self, bound):
if hasattr(bound, "__len__"):
return (np.array(bound) > -1e20).any()
else:
return bound

def _upper_bound_used(self, bound):
if hasattr(bound, "__len__"):
return (np.array(bound) < 1e20).any()
else:
return bound

def _add_constraints_from_baseline_model(self, output_dict):
for con in output_dict["constraints"].keys():
self.add_output(
Expand All @@ -472,9 +484,10 @@ def _add_constraints_from_baseline_model(self, output_dict):
),
)
else:
if (
output_dict["constraints"][con]["lower"] > -1e20
and output_dict["constraints"][con]["upper"] < 1e20
if self._lower_bound_used(
output_dict["constraints"][con]["lower"]
) and self._upper_bound_used(
output_dict["constraints"][con]["upper"]
): # enforce lower and upper bounds
self.add_constraint(
con.replace(".", self.var_naming_dot_replacement),
Expand All @@ -491,8 +504,8 @@ def _add_constraints_from_baseline_model(self, output_dict):
else None
),
)
elif (
output_dict["constraints"][con]["lower"] > -1e20
elif self._lower_bound_used(
output_dict["constraints"][con]["lower"]
): # enforce lower bound
self.add_constraint(
con.replace(".", self.var_naming_dot_replacement),
Expand Down
20 changes: 16 additions & 4 deletions mphys/network/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,18 @@ def _apply_reference_vals_to_desvar_bounds(self, desvar_dict):
)
return desvar_dict

def _lower_bound_used(self, bound):
if hasattr(bound, "__len__"):
return (bound > -1e20).any()
else:
return bound

def _upper_bound_used(self, bound):
if hasattr(bound, "__len__"):
return (bound < 1e20).any()
else:
return bound

def _apply_reference_vals_to_constraint_bounds(self, constraint_dict):
if (
constraint_dict["adder"] is None and constraint_dict["scaler"] is None
Expand All @@ -287,13 +299,13 @@ def _apply_reference_vals_to_constraint_bounds(self, constraint_dict):
+ constraint_dict["ref0"]
)
else:
if constraint_dict["lower"] > -1e20:
if self._lower_bound_used(constraint_dict["lower"]):
constraint_dict["lower"] = (
constraint_dict["lower"]
* (constraint_dict["ref"] - constraint_dict["ref0"])
+ constraint_dict["ref0"]
)
if constraint_dict["upper"] < 1e20:
if self._upper_bound_used(constraint_dict["upper"]):
constraint_dict["upper"] = (
constraint_dict["upper"]
* (constraint_dict["ref"] - constraint_dict["ref0"])
Expand All @@ -306,12 +318,12 @@ def _apply_reference_vals_to_constraint_bounds(self, constraint_dict):
- constraint_dict["adder"]
)
else:
if constraint_dict["lower"] > -1e20:
if self._lower_bound_used(constraint_dict["lower"]):
constraint_dict["lower"] = (
constraint_dict["lower"] / constraint_dict["scaler"]
- constraint_dict["adder"]
)
if constraint_dict["upper"] < 1e20:
if self._upper_bound_used(constraint_dict["upper"]):
constraint_dict["upper"] = (
constraint_dict["upper"] / constraint_dict["scaler"]
- constraint_dict["adder"]
Expand Down
Loading