def worker_function(*args, config_path=None, config=None, **kwargs): from baselines.common.cmd_util import common_arg_parser from nvidia_gpu_scheduler.utils import log_tqdm import os from tqdm import tqdm # Display addtional info (real-time child process progress not working) arg_parser = common_arg_parser() parsed_args, parsed_unknown_args = arg_parser.parse_known_args(*args) pbar = tqdm(total=parsed_args.num_timesteps) config_filename = os.path.basename(os.path.basename(config_path)) log_tqdm(pbar, config_filename, remove=True) os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' # Execute OpenAI baselines.run module run_baseline(args) # Close tqdm and remove tqdm logs log_tqdm(pbar, config_filename, remove=True) pbar.close()
def run(steps=0, error_rate=0): pbar = tqdm(total=steps) config_filename = os.path.basename(os.path.basename(config_path)) log_tqdm(pbar, config_filename) for i in range(steps): time.sleep(1) pbar.update(n=1) log_tqdm(pbar, config_filename) log_tqdm(pbar, config_filename, remove=True) pbar.close() # intentionally trigger error trigger_error = random.random() < error_rate if trigger_error: raise ValueError('failed with %d%% probability' % (error_rate * 100)) else: print('succeeded with %d%% probability' % (100 - error_rate * 100))
def worker_function(*args, config_path=None, config=None, **kwargs): import os import random import time from tqdm import tqdm from nvidia_gpu_scheduler.utils import log_tqdm n = config.steps pbar = tqdm(total=n) config_filename = os.path.basename(os.path.basename(config_path)) log_tqdm(pbar, config_filename) for i in range(n): time.sleep(1) pbar.update(n=1) log_tqdm(pbar, config_filename) log_tqdm(pbar, config_filename, remove=True) pbar.close() # intentionally trigger with 50% probability trigger_error = random.random() < config.error_rate if trigger_error: raise ValueError('failed with 50% probability') else: print('succeeded with 50% probability')