Saving and reusing paths
Save the network, path, and slicing information for repeated execution with updated arrays; compile unsliced plans to reduce per-call preparation.
On this page
First prepare the example network structure, dimensions, and numerical arrays from Tensor-network input in Quick start.
Saving and loading across processes
Reuse the network and arrays in Quick start, or supply your own. Another process can load the saved path and slicing information; numerical arrays must still be created or loaded separately.
from arctn import ArcTNExecutionPlan, arctn_plan
plan = arctn_plan(
inputs, output, size_dict,
preset="heavy", seed=0,
target_size=2**24, slicing_mode="fixed",
)
plan.save("plan.json")
loaded = ArcTNExecutionPlan.load("plan.json")
loaded.validate(inputs, output, size_dict, arrays=arrays)
result = loaded.execute(arrays, backend="native")
ArcTNExecutionPlan stores the normalized network, SSA path, and sliced-index set, but no numerical arrays. Neither load() nor execute() repeats path optimization; execution follows the saved path and slicing information.
Compiling for repeated execution in one process
unsliced = arctn_plan(
inputs, output, size_dict, preset="heavy", seed=0
)
compiled = unsliced.compile(backend="native")
arrays_1 = arrays
arrays_2 = [array * 2 for array in arrays]
result_1 = compiled.execute(arrays_1)
result_2 = compiled.execute(arrays_2)
print(compiled.stats())
- Each call must supply
arrayswith the count and shapes of the compiled network, and all arrays within one execution must share a supported dtype. Compilation does not fix the dtype. ArcTNExecutionPlancan be saved to a file and is independent of the execution backend.ArcTNCompiledContractionis bound to an execution backend and is local to the current process.plan.compile()is unavailable for a nonempty slice set. Useplan.execute(), or passplan.to_tree()to Cotengra for execution.
Reusing paths as parameters change
During parameter iterations in VQE, QAOA, or quantum machine learning, gate values usually change while circuit connectivity can remain fixed. For a fixed circuit structure and observable, construct the expectation network once, optimize its path with arctn_plan, and update gate tensors and their conjugates for each new parameter set.
Without slicing, call plan.compile() once and compiled.execute(arrays) for each parameter set. With saved slices, use plan.execute(arrays) to execute every slice along the existing path without searching again. Execution information is still prepared on each call; the current unsliced compilation interface cannot be used.
Reuse requires identical tensor order, index-to-axis mappings, dimensions, and output order, not merely the same qubit count or array shapes. If frontend simplification, observables, or circuit changes alter these properties, optimize a new path for the new network. Separate paths can be saved for the networks of multiple observables.
The application must still weight and sum numerical results by operator coefficients to form energies or model outputs. Saved paths do not perform parameter updates or training loops. For Quimb usage, see the VQE and QAOA example.
When reuse helps
Optimize and compile once, then execute the same compiled object times. If path optimization costs , compilation costs , and each execution costs , total time is approximately
Repeated calls to arctn_contract repeat path optimization; reusing an existing path avoids that work. For unsliced execution, reusing a compiled object also avoids repeated compilation.
This relationship describes only the timing components. Cross-library speed comparisons still require measurements on the same network, dtype, backend, thread settings, and synchronization boundaries.