This folder contains runnable scripts for every supported backend plus one larger TensorKrowch
example. For the full package guide, see ../docs/guide.md.
Run examples from the project root, using the project virtual environment or an equivalent Python environment with the needed optional dependencies installed.
Demonstrates the TensorKrowch backend with regular toy topologies.
python examples/tensorkrowch_demo.py mps 2d
python examples/tensorkrowch_demo.py weird 3d
python examples/tensorkrowch_demo.py disconnected 2d
python examples/tensorkrowch_demo.py mps 2d --from-listShows:
mps,mpo,peps,weird, anddisconnectedexamples- object-level dispatch with a full TensorKrowch network
- subset-style dispatch by passing a list of nodes with
--from-list
Demonstrates the TensorNetwork backend using tensornetwork.Node collections.
python examples/tensornetwork_demo.py mps 2d
python examples/tensornetwork_demo.py weird 3d
python examples/tensornetwork_demo.py disconnected 2d
python examples/tensornetwork_demo.py mps 2d --save mps.png --no-showShows:
mps,mpo,peps,weird, anddisconnectedexamples- non-interactive rendering with
--saveand--no-show - the iterable-of-nodes input style used by the TensorNetwork adapter
Demonstrates the Quimb backend, including a hypergraph-style example.
python examples/quimb_demo.py hyper 2d
python examples/quimb_demo.py mps 2d
python examples/quimb_demo.py weird 3d
python examples/quimb_demo.py mps 2d --from-list --save quimb.png --no-showShows:
hyper,mps,mpo,peps,weird, anddisconnectedexamples- dispatch with a full
TensorNetwork - dispatch with a list of tensors via
--from-list
Demonstrates the TeNPy backend for both finite and infinite structures.
python examples/tenpy_demo.py mps 2d
python examples/tenpy_demo.py mpo 3d --save tenpy.png --no-show
python examples/tenpy_demo.py imps 2d
python examples/tenpy_demo.py impo 3d --save tenpy-infinite.png --no-showShows:
- finite
mpsandmpo - infinite
impsandimpo - headless rendering and saving from the command line
Demonstrates the einsum backend in both auto-traced and manual-trace modes.
python examples/einsum_demo.py mps 2d
python examples/einsum_demo.py mps 2d --mode manual
python examples/einsum_demo.py peps 3d
python examples/einsum_demo.py disconnected 3d
python examples/einsum_demo.py mps 2d --save einsum.png --no-showShows:
mps,peps, anddisconnectedtraces--mode autousingEinsumTrace+tensor_network_viz.einsum(...)--mode manualusing orderedpair_tensorentries +torch.einsum(...)
Note:
- install
tensor-network-visualization[einsum]if you want to execute the examples with PyTorch
Builds and visualizes the TensorKrowch tensor network used for a TSP formulation before contraction.
python examples/tn_tsp.py -n 4 --view 2d
python examples/tn_tsp.py -n 5 --view 3d
python examples/tn_tsp.py --cities 6 --view 2dUseful when you want:
- a larger TensorKrowch example than the toy demos
- a concrete grid-like layout use case
- an example tied to a real tensor-network modeling workflow