Skip to content

Halt Rule

The QD-score halt rule, which the survey driver runs by default. The driver records one row (S, N, m) per checkpoint: the sum and the count of the elite log-likelihoods, and their running minimum. The functions here read those rows. qd_scores gives the QD-score of each checkpoint under one offset. growth_exponent gives the exponent beta against the half checkpoint. past_guard applies the guard, and qd_halts applies the whole rule: the growth exponent must be at or below qd_tau at a checkpoint and at its half checkpoint. persist=False judges the reading at the checkpoint alone, which an analysis can use to see what the second condition changes. The driver always applies both conditions.

When a budget ends before the halt, budget_message gives the text of the warning. It calls fit_models and variations_to_tau for the three accumulation functions in MODELS. Section 6 of the theory overview gives the theory of the rule, and Stopping a Survey: Settings and Trade-offs gives the guidance for using it.

The constants of the rule are in hifuku.constants: HALT_QD_TAU, the default of qd_tau; HALT_QD_GUARD_DOUBLINGS, the guard; and HALT_QD_MIN_CHECKPOINTS, the fewest checkpoints the automatic cadence leaves in a budget.

halt

The QD-score halt rule.

The QD-score of an archive (Pugh et al. 2016) is the sum over its filled niches of each elite's log-likelihood above an offset. Here the offset is the lowest elite the survey has held, so the whole archive counts. The driver records, at every checkpoint, the sum S and the count N of the elite log-likelihoods and the running minimum m, so the QD-score of any checkpoint under any later offset is S - N * m exactly.

The growth exponent at a checkpoint at v variations, against the half checkpoint h, is beta = log2(Q_v / Q_h) / log2(v / v_h): a doubling of effort multiplies the QD-score by 2**beta. A survey halts at a checkpoint when beta <= tau there and at its half checkpoint, so the low reading holds across two consecutive doublings and a one-doubling stall of growth does not halt it. Only checkpoints at least HALT_QD_GUARD_DOUBLINGS doublings past the first are judged.

When a budget ends before the halt, three accumulation functions (Soberon and Llorente 1993) are fitted to the survey's QD-score history and each gives the variations at which its growth exponent reaches tau. The growth exponent of each falls monotonically, so the halt comes one doubling after that count. The forms and the monotone fall are derived in docs/theory/algebra/soberon1993accumulation-growth-exponent.py. The three disagree when extrapolated, so the message reports them as a range.

qd_scores

qd_scores(sums, counts, offset: float) -> np.ndarray

The QD-score of each checkpoint, read with one offset.

Source code in src/hifuku/halt.py
def qd_scores(sums, counts, offset: float) -> np.ndarray:
    """The QD-score of each checkpoint, read with one offset."""
    return np.asarray(sums, float) - np.asarray(counts, float) * float(offset)

growth_exponent

growth_exponent(variations, qd, i: int) -> float | None

The growth exponent at checkpoint i, or None when undecided.

Undecided when there is no earlier checkpoint, when the half checkpoint has no variations, or when either QD-score is not positive.

Source code in src/hifuku/halt.py
def growth_exponent(variations, qd, i: int) -> float | None:
    """The growth exponent at checkpoint ``i``, or None when undecided.

    Undecided when there is no earlier checkpoint, when the half checkpoint
    has no variations, or when either QD-score is not positive.
    """
    variations = np.asarray(variations, float)
    qd = np.asarray(qd, float)
    h = _half(variations, i)
    if h is None or variations[h] <= 0.0 or qd[h] <= 0.0 or qd[i] <= 0.0:
        return None
    return math.log2(qd[i] / qd[h]) / math.log2(variations[i] / variations[h])

past_guard

past_guard(variations, i: int) -> bool

True when checkpoint i is at least HALT_QD_GUARD_DOUBLINGS doublings past the first checkpoint with positive variations.

Source code in src/hifuku/halt.py
def past_guard(variations, i: int) -> bool:
    """True when checkpoint ``i`` is at least ``HALT_QD_GUARD_DOUBLINGS``
    doublings past the first checkpoint with positive variations."""
    variations = np.asarray(variations, float)
    positive = variations[variations > 0.0]
    return bool(positive.size and variations[i] >= positive[0] * 2.0 ** (
        HALT_QD_GUARD_DOUBLINGS))

