gurudesh/pytracebugs huggingface dataset:
# Buggy code
def _clean_log(obj):
    # Fixes https://github.com/ray-project/ray/issues/10631
    if isinstance(obj, dict):
        return {k: _clean_log(v) for k, v in obj.items()}
    elif isinstance(obj, list):
        return [_clean_log(v) for v in obj]

    # Else
    try:
        pickle.dumps(obj)
        return obj
    except Exception:
        # give up, similar to _SafeFallBackEncoder
        return str(obj)


# Traceback (yaml.representer.RepresenterError)
Process _WandbLoggingProcess-1:
Traceback (most recent call last):
File "/usr/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
self.run()
File "[...]/ray/tune/integration/wandb.py", line 127, in run
wandb.init(*self.args, **self.kwargs)
File "[...]/wandb/__init__.py", line 1303, in init
as_defaults=not allow_val_change)
File "[...]/wandb/wandb_config.py", line 333, in _update
self.persist()
File "[...]/wandb/wandb_config.py", line 238, in persist
conf_file.write(str(self))
File "[...]/wandb/wandb_config.py", line 374, in __str__
allow_unicode=True, encoding='utf-8')
File "[...]/yaml/__init__.py", line 290, in dump
return dump_all([data], stream, Dumper=Dumper, **kwds)
File "[...]/yaml/__init__.py", line 278, in dump_all
dumper.represent(data)
File "[...]/yaml/representer.py", line 27, in represent
node = self.represent_data(data)
File "[...]/yaml/representer.py", line 48, in represent_data
node = self.yaml_representers[data_types[0]](self, data)
File "[...]/yaml/representer.py", line 207, in represent_dict
return self.represent_mapping('tag:yaml.org,2002:map', data)
File "[...]/yaml/representer.py", line 118, in represent_mapping
node_value = self.represent_data(item_value)
File "[...]/yaml/representer.py", line 48, in represent_data
node = self.yaml_representers[data_types[0]](self, data)
File "[...]/yaml/representer.py", line 207, in represent_dict
return self.represent_mapping('tag:yaml.org,2002:map', data)
File "[...]/yaml/representer.py", line 118, in represent_mapping
node_value = self.represent_data(item_value)
File "[...]/yaml/representer.py", line 58, in represent_data
node = self.yaml_representers[None](self, data)
File "[...]/yaml/representer.py", line 231, in represent_undefined
raise RepresenterError("cannot represent an object", data)
yaml.representer.RepresenterError: ('cannot represent an object', <class '__main__.MyCallbacks'>)

# Fixed code
def _clean_log(obj):
    # Fixes https://github.com/ray-project/ray/issues/10631
    if isinstance(obj, dict):
        return {k: _clean_log(v) for k, v in obj.items()}
    elif isinstance(obj, list):
        return [_clean_log(v) for v in obj]

    # Else
    try:
        pickle.dumps(obj)
        yaml.dump(
            obj,
            Dumper=yaml.SafeDumper,
            default_flow_style=False,
            allow_unicode=True,
            encoding="utf-8",
        )
        return obj
    except Exception:
        # give up, similar to _SafeFallBackEncoder
        return str(obj)
# Buggy code
def _handle_result(self, result):
    config_update = result.get("config", {}).copy()
    log = {}
    flat_result = flatten_dict(result, delimiter="/")

    for k, v in flat_result.items():
        if any(k.startswith(item + "/") or k == item for item in self._to_config):
            config_update[k] = v
        elif any(k.startswith(item + "/") or k == item for item in self._exclude):
            continue
        elif not isinstance(v, Number):
            continue
        else:
            log[k] = v

    config_update.pop("callbacks", None)  # Remove callbacks
    return log, config_update


# Traceback (yaml.representer.RepresenterError)
Process _WandbLoggingProcess-1:
Traceback (most recent call last):
File "/usr/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
self.run()
File "[...]/ray/tune/integration/wandb.py", line 127, in run
wandb.init(*self.args, **self.kwargs)
File "[...]/wandb/__init__.py", line 1303, in init
as_defaults=not allow_val_change)
File "[...]/wandb/wandb_config.py", line 333, in _update
self.persist()
File "[...]/wandb/wandb_config.py", line 238, in persist
conf_file.write(str(self))
File "[...]/wandb/wandb_config.py", line 374, in __str__
allow_unicode=True, encoding='utf-8')
File "[...]/yaml/__init__.py", line 290, in dump
return dump_all([data], stream, Dumper=Dumper, **kwds)
File "[...]/yaml/__init__.py", line 278, in dump_all
dumper.represent(data)
File "[...]/yaml/representer.py", line 27, in represent
node = self.represent_data(data)
File "[...]/yaml/representer.py", line 48, in represent_data
node = self.yaml_representers[data_types[0]](self, data)
File "[...]/yaml/representer.py", line 207, in represent_dict
return self.represent_mapping('tag:yaml.org,2002:map', data)
File "[...]/yaml/representer.py", line 118, in represent_mapping
node_value = self.represent_data(item_value)
File "[...]/yaml/representer.py", line 48, in represent_data
node = self.yaml_representers[data_types[0]](self, data)
File "[...]/yaml/representer.py", line 207, in represent_dict
return self.represent_mapping('tag:yaml.org,2002:map', data)
File "[...]/yaml/representer.py", line 118, in represent_mapping
node_value = self.represent_data(item_value)
File "[...]/yaml/representer.py", line 58, in represent_data
node = self.yaml_representers[None](self, data)
File "[...]/yaml/representer.py", line 231, in represent_undefined
raise RepresenterError("cannot represent an object", data)
yaml.representer.RepresenterError: ('cannot represent an object', <class '__main__.MyCallbacks'>)

