{ "cells": [ { "attachments": {}, "cell_type": "markdown", "id": "a8004610-4943-45cc-9e30-86000015baf2", "metadata": { "raw_mimetype": "text/restructuredtext", "tags": [] }, "source": [ "(tensor-network-contraction)=\n", "\n", "# Contraction\n", "\n", "one of the core tasks of any tensor network algorithm: collection of tensors -> single tensor\n", "\n", "defined as sum of products\n", "$$\n", "\\sum_{\\sigma} \\prod_{i} T_i(\\sigma_i)\n", "$$\n", "\n", "exponentially slow to do sum directly since we would have evaluate every single\n", "combination of index value assignments.\n", "\n", "Instead pairwise path of intermediates always best cost wise -> contracting a\n", "pair of tenosrs can remove indices entirely from the rest of the contraction\n", "\n", "specified by \"contraction tree\", cost is incredibly sensitive \n", "to the choice and the space of these trees is very large -> tricky problem, \n", "but can be automated.\n", "\n", "Tradeoff between time spent finding the path and the time spent actually doing \n", "the contraction.\n", "\n", "The optimize kwarg.\n", "\n", "\n", "## contraction interfaces\n", "\n", "* [qtn.tensor_contract](quimb.tensor.tensor_core.tensor_contract)\n", "* [ta @ tb](quimb.tensor.tensor_core.Tensor.__matmul__) \n", " for simple two tensor contract\n", "* [TensorNewtork.contract](quimb.tensor.tensor_core.TensorNetwork.contract)\n", "\n", "special forms of contraction\n", "\n", "* [TensorNetwork.contract_tags](quimb.tensor.tensor_core.TensorNetwork.contract_tags)\n", "* [TensorNetwork.contract_between](quimb.tensor.tensor_core.TensorNetwork.contract_between)\n", "* [TensorNetwork.contract_ind](quimb.tensor.tensor_core.TensorNetwork.contract_ind)\n", "* [TensorNetwork.contract_cumulative](quimb.tensor.tensor_core.TensorNetwork.contract_cumulative)\n", "* [TensorNetwork.to_dense](quimb.tensor.tensor_core.TensorNetwork.to_dense)\n", "* [TensorNetwork.trace](quimb.tensor.tensor_core.TensorNetwork.trace)\n", "\n", "And information methods:\n", "\n", "* [TensorNetwork.contraction_path](quimb.tensor.tensor_core.TensorNetwork.contraction_path)\n", " : the [opt_einsum](https://optimized-einsum.readthedocs.io) path\n", "* [TensorNetwork.contraction_info](quimb.tensor.tensor_core.TensorNetwork.contraction_info)\n", " : the opt_einsum.PathInfo object\n", "* [TensorNetwork.contraction_tree](quimb.tensor.tensor_core.TensorNetwork.contraction_tree)\n", " : the cotengra.ContractionTree object\n", "* [TensorNetwork.contraction_width](quimb.tensor.tensor_core.TensorNetwork.contraction_width)\n", " : log2 of the maximum size of any intermediate tensor.\n", "* [TensorNetwork.contraction_cost](quimb.tensor.tensor_core.TensorNetwork.contraction_cost)\n", " : the total number of scalar operations required to perform the contraction\n", "\n", "called within many algorithms (wherever you see the optimize kwarg)\n", "\n", "\n", "## Things you can supply to the optimize kwarg:\n", "\n", "\n", "### str preset\n", "\n", "\n", "### opt_einsum PathOptimizer\n", "\n", "\n", "### cotengra HyperOptimizer\n", "\n", "\n", "### explicit contraction path\n", "\n", "\n", "### path caching\n", "\n", "geometry hash\n", "\n", "caching within cotengra\n", "\n", "\n", "## Hyper edges\n", "\n", "most general einsum equation\n", "\n", "\n", "## Structured Contractions\n", "\n", "e.g. 1D chain\n", "\n", "\n", "## Approximate boundary contraction\n", "\n", "coarse graining contractions\n", "\n", "hyper edges not supported\n", "\n", "\n", "## Automatic approximate / compressed contraction\n", "\n", "* contract_copmressed\n", "* contract_around" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.10.8 ('numpy')", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.8 (main, Nov 4 2022, 13:48:29) [GCC 11.2.0]" }, "vscode": { "interpreter": { "hash": "39c10650315d977fb13868ea1402e99f3e10e9885c2c202e692ae90b8995050d" } } }, "nbformat": 4, "nbformat_minor": 5 }