qd_halts

qd_halts(variations, sums, counts, minima, i: int, tau: float, *, persist: bool = True) -> bool

True when the survey halts at checkpoint i under the QD-score rule.

The offset is the running minimum at i, for every QD-score read here. The growth exponent at i must be at or below tau, and with persist so must the growth exponent at i's half checkpoint. A checkpoint before the guard, or with an undecided growth exponent at either, does not halt. persist=False judges the reading at i alone, which is the rule records of schema 14 and earlier halted by.

Source code in src/hifuku/halt.py
def qd_halts(variations, sums, counts, minima, i: int, tau: float, *,
             persist: bool = True) -> bool:
    """True when the survey halts at checkpoint ``i`` under the QD-score rule.

    The offset is the running minimum at ``i``, for every QD-score read
    here.  The growth exponent at ``i`` must be at or below ``tau``, and with
    ``persist`` so must the growth exponent at ``i``'s half checkpoint.  A
    checkpoint before the guard, or with an undecided growth exponent at
    either, does not halt.  ``persist=False`` judges the reading at ``i``
    alone, which is the rule records of schema 14 and earlier halted by.
    """
    variations = np.asarray(variations, float)
    if not past_guard(variations, i):
        return False
    qd = qd_scores(sums, counts, float(np.asarray(minima)[i]))
    beta = growth_exponent(variations, qd, i)
    if beta is None or beta > tau:
        return False
    if not persist:
        return True
    h = _half(variations, i)
    beta_h = growth_exponent(variations, qd, h)
    return beta_h is not None and beta_h <= tau

fit_models

fit_models(variations, qd) -> dict

Fit each accumulation function by least squares on log Q.

Only checkpoints with positive variations and positive QD-score are used. Of these, the fit uses the checkpoints at or past the guard of :func:past_guard. When fewer than three such checkpoints are past the guard, the fit uses all of them. A model whose fit fails, or that has fewer than three points to fit, is left out of the result.

Source code in src/hifuku/halt.py
def fit_models(variations, qd) -> dict:
    """Fit each accumulation function by least squares on ``log Q``.

    Only checkpoints with positive variations and positive QD-score are
    used.  Of these, the fit uses the checkpoints at or past the guard of
    :func:`past_guard`.  When fewer than three such checkpoints are past
    the guard, the fit uses all of them.  A model whose fit fails, or that
    has fewer than three points to fit, is left out of the result.
    """
    v = np.asarray(variations, float)
    q = np.asarray(qd, float)
    keep = (v > 0.0) & (q > 0.0)
    guarded = keep & np.array([past_guard(v, i) for i in range(v.size)],
                              dtype=bool)
    if np.count_nonzero(guarded) >= 3:
        keep = guarded
    v, q = v[keep], q[keep]
    out = {}
    if v.size < 3:
        return out
    for name, f in MODELS.items():
        try:
            with np.errstate(invalid="ignore", divide="ignore",
                             over="ignore"), warnings.catch_warnings():
                warnings.simplefilter("ignore", OptimizeWarning)
                p, _ = curve_fit(lambda x, a, b: np.log(f(x, a, b)), v,
                                 np.log(q), p0=_start(name, v, q),
                                 maxfev=20000)
            if np.all(np.isfinite(p)) and np.all(p > 0.0):
                out[name] = (float(p[0]), float(p[1]))
        except (RuntimeError, ValueError, FloatingPointError):
            continue
    return out

variations_to_tau

variations_to_tau(model: str, params, tau: float) -> float | None

Variations at which a fitted model's growth exponent reaches tau.

