Third-party integrations
Use the ArcTN Python interface to optimize contraction paths and pass paths or trees to existing tensor-network tools.
On this page
Using an opt_einsum PathOptimizer
Reuse the three arrays from the quick start. The expression "ab,bc,cd->ad" connects the three inputs by their indices and retains a and d in the result. Commas separate inputs, and the right-hand side of -> specifies output axes:
import opt_einsum as oe
from arctn import ArcTNOptimizer
equation = "ab,bc,cd->ad"
optimizer = ArcTNOptimizer(
preset="heavy", seed=0, max_time=30,
flops_weight=1, read_write_weight=64,
)
result = oe.contract(equation, *arrays, optimize=optimizer)
opt_einsum calls ArcTNOptimizer.__call__ directly. The PathOptimizer interface returns only a path, not slicing indices. A non-None memory_limit, or a target_size configured in ArcTNOptimizer, makes this call raise NotImplementedError. For slicing, use ArcTNOptimizer.search() through Cotengra/Quimb to obtain a tree, or call arctn_tree / arctn_contract directly.
Returning a Cotengra ContractionTree
Reuse inputs, output, size_dict, and arrays from the quick start. Generate a tree and execute it directly:
from arctn import arctn_tree
tree, info = arctn_tree(
inputs, output, size_dict,
preset="heavy", seed=0,
target_size=2**24, slicing_mode="fixed",
return_info=True,
)
result = tree.contract(arrays)
With return_info=True, the result is (tree, info), where info is a dictionary of path metrics and slicing information. If arctn_plan has already produced a plan, convert it directly instead of searching again with arctn_tree:
tree = plan.to_tree()
result = tree.contract(arrays)
ArcTNOptimizer.search() and arctn_tree() run path optimization. plan.to_tree() reuses the existing path and slicing indices without searching again. All of these interfaces can produce a Cotengra ContractionTree representing the path and slicing information.
Using Quimb
Quimb obtains a contraction tree through ArcTNOptimizer.search(). Pass the optimizer to optimize to use ArcTN for circuit tasks or tensor-network contractions.
- Using ArcTN in Quimb — Compute amplitudes, set slicing limits, and construct tensor networks.
Explicit array-backend selection
With arctn_contract, choose native or an explicit array backend. When executing through Quimb or a Cotengra tree, use the execution interface of the corresponding library.
- Execution backends — Supported backends, array types, and timing.