# Fixed code
def _handle_result(self, result):
    config_update = result.get("config", {}).copy()
    log = {}
    flat_result = flatten_dict(result, delimiter="/")

    for k, v in flat_result.items():
        if any(k.startswith(item + "/") or k == item for item in self._to_config):
            config_update[k] = v
        elif any(k.startswith(item + "/") or k == item for item in self._exclude):
            continue
        elif not _is_allowed_type(v):
            continue
        else:
            log[k] = v

    config_update.pop("callbacks", None)  # Remove callbacks
    return log, config_update
# Buggy code
def memory(address, redis_password):
    """Print object references held in a Ray cluster."""
    if not address:
        address = services.find_redis_address_or_die()
    logger.info(f"Connecting to Ray instance at {address}.")
    ray.init(address=address, redis_password=redis_password)
    print(ray.internal.internal_api.memory_summary())


# Traceback (TypeError)
$ ray memory
2020-09-09 05:24:50,248 INFO scripts.py:1474 -- Connecting to Ray instance at 172.31.56.46:6379.
Traceback (most recent call last):
File "/home/ubuntu/anaconda3/bin/ray", line 8, in <module>
sys.exit(main())
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/ray/scripts/scripts.py", line 1602, in main
return cli()
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/ubuntu/anaconda3/lib/python3.6/site-packages/ray/scripts/scripts.py", line 1475, in memory
ray.init(address=address, redis_password=redis_password)
TypeError: init() got an unexpected keyword argument 'redis_password'

# Fixed code
def memory(address, redis_password):
    """Print object references held in a Ray cluster."""
    if not address:
        address = services.find_redis_address_or_die()
    logger.info(f"Connecting to Ray instance at {address}.")
    ray.init(address=address, _redis_password=redis_password)
    print(ray.internal.internal_api.memory_summary())
# Buggy code
def run_rsync_up(self, source, target):
    if target.startswith("~"):
        target = "/root" + target[1:]

    try:
        self.process_runner.check_call(
            [
                KUBECTL_RSYNC,
                "-avz",
                source,
                "{}@{}:{}".format(self.node_id, self.namespace, target),
            ]
        )
    except Exception as e:
        logger.warning(
            self.log_prefix
            + "rsync failed: '{}'. Falling back to 'kubectl cp'".format(e)
        )
        self.process_runner.check_call(
            self.kubectl
            + ["cp", source, "{}/{}:{}".format(self.namespace, self.node_id, target)]
        )


# Traceback (ray.tune.error.TuneError)
2020-07-17 21:53:48,101	ERROR trial_runner.py:550 -- Trial TrainExample_fd24b_00001: Error handling checkpoint /root/ray_results/TrainExample/TrainExample_1_randomforestclassifier__n_estimators=5_2020-07-17_21-53-462l3hkjfs/checkpoint_1/
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/ray/tune/trial_runner.py", line 546, in _process_trial_save
trial.on_checkpoint(trial.saving_to)
File "/opt/conda/lib/python3.6/site-packages/ray/tune/trial.py", line 448, in on_checkpoint
self, checkpoint.value))
ray.tune.error.TuneError: Trial TrainExample_fd24b_00001: Checkpoint path /root/ray_results/TrainExample/TrainExample_1_randomforestclassifier__n_estimators=5_2020-07-17_21-53-462l3hkjfs/checkpoint_1/ not found after successful sync down.

# Fixed code
def run_rsync_up(self, source, target):
    if target.startswith("~"):
        target = "/root" + target[1:]

    try:
        self.process_runner.check_call(
            [
                KUBECTL_RSYNC,
                "-avz",
                source,
                "{}@{}:{}".format(self.node_id, self.namespace, target),
            ]
        )
    except Exception as e:
        logger.warning(
            self.log_prefix
            + "rsync failed: '{}'. Falling back to 'kubectl cp'".format(e)
        )
        self.run_cp_up(source, target)
# Buggy code
def run_rsync_down(self, source, target):
    if target.startswith("~"):
        target = "/root" + target[1:]

    try:
        self.process_runner.check_call(
            [
                KUBECTL_RSYNC,
                "-avz",
                "{}@{}:{}".format(self.node_id, self.namespace, source),
                target,
            ]
        )
    except Exception as e:
        logger.warning(
            self.log_prefix
            + "rsync failed: '{}'. Falling back to 'kubectl cp'".format(e)
        )
        self.process_runner.check_call(
            self.kubectl
            + ["cp", "{}/{}:{}".format(self.namespace, self.node_id, source), target]
        )


# Traceback (ray.tune.error.TuneError)
2020-07-17 21:53:48,101	ERROR trial_runner.py:550 -- Trial TrainExample_fd24b_00001: Error handling checkpoint /root/ray_results/TrainExample/TrainExample_1_randomforestclassifier__n_estimators=5_2020-07-17_21-53-462l3hkjfs/checkpoint_1/
Traceback (most recent call last):
File "/opt/conda/lib/python3.6/site-packages/ray/tune/trial_runner.py", line 546, in _process_trial_save
trial.on_checkpoint(trial.saving_to)
File "/opt/conda/lib/python3.6/site-packages/ray/tune/trial.py", line 448, in on_checkpoint
self, checkpoint.value))
ray.tune.error.TuneError: Trial TrainExample_fd24b_00001: Checkpoint path /root/ray_results/TrainExample/TrainExample_1_randomforestclassifier__n_estimators=5_2020-07-17_21-53-462l3hkjfs/checkpoint_1/ not found after successful sync down.

