# Buggy code
def __init__(
    self,
    space: Optional[Dict] = None,
    metric: Optional[str] = None,
    mode: Optional[str] = None,
    utility_kwargs: Optional[Dict] = None,
    random_state: int = 42,
    random_search_steps: int = 10,
    verbose: int = 0,
    patience: int = 5,
    skip_duplicate: bool = True,
    analysis: Optional[ExperimentAnalysis] = None,
    max_concurrent: Optional[int] = None,
    use_early_stopped_trials: Optional[bool] = None,
):
    """Instantiate new BayesOptSearch object.

    Args:
        space (dict): Continuous search space.
            Parameters will be sampled from
            this space which will be used to run trials.
        metric (str): The training result objective value attribute.
        mode (str): One of {min, max}. Determines whether objective is
            minimizing or maximizing the metric attribute.
        utility_kwargs (dict): Parameters to define the utility function.
            Must provide values for the keys `kind`, `kappa`, and `xi`.
        random_state (int): Used to initialize BayesOpt.
        random_search_steps (int): Number of initial random searches.
            This is necessary to avoid initial local overfitting
            of the Bayesian process.
        patience (int): Must be > 0. If the optimizer suggests a set of
            hyperparameters more than 'patience' times,
            then the whole experiment will stop.
        skip_duplicate (bool): If true, BayesOptSearch will not create
            a trial with a previously seen set of hyperparameters. By
            default, floating values will be reduced to a digit precision
            of 5. You can override this by setting
            ``searcher.repeat_float_precision``.
        analysis (ExperimentAnalysis): Optionally, the previous analysis
            to integrate.
        verbose (int): Sets verbosity level for BayesOpt packages.
        max_concurrent: Deprecated.
        use_early_stopped_trials: Deprecated.
    """
    assert byo is not None, (
        "BayesOpt must be installed!. You can install BayesOpt with"
        " the command: `pip install bayesian-optimization`."
    )
    if mode:
        assert mode in ["min", "max"], "`mode` must be 'min' or 'max'."
    self.max_concurrent = max_concurrent
    self._config_counter = defaultdict(int)
    self._patience = patience
    # int: Precision at which to hash values.
    self.repeat_float_precision = 5
    if self._patience <= 0:
        raise ValueError("patience must be set to a value greater than 0!")
    self._skip_duplicate = skip_duplicate
    super(BayesOptSearch, self).__init__(
        metric=metric,
        mode=mode,
        max_concurrent=max_concurrent,
        use_early_stopped_trials=use_early_stopped_trials,
    )

    if utility_kwargs is None:
        # The defaults arguments are the same
        # as in the package BayesianOptimization
        utility_kwargs = dict(
            kind="ucb",
            kappa=2.576,
            xi=0.0,
        )

    if mode == "max":
        self._metric_op = 1.0
    elif mode == "min":
        self._metric_op = -1.0

    self._live_trial_mapping = {}
    self._buffered_trial_results = []
    self.random_search_trials = random_search_steps
    self._total_random_search_trials = 0

    self.utility = byo.UtilityFunction(**utility_kwargs)

    # Registering the provided analysis, if given
    if analysis is not None:
        self.register_analysis(analysis)

    self._space = space
    self._verbose = verbose
    self._random_state = random_state

    self.optimizer = None
    if space:
        self.setup_optimizer()


