mealpy icon indicating copy to clipboard operation
mealpy copied to clipboard

termination - TB

Open cumttc opened this issue 1 year ago • 5 comments

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 avatar Oct 08 '24 08:10 cumttc

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

cumttc avatar Oct 08 '24 08:10 cumttc

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

cumttc avatar Oct 08 '24 08:10 cumttc

@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.

thieu1995 avatar Oct 08 '24 17:10 thieu1995

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

cumttc avatar Oct 09 '24 07:10 cumttc

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

thieu1995 avatar Oct 09 '24 10:10 thieu1995