# Fixed code
def run_rsync_down(self, source, target):
    if target.startswith("~"):
        target = "/root" + target[1:]

    try:
        self.process_runner.check_call(
            [
                KUBECTL_RSYNC,
                "-avz",
                "{}@{}:{}".format(self.node_id, self.namespace, source),
                target,
            ]
        )
    except Exception as e:
        logger.warning(
            self.log_prefix
            + "rsync failed: '{}'. Falling back to 'kubectl cp'".format(e)
        )
        self.run_cp_down(source, target)
# Buggy code
def group(self, msg, *args, **kwargs):
    """Print a group title in a special color and start an indented block.

    For arguments, see `_format_msg`.
    """
    self._print(_format_msg(cf.cornflowerBlue(msg), *args, **kwargs))

    return self.indented()


# Traceback (ValueError)
Error executing: unmatched '{' in format spec

Exception in thread Thread-2:
Traceback (most recent call last):
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/updater.py", line 74, in run
self.do_update()
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/updater.py", line 285, in do_update
cmd_to_print, _numbered=("()", i, total))
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 323, in print
self._print(_format_msg(msg, *args, **kwargs))
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 96, in _format_msg
return numbering_str + msg.format(*args, **kwargs) + tags_str
ValueError: unmatched '{' in format spec

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/allenyin/anaconda3/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/updater.py", line 95, in run
cli_logger.error(str(e))  # todo: handle this better somehow?
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 316, in error
self._print(_format_msg(cf.red(msg), *args, **kwargs))
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 96, in _format_msg
return numbering_str + msg.format(*args, **kwargs) + tags_str
ValueError: expected '}' before end of string

# Fixed code
def group(self, msg, *args, **kwargs):
    """Print a group title in a special color and start an indented block.

    For arguments, see `_format_msg`.
    """
    self.print(cf.cornflowerBlue(msg), *args, **kwargs)

    return self.indented()
# Buggy code
def verbatim_error_ctx(self, msg, *args, **kwargs):
    """Context manager for printing multi-line error messages.

    Displays a start sequence "!!! {optional message}"
    and a matching end sequence "!!!".

    The string "!!!" can be used as a "tombstone" for searching.

    For arguments, see `_format_msg`.
    """
    cli_logger = self

    class VerbatimErorContextManager:
        def __enter__(self):
            cli_logger.error(cf.bold("!!! ") + msg, *args, **kwargs)

        def __exit__(self, type, value, tb):
            cli_logger.error(cf.bold("!!!"))

    return VerbatimErorContextManager()


# Traceback (ValueError)
Error executing: unmatched '{' in format spec

Exception in thread Thread-2:
Traceback (most recent call last):
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/updater.py", line 74, in run
self.do_update()
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/updater.py", line 285, in do_update
cmd_to_print, _numbered=("()", i, total))
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 323, in print
self._print(_format_msg(msg, *args, **kwargs))
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 96, in _format_msg
return numbering_str + msg.format(*args, **kwargs) + tags_str
ValueError: unmatched '{' in format spec

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/allenyin/anaconda3/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/updater.py", line 95, in run
cli_logger.error(str(e))  # todo: handle this better somehow?
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 316, in error
self._print(_format_msg(cf.red(msg), *args, **kwargs))
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 96, in _format_msg
return numbering_str + msg.format(*args, **kwargs) + tags_str
ValueError: expected '}' before end of string

# Fixed code
def verbatim_error_ctx(self, msg, *args, **kwargs):
    """Context manager for printing multi-line error messages.

    Displays a start sequence "!!! {optional message}"
    and a matching end sequence "!!!".

    The string "!!!" can be used as a "tombstone" for searching.

    For arguments, see `_format_msg`.
    """
    cli_logger = self

    class VerbatimErorContextManager:
        def __enter__(self):
            cli_logger.error(cf.bold("!!! ") + "{}", msg, *args, **kwargs)

        def __exit__(self, type, value, tb):
            cli_logger.error(cf.bold("!!!"))

    return VerbatimErorContextManager()
# Buggy code
def __enter__(self):
    cli_logger.error(cf.bold("!!! ") + msg, *args, **kwargs)


# Traceback (ValueError)
Error executing: unmatched '{' in format spec

Exception in thread Thread-2:
Traceback (most recent call last):
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/updater.py", line 74, in run
self.do_update()
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/updater.py", line 285, in do_update
cmd_to_print, _numbered=("()", i, total))
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 323, in print
self._print(_format_msg(msg, *args, **kwargs))
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 96, in _format_msg
return numbering_str + msg.format(*args, **kwargs) + tags_str
ValueError: unmatched '{' in format spec

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/allenyin/anaconda3/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/updater.py", line 95, in run
cli_logger.error(str(e))  # todo: handle this better somehow?
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 316, in error
self._print(_format_msg(cf.red(msg), *args, **kwargs))
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 96, in _format_msg
return numbering_str + msg.format(*args, **kwargs) + tags_str
ValueError: expected '}' before end of string

# Fixed code
def __enter__(self):
    cli_logger.error(cf.bold("!!! ") + "{}", msg, *args, **kwargs)
# Buggy code
def labeled_value(self, key, msg, *args, **kwargs):
    """Displays a key-value pair with special formatting.

    Args:
        key (str): Label that is prepended to the message.

    For other arguments, see `_format_msg`.
    """
    self._print(cf.cyan(key) + ": " + _format_msg(cf.bold(msg), *args, **kwargs))


# Traceback (ValueError)
Error executing: unmatched '{' in format spec

