# Buggy code
def _generate_hp_values(self, hp_names):
    best_hps = self._get_best_hps()

    collisions = 0
    while True:
        hps = kerastuner.HyperParameters()
        # Generate a set of random values.
        for hp in best_hps.space:
            hps.merge([hp])
            # if not active, do nothing.
            # if active, check if selected to be changed.
            if hps.is_active(hp):
                # if was active and not selected, do nothing.
                if best_hps.is_active(hp.name) and hp.name not in hp_names:
                    continue
                # if was not active or selected, sample.
                hps.values[hp.name] = hp.random_sample(self._seed_state)
                self._seed_state += 1
        values = hps.values
        # Keep trying until the set of values is unique,
        # or until we exit due to too many collisions.
        values_hash = self._compute_values_hash(values)
        if values_hash in self._tried_so_far:
            collisions += 1
            if collisions <= self._max_collisions:
                continue
            return None
        self._tried_so_far.add(values_hash)
        break
    return values


# Traceback (KeyError)
Traceback (most recent call last):
File "P:\ProgramFiles\anaconda\envs\python\test\lib\site-packages\kerastuner\engine\hypermodel.py", line 104, in build
model = self.hypermodel.build(hp)
File "P:\ProgramFiles\anaconda\envs\python\test\lib\site-packages\kerastuner\engine\hypermodel.py", line 64, in _build_wrapper
return self._build(hp, *args, **kwargs)
File "P:\ProgramFiles\anaconda\envs\python\test\lib\site-packages\autokeras\graph.py", line 263, in build
outputs = block.build(hp, inputs=temp_inputs)
File "P:\ProgramFiles\anaconda\envs\python\test\lib\site-packages\autokeras\engine\block.py", line 48, in _build_wrapper
return super()._build_wrapper(hp, *args, **kwargs)
File "P:\ProgramFiles\anaconda\envs\python\test\lib\site-packages\kerastuner\engine\hypermodel.py", line 64, in _build_wrapper
return self._build(hp, *args, **kwargs)
File "P:\ProgramFiles\anaconda\envs\python\test\lib\site-packages\autokeras\blocks\wrapper.py", line 102, in build
output_node = self._build_block(hp, output_node, block_type)
File "P:\ProgramFiles\anaconda\envs\python\test\lib\site-packages\autokeras\blocks\wrapper.py", line 77, in _build_block
return basic.XceptionBlock().build(hp, output_node)
File "P:\ProgramFiles\anaconda\envs\python\test\lib\site-packages\autokeras\engine\block.py", line 48, in _build_wrapper
return super()._build_wrapper(hp, *args, **kwargs)
File "P:\ProgramFiles\anaconda\envs\python\test\lib\site-packages\kerastuner\engine\hypermodel.py", line 64, in _build_wrapper
return self._build(hp, *args, **kwargs)
File "P:\ProgramFiles\anaconda\envs\python\test\lib\site-packages\autokeras\blocks\basic.py", line 574, in build
model.trainable = hp.Boolean("trainable", default=False)
File "P:\ProgramFiles\anaconda\envs\python\test\lib\site-packages\kerastuner\engine\hyperparameters.py", line 814, in Boolean
return self._retrieve(hp)
File "P:\ProgramFiles\anaconda\envs\python\test\lib\site-packages\kerastuner\engine\hyperparameters.py", line 625, in _retrieve
return self.values[hp.name]
KeyError: 'image_block_1/xception_block_1/trainable'

# Fixed code
def _generate_hp_values(self, hp_names):
    best_hps = self._get_best_hps()

    collisions = 0
    while True:
        hps = kerastuner.HyperParameters()
        # Generate a set of random values.
        for hp in self.hyperparameters.space:
            hps.merge([hp])
            # if not active, do nothing.
            # if active, check if selected to be changed.
            if hps.is_active(hp):
                # if was active and not selected, do nothing.
                if best_hps.is_active(hp.name) and hp.name not in hp_names:
                    hps.values[hp.name] = best_hps.values[hp.name]
                    continue
                # if was not active or selected, sample.
                hps.values[hp.name] = hp.random_sample(self._seed_state)
                self._seed_state += 1
        values = hps.values
        # Keep trying until the set of values is unique,
        # or until we exit due to too many collisions.
        values_hash = self._compute_values_hash(values)
        if values_hash in self._tried_so_far:
            collisions += 1
            if collisions <= self._max_collisions:
                continue
            return None
        self._tried_so_far.add(values_hash)
        break
    return values