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.

python
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

python
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())

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 NN times. If path optimization costs PP, compilation costs KK, and each execution costs EE, total time is approximately

T(N)P+K+NE.T(N)\approx P+K+NE.

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.