Persistence and Caching¶
Experiment store¶
store ¶
SQLite-backed study, trial, attempt, observation, and event persistence.
StudyStatus ¶
Bases: str, Enum
Durable lifecycle states for a study.
TrialStatus ¶
Bases: str, Enum
Durable lifecycle states for a trial.
AttemptStatus ¶
Bases: str, Enum
Durable lifecycle states for a trial attempt.
StudyRecord
dataclass
¶
StudyRecord(id: str, name: str, config_hash: str, status: StudyStatus, created_at: str, updated_at: str)
Persisted study identity and lifecycle state.
TrialRecord
dataclass
¶
TrialRecord(id: str, study_id: str, sequence: int, candidate_hash: str, candidate_json: str, status: TrialStatus, error: str | None, created_at: str, updated_at: str)
Persisted trial identity and lifecycle state.
AttemptRecord
dataclass
¶
AttemptRecord(id: str, trial_id: str, number: int, status: AttemptStatus, started_at: float, lease_expires_at: float, finished_at: float | None, error: str | None)
Persisted execution attempt with a recovery lease.
PersistedUsageRecord
dataclass
¶
PersistedUsageRecord(id: str, trial_id: str, attempt_id: str | None, usage: UsageRecord, created_at: str)
Append-only usage observation associated with a trial and optional attempt.
StudyEvent
dataclass
¶
SQLiteStore ¶
Transactional SQLite authority for optimization lifecycle state.
Source code in src/tunarag/store.py
initialize ¶
Create or migrate the experiment schema to the supported version.
Source code in src/tunarag/store.py
create_study ¶
create_study(name: str, configuration: object) -> StudyRecord
Create a study in the created state.
Source code in src/tunarag/store.py
get_study ¶
get_study(study_id: str) -> StudyRecord
Load one study or raise KeyError.
Source code in src/tunarag/store.py
transition_study ¶
transition_study(study_id: str, status: StudyStatus) -> StudyRecord
Apply a guarded study lifecycle transition.
Source code in src/tunarag/store.py
create_trial ¶
create_trial(study_id: str, sequence: int, candidate: Candidate) -> TrialRecord
Create a trial with an explicit nonnegative sequence.
Source code in src/tunarag/store.py
reserve_trial ¶
reserve_trial(study_id: str, candidate: Candidate) -> TrialRecord
Atomically allocate the next sequence and reserve a unique candidate.
Source code in src/tunarag/store.py
get_trial ¶
get_trial(trial_id: str) -> TrialRecord
Load one trial or raise KeyError.
Source code in src/tunarag/store.py
list_trials ¶
list_trials(study_id: str) -> list[TrialRecord]
Return trials in durable sequence order.
Source code in src/tunarag/store.py
transition_trial ¶
transition_trial(trial_id: str, status: TrialStatus, *, error: str | None = None) -> TrialRecord
Apply a guarded trial lifecycle transition.
Source code in src/tunarag/store.py
start_attempt ¶
start_attempt(trial_id: str, *, lease_seconds: float, now: float | None = None) -> AttemptRecord
Start the next attempt and acquire its recovery lease.
Source code in src/tunarag/store.py
get_attempt ¶
get_attempt(attempt_id: str) -> AttemptRecord
Load one attempt or raise KeyError.
Source code in src/tunarag/store.py
list_attempts ¶
list_attempts(trial_id: str) -> list[AttemptRecord]
Return attempts in monotonic attempt-number order.
Source code in src/tunarag/store.py
finish_attempt ¶
finish_attempt(attempt_id: str, status: AttemptStatus, *, usage: Sequence[UsageRecord] = (), error: str | None = None, now: float | None = None) -> AttemptRecord
Finish a running attempt while leaving retryable trial state intact.
Source code in src/tunarag/store.py
abandon_expired_attempts ¶
abandon_expired_attempts(*, study_id: str | None = None, now: float | None = None) -> list[AttemptRecord]
Persist abandonment for expired attempts, optionally scoped to one study.
Source code in src/tunarag/store.py
list_recoverable_trials ¶
list_recoverable_trials(study_id: str) -> list[TrialRecord]
Return running trials that have no active attempt.
Source code in src/tunarag/store.py
commit_trial_result ¶
commit_trial_result(trial_id: str, *, status: TrialStatus, metrics: Sequence[MetricValue] = (), usage: Sequence[UsageRecord] = (), attempt_id: str | None = None, error: str | None = None, now: float | None = None) -> TrialRecord
Atomically persist observations, attempt completion, and terminal trial state.
Source code in src/tunarag/store.py
list_metrics ¶
list_metrics(trial_id: str) -> list[MetricValue]
Return committed metrics ordered by name.
Source code in src/tunarag/store.py
list_usage ¶
list_usage(trial_id: str) -> list[PersistedUsageRecord]
Return append-only usage in insertion order.
Source code in src/tunarag/store.py
append_event ¶
append_event(study_id: str, event_type: str, payload: Mapping[str, Any]) -> StudyEvent
Append a canonical event with an atomic per-study sequence.
Source code in src/tunarag/store.py
list_events ¶
list_events(study_id: str, *, after_sequence: int = -1) -> list[StudyEvent]
Return durable events after a sequence in replay order.
Source code in src/tunarag/store.py
Evaluation cache¶
cache ¶
Versioned, checksum-verified local cache persistence.
CachePrivacy ¶
CacheLookupStatus ¶
Bases: str, Enum
Outcome of a cache lookup.
CacheEntryState ¶
CacheKey
dataclass
¶
Namespaced identity for one semantic cache value.
from_parts
classmethod
¶
from_parts(namespace: str, *parts: Any, format_version: int = 1) -> CacheKey
Build a key from canonical semantic inputs.
Source code in src/tunarag/cache.py
CacheEntry
dataclass
¶
CacheEntry(key: CacheKey, checksum: str, privacy: CachePrivacy, created_at: float, expires_at: float | None)
CacheLookup
dataclass
¶
CacheLookup(key: CacheKey, status: CacheLookupStatus, payload: bytes | None = None, checksum: str | None = None, privacy: CachePrivacy | None = None, created_at: float | None = None, expires_at: float | None = None, reason: str | None = None)
Payload and metadata returned by a cache lookup.
SQLiteCache ¶
Transactional SQLite cache with expiry and corruption quarantine.
Source code in src/tunarag/cache.py
initialize ¶
Create the independently versioned cache schema.
Source code in src/tunarag/cache.py
put ¶
put(key: CacheKey, payload: bytes | bytearray | memoryview, *, privacy: CachePrivacy = STANDARD, ttl_seconds: float | None = None) -> CacheEntry
Atomically insert or replace a cache payload.
Source code in src/tunarag/cache.py
get ¶
get(key: CacheKey) -> CacheLookup
Return a verified payload or an explicit miss reason.
Source code in src/tunarag/cache.py
delete ¶
delete(key: CacheKey) -> bool
Delete one cache entry and report whether it existed.
Source code in src/tunarag/cache.py
prune ¶
Remove expired entries and optionally quarantined entries.