Operators are objects that act on populations. They can be applied to populations directly using their function forms, but they are usually managed and applied by a simulator. In the latter case, operators are passed to the evolve function of a simulator, and are applied repeatedly during the evolution of the simulator.
The BaseOperator class is the base class for all operators. It defines a common user interface that specifies at which generations, at which stage of a life cycle, to which populations and subpopulations an operator is applied. These are achieved by a common set of parameters such as begin, end, step, at, stage for all operators. Note that a specific operator does not have to honor all these parameters. For example, a Recombinator can only be applied during mating so it ignores the stage parameter.
An operator can be applied to all or part of the generations during the evolution of a simulator. At the beginning of an evolution, a simulator is usually at the beginning of generation 0. If it evolves 10 generations, it evolves generations 0, 1, ,,,., and 9 (10 generations) and stops at the begging of generation 10. A negative generation number a has generation number 10 + a, with -1 referring to the last evolved generation 9. Note that the starting generation number of a simulator can be changed by its setGen() member function.
Output from an operator is usually directed to the standard output (sys.stdout). This can be configured using a output specification string, which can be '' for no output, '>' standard terminal output (default), a filename prefixed by one or more '>' characters or a Python expression indicated by a leading exclamation mark ('!expr'). In the case of '>filename' (or equivalently 'filename'), the output from an operator is written to this file. However, if two operators write to the same file filename, or if an operator writes to this file more than once, only the last write operation will succeed. In the case of '>>filename', file filename will be opened at the beginning of the evolution and closed at the end. Outputs from multiple operators are appended. >>>filename works similar to >>filename but filename, if it already exists at the beginning of an evolutionary process, will not be cleared. If the output specification is prefixed by an exclamation mark, the string after the mark is considered as a Python expression. When an operator is applied to a population, this expression will be evaluated within the population’s local namespace to obtain a population specific output specification. As an advanced feature, a Python function can be assigned to this parameter. Output strings will be sent to this function for processing. Lastly, if the output stream only accept a binary output (e.g. a gzip stream), WithMode(output, 'b') should be used to let simuPOP convert string to bytes before writing to the output.
The following parameters can be specified by all operators. However, an operator can ignore some parameters and the exact meaning of a parameter can vary.