**Mutator** is one of algorithm components, which provides some useful functions used for mutable management, such as sample choice, set choicet and so on. With Mutator's help, you can implement some NAS or pruning algorithms quickly.
### What is the relationship between Mutator and Mutable
In a word, Mutator is the manager of Mutable. Each different type of mutable is commonly managed by their one correlative mutator, respectively.
As shown in the figure, Mutable is a component of supernet, therefore Mutator can implement some functions about subnet from supernet by handling Mutable.
### Supported mutators
In MMRazor, we have implemented some mutators, their relationship is as below.
`OneShotModuleMutator` / `DiffModuleMutator`: Inherit from `ModuleMuator`, they are for implementing different types algorithms, such as [SPOS](https://arxiv.org/abs/1904.00420), [Darts](https://arxiv.org/abs/1806.09055) and so on.
`OneShotChannelMutator` / `SlimmableChannelMutator`: Inherit from `ChannelMutator`, they are also for meeting the needs of different types algorithms, such as [AotuSlim](https://arxiv.org/abs/1903.11728).
- Make some necessary preparations according to the given supernet. These preparations may include, but are not limited to, grouping the search space, and initializing mutator with the parameters needed for itself.
- Note that **search groups** and **search space** are two different concepts. The latter defines what choices can be used for searching. The former groups the search space, and searchable blocks that are grouped into the same group will share the same search space and the same sample result.
Type[OneShotMutableModule]: Class type of one-shot mutable.
"""
return OneShotMutableModule
```
2.2. Rewrite `search_groups` and `prepare_from_supernet()`
As the `prepare_from_supernet()` method and the `search_groups` property are already implemented in the `ModuleMutator` and we don't need to add our own logic, the second step is already over.
If you need to implement them by yourself, you can refer to these as follows.
In this case, each `OneShotMutableModule` will be divided into a group. Thus, the search groups have 3 groups.
If you want to custom group according to your requirement, you can implement it by passing the arg `custom_group`.
```Python
custom_group = [
['op1', 'op2'],
['op3']
]
mutator2 = OneShotMutator(custom_group)
mutator2.prepare_from_supernet(supernet)
```
Then `choice_block1` and `choice_block2` will share the same search space and the same sample result, and `choice_block3` will have its own independent search space. Thus, the search groups have only 2 groups.
```Python
>>> mutator2.search_groups.keys()
dict_keys([0, 1])
```
### 3. Implement other methods
After finishing some required methods, we need to add some special methods, such as `sample_choices` and `set_choices`.