saealib.TerminationCondition#

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

ベースクラス: 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.

パラメータ:
  • 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)

例外:

TypeError -- If func is not callable.

サンプル

>>> 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)[ソース]#
パラメータ:
  • func (ConditionFunc)

  • name (str | None)

  • doc (str | None)

  • spec (dict | None)

戻り値の型:

None