saealib.TerminationCondition#

class saealib.TerminationCondition(func, *, name=None, doc=None, spec=None)[source]#

Bases: object

Composable termination condition.

Wraps a callable ctx -> bool and adds logical operators so that conditions can be combined declaratively:

  • a | b : terminate when either a or b is met (OR)

  • a & b : terminate when both a and b are met (AND)

  • ~a : terminate when a is not met (NOT)

The other operand may be a plain Callable[[ctx], bool]; it is wrapped automatically. Reflected operators (__ror__ / __rand__) let a plain callable appear on the left-hand side as well.

Parameters:
  • func (Callable[[OptimizationState], bool]) – The underlying condition callable.

  • name (str, optional) – Human-readable name used for repr and __qualname__. Defaults to func.__qualname__ when available.

  • doc (str, optional) – Docstring for the wrapped condition. Defaults to func.__doc__.

  • spec (dict | None)

Raises:

TypeError – If func is not callable.

Examples

>>> cond = max_fe(2000) & (lambda ctx: ctx.archive.get("f").min() < 1e-6)
>>> cond = max_gen(100) | max_fe(2000)
>>> cond = ~stalled(20)

Methods

Method Details

TerminationCondition.__init__(func, *, name=None, doc=None, spec=None)[source]#
Parameters:
  • func (ConditionFunc)

  • name (str | None)

  • doc (str | None)

  • spec (dict | None)

Return type:

None