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

termination - TB #169

Open
cumttc opened this issue Oct 8, 2024 · 5 comments
Open

termination - TB #169

cumttc opened this issue Oct 8, 2024 · 5 comments

Comments

@cumttc
Copy link

cumttc commented Oct 8, 2024

term_dict = {
"max_epoch": 15,
"max_time": 60,
"max_fe": 1000,
}
model.solve(xxxxxxxxxxxxx,,termination=term_dict)
2024/10/08 04:34:00 PM, INFO, mealpy.swarm_based.PSO.P_PSO [line: 162]: Solving single objective optimization problem.
2024/10/08 04:34:13 PM, INFO, mealpy.swarm_based.PSO.P_PSO [line: 270]: >>>Problem: P, Epoch: 1, Current best: 0.052123457433011944, Global best: 0.052123457433011944, Runtime: 6.29122 seconds
2024/10/08 04:34:13 PM, WARNING, mealpy.swarm_based.PSO.P_PSO [line: 199]: Stopping criterion with maximum running time/time bound (TB) (seconds) occurred. End program!

As shown above, when “max_time”: 60, according to ’https://mealpy.readthedocs.io/en/latest/pages/general/advance_guide.html#stopping-condition-termination‘, the program should stop at 600s (or epoch=15). program should stop at 60s (or epoch=15). But in fact, it only runs for 6.92s, and the stop condition output stops because of 'TB'. To add to this, the same result is achieved with “max_time”: 600.
I'm wondering if it's a usage error or if you have an error in this area.

Translated with DeepL.com (free version)

@cumttc
Copy link
Author

cumttc commented Oct 8, 2024

As I understand it, TB is limiting the duration of “solve” as a whole.

@cumttc
Copy link
Author

cumttc commented Oct 8, 2024

In short, if I need it to run for a maximum of 60s, what should I do

@thieu1995
Copy link
Owner

@cumttc,

I don't really know what is wrong with your environment. But the logic in the code is not wrong. My environment is running okay.
Are you runing on linux or window or macOS?
You can check the source code from here:
start_time: https://github.com/thieu1995/mealpy/blob/master/mealpy/optimizer.py#L192
end_time: https://github.com/thieu1995/mealpy/blob/master/mealpy/optimizer.py#L197
max_time: https://github.com/thieu1995/mealpy/blob/master/mealpy/utils/termination.py#L113
I use time.perf_counter() function to get the current time. May be with different OS system, it will perform differently.
This time-bound stopping condition is for the .solve() function. It will count when .solve() function is called and run.

@cumttc
Copy link
Author

cumttc commented Oct 9, 2024

import time
print(time.perf_counter())
a = time.perf_counter()
time.sleep(10)
b = time.perf_counter()
print(b-a)
result :
523.7991811
10.00754209999991

As a matter of fact, I also looked at your source code
You are using 'time.perf_counter()' and this function alone is fine with me.That's why I asked the question above.

environment: win10
mealpy 3.0.0
mkl 2023.1.0
numpy 1.26.4
ipykernel 6.23.0
ipython 8.13.2
scipy 1.10.1
seaborn 0.12.2
cvxpy 1.3.1

@thieu1995
Copy link
Owner

I think in previous version 3.0.0 has the problem with time bound that someone has raised the issued. So you should use the latest version 3.0.1 to avoid this bug.

pip install mealpy==3.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants