-
-
Notifications
You must be signed in to change notification settings - Fork 212
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
BUG:alive_progress:3.2.0 Exception problem at parallel runtime #286
Comments
When I use TQDM, I can handle this import time
from alns.stop import MaxRuntime
from numpy.random import Generator
from alns.State import State
from tqdm import tqdm
class MaxRuntimeWithProgress(MaxRuntime):
def __init__(self, max_runtime: float):
super().__init__(max_runtime)
self._pbar = None
self._elapsed = 0
self._iterations = 0
def _create_new_bar(self):
self._pbar = tqdm(total=self._max_runtime, desc="MaxRuntime", unit="s")
def __call__(self, rng: Generator, best: State, current: State) -> bool:
result = super().__call__(rng, best, current)
current_elapsed = int(time.perf_counter() - self._start_runtime)
if not self._pbar:
self._create_new_bar()
self._pbar.set_description(
f"[MaxRuntime] B:{best.objective():.2f}, C:{current.objective():.2f} I:{self._iterations}")
self._pbar.set_postfix_str(f"[{current_elapsed / self._max_runtime * 100:5.2f}%]")
if not result:
self._iterations += 1
if self._elapsed != current_elapsed:
self._pbar.update(current_elapsed - self._elapsed)
else:
self._pbar.close()
self._elapsed = current_elapsed
return result
def __getstate__(self):
# Remove the progress bar before pickling
state = self.__dict__.copy()
state['_pbar'] = None
return state
def __setstate__(self, state):
# Restore the object without the progress bar
self.__dict__.update(state) testcode: class State:
def objective(self) -> float:
return 1
state = State()
stop = MaxRuntimeWithProgress(500)
while not stop(rng=np.random.default_rng(1),best=state,current=state):
time.sleep(1) |
I hope we can fix this, because I feel close to success, perfect use already, do not want to go back to use TQDM, because I come from TQDM If there's anything I can do, I'll do my best |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
code:
This is the problem with all of the code above, they're all used in iterations, and it's the same problem when they're used alone, but there's also the problem of overwriting each other in parallel, right?
The text was updated successfully, but these errors were encountered: