-
Notifications
You must be signed in to change notification settings - Fork 248
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
[OptApp] Small fixes to RGP, Conv Crit, NLOPT test #12844
Open
Igarizza
wants to merge
4
commits into
master
Choose a base branch
from
optapp/small-rgp-fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+175
−54
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,26 @@ def CreateConvergenceCriteria(parameters: Kratos.Parameters, optimization_proble | |
raise RuntimeError(f"CreateConvergenceCriteria: unsupported convergence type {type}.") | ||
|
||
class MaxIterConvCriterion: | ||
""" | ||
A convergence criterion class that checks if the maximum number of iterations has been reached. | ||
|
||
Methods | ||
------- | ||
GetDefaultParameters(): | ||
Returns the default parameters for the convergence criterion. | ||
|
||
__init__(parameters: Kratos.Parameters, optimization_problem: OptimizationProblem): | ||
Initializes the convergence criterion with the given parameters and optimization problem. | ||
|
||
IsMaxIterationsReached(): | ||
Checks if the maximum number of iterations has been reached. | ||
|
||
IsConverged(search_direction=None) -> bool: | ||
Checks if the optimization problem has converged based on the maximum number of iterations. | ||
|
||
GetInfo() -> dict: | ||
Returns a dictionary with information about the current state of convergence. | ||
""" | ||
Comment on lines
+25
to
+44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @matekelemen, does this way of writing method docs within the class doc works? can doxygen decipher this and put it to correct method? |
||
@classmethod | ||
def GetDefaultParameters(cls): | ||
return Kratos.Parameters("""{ | ||
|
@@ -34,6 +54,9 @@ def __init__(self, parameters: Kratos.Parameters, optimization_problem: Optimiza | |
self.__max_iter = parameters["max_iter"].GetInt() | ||
self.__optimization_problem = optimization_problem | ||
|
||
def IsMaxIterationsReached(self): | ||
return self.__optimization_problem.GetStep() >= self.__max_iter | ||
|
||
@time_decorator() | ||
def IsConverged(self, search_direction=None) -> bool: | ||
iter = self.__optimization_problem.GetStep() | ||
|
@@ -50,6 +73,26 @@ def GetInfo(self) -> dict: | |
return info | ||
|
||
class L2ConvCriterion: | ||
""" | ||
A class to check the convergence of an optimization problem using the L2 norm criterion. | ||
|
||
Methods | ||
------- | ||
GetDefaultParameters(): | ||
Returns the default parameters for the L2ConvCriterion. | ||
|
||
__init__(parameters: Kratos.Parameters, optimization_problem: OptimizationProblem): | ||
Initializes the L2ConvCriterion with given parameters and optimization problem. | ||
|
||
IsMaxIterationsReached() -> bool: | ||
Checks if the maximum number of iterations has been reached. | ||
|
||
IsConverged() -> bool: | ||
Checks if the optimization problem has converged based on the L2 norm of the search direction. | ||
|
||
GetInfo() -> dict: | ||
Returns a dictionary with information about the current state of convergence. | ||
""" | ||
@classmethod | ||
def GetDefaultParameters(cls): | ||
return Kratos.Parameters("""{ | ||
|
@@ -64,6 +107,9 @@ def __init__(self, parameters: Kratos.Parameters, optimization_problem: Optimiza | |
self.__optimization_problem = optimization_problem | ||
self.__tolerance = parameters["tolerance"].GetDouble() | ||
|
||
def IsMaxIterationsReached(self): | ||
return self.__optimization_problem.GetStep() >= self.__max_iter | ||
|
||
@time_decorator() | ||
def IsConverged(self) -> bool: | ||
iter = self.__optimization_problem.GetStep() | ||
|
@@ -90,6 +136,27 @@ def GetInfo(self) -> dict: | |
return info | ||
|
||
class AverageAbsoluteImprovement: | ||
""" | ||
A class to monitor the convergence of an optimization problem based on the average absolute improvement | ||
of a tracked value over a specified number of iterations. | ||
|
||
Methods | ||
------- | ||
GetDefaultParameters(): | ||
Returns the default parameters for the convergence criteria. | ||
|
||
__init__(parameters: Kratos.Parameters, optimization_problem: OptimizationProblem): | ||
Initializes the convergence criteria with the given parameters and optimization problem. | ||
|
||
IsMaxIterationsReached() -> bool: | ||
Checks if the maximum number of iterations has been reached. | ||
|
||
IsConverged() -> bool: | ||
Checks if the optimization problem has converged based on the average absolute improvement. | ||
|
||
GetInfo() -> dict: | ||
Returns a dictionary with information about the current state of the convergence criteria. | ||
""" | ||
@classmethod | ||
def GetDefaultParameters(cls): | ||
return Kratos.Parameters("""{ | ||
|
@@ -108,6 +175,9 @@ def __init__(self, parameters: Kratos.Parameters, optimization_problem: Optimiza | |
self.__abs_value_change = [] | ||
self.value = None | ||
|
||
def IsMaxIterationsReached(self): | ||
return self.__optimization_problem.GetStep() >= self.__max_iter | ||
|
||
@time_decorator() | ||
def IsConverged(self) -> bool: | ||
iter = self.__optimization_problem.GetStep() | ||
|
@@ -147,6 +217,26 @@ def GetInfo(self) -> dict: | |
return info | ||
|
||
class TargetValueCriterion: | ||
""" | ||
A class to check the convergence of an optimization problem based on a target value criterion. | ||
|
||
Methods | ||
------- | ||
GetDefaultParameters(): | ||
Returns the default parameters for the criterion. | ||
|
||
__init__(parameters: Kratos.Parameters, optimization_problem: OptimizationProblem): | ||
Initializes the criterion with given parameters and optimization problem. | ||
|
||
IsMaxIterationsReached() -> bool: | ||
Checks if the maximum number of iterations has been reached. | ||
|
||
IsConverged() -> bool: | ||
Checks if the optimization problem has converged based on the target value. | ||
|
||
GetInfo() -> dict: | ||
Returns a dictionary with information about the current state of convergence. | ||
""" | ||
@classmethod | ||
def GetDefaultParameters(cls): | ||
return Kratos.Parameters("""{ | ||
|
@@ -161,6 +251,9 @@ def __init__(self, parameters: Kratos.Parameters, optimization_problem: Optimiza | |
self.__optimization_problem = optimization_problem | ||
self.__target_value = parameters["target_value"].GetDouble() | ||
|
||
def IsMaxIterationsReached(self): | ||
return self.__optimization_problem.GetStep() >= self.__max_iter | ||
|
||
@time_decorator() | ||
def IsConverged(self) -> bool: | ||
iter = self.__optimization_problem.GetStep() | ||
|
@@ -202,6 +295,9 @@ def __init__(self, parameters: Kratos.Parameters, optimization_problem: Optimiza | |
self.__target_scaling_factor = parameters["target_scaling_factor"].GetDouble() | ||
self.__machine_precision = parameters["machine_precision"].GetDouble() | ||
|
||
def IsMaxIterationsReached(self): | ||
return self.__optimization_problem.GetStep() >= self.__max_iter | ||
|
||
@time_decorator() | ||
def IsConverged(self) -> bool: | ||
iter = self.__optimization_problem.GetStep() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...ionApplication/tests/algorithm_tests/nlopt_tests/mma_shell_thickness_opt/summary_orig.csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Optimization problem ascii output | ||
# Kratos version: not_given | ||
# Timestamp : not_specified | ||
# ----------------------------------------------- | ||
# --------------- Initial values ---------------- | ||
# mass_shell: | ||
# initial_value: 3.401453818e+03 | ||
# ------------ End of initial values ------------ | ||
# ----------------------------------------------- | ||
# ------------ Start of step values ------------- | ||
# Headers: | ||
# STEP, mass_shell:value, mass_shell:rel_change [%], mass_shell:abs_change [%] | ||
0, 3.401453818e+03, 0.000000000e+00, 0.000000000e+00 | ||
1, 4.902371672e+02, -8.558742252e+01, -8.558742252e+01 | ||
2, 4.901410945e+02, -1.959717609e-02, -8.559024697e+01 | ||
3, 4.900978469e+02, -8.823507807e-03, -8.559151842e+01 | ||
4, 4.900779556e+02, -4.058629529e-03, -8.559210321e+01 | ||
# End of file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice :)