# Buggy code
def __init__(
    self,
    trainable_name,
    config=None,
    local_dir=DEFAULT_RESULTS_DIR,
    experiment_tag=None,
    resources=Resources(cpu=1, gpu=0),
    stopping_criterion=None,
    checkpoint_freq=0,
    restore_path=None,
    upload_dir=None,
    max_failures=0,
):
    """Initialize a new trial.

    The args here take the same meaning as the command line flags defined
    in ray.tune.config_parser.
    """

    if not _default_registry.contains(TRAINABLE_CLASS, trainable_name):
        raise TuneError("Unknown trainable: " + trainable_name)

    if stopping_criterion:
        for k in stopping_criterion:
            if k not in TrainingResult._fields:
                raise TuneError(
                    "Stopping condition key `{}` must be one of {}".format(
                        k, TrainingResult._fields
                    )
                )

    # Trial config
    self.trainable_name = trainable_name
    self.config = config or {}
    self.local_dir = local_dir
    self.experiment_tag = experiment_tag
    self.resources = resources
    self.stopping_criterion = stopping_criterion or {}
    self.checkpoint_freq = checkpoint_freq
    self.upload_dir = upload_dir
    self.verbose = True
    self.max_failures = max_failures

    # Local trial state that is updated during the run
    self.last_result = None
    self._checkpoint_path = restore_path
    self._checkpoint_obj = None
    self.runner = None
    self.status = Trial.PENDING
    self.location = None
    self.logdir = None
    self.result_logger = None
    self.last_debug = 0
    self.trial_id = binary_to_hex(random_string())[:8]
    self.error_file = None
    self.num_failures = 0


# Traceback (ImportError)
Traceback (most recent call last):
File "/home/ubuntu/ray/python/ray/worker.py", line 1694, in fetch_and_execute_function_to_run
function = pickle.loads(serialized_function)
File "/home/ubuntu/ray/python/ray/tune/registry.py", line 12, in <module>
from ray.tune.trainable import Trainable, wrap_function
File "/home/ubuntu/ray/python/ray/tune/__init__.py", line 6, in <module>
from ray.tune.tune import run_experiments
File "/home/ubuntu/ray/python/ray/tune/tune.py", line 8, in <module>
from ray.tune.hyperband import HyperBandScheduler
File "/home/ubuntu/ray/python/ray/tune/hyperband.py", line 8, in <module>
from ray.tune.trial_scheduler import FIFOScheduler, TrialScheduler
File "/home/ubuntu/ray/python/ray/tune/trial_scheduler.py", line 5, in <module>
from ray.tune.trial import Trial
File "/home/ubuntu/ray/python/ray/tune/trial.py", line 15, in <module>
from ray.tune.registry import _default_registry, get_registry, TRAINABLE_CLASS
ImportError: cannot import name '_default_registry'

# Fixed code
def __init__(
    self,
    trainable_name,
    config=None,
    local_dir=DEFAULT_RESULTS_DIR,
    experiment_tag=None,
    resources=Resources(cpu=1, gpu=0),
    stopping_criterion=None,
    checkpoint_freq=0,
    restore_path=None,
    upload_dir=None,
    max_failures=0,
):
    """Initialize a new trial.

    The args here take the same meaning as the command line flags defined
    in ray.tune.config_parser.
    """

    if not ray.tune.registry._default_registry.contains(
        ray.tune.registry.TRAINABLE_CLASS, trainable_name
    ):
        raise TuneError("Unknown trainable: " + trainable_name)

    if stopping_criterion:
        for k in stopping_criterion:
            if k not in TrainingResult._fields:
                raise TuneError(
                    "Stopping condition key `{}` must be one of {}".format(
                        k, TrainingResult._fields
                    )
                )

    # Trial config
    self.trainable_name = trainable_name
    self.config = config or {}
    self.local_dir = local_dir
    self.experiment_tag = experiment_tag
    self.resources = resources
    self.stopping_criterion = stopping_criterion or {}
    self.checkpoint_freq = checkpoint_freq
    self.upload_dir = upload_dir
    self.verbose = True
    self.max_failures = max_failures

    # Local trial state that is updated during the run
    self.last_result = None
    self._checkpoint_path = restore_path
    self._checkpoint_obj = None
    self.runner = None
    self.status = Trial.PENDING
    self.location = None
    self.logdir = None
    self.result_logger = None
    self.last_debug = 0
    self.trial_id = binary_to_hex(random_string())[:8]
    self.error_file = None
    self.num_failures = 0