Exception in thread Thread-2:
Traceback (most recent call last):
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/updater.py", line 74, in run
self.do_update()
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/updater.py", line 285, in do_update
cmd_to_print, _numbered=("()", i, total))
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 323, in print
self._print(_format_msg(msg, *args, **kwargs))
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 96, in _format_msg
return numbering_str + msg.format(*args, **kwargs) + tags_str
ValueError: unmatched '{' in format spec

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/allenyin/anaconda3/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/updater.py", line 95, in run
cli_logger.error(str(e))  # todo: handle this better somehow?
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 316, in error
self._print(_format_msg(cf.red(msg), *args, **kwargs))
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 96, in _format_msg
return numbering_str + msg.format(*args, **kwargs) + tags_str
ValueError: expected '}' before end of string

# Fixed code
def labeled_value(self, key, msg, *args, **kwargs):
    """Displays a key-value pair with special formatting.

    Args:
        key (str): Label that is prepended to the message.

    For other arguments, see `_format_msg`.
    """
    if self.old_style:
        return

    self._print(cf.cyan(key) + ": " + _format_msg(cf.bold(msg), *args, **kwargs))
# Buggy code
def success(self, msg, *args, **kwargs):
    """Prints a formatted success message.

    For arguments, see `_format_msg`.
    """
    self._print(_format_msg(cf.green(msg), *args, **kwargs))


# Traceback (ValueError)
Error executing: unmatched '{' in format spec

Exception in thread Thread-2:
Traceback (most recent call last):
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/updater.py", line 74, in run
self.do_update()
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/updater.py", line 285, in do_update
cmd_to_print, _numbered=("()", i, total))
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 323, in print
self._print(_format_msg(msg, *args, **kwargs))
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 96, in _format_msg
return numbering_str + msg.format(*args, **kwargs) + tags_str
ValueError: unmatched '{' in format spec

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/allenyin/anaconda3/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/updater.py", line 95, in run
cli_logger.error(str(e))  # todo: handle this better somehow?
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 316, in error
self._print(_format_msg(cf.red(msg), *args, **kwargs))
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 96, in _format_msg
return numbering_str + msg.format(*args, **kwargs) + tags_str
ValueError: expected '}' before end of string

# Fixed code
def success(self, msg, *args, **kwargs):
    """Prints a formatted success message.

    For arguments, see `_format_msg`.
    """
    self.print(cf.green(msg), *args, **kwargs)
# Buggy code
def warning(self, msg, *args, **kwargs):
    """Prints a formatted warning message.

    For arguments, see `_format_msg`.
    """
    self._print(_format_msg(cf.yellow(msg), *args, **kwargs))


# Traceback (ValueError)
Error executing: unmatched '{' in format spec

Exception in thread Thread-2:
Traceback (most recent call last):
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/updater.py", line 74, in run
self.do_update()
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/updater.py", line 285, in do_update
cmd_to_print, _numbered=("()", i, total))
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 323, in print
self._print(_format_msg(msg, *args, **kwargs))
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 96, in _format_msg
return numbering_str + msg.format(*args, **kwargs) + tags_str
ValueError: unmatched '{' in format spec

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/allenyin/anaconda3/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/updater.py", line 95, in run
cli_logger.error(str(e))  # todo: handle this better somehow?
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 316, in error
self._print(_format_msg(cf.red(msg), *args, **kwargs))
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 96, in _format_msg
return numbering_str + msg.format(*args, **kwargs) + tags_str
ValueError: expected '}' before end of string

# Fixed code
def warning(self, msg, *args, **kwargs):
    """Prints a formatted warning message.

    For arguments, see `_format_msg`.
    """
    self.print(cf.yellow(msg), *args, **kwargs)
# Buggy code
def error(self, msg, *args, **kwargs):
    """Prints a formatted error message.

    For arguments, see `_format_msg`.
    """
    self._print(_format_msg(cf.red(msg), *args, **kwargs))


# Traceback (ValueError)
Error executing: unmatched '{' in format spec

Exception in thread Thread-2:
Traceback (most recent call last):
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/updater.py", line 74, in run
self.do_update()
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/updater.py", line 285, in do_update
cmd_to_print, _numbered=("()", i, total))
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 323, in print
self._print(_format_msg(msg, *args, **kwargs))
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 96, in _format_msg
return numbering_str + msg.format(*args, **kwargs) + tags_str
ValueError: unmatched '{' in format spec

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/allenyin/anaconda3/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/updater.py", line 95, in run
cli_logger.error(str(e))  # todo: handle this better somehow?
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 316, in error
self._print(_format_msg(cf.red(msg), *args, **kwargs))
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 96, in _format_msg
return numbering_str + msg.format(*args, **kwargs) + tags_str
ValueError: expected '}' before end of string

# Fixed code
def error(self, msg, *args, **kwargs):
    """Prints a formatted error message.

    For arguments, see `_format_msg`.
    """
    self.print(cf.red(msg), *args, **kwargs)
# Buggy code
def print(self, msg, *args, **kwargs):
    """Prints a message.

    For arguments, see `_format_msg`.
    """
    self._print(_format_msg(msg, *args, **kwargs))


# Traceback (ValueError)
Error executing: unmatched '{' in format spec

