Resultbag
This page lists Resultbag methods for storing, filtering, loading, and maintaining results.
Pass a Resultbag to solve with the resultbag= keyword to reuse stored
results. See the Core API, Resultbag guide, and
Solving Projects for the complete workflow.
Warning
Only open Resultbag files from trusted sources. Loading stored results or logs uses Python pickle and can execute code from the file.
Resultbag
- class jcmsuite.results.Resultbag(filepath, keys=None)[source]
Store and query solve results in a persistent Resultbag.
Warning
Open Resultbag files only from trusted sources. Loading stored results or logs uses Python pickle and can execute code from the file.
- Parameters:
filepath (str | Path) – Resultbag storage path. When the path has no suffix, .jcmrb is appended automatically.
keys (Mapping[str, object] | Sequence[str] | None, optional) – project keys or a sequence of project key names that defines the stored fields. When you reopen a Resultbag, None preserves its existing fields. If stored data exists, call resultbag.management.reset() before you change the fields.
Notes
Use one Resultbag for one logical project and one set of source files. Source-file checks determine whether stored results can be reused.
- __enter__()[source]
Return this Resultbag for context-managed usage.
- Returns:
This Resultbag instance.
- Return type:
- __exit__(exc_type, exc, tb)[source]
Close the Resultbag when the context-managed block exits.
- Parameters:
exc_type (type[BaseException] | None) – Exception type raised in the managed block, if any.
exc (BaseException | None) – Exception instance raised in the managed block, if any.
tb (object | None) – Traceback object associated with exc, if any.
- __init__(filepath, keys=None)[source]
Open or create a Resultbag.
- Parameters:
filepath (str | Path) – Resultbag storage path. When the path has no suffix, .jcmrb is appended automatically.
keys (Mapping[str, object] | Sequence[str] | None, optional) – project keys or a sequence of project key names that defines the stored fields. When you reopen a Resultbag, None preserves its existing fields. If stored data exists, call resultbag.management.reset() before you change the fields.
- Raises:
InvalidConfigurationError – If the parent directory does not exist, or if stored data exists and the requested project key fields differ.
- filter(key=None, filter_value=None, /, **criteria)[source]
Return a read-only view filtered by project keys.
- Parameters:
key (str | None, optional) – project key name for a positional filter.
filter_value (FilterInput | None, optional) – Exact value or an inclusive range created by between(…).
**criteria (FilterInput) – project key filters. An entry must match all filters.
- Returns:
Read-only access to matching Resultbag entries.
- Return type:
- Raises:
InvalidConfigurationError – If the filter is incomplete, empty, duplicated, or cannot compare its bounds with a stored value.
- get_results(keys=None, *, jcmt_pattern=None)[source]
Load selected entries as their supported solve result shape.
- Parameters:
keys (Mapping[str, object] | Sequence[Mapping[str, object]] | None, optional) – One set or a sequence of project keys to load. None loads all entries in the Resultbag.
jcmt_pattern (str | None, optional) – JCMT pattern to select. None selects entries without a pattern.
- Returns:
Solve result shape for the selected entries.
- Return type:
SolveResult | BatchSolveResult | BundledSolveResult | BundledBatchSolveResult
- Raises:
InvalidConfigurationError – If no entry matches, the selection is ambiguous, the supplied project keys are empty, or stored result shapes are incompatible.
Notes
When project keys are provided, batch positions follow their supplied sequence. With no selection, entries retain Resultbag storage order. Only load results from a Resultbag file that you trust. This method uses Python pickle to load stored results.
- has_results()[source]
Return whether at least one stored result exists.
- Returns:
True when the Resultbag contains a stored result. Otherwise, False.
- Return type:
bool
- items()[source]
Iterate over stored project keys and result payloads.
- Returns:
project keys and stored raw result pairs in storage order.
- Return type:
Iterator[tuple[dict[str, object], object]]
Notes
Only iterate over a Resultbag file that you trust. This method loads serialized raw result data.
- property keys
Return stored project keys without loading result payloads.
- Returns:
project keys in stable order. The collection cannot be changed.
- Return type:
ResultbagKeys
- management
Provide advanced Resultbag maintenance and solve integration.
Use this namespace to add, inspect, remove, or reset stored entries, manage attempt logs, and connect daemon submissions to Resultbag storage. These operations access persisted data directly. Use Resultbag.get_results(…) for normal result selection and the current typed result interfaces.
- property suffixes
Return stored JCMT patterns in stable order.
- Returns:
Available JCMT patterns. None identifies entries without a JCMT pattern.
- Return type:
tuple[str | None, …]
Filter Helpers
Read-Only Views
Call resultbag.filter to get these views. Do not construct
ResultbagView or
ResultbagQuery directly.
- class jcmsuite.results.ResultbagView(source, specs)[source]
Provide read-only access to selected Resultbag entries.
The Resultbag loads each entry only when an operation needs the entry. Obtain a view from Resultbag.filter(…); do not construct this class directly.
- filter(key=None, filter_value=None, /, **criteria)[source]
Narrow the selection by adding project key filters.
- Parameters:
key (str | None, optional) – project key name for a positional filter.
filter_value (object | None, optional) – Value for a positional filter. Use a plain value for an exact match. Use between(lower, upper) to include both limits.
**criteria (object) – project key filters. An entry must match all filters.
- Returns:
Read-only access to entries that match all old and new filters.
- Return type:
- Raises:
InvalidConfigurationError – If no filter is supplied, a positional filter is incomplete, a project key name is empty or duplicated, or bounds cannot be compared with a stored value.
- get_results(keys=None, *, jcmt_pattern=None)[source]
Load the selected Resultbag entries as solve results.
- Parameters:
keys (Mapping[str, object] | Sequence[Mapping[str, object]] | None, optional) – One set or a sequence of project keys to load. None loads all entries in this view.
jcmt_pattern (str | None, optional) – JCMT pattern to select. None selects entries without a pattern.
- Returns:
Solve result shape for the selected entries.
- Return type:
SolveResult | BatchSolveResult | BundledSolveResult | BundledBatchSolveResult
- Raises:
InvalidConfigurationError – If no entry matches, the selection is ambiguous, an empty sequence of project keys is supplied, or stored result shapes are not compatible.
Notes
If a sequence of project keys is supplied, the selected entries follow that sequence and receive new batch positions that start at zero. Duplicate project keys are included once at their first requested position. With no selection, entries retain Resultbag storage order. Only load results from a Resultbag file that you trust. This method uses Python pickle to load stored objects.
- property keys
Return the project keys for the selected Resultbag entries.
- Returns:
project keys in a stable order. The collection cannot be changed.
- Return type:
ResultbagKeys
- property suffixes
Return the JCMT patterns for the selected Resultbag entries.
The result is in a stable order. None identifies entries that have no JCMT pattern.
- Returns:
Available JCMT patterns.
- Return type:
tuple[str | None, …]
- class jcmsuite.results.resultbag.ResultbagQuery(resultbag, specs)[source]
Provide read-only access to Resultbag entries that match filters.
The Resultbag loads each entry only when an operation needs the entry. Obtain a query from Resultbag.filter(…); do not construct this class directly.
- filter(key=None, filter_value=None, /, **criteria)[source]
Narrow the selection by adding project key filters.
- Parameters:
key (str | None, optional) – project key name for a positional filter.
filter_value (object | None, optional) – Value for a positional filter. Use a plain value for an exact match. Use between(lower, upper) to include both limits.
**criteria (object) – project key filters. An entry must match all filters. Plain values, including tuples, require an exact match. Use between(lower, upper) to include both limits.
- Returns:
Read-only access to entries that match all old and new filters.
- Return type:
- Raises:
InvalidConfigurationError – If no filter is supplied, a positional filter is incomplete, a project key name is empty or duplicated, or bounds cannot be compared with a stored value.
- get_results(keys=None, *, jcmt_pattern=None)[source]
Load matching Resultbag entries as solve results.
- Parameters:
keys (Mapping[str, object] | Sequence[Mapping[str, object]] | None, optional) – One set or a sequence of project keys to load. None loads all matching entries.
jcmt_pattern (str | None, optional) – JCMT pattern to select. None selects entries without a pattern.
- Returns:
Solve result shape for the selected entries.
- Return type:
SolveResult | BatchSolveResult | BundledSolveResult | BundledBatchSolveResult
- Raises:
InvalidConfigurationError – If no entry matches, the selection is ambiguous, an empty sequence of project keys is supplied, or stored result shapes are not compatible.
Notes
Multiple entries are sorted by project keys before the method assigns new batch positions. Only load results from a Resultbag file that you trust. This method uses Python pickle to load stored objects.
- items()[source]
Return matching project keys with their stored results.
- Returns:
Matching pairs sorted by project keys.
- Return type:
Iterator[tuple[dict[str, object], object]]
Notes
Only iterate over a Resultbag file that you trust. This method uses Python pickle to load stored results.
- property keys
Return the project keys that match all filters.
- Returns:
Matching project keys in a stable order.
- Return type:
ResultbagKeys
- property suffixes
Return JCMT patterns for the matching Resultbag entries.
- Returns:
Matching JCMT patterns in a stable order.
- Return type:
tuple[str | None, …]
Resultbag Management
Use resultbag.management for advanced Resultbag maintenance and solve
operations. Normal result analysis does not require these methods.
Management result access uses versioned raw dictionaries. Use
resultbag.get_results when you want the current
SolveResult or batch result interface. Stored raw
dictionaries contain result data, not project or result-directory paths.
- class jcmsuite.results.resultbag_management.ResultbagManagement(store)[source]
Provide advanced Resultbag maintenance and solve operations.
- add(*, keys, result, log=None, jcmt_pattern=None)[source]
Add or replace one Resultbag entry.
- Parameters:
keys (Mapping[str, object]) – project keys that identify the Resultbag entry.
result (object) – Versioned raw result dictionary to store. Other pickleable values remain available through this low-level management surface. Older result objects are converted before persistence.
log (object | None, optional) – Log to store with the result.
jcmt_pattern (str | None, optional) – JCMT pattern that identifies the result. None identifies the unsuffixed result.
- Returns:
This method has no return value. The method adds or replaces the Resultbag entry.
- Return type:
None
- add_attempt_log(*, keys, attempt_index, payload, jcmt_pattern=None)[source]
Store the log from one solve attempt.
- Parameters:
keys (Mapping[str, object]) – project keys that identify the Resultbag entry.
attempt_index (int) – Zero-based attempt index.
payload (object) – Attempt log to store.
jcmt_pattern (str | None, optional) – JCMT pattern that identifies the result. None identifies the unsuffixed result.
- Returns:
This method has no return value. The method stores the attempt log.
- Return type:
None
- Raises:
InvalidConfigurationError – If attempt_index is negative.
- bind_job(*, keys, job_id, jcmt_pattern)[source]
Associate a daemon submission with project keys.
- Parameters:
keys (Mapping[str, object]) – project keys for the daemon submission.
job_id (int) – Daemon submission identifier.
jcmt_pattern (str | None) – JCMT pattern for the result. None identifies the unsuffixed result.
- Returns:
This method has no return value. The Resultbag stores the association until the daemon result is available.
- Return type:
None
- check_result(keys, *, jcmt_pattern=None)[source]
Check whether one Resultbag entry exists.
- Parameters:
keys (Mapping[str, object]) – project keys that identify the Resultbag entry.
jcmt_pattern (str | None, optional) – JCMT pattern that identifies the result. None identifies the unsuffixed result.
- Returns:
True if the exact Resultbag entry exists. Otherwise, False.
- Return type:
bool
- check_source_files(files)[source]
Check whether source files are unchanged.
- Parameters:
files (Sequence[str | Path]) – Source files to compare with the stored file information.
- Returns:
True if the files match or source-file checks are ignored. Otherwise, False.
- Return type:
bool
- clear_attempt_logs(keys, *, jcmt_pattern=None)[source]
Remove the solve-attempt logs for one Resultbag entry.
- Parameters:
keys (Mapping[str, object]) – project keys that identify the Resultbag entry.
jcmt_pattern (str | None, optional) – JCMT pattern that identifies the result. None identifies the unsuffixed result.
- Returns:
This method has no return value. The method removes all matching attempt logs.
- Return type:
None
- get_attempt_logs(keys, *, jcmt_pattern=None)[source]
Return the stored solve-attempt logs for one Resultbag entry.
- Parameters:
keys (Mapping[str, object]) – project keys that identify the Resultbag entry.
jcmt_pattern (str | None, optional) – JCMT pattern that identifies the result. None identifies the unsuffixed result.
- Returns:
Attempt logs in order of their attempt_index values.
- Return type:
tuple[object, …]
Notes
Only load attempt logs from a Resultbag file that you trust. This method uses Python pickle to load stored objects.
- get_log(keys, *, jcmt_pattern=None)[source]
Return the stored log for one set of project keys.
- Parameters:
keys (Mapping[str, object]) – project keys that identify the Resultbag entry.
jcmt_pattern (str | None, optional) – JCMT pattern that identifies the result. None identifies the unsuffixed result.
- Returns:
Stored log.
- Return type:
object
- Raises:
InvalidConfigurationError – If the entry does not exist.
Notes
Only load logs from a Resultbag file that you trust. This method uses Python pickle to load the stored object.
- get_result(keys, *, jcmt_pattern=None)[source]
Return the stored result for one set of project keys.
- Parameters:
keys (Mapping[str, object]) – project keys that identify the Resultbag entry.
jcmt_pattern (str | None, optional) – JCMT pattern that identifies the result. None identifies the unsuffixed result.
- Returns:
Stored raw result dictionary or other management data.
- Return type:
object
- Raises:
InvalidConfigurationError – If the entry does not exist.
Notes
Only load results from a Resultbag file that you trust. This method uses serialized storage data to load the raw result data.
- ignore_source_files(ignore=True)[source]
Enable or disable source-file consistency checks.
- Parameters:
ignore (bool, optional) – If True, do not check source files. If False, check the source files before reusing results.
- Returns:
This method has no return value. The method stores the setting.
- Return type:
None
- release_job(job_id)[source]
Release a daemon submission association.
- Parameters:
job_id (int) – Daemon submission identifier to release.
- Returns:
This method has no return value. If the association exists, the method removes it.
- Return type:
None
- remove(filter_function)[source]
Remove entries selected by a filter function.
- Parameters:
filter_function (Callable[[dict[str, object]], bool]) – Filter function that receives project keys. The function returns True for each Resultbag entry to remove.
Examples
Remove entries whose material project key is “Si”:
>>> resultbag.management.remove( ... filter_function=lambda project_keys: project_keys.get("material") == "Si" ... )
- Returns:
This method has no return value. The method removes matching entries, suffix variants, and attempt logs.
- Return type:
None
- remove_result(keys, *, jcmt_pattern=None)[source]
Remove one Resultbag entry.
- Parameters:
keys (Mapping[str, object]) – project keys that identify the Resultbag entry.
jcmt_pattern (str | None, optional) – JCMT pattern that identifies the result. None identifies the unsuffixed result.
- Returns:
This method has no return value. The method removes the matching Resultbag entry and its attempt logs.
- Return type:
None
- reset()[source]
Remove all stored entries and attempt logs.
- Returns:
This method has no return value. Resultbag settings remain stored.
- Return type:
None
- set_source_files(files)[source]
Store information about the Resultbag source files.
- Parameters:
files (Sequence[str | Path]) – Source files that determine whether stored results can be reused.
- Returns:
This method has no return value. The method stores each file path and a value that detects file changes.
- Return type:
None
- Raises:
InvalidConfigurationError – If a path is missing or is not a regular file.
- store_job_result(*, job_id, result, log)[source]
Store the result for an associated daemon submission.
- Parameters:
job_id (int) – Daemon submission identifier previously passed to bind_job(…).
result (object) – Result to store.
log (object) – Log to store with the result.
- Returns:
This method has no return value. The method stores the result and removes the daemon submission association.
- Return type:
None
The following methods connect Resultbag storage to daemon submissions. Normal user code does not need to call these methods.