# Traceback (TypeError)
Traceback (most recent call last):
(pid=82997)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/threading.py", line 916, in _bootstrap_inner
(pid=82997)     self.run()
(pid=82997)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/ray/tune/function_runner.py", line 246, in run
(pid=82997)     raise e
(pid=82997)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/ray/tune/function_runner.py", line 227, in run
(pid=82997)     self._entrypoint()
(pid=82997)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/ray/tune/function_runner.py", line 290, in entrypoint
(pid=82997)     self._status_reporter.get_checkpoint())
(pid=82997)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/ray/tune/function_runner.py", line 497, in _trainable_func
(pid=82997)     output = train_func(config)
(pid=82997)   File "test_ray.py", line 49, in trainer
(pid=82997)     keras.layers.Dense(config["neurons1"], input_shape=(784,), activation='relu', name='dense_1'),
(pid=82997)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/keras/layers/core.py", line 1081, in __init__
(pid=82997)     self.units = int(units) if not isinstance(units, int) else units
(pid=82997) TypeError: int() argument must be a string, a bytes-like object or a number, not 'Integer'
------------------------------------------------------------
(pid=84324) Traceback (most recent call last):
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/threading.py", line 916, in _bootstrap_inner
(pid=84324)     self.run()
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/ray/tune/function_runner.py", line 246, in run
(pid=84324)     raise e
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/ray/tune/function_runner.py", line 227, in run
(pid=84324)     self._entrypoint()
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/ray/tune/function_runner.py", line 290, in entrypoint
(pid=84324)     self._status_reporter.get_checkpoint())
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/ray/tune/function_runner.py", line 497, in _trainable_func
(pid=84324)     output = train_func(config)
(pid=84324)   File "test_ray.py", line 50, in trainer
(pid=84324)     keras.layers.Dense(10, activation='softmax', name='predictions'),
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/training/tracking/base.py", line 457, in _method_wrapper
(pid=84324)     result = method(self, *args, **kwargs)
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/sequential.py", line 116, in __init__
(pid=84324)     self.add(layer)
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/training/tracking/base.py", line 457, in _method_wrapper
(pid=84324)     result = method(self, *args, **kwargs)
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/sequential.py", line 203, in add
(pid=84324)     output_tensor = layer(self.outputs[0])
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 773, in __call__
(pid=84324)     outputs = call_fn(cast_inputs, *args, **kwargs)
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/keras/layers/core.py", line 183, in call
(pid=84324)     lambda: array_ops.identity(inputs))
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/keras/utils/tf_utils.py", line 59, in smart_cond
(pid=84324)     pred, true_fn=true_fn, false_fn=false_fn, name=name)
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/framework/smart_cond.py", line 59, in smart_cond
(pid=84324)     name=name)
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/util/deprecation.py", line 507, in new_func
(pid=84324)     return func(*args, **kwargs)
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/ops/control_flow_ops.py", line 1174, in cond
(pid=84324)     return cond_v2.cond_v2(pred, true_fn, false_fn, name)
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/ops/cond_v2.py", line 83, in cond_v2
(pid=84324)     op_return_value=pred)
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/framework/func_graph.py", line 978, in func_graph_from_py_func
(pid=84324)     func_outputs = python_func(*func_args, **func_kwargs)
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/keras/layers/core.py", line 179, in dropped_inputs
(pid=84324)     rate=self.rate)
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/util/deprecation.py", line 507, in new_func
(pid=84324)     return func(*args, **kwargs)
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/ops/nn_ops.py", line 4289, in dropout
(pid=84324)     return dropout_v2(x, rate, noise_shape=noise_shape, seed=seed, name=name)
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/ops/nn_ops.py", line 4383, in dropout_v2
(pid=84324)     rate, dtype=x.dtype, name="rate")
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py", line 1314, in convert_to_tensor
(pid=84324)     ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/framework/constant_op.py", line 317, in _constant_tensor_conversion_function
(pid=84324)     return constant(v, dtype=dtype, name=name)
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/framework/constant_op.py", line 258, in constant
(pid=84324)     allow_broadcast=True)
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/framework/constant_op.py", line 296, in _constant_impl
(pid=84324)     allow_broadcast=allow_broadcast))
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/framework/tensor_util.py", line 451, in make_tensor_proto
(pid=84324)     _AssertCompatible(values, dtype)
(pid=84324)   File "/home/gsukhorukov/.conda/envs/tf2/lib/python3.6/site-packages/tensorflow_core/python/framework/tensor_util.py", line 331, in _AssertCompatible
(pid=84324)     (dtype.name, repr(mismatch), type(mismatch).__name__))
(pid=84324) TypeError: Expected float32, got <ray.tune.sample.Categorical object at 0x7fe7d1835a90> of type 'Categorical' instead.