Exception in thread Thread-2:
Traceback (most recent call last):
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/updater.py", line 74, in run
self.do_update()
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/updater.py", line 285, in do_update
cmd_to_print, _numbered=("()", i, total))
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 323, in print
self._print(_format_msg(msg, *args, **kwargs))
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 96, in _format_msg
return numbering_str + msg.format(*args, **kwargs) + tags_str
ValueError: unmatched '{' in format spec

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/Users/allenyin/anaconda3/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/updater.py", line 95, in run
cli_logger.error(str(e))  # todo: handle this better somehow?
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 316, in error
self._print(_format_msg(cf.red(msg), *args, **kwargs))
File "/Users/allenyin/anaconda3/lib/python3.7/site-packages/ray/autoscaler/cli_logger.py", line 96, in _format_msg
return numbering_str + msg.format(*args, **kwargs) + tags_str
ValueError: expected '}' before end of string

# Fixed code
def print(self, msg, *args, **kwargs):
    """Prints a message.

    For arguments, see `_format_msg`.
    """
    if self.old_style:
        return

    self._print(_format_msg(msg, *args, **kwargs))
# Buggy code
def stats(self):
    if not self.count:
        quantiles = []
    else:
        quantiles = np.percentile(
            self.items[: self.count], [0, 10, 50, 90, 100]
        ).tolist()
    return {
        self.name + "_count": int(self.count),
        self.name + "_mean": float(np.mean(self.items[: self.count])),
        self.name + "_std": float(np.std(self.items[: self.count])),
        self.name + "_quantiles": quantiles,
    }


# Traceback (FloatingPointError)
/home/axion/anaconda3/envs/trading/lib/python3.7/site-packages/numpy/core/fromnumeric.py:3257: RuntimeWarning: Mean of empty slice.
out=out, **kwargs)
Traceback (most recent call last):
File "/home/axion/anaconda3/envs/trading/lib/python3.7/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/home/axion/anaconda3/envs/trading/lib/python3.7/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/axion/git/jengu/jengu/train/impala_train.py", line 43, in <module>
result = agent.train()
File "/home/axion/anaconda3/envs/trading/lib/python3.7/site-packages/ray/rllib/agents/trainer.py", line 505, in train
raise e
File "/home/axion/anaconda3/envs/trading/lib/python3.7/site-packages/ray/rllib/agents/trainer.py", line 491, in train
result = Trainable.train(self)
File "/home/axion/anaconda3/envs/trading/lib/python3.7/site-packages/ray/tune/trainable.py", line 261, in train
result = self._train()
File "/home/axion/anaconda3/envs/trading/lib/python3.7/site-packages/ray/rllib/agents/trainer_template.py", line 161, in _train
res = self.collect_metrics()
File "/home/axion/anaconda3/envs/trading/lib/python3.7/site-packages/ray/rllib/agents/trainer.py", line 899, in collect_metrics
selected_workers=selected_workers)
File "/home/axion/anaconda3/envs/trading/lib/python3.7/site-packages/ray/rllib/optimizers/policy_optimizer.py", line 113, in collect_metrics
res.update(info=self.stats())
File "/home/axion/anaconda3/envs/trading/lib/python3.7/site-packages/ray/rllib/optimizers/async_samples_optimizer.py", line 166, in stats
stats["learner_queue"] = self.learner.learner_queue_size.stats()
File "/home/axion/anaconda3/envs/trading/lib/python3.7/site-packages/ray/rllib/utils/window_stat.py", line 25, in stats
self.name + "_mean": float(np.mean(self.items[:self.count])),
File "<__array_function__ internals>", line 6, in mean
File "/home/axion/anaconda3/envs/trading/lib/python3.7/site-packages/numpy/core/fromnumeric.py", line 3257, in mean
out=out, **kwargs)
File "/home/axion/anaconda3/envs/trading/lib/python3.7/site-packages/numpy/core/_methods.py", line 161, in _mean
ret = ret.dtype.type(ret / rcount)
FloatingPointError: invalid value encountered in double_scalars

# Fixed code
def stats(self):
    if not self.count:
        _quantiles = []
    else:
        _quantiles = np.nanpercentile(
            self.items[: self.count], [0, 10, 50, 90, 100]
        ).tolist()
    return {
        self.name + "_count": int(self.count),
        self.name + "_mean": float(np.nanmean(self.items[: self.count])),
        self.name + "_std": float(np.nanstd(self.items[: self.count])),
        self.name + "_quantiles": _quantiles,
    }
# Buggy code
def get_command_runner(
    self,
    log_prefix,
    node_id,
    auth_config,
    cluster_name,
    process_runner,
    use_internal_ip,
):
    return KubernetesCommandRunner(
        log_prefix, self.namespace, node_id, auth_config, process_runner
    )


