Mutation error. Crash in random package.
Created by: MAGLeb
If build composer with initial chain contains only ONE node.
**initial_chain** = PrimaryNode('xgboost')
builder = GPComposerBuilder(task=task).
with_requirements(composer_requirements).
with_metrics(metric_function).
with_optimiser_parameters(optimiser_parameters).
with_initial_chain(**initial_chain**)
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-36-7c15fbfd9fe1> in <module>
10
11 # the optimal chain generation by composition - the most time-consuming task
---> 12 chain_evo_composed = composer.compose_chain(data=input_data,
13 is_visualise=True)
~/.local/lib/python3.8/site-packages/fedot/core/composer/gp_composer/gp_composer.py in compose_chain(self, data, is_visualise, is_tune, on_next_iteration_callback)
138 self.cache = OperationsCache(self.cache_path, clear_exiting=not self.use_existing_cache)
139
--> 140 best_chain = self.optimiser.optimise(metric_function_for_nodes,
141 on_next_iteration_callback=on_next_iteration_callback)
142
~/.local/lib/python3.8/site-packages/fedot/core/composer/optimisers/gp_comp/param_free_gp_optimiser.py in optimise(self, objective_function, offspring_rate, on_next_iteration_callback)
118
119 for parent_num in range(0, len(selected_individuals), 2):
--> 120 new_population += self.reproduce(selected_individuals[parent_num],
121 selected_individuals[parent_num + 1])
122
~/.local/lib/python3.8/site-packages/fedot/core/composer/optimisers/gp_comp/gp_optimiser.py in reproduce(self, selected_individual_first, selected_individual_second)
299 new_inds = [selected_individual_first]
300
--> 301 new_inds = tuple([mutation(types=self.parameters.mutation_types,
302 chain_generation_params=self.chain_generation_params,
303 ind=new_ind, requirements=self.requirements,
~/.local/lib/python3.8/site-packages/fedot/core/composer/optimisers/gp_comp/gp_optimiser.py in <listcomp>(.0)
299 new_inds = [selected_individual_first]
300
--> 301 new_inds = tuple([mutation(types=self.parameters.mutation_types,
302 chain_generation_params=self.chain_generation_params,
303 ind=new_ind, requirements=self.requirements,
~/.local/lib/python3.8/site-packages/fedot/core/composer/optimisers/gp_comp/operators/mutation.py in mutation(types, chain_generation_params, ind, requirements, log, max_depth)
63 if mutation_type in mutation_by_type:
64 for _ in range(MAX_NUM_OF_ATTEMPTS):
---> 65 new_chain = mutation_by_type[mutation_type](chain=deepcopy(ind.chain), requirements=requirements,
66 chain_generation_params=chain_generation_params,
67 max_depth=max_depth)
~/.local/lib/python3.8/site-packages/fedot/core/composer/optimisers/gp_comp/operators/mutation.py in reduce_mutation(chain, requirements, chain_generation_params, max_depth)
143
144 nodes = [node for node in chain.nodes if node is not chain.root_node]
--> 145 node_to_del = choice(nodes)
146 children = chain.operator.node_children(node_to_del)
147 is_possible_to_delete = all([len(child.nodes_from) - 1 >= requirements.min_arity for child in children])
/usr/lib/python3.8/random.py in choice(self, seq)
288 i = self._randbelow(len(seq))
289 except ValueError:
--> 290 raise IndexError('Cannot choose from an empty sequence') from None
291 return seq[i]
292
IndexError: Cannot choose from an empty sequence