sisl.mixing.StepMixer

class sisl.mixing.StepMixer(*yield_funcs: Callable[[], Iterator[BaseMixer]])

Bases: BaseMixer

Step between different mixers in a user-defined fashion

This is handy for creating variable mixing schemes that alternates (or differently) between multiple mixers.

Examples

Alternate between two mixers:

>>> mixer = StepMixer(
...        StepMixer.yield_repeat(mix1, 1),
...        StepMixer.yield_repeat(mix2, 1))

One may also create custom based generators which can interact with the mixers in between different mixers:

>>> def gen():
...     yield mix1
...     mix1.history.clear()
...     yield mix1
...     yield mix1
...     yield mix2

A restart mixer for history mixers:

>>> def gen():
...     for _ in range(50):
...         yield mix
...     mix.history.clear()

Methods

next()

Return the current mixer, and step the internal mixer

yield_chain(*yield_funcs)

Returns a function which yields from each of the function arguments in turn

yield_repeat(mixer, n)

Returns a function which repeats mixer n times

Attributes

mixer

Return the current mixer

__call__(f: T, df: T, *args: Any, **kwargs: Any) T[source]

Apply the mixing routine

next() BaseMixer[source]

Return the current mixer, and step the internal mixer

classmethod yield_chain(*yield_funcs: Callable[[], Iterator[BaseMixer]]) Callable[[], Iterator[BaseMixer]][source]

Returns a function which yields from each of the function arguments in turn

Basically equivalent to a function which does this:

>>> for yield_func in yield_funcs:
...     yield from yield_func()
Parameters:

*yield_funcs – every function will be yield from

classmethod yield_repeat(mixer: BaseMixer, n: int) Callable[[], Iterator[BaseMixer]][source]

Returns a function which repeats mixer n times

property mixer: BaseMixer

Return the current mixer