# Traceback (AssertionError)
ray up config/example_full.yaml
2020-06-08 01:13:10,526 INFO config.py:143 -- _configure_iam_role: Role not specified for head node, using arn:aws:iam::<redacted>:instance-profile/ray-autoscaler-v1
2020-06-08 01:13:11,089 INFO config.py:194 -- _configure_key_pair: KeyName not specified for nodes, using ray-autoscaler_us-west-2
2020-06-08 01:13:11,365 INFO config.py:235 -- _configure_subnet: SubnetIds not specified for head node, using [('subnet-<redacted>', 'us-west-2b'), ('subnet-<redacted>', 'us-west-2a')]
2020-06-08 01:13:11,366 INFO config.py:241 -- _configure_subnet: SubnetId not specified for workers, using [('subnet-<redacted>', 'us-west-2b'), ('subnet-<redacted>', 'us-west-2a')]
2020-06-08 01:13:11,725 INFO config.py:261 -- _configure_security_group: SecurityGroupIds not specified for head node, using ray-autoscaler-default (sg-<redacted>)
2020-06-08 01:13:11,725 INFO config.py:268 -- _configure_security_group: SecurityGroupIds not specified for workers, using ray-autoscaler-default (sg-<redacted>)
This will restart cluster services [y/N]: y
2020-06-08 01:13:15,214 INFO commands.py:238 -- get_or_create_head_node: Updating files on head node...
2020-06-08 01:13:15,215 INFO updater.py:379 -- NodeUpdater: i-<redacted>: Updating to <redacted>
2020-06-08 01:13:15,216 INFO updater.py:423 -- NodeUpdater: i-<redacted>: Waiting for remote shell...
2020-06-08 01:13:15,422 INFO log_timer.py:22 -- AWSNodeProvider: Set tag ray-node-status=waiting-for-ssh on ['i-<redacted>
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/home/richard/improbable/ray/python/ray/autoscaler/updater.py", line 383, in run
self.do_update()
File "/home/richard/improbable/ray/python/ray/autoscaler/updater.py", line 450, in do_update
self.wait_ready(deadline)
File "/home/richard/improbable/ray/python/ray/autoscaler/updater.py", line 444, in wait_ready
assert False, "Unable to connect to node"
AssertionError: Unable to connect to node

2020-06-08 01:11:59,679 ERROR commands.py:304 -- get_or_create_head_node: Updating <redacted> failed
2020-06-08 01:11:59,701 INFO log_timer.py:22 -- AWSNodeProvider: Set tag ray-node-status=update-failed on ['i-<redacted>']  [LogTimer=333ms]

# Fixed code
def get_command_runner(
    self,
    log_prefix,
    node_id,
    auth_config,
    cluster_name,
    process_runner,
    use_internal_ip,
    docker_config=None,
):
    return KubernetesCommandRunner(
        log_prefix, self.namespace, node_id, auth_config, process_runner
    )
# Buggy code
def run_rsync_up(self, source, target):
    self.set_ssh_ip_if_required()
    self.process_runner.check_call(
        [
            "rsync",
            "--rsh",
            " ".join(["ssh"] + self.get_default_ssh_options(120)),
            "-avz",
            source,
            "{}@{}:{}".format(self.ssh_user, self.ssh_ip, target),
        ]
    )


# Traceback (AssertionError)
ray up config/example_full.yaml
2020-06-08 01:13:10,526 INFO config.py:143 -- _configure_iam_role: Role not specified for head node, using arn:aws:iam::<redacted>:instance-profile/ray-autoscaler-v1
2020-06-08 01:13:11,089 INFO config.py:194 -- _configure_key_pair: KeyName not specified for nodes, using ray-autoscaler_us-west-2
2020-06-08 01:13:11,365 INFO config.py:235 -- _configure_subnet: SubnetIds not specified for head node, using [('subnet-<redacted>', 'us-west-2b'), ('subnet-<redacted>', 'us-west-2a')]
2020-06-08 01:13:11,366 INFO config.py:241 -- _configure_subnet: SubnetId not specified for workers, using [('subnet-<redacted>', 'us-west-2b'), ('subnet-<redacted>', 'us-west-2a')]
2020-06-08 01:13:11,725 INFO config.py:261 -- _configure_security_group: SecurityGroupIds not specified for head node, using ray-autoscaler-default (sg-<redacted>)
2020-06-08 01:13:11,725 INFO config.py:268 -- _configure_security_group: SecurityGroupIds not specified for workers, using ray-autoscaler-default (sg-<redacted>)
This will restart cluster services [y/N]: y
2020-06-08 01:13:15,214 INFO commands.py:238 -- get_or_create_head_node: Updating files on head node...
2020-06-08 01:13:15,215 INFO updater.py:379 -- NodeUpdater: i-<redacted>: Updating to <redacted>
2020-06-08 01:13:15,216 INFO updater.py:423 -- NodeUpdater: i-<redacted>: Waiting for remote shell...
2020-06-08 01:13:15,422 INFO log_timer.py:22 -- AWSNodeProvider: Set tag ray-node-status=waiting-for-ssh on ['i-<redacted>
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/home/richard/improbable/ray/python/ray/autoscaler/updater.py", line 383, in run
self.do_update()
File "/home/richard/improbable/ray/python/ray/autoscaler/updater.py", line 450, in do_update
self.wait_ready(deadline)
File "/home/richard/improbable/ray/python/ray/autoscaler/updater.py", line 444, in wait_ready
assert False, "Unable to connect to node"
AssertionError: Unable to connect to node

2020-06-08 01:11:59,679 ERROR commands.py:304 -- get_or_create_head_node: Updating <redacted> failed
2020-06-08 01:11:59,701 INFO log_timer.py:22 -- AWSNodeProvider: Set tag ray-node-status=update-failed on ['i-<redacted>']  [LogTimer=333ms]

# Fixed code
def run_rsync_up(self, source, target):
    self.ssh_command_runner.run_rsync_up(source, target)
    if self.check_container_status():
        self.ssh_command_runner.run(
            "docker cp {} {}:{}".format(
                target, self.docker_name, self.docker_expand_user(target)
            )
        )
# Buggy code
def run_rsync_down(self, source, target):
    self.set_ssh_ip_if_required()
    self.process_runner.check_call(
        [
            "rsync",
            "--rsh",
            " ".join(["ssh"] + self.get_default_ssh_options(120)),
            "-avz",
            "{}@{}:{}".format(self.ssh_user, self.ssh_ip, source),
            target,
        ]
    )


# Traceback (AssertionError)
ray up config/example_full.yaml
2020-06-08 01:13:10,526 INFO config.py:143 -- _configure_iam_role: Role not specified for head node, using arn:aws:iam::<redacted>:instance-profile/ray-autoscaler-v1
2020-06-08 01:13:11,089 INFO config.py:194 -- _configure_key_pair: KeyName not specified for nodes, using ray-autoscaler_us-west-2
2020-06-08 01:13:11,365 INFO config.py:235 -- _configure_subnet: SubnetIds not specified for head node, using [('subnet-<redacted>', 'us-west-2b'), ('subnet-<redacted>', 'us-west-2a')]
2020-06-08 01:13:11,366 INFO config.py:241 -- _configure_subnet: SubnetId not specified for workers, using [('subnet-<redacted>', 'us-west-2b'), ('subnet-<redacted>', 'us-west-2a')]
2020-06-08 01:13:11,725 INFO config.py:261 -- _configure_security_group: SecurityGroupIds not specified for head node, using ray-autoscaler-default (sg-<redacted>)
2020-06-08 01:13:11,725 INFO config.py:268 -- _configure_security_group: SecurityGroupIds not specified for workers, using ray-autoscaler-default (sg-<redacted>)
This will restart cluster services [y/N]: y
2020-06-08 01:13:15,214 INFO commands.py:238 -- get_or_create_head_node: Updating files on head node...
2020-06-08 01:13:15,215 INFO updater.py:379 -- NodeUpdater: i-<redacted>: Updating to <redacted>
2020-06-08 01:13:15,216 INFO updater.py:423 -- NodeUpdater: i-<redacted>: Waiting for remote shell...
2020-06-08 01:13:15,422 INFO log_timer.py:22 -- AWSNodeProvider: Set tag ray-node-status=waiting-for-ssh on ['i-<redacted>
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/home/richard/improbable/ray/python/ray/autoscaler/updater.py", line 383, in run
self.do_update()
File "/home/richard/improbable/ray/python/ray/autoscaler/updater.py", line 450, in do_update
self.wait_ready(deadline)
File "/home/richard/improbable/ray/python/ray/autoscaler/updater.py", line 444, in wait_ready
assert False, "Unable to connect to node"
AssertionError: Unable to connect to node

2020-06-08 01:11:59,679 ERROR commands.py:304 -- get_or_create_head_node: Updating <redacted> failed
2020-06-08 01:11:59,701 INFO log_timer.py:22 -- AWSNodeProvider: Set tag ray-node-status=update-failed on ['i-<redacted>']  [LogTimer=333ms]

# Fixed code
def run_rsync_down(self, source, target):
    self.ssh_command_runner.run(
        "docker cp {}:{} {}".format(
            self.docker_name, self.docker_expand_user(source), source
        )
    )
    self.ssh_command_runner.run_rsync_down(source, target)
# Buggy code
def remote_shell_command_str(self):
    return "ssh -o IdentitiesOnly=yes -i {} {}@{}\n".format(
        self.ssh_private_key, self.ssh_user, self.ssh_ip
    )


# Traceback (AssertionError)
ray up config/example_full.yaml
2020-06-08 01:13:10,526 INFO config.py:143 -- _configure_iam_role: Role not specified for head node, using arn:aws:iam::<redacted>:instance-profile/ray-autoscaler-v1
2020-06-08 01:13:11,089 INFO config.py:194 -- _configure_key_pair: KeyName not specified for nodes, using ray-autoscaler_us-west-2
2020-06-08 01:13:11,365 INFO config.py:235 -- _configure_subnet: SubnetIds not specified for head node, using [('subnet-<redacted>', 'us-west-2b'), ('subnet-<redacted>', 'us-west-2a')]
2020-06-08 01:13:11,366 INFO config.py:241 -- _configure_subnet: SubnetId not specified for workers, using [('subnet-<redacted>', 'us-west-2b'), ('subnet-<redacted>', 'us-west-2a')]
2020-06-08 01:13:11,725 INFO config.py:261 -- _configure_security_group: SecurityGroupIds not specified for head node, using ray-autoscaler-default (sg-<redacted>)
2020-06-08 01:13:11,725 INFO config.py:268 -- _configure_security_group: SecurityGroupIds not specified for workers, using ray-autoscaler-default (sg-<redacted>)
This will restart cluster services [y/N]: y
2020-06-08 01:13:15,214 INFO commands.py:238 -- get_or_create_head_node: Updating files on head node...
2020-06-08 01:13:15,215 INFO updater.py:379 -- NodeUpdater: i-<redacted>: Updating to <redacted>
2020-06-08 01:13:15,216 INFO updater.py:423 -- NodeUpdater: i-<redacted>: Waiting for remote shell...
2020-06-08 01:13:15,422 INFO log_timer.py:22 -- AWSNodeProvider: Set tag ray-node-status=waiting-for-ssh on ['i-<redacted>
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/home/richard/improbable/ray/python/ray/autoscaler/updater.py", line 383, in run
self.do_update()
File "/home/richard/improbable/ray/python/ray/autoscaler/updater.py", line 450, in do_update
self.wait_ready(deadline)
File "/home/richard/improbable/ray/python/ray/autoscaler/updater.py", line 444, in wait_ready
assert False, "Unable to connect to node"
AssertionError: Unable to connect to node

2020-06-08 01:11:59,679 ERROR commands.py:304 -- get_or_create_head_node: Updating <redacted> failed
2020-06-08 01:11:59,701 INFO log_timer.py:22 -- AWSNodeProvider: Set tag ray-node-status=update-failed on ['i-<redacted>']  [LogTimer=333ms]

# Fixed code
def remote_shell_command_str(self):
    inner_str = (
        self.ssh_command_runner.remote_shell_command_str()
        .replace("ssh", "ssh -tt", 1)
        .strip("\n")
    )
    return inner_str + " docker exec -it {} /bin/bash\n".format(self.docker_name)
# Buggy code
def compute_action(self, observation):
    return self.policy.compute(observation, update=True)[0]


# Traceback (NameError)
2020-02-12 05:41:30,922 INFO trainable.py:423 -- Current state after restoring: {'_iteration': 50, '_timesteps_total': 16979666, '_time_total': 2578.4048051834106, '_episodes_total': None}
Traceback (most recent call last):
File "/home/andriy/miniconda3/envs/myproj/bin/rllib", line 8, in <module>
sys.exit(cli())
File "/home/andriy/miniconda3/envs/myproj/lib/python3.7/site-packages/ray/rllib/scripts.py", line 36, in cli
rollout.run(options, rollout_parser)
File "/home/andriy/miniconda3/envs/myproj/lib/python3.7/site-packages/ray/rllib/rollout.py", line 265, in run
args.no_render, args.monitor)
File "/home/andriy/miniconda3/envs/myproj/lib/python3.7/site-packages/ray/rllib/rollout.py", line 364, in rollout
prev_action=prev_actions[agent_id],
File "/home/andriy/miniconda3/envs/myproj/lib/python3.7/site-packages/ray/rllib/rollout.py", line 272, in __missing__
self[key] = value = self.default_factory(key)
File "/home/andriy/miniconda3/envs/myproj/lib/python3.7/site-packages/ray/rllib/rollout.py", line 340, in <lambda>
lambda agent_id: action_init[mapping_cache[agent_id]])
NameError: free variable 'action_init' referenced before assignment in enclosing scope

# Fixed code
def compute_action(self, observation, *args, **kwargs):
    return self.policy.compute(observation, update=True)[0]
# Buggy code
def compute_action(self, observation):
    return self.policy.compute(observation, update=False)[0]


# Traceback (NameError)
2020-02-12 05:41:30,922 INFO trainable.py:423 -- Current state after restoring: {'_iteration': 50, '_timesteps_total': 16979666, '_time_total': 2578.4048051834106, '_episodes_total': None}
Traceback (most recent call last):
File "/home/andriy/miniconda3/envs/myproj/bin/rllib", line 8, in <module>
sys.exit(cli())
File "/home/andriy/miniconda3/envs/myproj/lib/python3.7/site-packages/ray/rllib/scripts.py", line 36, in cli
rollout.run(options, rollout_parser)
File "/home/andriy/miniconda3/envs/myproj/lib/python3.7/site-packages/ray/rllib/rollout.py", line 265, in run
args.no_render, args.monitor)
File "/home/andriy/miniconda3/envs/myproj/lib/python3.7/site-packages/ray/rllib/rollout.py", line 364, in rollout
prev_action=prev_actions[agent_id],
File "/home/andriy/miniconda3/envs/myproj/lib/python3.7/site-packages/ray/rllib/rollout.py", line 272, in __missing__
self[key] = value = self.default_factory(key)
File "/home/andriy/miniconda3/envs/myproj/lib/python3.7/site-packages/ray/rllib/rollout.py", line 340, in <lambda>
lambda agent_id: action_init[mapping_cache[agent_id]])
NameError: free variable 'action_init' referenced before assignment in enclosing scope

