Data Cache
SRToolkit.dataset.data_cache
Persistent cache for symbolic regression benchmark datasets.
Datasets are stored as .npz files in a platform-appropriate data directory,
keyed by benchmark name, version, and dataset name. This module is the public
interface for locating, listing, refreshing, and garbage-collecting cached
datasets, and also houses the materialisation engine used internally by the
dataset subpackage.
data_root
dataset_path
Return the expected cache path for a dataset (the file may not exist yet).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
benchmark
|
str
|
Benchmark name (e.g. |
required |
version
|
str
|
Version string (e.g. |
required |
key
|
str
|
Dataset key / name (e.g. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
The |
Source code in SRToolkit/dataset/data_cache.py
resolve
resolve(benchmark: str, version: str, key: str, config: Optional[dict] = None, *, force: bool = False) -> Path
Return the cache path for <benchmark>/<version>/<key>.npz, materialising
it first if necessary.
The data source is reconstructed from config["data_source"] via
DataSource.from_dict. Passing
config=None (or a config whose "data_source" is None) is valid only when
the cache entry already exists — it asserts presence without triggering
materialisation.
On a cache hit (file exists and force is False): if the source is volatile
(e.g. SampleSource), the stored sidecar
.meta.json hash is compared against the current data_source + samplers
config. A mismatch emits a warning telling the user to call refresh().
On a cache miss (or force=True): the data is materialised by calling the source's
materialize.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
benchmark
|
str
|
Benchmark name (e.g. |
required |
version
|
str
|
Version string (e.g. |
required |
key
|
str
|
Dataset key / name (e.g. |
required |
config
|
Optional[dict]
|
Full dataset config dict containing a |
None
|
force
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the cache entry is absent and no source is available. |
Source code in SRToolkit/dataset/data_cache.py
extract_zip_into_version_dir
Extract an open ZipFile into version_dir, accepting both archive layouts.
to_archivelayout: data files live under adata/prefix (alongside abenchmark.json/dataset.jsonthat is not a data file). Thedata/prefix is stripped so the.npz(and_gt.npy) files land directly in the version directory; non-data/members are ignored.- flat layout: the
.npzfiles sit at the archive root (as served by the built-in benchmarks). Whenflat_fallbackisTrue(the default) and nodata/-prefixed member is present, the whole archive is extracted as-is.
The layout is detected automatically by the presence of any data/-prefixed
member, so a single hosted to_archive archive can be consumed both by
SR_benchmark.from_url and by a
config carrying a UrlSource.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
zf
|
ZipFile
|
An open |
required |
version_dir
|
Path
|
Destination cache version directory. |
required |
flat_fallback
|
bool
|
If |
True
|
Source code in SRToolkit/dataset/data_cache.py
import_archive
Extract a .zip archive into the cache version directory
<data_root>/<benchmark>/<version_slug>/.
Both the to_archive layout (data under a data/ prefix) and a flat layout
(.npz files at the archive root) are handled — see
extract_zip_into_version_dir.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
archive_path
|
Path
|
Path to a |
required |
benchmark
|
str
|
Benchmark name used to determine the cache directory. |
required |
version
|
str
|
Version string used to determine the cache directory. |
required |
Source code in SRToolkit/dataset/data_cache.py
list
List all datasets currently stored in the cache.
Walks data_root() and returns one dict per cached .npz.
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
A list of dicts, each with keys |
List[Dict[str, Any]]
|
|
Source code in SRToolkit/dataset/data_cache.py
gc
Garbage-collect the data cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
keep_latest
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
List[Path]
|
A list of |
Source code in SRToolkit/dataset/data_cache.py
remove
Remove a specific cached benchmark, version, or dataset.
The deletion granularity widens as fewer arguments are given:
remove("feynman")— delete every cached version of the benchmark.remove("feynman", "1.0.0")— delete just that version directory.remove("feynman", "1.0.0", "I.16.6")— delete a single dataset's.npzplus its_gt.npyand.meta.jsonsidecars.
Targeting something that is not in the cache is a no-op (returns an empty list); nothing is raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
benchmark
|
str
|
Benchmark name (e.g. |
required |
version
|
Optional[str]
|
Version string. If |
None
|
key
|
Optional[str]
|
Dataset key / name. If |
None
|
Returns:
| Type | Description |
|---|---|
List[Path]
|
List of paths that were removed. |
Source code in SRToolkit/dataset/data_cache.py
refresh
Force-refresh a cached dataset entry by re-materialising it from source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
benchmark
|
str
|
Benchmark name. |
required |
version
|
str
|
Version string. |
required |
key
|
str
|
Dataset key / name. |
required |
source
|
'DataSource'
|
A DataSource describing the origin of the data (e.g. UrlSource). For a SampleSource — which needs the dataset's samplers — use SR_dataset.refresh instead. |
required |