"
],
"text/plain": [
"TensorNetwork2D(tensors=200, indices=460, Lx=10, Ly=10, max_bond=7)"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# and if we combine two PEPS, which are both TensorNetwork2D\n",
"peps_a = qtn.PEPS.rand(10, 10, 7)\n",
"peps_b = qtn.PEPS.rand(10, 10, 7)\n",
"\n",
"# we get a TensorNetwork2D\n",
"peps_a | peps_b"
]
},
{
"cell_type": "markdown",
"id": "e06bf174-9d66-4c1f-9933-c2de84433c20",
"metadata": {
"raw_mimetype": "text/restructuredtext"
},
"source": [
"One key thing this allows is for structured contraction schemes\n",
"to remain avaiable once norm- or expectation- TNs have been formed\n",
"for example, without calling\n",
"{meth}`~quimb.tensor.tensor_core.TensorNetwork.view_like`."
]
},
{
"cell_type": "markdown",
"id": "902ddfb1-67b7-41bd-ade2-57cc6b30672b",
"metadata": {
"raw_mimetype": "text/restructuredtext"
},
"source": [
"## Standard vs. Hyper Indices & Tensor Networks\n",
"\n",
"- In standard summation expressions and tensor networks, if an index appears\n",
" twice it is contracted, and if it appears once, it is an 'outer' index that\n",
" will be retained. Such a setup is assumed to be the default when contracting\n",
" tensors, and an error will be raised if an index is encountered more than\n",
" twice.\n",
"- On the other hand, it is a perfectly valid 'sum-of-products-of-tensor-entries'\n",
" expression to have indices appear an arbitrary number of times.\n",
" It can be very beneficial to do so in fact. `quimb`\n",
" supports this, with the main difference being that you will have to\n",
" explicitly name the `output_inds` for contractions, which can no\n",
" longer be automatically inferred."
]
},
{
"cell_type": "code",
"execution_count": 46,
"id": "3dfbf976-85ca-403a-90a4-cd9e872cecc1",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Tensor(shape=(2, 2, 2), inds=[a, b, c], tags={}),backend=numpy, dtype=float64, data=array([[[ 0.20015531, -0.0434293 ],\n",
" [-0.18780095, 0.06465794]],\n",
"\n",
" [[ 0.17666851, -0.26065482],\n",
" [-0.12846997, 0.18518863]]])"
],
"text/plain": [
"Tensor(shape=(2, 2, 2), inds=('a', 'b', 'c'), tags=oset([]))"
]
},
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"T1 = qtn.rand_tensor((2, 2), ('a', 'x'))\n",
"T2 = qtn.rand_tensor((2, 2), ('b', 'x'))\n",
"T3 = qtn.rand_tensor((2, 2), ('c', 'x'))\n",
"\n",
"# we'll get an error due to 'x' unless we specify output_inds\n",
"qtn.tensor_contract(T1, T2, T3, output_inds=['a', 'b', 'c'])"
]
},
{
"cell_type": "markdown",
"id": "00a83fb4-72c9-49bc-b448-232fc6fdeb9b",
"metadata": {
"raw_mimetype": "text/restructuredtext"
},
"source": [
"The above has performed the summation:\n",
"\n",
"$$\n",
"T[a, b, c] = \\sum_{x} T_1[a, x] T_2[b, x] T_2[c, x]\n",
"$$\n",
"\n",
"I.e. everything that doesn't appear in the `output_inds` is\n",
"summed over and removed. Indices such as 'x' can be thought\n",
"of as hyperedges:"
]
},
{
"cell_type": "code",
"execution_count": 47,
"id": "196a47aa-e073-4174-8a79-a04e6d0322bd",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
""
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"(T1 | T2 | T3).draw(highlight_inds=['x'])"
]
},
{
"cell_type": "markdown",
"id": "1a076910-c430-4a98-baff-f74294e7c4f2",
"metadata": {
"raw_mimetype": "text/restructuredtext"
},
"source": [
":::{note}\n",
"Contractions of 'standard' tensor networks can be performed just using\n",
"pairwise 'matrix-multiplication equivalent' contractions,\n",
"i.e. using {func}`~numpy.tensordot`. While 'hyper' tensor networks\n",
"are still contracted using pairwise operations, these might require\n",
"routines equivalent to 'batched-matrix-multiplication' and so\n",
"{func}`~numpy.einsum`.\n",
":::"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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"
},
"vscode": {
"interpreter": {
"hash": "39c10650315d977fb13868ea1402e99f3e10e9885c2c202e692ae90b8995050d"
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}