# Migration Guide Use this guide to update code from the legacy Python interface to `jcmsuite`. The `jcmsuite` package uses a clean-break redesign. It does not provide a compatibility package or the legacy API shape. Read [Installation](installation.md) first. Then use the [Quickstart](quickstart.md) to verify the local setup. Use the [API Reference](reference/index.md) to check the current signatures. ## Change the imports Replace the legacy package import with the new package import: ```python # Legacy import jcmwave # jcmsuite import jcmsuite ``` ## Configure the context `jcmsuite` uses a context to manage the JCMsuite installation and connections to the installation. The package manages a default context automatically. In many cases, you do not need to manage a context. A context is different from a daemon. The default context uses the JCMsuite installation identified by `JCMROOT`. Before the first solve, set `JCMROOT` to the JCMsuite installation directory. Alternatively, create a context with {func}`create_context(jcm_root=...) `. Use the default context for a local solve: ```python import jcmsuite jcmsuite.info() result = jcmsuite.solve("project.jcmp") ``` Create and use an explicit context with {func}`create_context ` when a script needs different installation or resource settings: ```python import jcmsuite context = jcmsuite.context.create_context(num_threads=4) with context: result = jcmsuite.solve("project.jcmp") ``` A context controls installation and runtime settings. A context is not a replacement for a {term}`project` or a set of project keys. See [Contexts](runtime/contexts.md) and the [Context API](reference/contexts.md) for details. ## Update solve calls The project path is positional. All solve options, including `keys=`, are keyword-only: ```python # Legacy positional style result = jcmwave.solve("project.jcmp", {"radius": 0.5}) # jcmsuite result = jcmsuite.solve("project.jcmp", keys={"radius": 0.5}) ``` See [Solving Projects](core/solve/index.md) and the {func}`solve ` reference for solve options and project inputs. ## Batched Project Keys A single set of project keys returns a {class}`SolveResult `. A sequence of project keys returns a {class}`BatchSolveResult `: ```python batch = jcmsuite.solve( "project.jcmp", keys=[{"radius": 0.3}, {"radius": 0.4}], ) ``` This lets you solve one project with many sets of project keys without a loop. The returned value provides individual and batched results. See [Batched Results](results/batched.md) for batch-result access. ## Access results `jcmwave` provided all data through result-list entries. `jcmsuite` provides result data through result attributes, for example {attr}`result.costs `. ```python result = jcmsuite.solve("project.jcmp") print(result.keys) print(result.costs) print(result.eigenvalues) print(result.postprocesses.titles()) postprocess = result.postprocesses[0] ``` An optional property can be `None` when the project does not produce a value for the property. Select a postprocess before you use its export methods. Use the typed loaders for data in result files: ```python table = result.load_table("table.jcm") fields = result.load_cartesian_fields("fieldbag.jcm") ``` Use {func}`jcmsuite.results.open ` to reopen a result directory or a project result file. See [SolveResult Access](results/solveresult/index.md) for result attributes and loaders. ## Result data export `jcmwave` provided exporting to a dictionary. `jcmsuite` provides exports of result data to dictionaries via {meth}`to_dict() `, to a pandas DataFrame via {meth}`to_df() `, and to an xarray DataTree via {meth}`to_xarray() `. The exact availability depends on the type of result data. See [Data Exporting](results/data_exports.md) for supported export methods. ## Field export handling When a postprocess exports field data, you can select, transform, and export the data. ```python import jcmsuite result = jcmsuite.solve("project.jcmp") field_export_postprocess = result.postprocesses[0] fields = field_export_postprocess.fields abs_transform_export = fields.transform("abs").to_xarray() ``` See [Field Export Postprocess](results/solveresult/field_exports.md) for field selection, transforms, and export methods. ## Use a Resultbag Pass a {class}`Resultbag ` to {func}`solve ` to store and reuse results: ```python import jcmsuite resultbag = jcmsuite.results.Resultbag("results.jcmrb") result = jcmsuite.solve("project.jcmp", resultbag=resultbag) ``` Use {meth}`get_results ` with `keys=` to load one exact set of project keys or a sequence of exact sets. For a sequence, the returned batch uses the same order as the supplied project keys: ```python one_result = resultbag.get_results( keys={"material": "Si", "radius": 0.5}, ) batch = resultbag.get_results( keys=[ {"material": "Si", "radius": 0.3}, {"material": "Si", "radius": 0.5}, ], ) ``` Use {meth}`filter ` to select Resultbag entries by project keys when the selection is a range or another condition. Then use {meth}`get_results ` to load the selected results. ```python from jcmsuite.results.resultbag import between resultbag = jcmsuite.results.Resultbag("results.jcmrb") selected = resultbag.filter(radius=between(0.3, 0.5)) materialized = selected.get_results() ``` Advanced Resultbag methods are in the management namespace: ```python resultbag = jcmsuite.results.Resultbag("results.jcmrb") rb_management = resultbag.management ``` See [Resultbag](resultbag/index.md) for filtering and result reuse. ## Use daemon execution Use a daemon handler to control the daemon. Activate the handler with a `with daemon:` statement. You can configure multiple resource types for different parts of the solve process. Add resources with {meth}`daemon.resources.add `. ```python import jcmsuite daemon = jcmsuite.daemon.handler() daemon.resources.add( jcmsuite.daemon.Workstation( hostname="localhost", multiplicity=2, n_threads=1 ) ) with daemon: result = jcmsuite.solve("project.jcmp") ``` ```{note} When the application makes many solve calls, place the daemon context manager around all of them. Do not open and close a daemon context for each solve call because each context startup and shutdown adds lifecycle overhead. The same context can cover solve calls for projects in different files. ``` Waiting for results is optional. By default, the solve call returns after it collects all results, even when it uses the daemon. To explicitly wait on results, use the `dispatch` keyword. ```python with daemon: submission = jcmsuite.solve("project.jcmp", dispatch="submit") result = submission.wait() ``` Use {class}`handler.lifecycle ` for startup and shutdown. Use {attr}`handler.resources ` to configure compute resources. Use {class}`handler.jobs ` to collect and manage Submissions. Preserve API identifiers such as {class}`daemon.jobs ` and {attr}`submission.job_id ` when you update the code. See [Daemon Execution](runtime/daemon/index.md) and the [Daemon API](reference/daemon.md) for handler and resource details. ## Use asynchronous calls When an event loop is running, pass `asynchronous=True` to a supported operation such as {func}`solve `. The operation returns a coroutine. Await the coroutine to obtain the result: ```python import asyncio import jcmsuite async def main() -> None: result = await jcmsuite.solve( "project.jcmp", asynchronous=True, ) print(result.project_file) asyncio.run(main()) ``` In a script entry point, use `asyncio.run(...)`. In a notebook or another running event loop, await the operation in the existing event loop. See [Async Execution](runtime/async.md) for asynchronous solve and submission handling. ## Next steps - [Core Functionality](core/index.md) for solve inputs and project tools. - [Working With Results](results/index.md) for navigation and data export. - [Resultbag](resultbag/index.md) for persistence and selection. - [Runtime And Execution](runtime/index.md) for contexts, daemon, and async use. - [API Reference](reference/index.md) for current names and signatures.