mixle.doe.oracle module¶
Verifiable oracle boundary for de novo optimization.
Given a design goal for which there is no data yet but there IS a way to check a candidate (a
simulator, an executable test, held-out truth, an assay), optimize_under_oracle() proposes
candidates, verifies them against the oracle, and keeps a full receipted history of what was tried and
why – the design-test-learn loop, made accountable, rather than “synthesize data and train” with no
account of what verified it.
The one hard precondition, checked before anything else: there must be a verifiable oracle.
VerifiableOracle rejects a “self-graded by a model” tier at CONSTRUCTION – that is the banned
reward this boundary exists to forbid – and optimize_under_oracle() refuses to run at all
without one (oracle=None -> the explicit “no verifiable objective; cannot optimize” refusal, never a
fabricated candidate).
This is a first, deliberately narrow slice: continuous/low-dimensional candidate spaces only, using the
GP Bayesian-optimization loop already in mixle.doe (BayesianOptimizer)
as the proposal model, validated here against a low-cost closed-form oracle before any domain oracle exists.
Not in this slice: structured/discrete candidate spaces (a protein
sequence, a program), amortizing the oracle into a calibrated surrogate, the shared expected-information-
gain acquisition, and full receipt objects – each is a separate surface and is
left explicit rather than half-built here.
A timeout is an abstention, not a data point: it means the oracle did not answer, not that the true
score at that candidate is catastrophic. OracleResult carries an explicit abstained flag
for exactly this, and optimize_under_oracle() never feeds an abstained result to the proposal
model’s fit as if it were ground truth, even though it is still kept in DesignRun.history for the
receipted record. VerifiableOracle also validates every result crossing its boundary (return type,
finite score unless abstained, finite nonnegative cost, receipt shape) rather than letting a malformed
score_fn return silently corrupt the run. Timeout workers are bounded by a circuit breaker,
cooperative cancellation is requested, and eventual late outcomes are linked back to their run by
immutable call IDs so side-effecting cost is never silently lost.
- class OracleResult(score, receipt=<factory>, cost=1.0, abstained=False, passed=True, valid=True, call_id=None, call_started=True)[source]
Bases:
objectOne candidate’s verification outcome: its score, a receipt of how it was scored, and its cost.
Construction validates its own shape (MXR-080-0189): a real, finite
scoreunlessabstained=True, a finite nonnegativecost, and adictreceipt. This is the boundary ascore_fn’s raw, untrusted return value crosses (seeVerifiableOracle._validate_returned), so a wrong type, a NaN/inf that leaked in from some computation, or a negative “cost” is caught immediately here rather than silently reaching a GP fit or a cost report.abstainedmarks a result that is NOT a genuine observation of the oracle’s true objective at the scored candidate – for example,VerifiableOracle’s timeout abstention. An abstained result’sscoreis a placeholder (-infby convention, never a claim about the true objective) kept only so the receipted history stays complete; consumers such asoptimize_under_oracle()gate onabstainedand must never feed one to a fit as if it were ground truth.
- class LateOracleResult(call_id, candidate, ok, result, error)[source]
Bases:
objectA timed-out oracle call’s outcome, captured after the fact.
VerifiableOraclecannot forcibly kill the worker thread a timeout abandons – Python has no API to do so (see_call_with_timeout). If ascore_fnthat ignores (or does not support) the cooperativecancel_eventeventually finishes anyway, its outcome is appended toVerifiableOracle.late_resultsinstead of being silently discarded, so a side-effecting oracle’s eventual cost/outcome is still visible somewhere, even though the caller had already moved on and received an abstention in its place.
- class VerifiableOracle(name, tier, score_fn, fidelity=None, timeout=None, max_outstanding_timeouts=4)[source]
Bases:
objectA callable
candidate -> OracleResultthat declares its verifiability tier and fidelity.score_fndoes the actual verification (wrap a simulator, an executable check, a held-out ground-truth lookup, or a real measurement pipeline;mixle.task.toolcall’sToolCalleris the same “external check as a callable” shape for tool calls). Construction raises iftieris not one ofVERIFIABILITY_TIERS– “self-graded by a model” is not a valid tier and is rejected here, not silently accepted and discovered later.score_fnmay optionally accept acancel_event: threading.Eventkeyword argument (detected once, at construction, via introspection – see_accepts_keyword). A side-effectingscore_fnthat wraps something cancellable (a subprocess, an HTTP request) should periodically checkcancel_event.is_set()and tear its underlying call down promptly once set. This is a best-effort, cooperative cancellation boundary, not a forced kill – Python cannot forcibly terminate a thread. Calls that ignore cancellation remain quarantined, count againstmax_outstanding_timeouts, and eventually open a circuit that prevents additional worker creation. Their outcomes are captured inlate_resultswhen they finish. See_call_with_timeout.- Parameters:
- property late_results: tuple[LateOracleResult, ...]
Immutable snapshot of late outcomes accumulated so far.
- property outstanding_timeouts: int
Number of timed-out workers that have not cooperatively stopped or completed.
- class DesignCandidate(x, result, phase=None)[source]
Bases:
objectOne proposed-and-verified candidate: the point tried and what the oracle said about it.
- class DesignRun(oracle_name, oracle_tier, oracle_fidelity, _oracle=None)[source]
Bases:
objectThe full receipted history of a design loop: every candidate tried, and the oracle’s identity.
- Parameters:
- property history: tuple[DesignCandidate, ...]
Immutable chronological snapshot of the append-only candidate ledger.
- append(candidate)[source]
Append one immutable candidate record; existing ledger entries can never be replaced.
- Parameters:
candidate (DesignCandidate)
- Return type:
None
- property oracle_calls: int
Return the number of candidates attempted against the oracle (abstentions included).
- property candidate_attempts: int
All proposed candidates, including circuit-breaker abstentions that started no external call.
- property genuine_history: tuple[DesignCandidate, ...]
Return
historyfiltered to genuine (non-abstained) observations.An abstention (see
OracleResult.abstained– e.g. a timeout) is not a real observation of the oracle’s objective, so it is excluded here; usehistorydirectly for the full, unfiltered receipted record, abstentions included.
- property best: DesignCandidate
Return the highest-scoring GENUINE candidate in the run history.
Abstained candidates (see
OracleResult.abstained) never win: an abstention is not a real observation of the oracle’s objective, and surfacing one as “the best candidate found” would report a fabricated result as if it were verified. Raises if every candidate abstained (no genuine observation exists to report), distinct from the empty-history case.
- scores()[source]
Return the run’s oracle scores in chronological order, abstentions included (not hidden).
- Return type:
- report()[source]
Named receipt of the run: which oracle, at what tier/fidelity, the best candidate found.
provisional_total_costis the cost known when calls returned. Late outcomes linked by immutable call IDs are reconciled intosettled_late_costandsettled_total_cost.total_costis only populated once no timed-out call remains outstanding or unresolved.
- optimize_under_oracle(oracle, bounds, *, n_init=5, n_iter=15, seed=None, **bo_kwargs)[source]
Run a propose-verify-refit design loop under a fixed oracle budget.
The loop proposes candidates, verifies each one with
oracle, keeps the receipted history, refits the proposal model on every GENUINE observation, and repeats under ann_init + n_iterbudget of oracle calls.oracle=Noneraises immediately with the explicit refusal (“no verifiable objective; cannot optimize”) – the hard precondition checked before any candidate is proposed. Continuous/low-dimensionalboundsonly (see module docstring); the proposal model isBayesianOptimizer, maximizing the oracle’s score.An abstained result (
OracleResult.abstained– e.g. a timeout; seeVerifiableOracle) is never told to the proposal model as if it were a real observation (MXR-080-0189): a timeout means the oracle did not answer, not that the true score at that candidate is-inf, and training a fit on a fabricated-inf“observation” can corrupt it. The abstained candidate is still appended torun.history– the receipted record keeps every attempt, genuine or not – it is simply excluded from what the optimizer learns from.BayesianOptimizer.askis explicitly designed to tolerate this (its initial-design dispensing is gated on points asked, not points told), so skippingtellfor an abstention does not desynchronize or corrupt the proposal model’s state.If the entire initial phase abstains, however, the model has no observation at all to fit an acquisition step on, and
askraises rather than guessing. The adaptive phase is therefore not entered in that case: the run stops and is returned with its receipts intact, so an all-abstention run still yields its audit report (status="no_verified_result") instead of dying inside the proposal model (MXR-080-1488).