# Working With Results Use this section after you create a result with {func}`solve `, retrieve a result from a {class}`Resultbag `, or open an existing result on disk. If you still need to create a result, start with [Solving Projects](../core/solve/index.md) and {func}`jcmsuite.solve `. ## Choose A Result Source - **Fresh solve:** use the value returned by {func}`jcmsuite.solve `. ```python import jcmsuite result = jcmsuite.solve("project.jcmp") ``` - **Resultbag query:** use the stored result from a {class}`Resultbag ` file with {meth}`resultbag.get_results `. ```python import jcmsuite resultbag = jcmsuite.results.Resultbag("runs.jcmrb") result = resultbag.get_results({"radius": 0.5}) ``` - **Existing result:** open a project file or result directory with {func}`open `. ```python import jcmsuite result = jcmsuite.results.open("project_results") ``` In each situation, you use the returned `result` in the same way. ## Select And Export Result Data A `result` provides several types of data through named attributes: - {term}`project keys` (via {attr}`result.keys `) - costs (via {attr}`result.costs `) - eigenvalues (via {attr}`result.eigenvalues `) - a collection of postprocesses (via {attr}`result.postprocesses `) Select result data through one of these attributes. Then use a method from [Data Exporting](data_exports) to export the selected data. The available methods depend on the data type. For postprocesses, first select one postprocess, for example with {attr}`result.postprocesses[0] `. Then export its data. The supported export methods are: - {meth}`to_dict() `, which exports the data into a dictionary. The deprecated {meth}`to_mapping() ` compatibility name is also available, - {meth}`to_df() `, which exports the data into a `pandas` DataFrame, - {meth}`to_xarray() `, which exports the data into an `xarray` DataTree structure. For numeric tables and table collections, inspect solver parameter derivatives through {attr}`postprocess.derivatives `. Call {meth}`keys() ` for a table or {meth}`keys() ` for a table collection to list available parameter names. Select a first derivative by name, then use its {attr}`derivatives ` collection to select a second derivative: ```python table = result.postprocesses[0] print(table.derivatives.keys()) first = table.derivatives["width_parameter"] second = first.derivatives["height"] values = second.to_dict()["ElectricFieldStrength"] ``` Each selected view keeps the original quantity names and supports the result's dictionary, DataFrame, and xarray exports. Table collections also keep their member names and omit members without the selected derivative. A missing parameter or pair raises `KeyError`; it is not replaced with zero. Whole-record exports are unchanged. See [Data Exports](data_exports.md) for collection exports. ## List-Style Access Use an index in square brackets to select one postprocess, batch entry, or bundled project result. Index `0` selects the first item: ```python postprocess = result.postprocesses[0] entry = batch[0] project_result = bundle[1] ``` Use a slice, such as {class}`batch[1:4] `, to select a range of items from a {class}`BatchSolveResult ` or a daemon {term}`submission`. The first number is included and the second number is excluded. The selected value keeps the documented input order. See the {ref}`Result API list-access reference ` for complete indexing and slicing behavior. ## Results From {func}`solve ` The {term}`project` input and `keys=` input determine whether {func}`solve ` returns results for one project, a batch, or an {term}`ordered project bundle`. See [Solving Projects](../core/solve/index.md) to choose the input form. See the [Result API](../reference/results.md) for the exact return types. Use [Torch Integration](../derivatives/torch.md) when a solve must participate in a PyTorch objective without changing ordinary result navigation. Use [SolveResult Access](solveresult/index.md) for results from one project. The guide contains sections for {attr}`costs `, {attr}`eigenvalues `, and {attr}`postprocesses `, as well as [field data](solveresult/field_exports.md) and [export formats](data_exports.md). Use [Batched Results](batched.md) for details about result data that was obtained using a single project file and {term}`batched project keys`. Use [Bundled Results](bundled.md) when an {term}`ordered project bundle` returns the result, with no project keys, one set of project keys, or batched project keys. ## Result Pages ```{toctree} :maxdepth: 3 :titlesonly: :caption: Results solveresult/index data_exports batched bundled ``` ## Related Pages - [Resultbag](../resultbag/index.md): store, query, and reuse results. - [Fresh solve results tutorial](../tutorials/result_access/01_result_sources/01_solve_output.md). - [Resultbag results tutorial](../tutorials/result_access/01_result_sources/02_using_resultbag.md). - [Existing results tutorial](../tutorials/result_access/01_result_sources/03_loading_existing_dir.md).