# Fixed code
def compute_action(self, observation, *args, **kwargs):
    return self.policy.compute(observation, update=False)[0]
# Buggy code
def _read_utilization(self):
    with self.lock:
        if psutil is not None:
            self.values["cpu_util_percent"].append(
                float(psutil.cpu_percent(interval=None))
            )
            self.values["ram_util_percent"].append(
                float(getattr(psutil.virtual_memory(), "percent"))
            )
        if GPUtil is not None:
            for gpu in GPUtil.getGPUs():
                self.values["gpu_util_percent" + str(gpu.id)].append(float(gpu.load))
                self.values["vram_util_percent" + str(gpu.id)].append(
                    float(gpu.memoryUtil)
                )


# Traceback (ValueError)
(pid=4628) Exception in thread Thread-2:
(pid=4628) Traceback (most recent call last):
(pid=4628)   File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
(pid=4628)     self.run()
(pid=4628)   File "/home/ubuntu/algo/lib/python3.6/site-packages/ray/tune/utils/util.py", line 89, in run
(pid=4628)     self._read_utilization()
(pid=4628)   File "/home/ubuntu/algo/lib/python3.6/site-packages/ray/tune/utils/util.py", line 65, in _read_utilization
(pid=4628)     for gpu in GPUtil.getGPUs():
(pid=4628)   File "/home/ubuntu/algo/lib/python3.6/site-packages/GPUtil/GPUtil.py", line 102, in getGPUs
(pid=4628)     deviceIds = int(vals[i])
(pid=4628) ValueError: invalid literal for int() with base 10: "NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. Make  sure that the latest NVIDIA driver is installed and running."

# Fixed code
def _read_utilization(self):
    with self.lock:
        if psutil is not None:
            self.values["cpu_util_percent"].append(
                float(psutil.cpu_percent(interval=None))
            )
            self.values["ram_util_percent"].append(
                float(getattr(psutil.virtual_memory(), "percent"))
            )
        if GPUtil is not None:
            gpu_list = []
            try:
                gpu_list = GPUtil.getGPUs()
            except Exception:
                logger.debug("GPUtil failed to retrieve GPUs.")
            for gpu in gpu_list:
                self.values["gpu_util_percent" + str(gpu.id)].append(float(gpu.load))
                self.values["vram_util_percent" + str(gpu.id)].append(
                    float(gpu.memoryUtil)
                )