Resultbag
Use a Resultbag to store solved results in a .jcmrb file and access the stored
entries later. A Resultbag entry uses project keys and an
optional JCMT pattern.
The suffix_pattern value selects one stored version for the same project. It selects
project support files with that suffix. It does not select a different project start
file.
Resultbag value
Using a Resultbag requires little additional setup. It can prevent repeated solves when you reuse results. For example, an analysis script can reuse completed results instead of recomputing them.
Create A Resultbag
Import Resultbag from jcmsuite.results and pass the
storage path. If the path has no suffix, Resultbag appends
.jcmrb. The parent directory must
exist.
import jcmsuite
resultbag = jcmsuite.results.Resultbag("results.jcmrb")
The Resultbag closes automatically at the end of the script. You can also use a context manager to close the Resultbag at the end of a block.
with jcmsuite.results.Resultbag("results.jcmrb") as resultbag:
print(resultbag.keys)
Use A Resultbag With jcmsuite.solve
Pass a Resultbag to
jcmsuite.solve with the resultbag= keyword argument.
jcmsuite.solve reuses a stored entry when the project, project keys, JCMT pattern,
and source files match. Set recompute=True to ignore a matching entry.
When no layout file or layout template is selected, an existing grid.jcm beside the
project is included among those source files. A changed grid then requires explicit
recomputation; when a layout is selected, grid-only changes do not invalidate the entry.
import jcmsuite
resultbag = jcmsuite.results.Resultbag("results.jcmrb")
result = jcmsuite.solve(
"project.jcmp",
keys={"radius": 0.5},
jcmt_pattern="mie",
resultbag=resultbag
)
For batched project keys, jcmsuite.solve stores and reuses one entry for each set
of project keys. For an ordered project bundle, the complete bundle is one resultbag entry
for each set of project keys. A result from one project is different from a result from an
ordered project bundle. See the Result API for the exact return
types.
Set recompute=True to run the solve again instead of reusing matching
resultbag entries.
Inspect Stored Entries
resultbag.keys returns the project keys stored in
the Resultbag. You cannot change this collection. Each set of project keys contains named
values.
project_keys = resultbag.keys
for stored_project_keys in project_keys:
print(stored_project_keys)
Iterate over resultbag.items() to access each stored set of project keys and
its raw dictionary. Use get_results when you need the current result
classes.
for stored_project_keys, result in resultbag.items():
print(stored_project_keys, result)
Filter Entries
Call resultbag.filter to create a read-only
query view. The view stores filter conditions and applies them when you read keys, items,
suffixes, or results. It does not copy Resultbag entries.
A resultbag entry must match every filter condition. You can add conditions to
an existing query with another filter call.
from jcmsuite.results.resultbag import between
selected = resultbag.filter(material="Si")
selected = selected.filter(radius=between(0.35, 0.45))
Plain values must match exactly. Lists and tuples also match as complete values, regardless
of length. Use between(lower, upper) for
inclusive bounds on values that can be ordered.
The query supports the same read operations as the resultbag:
selected.keys
selected.items()
selected.suffixes
selected.get_results(None)
Access Stored Results
Use get_results to load selected entries. The jcmt_pattern argument selects the
entry without a suffix when it is None. Pass a string to select the stored version with
that JCMT pattern.
all_default_results = resultbag.get_results(None)
one_result = resultbag.get_results({"material": "Si", "radius": 0.5})
mie_results = resultbag.get_results(None, jcmt_pattern="mie")
The keys argument accepts these forms:
None: select all entries visible in the resultbag or query.One set of project keys: select one exact set.
Batched project keys: select an explicit sequence of sets.
The return type depends on the selected entries:
One entry for one project returns
SolveResult.Multiple entries for one project return
BatchSolveResult.One entry for an ordered project bundle returns
BundledSolveResult.Multiple entries for ordered project bundles return
BundledBatchSolveResult.
When you select multiple resultbag entries, Resultbag builds a new batch result. The
entries can come from separate solves. They do not need to come from one original set of
batched project keys. The new result assigns its own indices. These indices do not preserve
the original batch indices.
Select entries from one project, or select entries from ordered project bundles. Do not mix
these two entry types. A mixed selection raises
InvalidConfigurationError.
Discover Suffixes
Use suffixes to discover the JCMT patterns visible in a resultbag or
resultbag query.
The value None represents the default unsuffixed entry.
patterns = resultbag.suffixes
# Example: (None, "mie", "curvilinear_mie")
The collection is deterministic and reflects only the current view.
Resultbag entries contain versioned dictionaries made from parsed result data. A
dictionary stores named values. get_results
returns that data as current solve results. Result data loaded from a Resultbag
reports resultbag as its source and does not retain project or result-directory
paths.
Advanced Management
resultbag.management provides advanced
methods for maintaining a Resultbag and connecting it to solve execution. Use the read
operations on this page for normal result analysis. See Resultbag Management
for these methods and their API reference.
Close A Resultbag
Calling close() is optional because the Resultbag
closes when the Python program ends. Use it when you need to close the Resultbag earlier.
resultbag.close()
See the Resultbag Tutorials for a complete reuse and filtering workflow.
See the Resultbag API for generated signatures and method descriptions.