Workspace and model registry

The Workbench persists user work as assets in a JSON-indexed workspace and keeps user-trained model packages in a separate registry. Both layers are plain files; there is no database.

Workspace

Directory resolution: $CC4Q_WORKSPACE > .cc4q_workspace/ next to a source checkout > ~/.cache/cc4q/workspace for wheel installs.

Workspace: the “everything is an asset” persistence layer (WP1A).

A workspace is a directory holding an index.json asset index plus per-asset payload files under assets/<type>/<id>/.

Asset types:

  • corpus — SCCU records (raw or labeled). Fields: name, source (url | dir | upload | precomputed), sccus, quantum_pct (labeled only), labeled (bool), files = {“corpus”: <jsonl path>, “labeled”?: <jsonl path>}.

  • annotation_session — schema/mode/progress of an annotation round. Fields: name, schema, mode, total, labeled_count, export_path?.

  • evaluation — a model-pair comparison report. Fields: name, pair = [model_a, model_b], corpus, metrics = {n, agreement, precision, recall, wilson95}, report_path.

  • model — NOT stored here; models live in cc4q.registry and are referenced by id (see list_models()).

Directory resolution: $CC4Q_WORKSPACE > .cc4q_workspace/ next to a source checkout (detected by pyproject.toml at the repo root) > ~/.cache/cc4q/workspace/ for wheel installs. The workspace and index are created on demand. The index is written atomically (tmp file + rename) and a corrupted index.json is backed up to index.json.bak and rebuilt empty (with a logged warning).

Asset types

Type

Required fields

Purpose

corpus

name, source

SCCU records (raw or labeled); files points at the JSONL payloads.

annotation_session

name, schema, mode

One annotation round, with total/labeled_count progress.

evaluation

name, pair

A model-pair comparison report and metrics.

Assets also carry a short id, created_at, and (after updates) an updated_at timestamp. The index is written atomically; a corrupt index.json is backed up to index.json.bak and rebuilt empty.

Lifecycle helpers

cc4q.workspace.workspace_dir()[source]

Resolve (and create) the workspace directory.

cc4q.workspace.create_asset(type_, root=None, **fields)[source]

Create an asset of type_ with the given fields. Injects id (short uuid), created_at, and (for sessions) updated_at. Returns the stored asset dict.

cc4q.workspace.list_assets(type_=None)[source]

All assets (newest-updated first); filter by type when given.

cc4q.workspace.get_asset(asset_id)[source]

Return one asset by id.

Parameters:

asset_id – Short asset id (for example "a1b2c3d4").

Returns:

A copy of the asset dictionary.

Raises:

KeyError – If no asset with that id exists.

cc4q.workspace.update_asset(asset_id, **fields)[source]

Merge fields into an asset; bumps updated_at. Returns the updated dict.

cc4q.workspace.rename_asset(asset_id, name)[source]

Set an asset’s display name.

Parameters:
  • asset_id – Asset id.

  • name – New display name.

Returns:

The updated asset dictionary.

Raises:

KeyError – If no asset with that id exists.

cc4q.workspace.delete_asset(asset_id)[source]

Remove the asset from the index and delete its payload directory.

cc4q.workspace.export_asset(asset_id, dest_dir)[source]

Zip the asset’s payload directory into dest_dir (created as needed) as <id>.zip including an asset.json manifest. Returns the zip path.

Payload helpers

cc4q.workspace.asset_path(asset_id, filename, type_=None, create_dir=False)[source]

Payload file path for an asset: assets/<type>/<id>/<filename>. The type is looked up from the index when not given.

cc4q.workspace.write_jsonl(asset_id, filename, records)[source]

Write records to a JSONL payload file inside an asset directory.

Parameters:
  • asset_id – Asset id whose payload directory should receive the file.

  • filename – File name relative to the asset directory.

  • records – Iterable of JSON-serializable records.

Returns:

The full path to the written file.

cc4q.workspace.read_jsonl(path)[source]

Read a JSONL file into a list of records (blank lines ignored).

cc4q.workspace.list_models()[source]

Model assets are delegated to the user model registry — the workspace only references model ids. Returns the registry entries.

Model registry

A user model package is a directory with one sub-directory per axis it provides (quantum_related and/or quantum_category), each a Hugging Face model directory. Packages may provide a single axis; missing axes fall back to the released checkpoints at prediction time.

Registry location: $CC4Q_USER_MODELS > user_models/ next to a source checkout > ~/.cache/cc4q/user_models.

User model registry for the web workbench.

A small JSON index over a directory of user-provided model packages. Each package is a directory in the same layout as models_checkpoints/: one sub-directory per label axis it provides (quantum_related / quantum_category), each a Hugging Face model directory. Packages may provide a single axis (e.g. a freshly trained classifier); missing axes fall back to the released checkpoints at prediction time.

The registry lives in user_models/ next to a source checkout, or in ~/.cache/cc4q/user_models for wheel installs.

cc4q.registry.registry_root()[source]

Return the user-model registry directory.

Resolution order: $CC4Q_USER_MODELS > user_models/ next to a source checkout > ~/.cache/cc4q/user_models for wheel installs.

cc4q.registry.list_models(root=None)[source]

Registry entries (newest first), with is_default set.

cc4q.registry.package_dir(model_id, root=None)[source]

Return the directory holding one registered model package.

Parameters:
  • model_id – Registry id (for example "my-bert-3ep").

  • root – Optional registry root override.

Returns:

Path to the package directory (which may not exist).

cc4q.registry.register(name, path, source='trained', root=None)[source]

Register an existing model package directory (copied into the registry). Returns the new entry.

cc4q.registry.register_uploaded_zip(uploaded_file, name=None, root=None)[source]

Extract an uploaded zip into the registry and register it.

cc4q.registry.set_default(model_id, root=None)[source]

Mark one registered model as the default for the Workbench.

Parameters:
  • model_id – Registry id to activate.

  • root – Optional registry root override.

Raises:

KeyError – If model_id is not registered.

cc4q.registry.delete(model_id, root=None)[source]

Remove a model package from the registry and delete its directory.

If the deleted model was the default, the next remaining model becomes the default (or the default is cleared when the registry is empty).

Parameters:
  • model_id – Registry id to delete.

  • root – Optional registry root override.

cc4q.registry.zip_package(model_id, dest_path, root=None)[source]

Write a zip archive of one model package.

Parameters:
  • model_id – Registry id to archive.

  • dest_path – Destination .zip path.

  • root – Optional registry root override.

Returns:

dest_path.

Example

from cc4q import workspace as ws

corpus = ws.create_asset(
    "corpus", name="qiskit-nature", source="url", sdk="qiskit-nature",
    version="0.7.2", sccus=1200, labeled=False,
)
path = ws.write_jsonl(corpus["id"], "corpus.jsonl", records)
ws.update_asset(corpus["id"], files={"corpus": path})