Source code in src/hifuku/halt.py
def variations_to_tau(model: str, params, tau: float) -> float | None:
    """Variations at which a fitted model's growth exponent reaches ``tau``."""
    a, b = params
    if model == "Clench (Michaelis-Menten)":
        return (1.0 / tau - 1.0) / b
    if model == "negative exponential":
        # math.expm1 overflows above about 709; s/expm1(s) is far below any
        # tau by 700, so the bracket holds the root.
        x = brentq(lambda s: s / math.expm1(s) - tau, 1e-12, 700.0)
        return x / b
    if model == "logarithmic":
        # Solve in w = ln(u): the root spans many orders of magnitude.  At
        # w = 690 the growth exponent is far below any tau in (0, 1).
        w = brentq(lambda w: math.exp(w) / ((1.0 + math.exp(w))
                                            * math.log1p(math.exp(w))) - tau,
                   -27.0, 690.0)
        return math.exp(w) / (b * a)
    return None

projected_totals

projected_totals(variations, qd, beta, tau: float, *, persist: bool = True) -> tuple

The projected total variations to the halt, for each fitted model.

Returns (totals, below). totals maps the name of each model that describes the survey to its projected total, which is above the variations spent. below lists the models that do not describe it.

Each fitted model gives the variations at which its growth exponent reaches tau. Its growth exponent falls monotonically, so with persist the halt comes one doubling later, and the projected total is twice that count. A model goes into below when it puts its growth exponent at or below tau while the measured beta is still above it, or when it projects a halt within the variations already spent. A model whose projection fails goes into neither.

Source code in src/hifuku/halt.py
def projected_totals(variations, qd, beta, tau: float, *,
                     persist: bool = True) -> tuple:
    """The projected total variations to the halt, for each fitted model.

    Returns ``(totals, below)``.  ``totals`` maps the name of each model
    that describes the survey to its projected total, which is above the
    variations spent.  ``below`` lists the models that do not describe it.

    Each fitted model gives the variations at which its growth exponent
    reaches ``tau``.  Its growth exponent falls monotonically, so with
    ``persist`` the halt comes one doubling later, and the projected total
    is twice that count.  A model goes into ``below`` when it puts its
    growth exponent at or below ``tau`` while the measured ``beta`` is still
    above it, or when it projects a halt within the variations already
    spent.  A model whose projection fails goes into neither.
    """
    used = float(np.asarray(variations, float)[-1])
    totals, below = {}, []
    for name, params in fit_models(variations, qd).items():
        try:
            target = variations_to_tau(name, params, tau)
        except (ValueError, ZeroDivisionError, OverflowError, RuntimeError):
            continue
        if target is None or not math.isfinite(target):
            continue
        if target <= used and (beta is None or beta > tau):
            below.append(name)
            continue
        if persist:
            target *= 2.0
        if target > used:
            totals[name] = target
        else:
            below.append(name)
    return totals, below

budget_message

budget_message(variations, qd, beta, tau: float, *, persist: bool = True) -> str

The warning for a survey whose budget ended before the halt.

The message gives the projected totals of :func:projected_totals, and names in a separate clause the models that do not describe this survey.

Source code in src/hifuku/halt.py
def budget_message(variations, qd, beta, tau: float, *,
                   persist: bool = True) -> str:
    """The warning for a survey whose budget ended before the halt.

    The message gives the projected totals of
    :func:`projected_totals`, and names in a separate clause the models
    that do not describe this survey.
    """
    used = float(np.asarray(variations, float)[-1])
    spent = _count(used)
    if beta is None:
        head = (f"The growth of the QD-score has not been measured past the "
                f"guard after {spent} variations, so the survey could not "
                f"halt at tau = {tau:g}.")
    else:
        head = (f"The QD-score is still growing (beta = {beta:.2f} per "
                f"doubling at {spent} variations); the landscape has not "
                f"settled to tau = {tau:g}.")
    totals, below = projected_totals(variations, qd, beta, tau,
                                     persist=persist)
    projected = [f"about {_count(t)} ({name})" for name, t in totals.items()]
    if projected:
        message = (head + " Projected total variations to the halt: "
                   + ", ".join(projected) + ". The models disagree by "
                   "design; read them as a range, not an estimate.")
    else:
        message = head + " No fitted model can project the cost."
    if below:
        one = len(below) == 1
        message += (f" The fitted {_names(below)} "
                    f"{'model puts' if one else 'models put'} the growth "
                    f"exponent at or below tau already, so "
                    f"{'it does' if one else 'they do'} not describe the "
                    f"growth of this survey.")
    return message