# Fixed code
def __init__(
    self,
    space: Optional[Dict] = None,
    metric: Optional[str] = None,
    mode: Optional[str] = None,
    utility_kwargs: Optional[Dict] = None,
    random_state: int = 42,
    random_search_steps: int = 10,
    verbose: int = 0,
    patience: int = 5,
    skip_duplicate: bool = True,
    analysis: Optional[ExperimentAnalysis] = None,
    max_concurrent: Optional[int] = None,
    use_early_stopped_trials: Optional[bool] = None,
):
    """Instantiate new BayesOptSearch object.

    Args:
        space (dict): Continuous search space.
            Parameters will be sampled from
            this space which will be used to run trials.
        metric (str): The training result objective value attribute.
        mode (str): One of {min, max}. Determines whether objective is
            minimizing or maximizing the metric attribute.
        utility_kwargs (dict): Parameters to define the utility function.
            Must provide values for the keys `kind`, `kappa`, and `xi`.
        random_state (int): Used to initialize BayesOpt.
        random_search_steps (int): Number of initial random searches.
            This is necessary to avoid initial local overfitting
            of the Bayesian process.
        patience (int): Must be > 0. If the optimizer suggests a set of
            hyperparameters more than 'patience' times,
            then the whole experiment will stop.
        skip_duplicate (bool): If true, BayesOptSearch will not create
            a trial with a previously seen set of hyperparameters. By
            default, floating values will be reduced to a digit precision
            of 5. You can override this by setting
            ``searcher.repeat_float_precision``.
        analysis (ExperimentAnalysis): Optionally, the previous analysis
            to integrate.
        verbose (int): Sets verbosity level for BayesOpt packages.
        max_concurrent: Deprecated.
        use_early_stopped_trials: Deprecated.
    """
    assert byo is not None, (
        "BayesOpt must be installed!. You can install BayesOpt with"
        " the command: `pip install bayesian-optimization`."
    )
    if mode:
        assert mode in ["min", "max"], "`mode` must be 'min' or 'max'."
    self.max_concurrent = max_concurrent
    self._config_counter = defaultdict(int)
    self._patience = patience
    # int: Precision at which to hash values.
    self.repeat_float_precision = 5
    if self._patience <= 0:
        raise ValueError("patience must be set to a value greater than 0!")
    self._skip_duplicate = skip_duplicate
    super(BayesOptSearch, self).__init__(
        metric=metric,
        mode=mode,
        max_concurrent=max_concurrent,
        use_early_stopped_trials=use_early_stopped_trials,
    )

    if utility_kwargs is None:
        # The defaults arguments are the same
        # as in the package BayesianOptimization
        utility_kwargs = dict(
            kind="ucb",
            kappa=2.576,
            xi=0.0,
        )

    if mode == "max":
        self._metric_op = 1.0
    elif mode == "min":
        self._metric_op = -1.0

    self._live_trial_mapping = {}
    self._buffered_trial_results = []
    self.random_search_trials = random_search_steps
    self._total_random_search_trials = 0

    self.utility = byo.UtilityFunction(**utility_kwargs)

    # Registering the provided analysis, if given
    if analysis is not None:
        self.register_analysis(analysis)

    if isinstance(space, dict) and space:
        resolved_vars, domain_vars, grid_vars = parse_spec_vars(space)
        if domain_vars or grid_vars:
            logger.warning(UNRESOLVED_SEARCH_SPACE.format(par="space", cls=type(self)))
            space = self.convert_search_space(space, join=True)

    self._space = space
    self._verbose = verbose
    self._random_state = random_state

    self.optimizer = None
    if space:
        self.setup_optimizer()