uniqc.task.store module#
SQLite-backed task storage for UnifiedQuantum.
This module is the single source of truth for task persistence. Both
uniqc.task_manager and uniqc.task.persistence delegate to
TaskStore; there is no JSON/JSONL fallback path.
Storage layout:
~/.uniqc/cache/
tasks.sqlite # single database file
Schema versioning (best practices)#
The database uses SQLite’s built-in metadata slots in the file header rather than a custom bookkeeping table:
PRAGMA application_idholdsAPPLICATION_ID(the 4 bytes"UNIC"). On open we refuse to touch a file whoseapplication_idis set to something else; a zero value means a fresh DB we can stamp.PRAGMA user_versionholds the integer schema version. It is bumped by each migration and used to decide what else to run.
MIGRATIONS is an ordered list of (target_version, migrate_fn)
tuples. To evolve the schema:
Append a new tuple
(N, _apply_vN)whereN = CURRENT_SCHEMA_VERSION + 1.Bump
CURRENT_SCHEMA_VERSIONtoN.Implement
_apply_vN(conn)(DDL or DML on the given connection).
On open, TaskStore iterates the list and runs each outstanding
migration in its own transaction; user_version is stamped as part of
the same transaction so a crashed migration rolls back the version bump
too.
- class uniqc.task.store.TaskInfo(task_id, backend, status=TaskStatus.PENDING, result=None, shots=1000, submit_time=<factory>, update_time=<factory>, metadata=<factory>)[source]#
Bases:
objectInformation about a submitted task.
- Variables:
task_id (str) – Unique identifier for the task.
backend (str) – The backend where the task was submitted.
status (str) – Current status of the task.
result (dict | None) – Task result (if completed).
shots (int) – Number of shots requested.
submit_time (str) – ISO format timestamp of submission.
update_time (str) – ISO format timestamp of last status update.
metadata (dict) – Additional metadata about the task.
- Parameters:
- class uniqc.task.store.TaskStatus(*values)[source]#
-
Enumeration of task statuses.
- CANCELLED = 'cancelled'#
- FAILED = 'failed'#
- PENDING = 'pending'#
- RUNNING = 'running'#
- SUCCESS = 'success'#
- class uniqc.task.store.TaskStore(cache_dir=None)[source]#
Bases:
objectSQLite-backed storage for task records.
TaskStoreis safe to construct multiple times against the same cache directory; all operations use short-lived connections guarded by a per-instance lock.- Parameters:
cache_dir (Path | str | None) – Directory that holds
tasks.sqlite. Defaults to~/.uniqc/cache/. The directory is created if missing.
- clear_all()[source]#
Delete the on-disk SQLite file (and its WAL/SHM siblings).
Matches the pre-SQLite
clear_cachesemantics: the cache file disappears. A subsequent operation re-initialises the schema.- Return type:
None
- clear_completed(terminal_statuses=('success', 'failed', 'cancelled'))[source]#
Delete tasks whose status is in
terminal_statuses.