From b066ece37f394e08111b0e80ffd410c0003ec498 Mon Sep 17 00:00:00 2001 From: Johnnie Gray Date: Mon, 6 May 2024 15:59:15 -0700 Subject: [PATCH] CircuitMPS: convenience functions and docs --- docs/index_tn.md | 1 + docs/tensor-circuit-mps.ipynb | 3854 +++++++++++++++++++++++++++++++++ docs/tensor-circuit.ipynb | 6 +- quimb/tensor/circuit.py | 120 +- 4 files changed, 3967 insertions(+), 14 deletions(-) create mode 100644 docs/tensor-circuit-mps.ipynb diff --git a/docs/index_tn.md b/docs/index_tn.md index 3fab34c4..d973764c 100644 --- a/docs/index_tn.md +++ b/docs/index_tn.md @@ -11,5 +11,6 @@ tensor-optimization tensor-1d tensor-2d tensor-circuit +tensor-circuit-mps tensor-design ``` diff --git a/docs/tensor-circuit-mps.ipynb b/docs/tensor-circuit-mps.ipynb new file mode 100644 index 00000000..ba856b26 --- /dev/null +++ b/docs/tensor-circuit-mps.ipynb @@ -0,0 +1,3854 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "e64d591e-72ce-4ce5-bbda-a93ad7a6a6a5", + "metadata": {}, + "source": [ + "(quantum-circuit-mps-example)=\n", + "\n", + "# Quantum Circuits with MPS\n", + "\n", + "While the standard method for circuit simulation (see [](#quantum-circuit-example)) uses a lazy tensor network representation of the entire quantum circuit before deciding what to compute, `quimb` also has support for simulating quantum circuits using matrix product states (MPS), which instead 'eagerly' contracts gates in and performs compression to maintain an MPS form of the full wavefunction." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "6b278534-b15a-4493-aecb-20ab89f50897", + "metadata": {}, + "outputs": [], + "source": [ + "%config InlineBackend.figure_formats = ['svg']\n", + "\n", + "import numpy as np\n", + "import quimb.tensor as qtn" + ] + }, + { + "cell_type": "markdown", + "id": "936018d8-c5ec-41c3-a3ed-6ccf7c534ebc", + "metadata": {}, + "source": [ + "We'll define a test circuit that is A) too large for state-vector simulation and B) too deep for exact contraction. It has arbitrarily long-range CZ entangling gates but depending on how small the angles of the single qubit U3 random rotations are, only builds up entanglement in a controlled manner." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "622d56a4-8a6f-4d6a-8d82-36dc948edb4b", + "metadata": {}, + "outputs": [], + "source": [ + "def gen_gates(N=64, x=0.1, depth=10, seed=42):\n", + " \"\"\"Generate a long range circuit that only slowly builds up entanglement.\n", + "\n", + " Parameters\n", + " ----------\n", + " N : int, optional\n", + " The number of qubits.\n", + " x : float, optional\n", + " The average angle magnitude of U3 rotations.\n", + " depth : int, optional\n", + " The number of fully entangling gate layers.\n", + " seed : int, optional\n", + " A random seed.\n", + "\n", + " Yields\n", + " ------\n", + " qtn.Gate\n", + " \"\"\"\n", + "\n", + " rng = np.random.default_rng(seed)\n", + " qubits = list(range(N))\n", + "\n", + " for _ in range(depth):\n", + " # random small single qubit rotations\n", + " for q in qubits:\n", + " yield qtn.Gate(\"U3\", params=rng.normal(scale=x, size=3), qubits=[q])\n", + "\n", + " # random CZs between arbitrary qubit pairs\n", + " rng.shuffle(qubits)\n", + " for i in range(0, N, 2):\n", + " qa = qubits[i]\n", + " qb = qubits[i + 1]\n", + " yield qtn.Gate(\"CZ\", params=(), qubits=[qa, qb])" + ] + }, + { + "cell_type": "markdown", + "id": "7f83ab43-b2d7-4538-a891-382446d2b4bc", + "metadata": {}, + "source": [ + "You can see that a very quick estimate of the amplitude brute-force contraction complexity gives a cost of $\\sim 10^{30}$ FLOPs, while this could be improved, its clearly not a circuit that is easy to simulate exactly." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "1eb65de5-b829-4b56-9ab6-e79c4001b050", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'tn': TensorNetworkGenVector(tensors=672, indices=448),\n", + " 'tree': ,\n", + " 'W': 77.0,\n", + " 'C': 28.60123015407627}" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "circ_ex = qtn.Circuit.from_gates(gen_gates())\n", + "circ_ex.amplitude_rehearse(optimize=\"greedy\")" + ] + }, + { + "cell_type": "markdown", + "id": "8b21eed9-3adb-48aa-82f7-ccc8bf0f2202", + "metadata": {}, + "source": [ + "## `CircuitMPS`\n", + "\n", + "Instead we can use the [`CircuitMPS`](quimb.tensor.circuit.CircuitMPS) class to simulate the circuit. This class is a subclass of [`Circuit`](quimb.tensor.circuit.Circuit) and has the same API for applying gates, but each time it does so it contracts the gate into the MPS representation of the wavefunction. The core gate contraction methods is uses to do so are:\n", + "\n", + "- [`MatrixProductState.gate_split`](quimb.tensor.tensor_1d.MatrixProductState.gate_split) - to contract a local gate into the MPS\n", + "- [`MatrixProductState.gate_with_auto_swap`](quimb.tensor.tensor_1d.MatrixProductState.gate_with_auto_swap) - to contract a non-local gate into the MPS, with automatic swapping of qubits if needed\n", + "- [`MatrixProductState.gate_nonlocal`](quimb.tensor.tensor_1d.MatrixProductState.gate_nonlocal) - to contract a non-local gate into the MPS, via an MPO representation that can handle multi-qubit gates and controls.\n", + "\n", + "The default `gate_contract` method is ``\"auto-mps\"``, which uses ``\"swap+split\"`` for 2-qubit gates and ``\"nonlocal\"`` for 3+ qubit gates.\n", + "\n", + "The [`CircuitMPS`](quimb.tensor.circuit.CircuitMPS) class can be created in the same ways as a normal [`Circuit`](quimb.tensor.circuit.Circuit),\n", + "but be aware that the gates are immediately contracted into the wavefunction and so the computation happens immediately. The ``progbar=True`` kwarg can thus be a useful to pass on to ``circ.apply_gates`` to see the progress of the simulation." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "71327334-93cd-49ea-a82d-8ef179e32cc6", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " 0%| | 0/960 [00:00─>─>─>──>──>──>──>──>──>──>──>──>──>──>──>──>──>──>──>──>━━━>━━━>━━━> ...\n", + " │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ \n", + " ... \n", + " 117 134 136 133 140 135 141 143 138 142 128 129 127 124 123 109 123 11 \n", + "... ━━━>━━━>━━━>━━━>━━━●━━━<━━━<━━━<━━━<━━━<━━━<━━━<━━━<━━━<━━━<━━━<━━━<━━ ...\n", + " │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ \n", + " ... \n", + " 5 105 102 90 87 76 74 75 66 60 49 43 32 27 23 20 15 12 11 7 5 3 2 \n", + " ━<━━━<━━━<──<──<──<──<──<──<──<──<──<──<──<──<──<──<──<──<─<─<─<─<\n", + " │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │\n" + ] + } + ], + "source": [ + "circ.psi.show()" + ] + }, + { + "cell_type": "markdown", + "id": "89d697ec", + "metadata": {}, + "source": [ + "Note some of the methods of `Circuit` may not be supported by `CircuitMPS` - it is recommended to work directly with the MPS tensor network." + ] + }, + { + "cell_type": "markdown", + "id": "ac01ef98-2953-4e8a-9449-3682b5d3683c", + "metadata": {}, + "source": [ + "## CircuitPermMPS\n", + "\n", + "\n", + "Another simple variant is [`CircuitPermMPS`](quimb.tensor.circuit.CircuitPermMPS), which is a subclass of [`CircuitMPS`](quimb.tensor.circuit.CircuitMPS) that uses the ``'swap+split'`` to apply non-local 2-qubit gates, but *doesn't* swap the qubits back, and instead lazily tracks the qubit locations. This can be quite advantageous for circuits without an expectation of locality, such as here:" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "d219e51d-c177-4a18-9138-5d8c41054729", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "max_bond=99, error~=0.00175: 100%|##########| 960/960 [00:10<00:00, 88.76it/s] \n" + ] + } + ], + "source": [ + "circ = qtn.CircuitPermMPS.from_gates(\n", + " gates=gen_gates(),\n", + " max_bond=None,\n", + " cutoff=1e-6,\n", + " progbar=True,\n", + ")" + ] + }, + { + "cell_type": "markdown", + "id": "25e59168", + "metadata": {}, + "source": [ + "You can see that the maximum bond dimension is lower, and the error is also lower. Note however that for efficiency the qubits are left in their swapped positions, and the `circ.psi` attribute now returns a generic [`TensorNetworkGenVector`](quimb.tensor.tensor_arbgeom.TensorNetworkGenVector) object with the indices and tags out of order:" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "36819545-06b0-4e50-be69-c269fb58153e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
TensorNetworkGenVector(tensors=64, indices=127)
Tensor(shape=(2, 2), inds=[_ee5449AAIZa, k0], tags={I0, PSI0}),backend=numpy, dtype=complex128, data=array([[-0.96560564+4.91419292e-21j, -0.25978125+1.09292731e-02j],\n", + " [ 0.26001106+2.44636224e-18j, -0.96475222+4.05881502e-02j]])
Tensor(shape=(2, 4, 2), inds=[_ee5449AAIZa, _ee5449AAIZb, k28], tags={I28, PSI0}),backend=numpy, dtype=complex128, data=array([[[-9.89303372e-01+1.23025170e-04j,\n", + " 8.54898696e-02+7.46861205e-03j],\n", + " [ 3.96500431e-04+2.40256410e-04j,\n", + " -3.18031447e-03-2.36832173e-03j],\n", + " [ 5.89537414e-03-7.98841896e-07j,\n", + " 5.02510459e-02+4.38490059e-03j],\n", + " [ 3.06292631e-06+4.23537666e-07j,\n", + " 2.13457383e-03+5.52232993e-04j]],\n", + "\n", + " [[-5.90070721e-03-1.68187637e-08j,\n", + " -5.03264018e-02-4.39670209e-03j],\n", + " [-6.62818515e-02-4.04345099e-02j,\n", + " -5.42596518e-03-4.00814468e-03j],\n", + " [ 4.55594022e-05+1.10569728e-05j,\n", + " -2.96553771e-02-2.59957135e-03j],\n", + " [-4.31311107e-04-7.13888109e-05j,\n", + " 3.61644786e-03+9.37287747e-04j]]])
Tensor(shape=(4, 6, 2), inds=[_ee5449AAIZb, _ee5449AAIZc, k48], tags={I48, PSI0}),backend=numpy, dtype=complex128, data=array([[[ 9.98554899e-01-2.25189407e-07j,\n", + " -5.95890904e-03+5.01464087e-02j],\n", + " [-2.43644200e-04-1.40718263e-04j,\n", + " 4.34114360e-03+1.31401406e-03j],\n", + " [ 4.05354378e-05+1.89155010e-05j,\n", + " 1.78152149e-04-3.52247426e-04j],\n", + " [-1.28446178e-03-5.82640521e-04j,\n", + " -1.25399202e-02+1.25006815e-02j],\n", + " [ 9.48535766e-07+1.14036117e-06j,\n", + " -1.62210020e-05-2.13976804e-05j],\n", + " [ 4.51927891e-05+3.53817578e-05j,\n", + " -1.09338720e-03-6.54910547e-04j]],\n", + "\n", + " [[ 3.37186710e-02+5.20108978e-03j,\n", + " 1.95466163e-01-6.03713274e-01j],\n", + " [ 6.42913909e-01+3.91262532e-01j,\n", + " 7.88388087e-02+1.01384238e-02j],\n", + " [-2.20989558e-02-1.34035486e-02j,\n", + " -3.73092672e-03+3.19868403e-03j],\n", + " [ 3.76772110e-03+2.31771726e-03j,\n", + " 5.23161619e-02-1.39082963e-01j],\n", + " [ 4.80568717e-05+5.80009684e-05j,\n", + " -5.07059665e-04-1.70680192e-04j],\n", + " [ 3.12851552e-03+2.20278872e-03j,\n", + " -2.45212052e-02-2.69135702e-03j]],\n", + "\n", + " [[ 8.00220544e-05-3.17172041e-05j,\n", + " -7.43939138e-04+7.41833549e-05j],\n", + " [-3.44595036e-02-6.84580480e-05j,\n", + " 4.42255696e-05-1.70852235e-03j],\n", + " [-9.98217898e-01-1.23696186e-04j,\n", + " 3.44271181e-03-4.80488501e-02j],\n", + " [-2.97167505e-03+1.38837729e-04j,\n", + " 3.16246612e-03-2.73336522e-03j],\n", + " [-2.35862976e-04+7.93011639e-05j,\n", + " 3.53463166e-03-2.26473221e-03j],\n", + " [ 1.23827385e-04+1.02754264e-04j,\n", + " 2.00310121e-03-1.21388605e-03j]],\n", + "\n", + " [[ 2.78797202e-04-2.29082236e-04j,\n", + " -4.22110538e-03+1.14412852e-03j],\n", + " [-9.01122280e-04+1.05905935e-03j,\n", + " 1.34982430e-02-1.72750232e-02j],\n", + " [ 2.54586596e-02+1.81458831e-02j,\n", + " 4.13687346e-01-4.96766714e-01j],\n", + " [-4.82526789e-03+2.23748711e-03j,\n", + " 2.41270973e-02-2.73276083e-02j],\n", + " [-7.53594832e-01-6.55153765e-02j,\n", + " -7.64882211e-02+2.62561863e-02j],\n", + " [ 8.12430391e-03-4.70461780e-04j,\n", + " 1.56971273e-02-1.41164912e-02j]]])
Tensor(shape=(6, 7, 2), inds=[_ee5449AAIZc, _ee5449AAIZd, k37], tags={I37, PSI0}),backend=numpy, dtype=complex128, data=array([[[ 9.99364876e-01-2.98229797e-04j,\n", + " 1.98825776e-02+4.73362135e-03j],\n", + " [-1.26699659e-05+3.94394148e-06j,\n", + " 8.63398293e-04+1.81892908e-05j],\n", + " [-1.31773800e-05-1.28236492e-05j,\n", + " -1.56010831e-03+1.86559806e-03j],\n", + " [ 5.13233119e-04-1.27329801e-04j,\n", + " -2.90309122e-02-1.27935351e-03j],\n", + " [ 1.63998489e-05+9.61381219e-06j,\n", + " 6.35027785e-04+1.01889259e-04j],\n", + " [-5.02874253e-07-2.98673493e-07j,\n", + " 5.44643119e-06+1.29695285e-06j],\n", + " [ 4.54246212e-05-1.37274618e-05j,\n", + " -4.67367137e-04+1.59756679e-04j]],\n", + "\n", + " [[ 1.12118540e-03-2.81134692e-04j,\n", + " 7.41181117e-02-1.52271228e-01j],\n", + " [ 3.81723930e-02+1.09050921e-02j,\n", + " -1.26075536e-03+5.17181683e-03j],\n", + " [-2.81326177e-01-9.30169128e-01j,\n", + " -1.61549523e-02-6.84585693e-02j],\n", + " [-1.56455959e-02+2.50475033e-02j,\n", + " 6.65682469e-02-1.17983118e-01j],\n", + " [ 5.58019703e-03-9.16171079e-03j,\n", + " -2.49610656e-03+2.08956855e-03j],\n", + " [-2.59080634e-05+1.35182989e-05j,\n", + " 4.32395027e-04-1.56866693e-04j],\n", + " [ 3.42344684e-04-1.90747887e-03j,\n", + " -8.61752313e-03+3.13090677e-02j]],\n", + "\n", + " [[-2.02301274e-04+5.72944370e-05j,\n", + " -2.24911325e-04+4.69272041e-03j],\n", + " [ 9.98905704e-01-6.71314823e-04j,\n", + " 2.21029438e-02+4.46187121e-03j],\n", + " [ 2.18528929e-02+3.21467796e-02j,\n", + " 8.31154774e-04+2.45595777e-03j],\n", + " [ 8.28874295e-03-8.83692010e-04j,\n", + " -6.04211371e-03+4.77744073e-03j],\n", + " [-3.40380536e-04+3.41605281e-04j,\n", + " 2.63263696e-03+1.79658404e-05j],\n", + " [-6.16893539e-06+7.37319040e-06j,\n", + " 1.17508539e-03+5.16081202e-04j],\n", + " [-7.97623670e-05+8.35192322e-05j,\n", + " -3.71493914e-04-9.56008914e-04j]],\n", + "\n", + " [[ 1.01430322e-02-5.71008540e-03j,\n", + " -4.82355574e-01+8.80261306e-02j],\n", + " [ 5.50300328e-04+6.79469944e-04j,\n", + " 4.31335811e-03+1.18904391e-03j],\n", + " [ 6.10011499e-02-6.78090008e-02j,\n", + " -1.06783733e-02-1.29974727e-03j],\n", + " [-5.06473795e-02-1.12882344e-03j,\n", + " 3.60193392e-02-5.52250477e-02j],\n", + " [-8.51192939e-01-2.88876742e-03j,\n", + " 1.12794501e-01+2.57317252e-03j],\n", + " [-1.76477220e-04-6.91994511e-05j,\n", + " -9.11679192e-04-3.92973629e-04j],\n", + " [ 9.78819958e-03-5.32334804e-03j,\n", + " 7.35648589e-02-3.57175303e-02j]],\n", + "\n", + " [[-6.69909934e-04+4.23686545e-04j,\n", + " 1.26798773e-02-8.49144132e-03j],\n", + " [ 2.87507915e-03-1.64024193e-03j,\n", + " -1.50699171e-01+4.31432259e-02j],\n", + " [ 5.11650711e-04+7.12295333e-04j,\n", + " -3.75758022e-03-2.66149298e-03j],\n", + " [ 1.64604194e-03+4.81860357e-03j,\n", + " -2.01887562e-02+7.50928235e-03j],\n", + " [-8.93340153e-03+2.03974578e-03j,\n", + " 1.32113704e-02-4.94689158e-03j],\n", + " [ 9.54911576e-01+2.41318275e-01j,\n", + " 6.15775453e-02+2.04851520e-02j],\n", + " [ 7.11939847e-03-5.20360889e-03j,\n", + " -2.83559438e-03+1.10959717e-03j]],\n", + "\n", + " [[-1.79105007e-02+5.95332740e-03j,\n", + " 7.30369824e-01-2.29906598e-01j],\n", + " [-2.05585355e-03-1.65504562e-03j,\n", + " -5.30241391e-03+7.62449514e-03j],\n", + " [-3.57321977e-02+1.26677346e-01j,\n", + " -8.87714460e-02-3.39779847e-01j],\n", + " [-1.40354418e-02+2.46177279e-02j,\n", + " -1.66671085e-01-5.77719217e-02j],\n", + " [-4.48472492e-01+2.40183122e-02j,\n", + " 7.99672161e-02-1.58431923e-01j],\n", + " [-2.12267261e-02-1.07135235e-02j,\n", + " -4.35309154e-04+3.65147968e-04j],\n", + " [ 2.53152225e-03-7.22604936e-03j,\n", + " -8.27912644e-02-5.72415195e-04j]]])
Tensor(shape=(7, 10, 2), inds=[_ee5449AAIZd, _ee5449AAIZe, k62], tags={I62, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(10, 14, 2), inds=[_ee5449AAIZe, _ee5449AAIZf, k57], tags={I57, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(14, 17, 2), inds=[_ee5449AAIZf, _ee5449AAIZg, k2], tags={I2, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(17, 18, 2), inds=[_ee5449AAIZg, _ee5449AAIZh, k11], tags={I11, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(18, 23, 2), inds=[_ee5449AAIZh, _ee5449AAIZi, k7], tags={I7, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(23, 27, 2), inds=[_ee5449AAIZi, _ee5449AAIZj, k6], tags={I6, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(27, 27, 2), inds=[_ee5449AAIZj, _ee5449AAIZk, k10], tags={I10, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(27, 30, 2), inds=[_ee5449AAIZk, _ee5449AAIZl, k3], tags={I3, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(30, 28, 2), inds=[_ee5449AAIZl, _ee5449AAIZm, k56], tags={I56, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(28, 33, 2), inds=[_ee5449AAIZm, _ee5449AAIZn, k43], tags={I43, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(33, 35, 2), inds=[_ee5449AAIZn, _ee5449AAIZo, k20], tags={I20, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(35, 36, 2), inds=[_ee5449AAIZo, _ee5449AAIZp, k19], tags={I19, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(36, 49, 2), inds=[_ee5449AAIZp, _ee5449AAIZq, k50], tags={I50, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(49, 43, 2), inds=[_ee5449AAIZq, _ee5449AAIZr, k15], tags={I15, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(43, 63, 2), inds=[_ee5449AAIZr, _ee5449AAIZs, k16], tags={I16, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(63, 65, 2), inds=[_ee5449AAIZs, _ee5449AAIZt, k38], tags={I38, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(65, 72, 2), inds=[_ee5449AAIZt, _ee5449AAIZu, k21], tags={I21, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(72, 72, 2), inds=[_ee5449AAIZu, _ee5449AAIZv, k31], tags={I31, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(72, 82, 2), inds=[_ee5449AAIZv, _ee5449AAIZw, k8], tags={I8, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(82, 66, 2), inds=[_ee5449AAIZw, _ee5449AAIZx, k13], tags={I13, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(66, 75, 2), inds=[_ee5449AAIZx, _ee5449AAIZy, k23], tags={I23, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(75, 77, 2), inds=[_ee5449AAIZy, _ee5449AAIZz, k49], tags={I49, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(77, 86, 2), inds=[_ee5449AAIZz, _ee5449AAIaA, k59], tags={I59, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(86, 88, 2), inds=[_ee5449AAIaA, _ee5449AAIaB, k58], tags={I58, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(88, 95, 2), inds=[_ee5449AAIaB, _ee5449AAIaC, k32], tags={I32, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(95, 92, 2), inds=[_ee5449AAIaC, _ee5449AAIaD, k33], tags={I33, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(92, 98, 2), inds=[_ee5449AAIaD, _ee5449AAIaE, k52], tags={I52, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(98, 90, 2), inds=[_ee5449AAIaE, _ee5449AAIaF, k47], tags={I47, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(90, 85, 2), inds=[_ee5449AAIaF, _ee5449AAIaG, k42], tags={I42, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(85, 82, 2), inds=[_ee5449AAIaG, _ee5449AAIaH, k17], tags={I17, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(82, 87, 2), inds=[_ee5449AAIaH, _ee5449AAIaI, k44], tags={I44, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(87, 88, 2), inds=[_ee5449AAIaI, _ee5449AAIaJ, k4], tags={I4, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(88, 82, 2), inds=[_ee5449AAIaJ, _ee5449AAIaK, k29], tags={I29, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(82, 82, 2), inds=[_ee5449AAIaK, _ee5449AAIaL, k46], tags={I46, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(82, 95, 2), inds=[_ee5449AAIaL, _ee5449AAIaM, k40], tags={I40, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(95, 99, 2), inds=[_ee5449AAIaM, _ee5449AAIaN, k24], tags={I24, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(99, 96, 2), inds=[_ee5449AAIaN, _ee5449AAIaO, k39], tags={I39, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(96, 80, 2), inds=[_ee5449AAIaO, _ee5449AAIaP, k53], tags={I53, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(80, 85, 2), inds=[_ee5449AAIaP, _ee5449AAIaQ, k41], tags={I41, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(85, 74, 2), inds=[_ee5449AAIaQ, _ee5449AAIaR, k1], tags={I1, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(74, 68, 2), inds=[_ee5449AAIaR, _ee5449AAIaS, k35], tags={I35, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(68, 68, 2), inds=[_ee5449AAIaS, _ee5449AAIaT, k9], tags={I9, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(68, 71, 2), inds=[_ee5449AAIaT, _ee5449AAIaU, k51], tags={I51, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(71, 63, 2), inds=[_ee5449AAIaU, _ee5449AAIaV, k14], tags={I14, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(63, 60, 2), inds=[_ee5449AAIaV, _ee5449AAIaW, k61], tags={I61, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(60, 56, 2), inds=[_ee5449AAIaW, _ee5449AAIaX, k36], tags={I36, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(56, 48, 2), inds=[_ee5449AAIaX, _ee5449AAIaY, k12], tags={I12, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(48, 44, 2), inds=[_ee5449AAIaY, _ee5449AAIaZ, k60], tags={I60, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(44, 37, 2), inds=[_ee5449AAIaZ, _ee5449AAIaa, k45], tags={I45, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(37, 30, 2), inds=[_ee5449AAIaa, _ee5449AAIab, k27], tags={I27, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(30, 25, 2), inds=[_ee5449AAIab, _ee5449AAIac, k25], tags={I25, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(25, 20, 2), inds=[_ee5449AAIac, _ee5449AAIad, k18], tags={I18, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(20, 16, 2), inds=[_ee5449AAIad, _ee5449AAIae, k30], tags={I30, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(16, 12, 2), inds=[_ee5449AAIae, _ee5449AAIaf, k63], tags={I63, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(12, 9, 2), inds=[_ee5449AAIaf, _ee5449AAIag, k26], tags={I26, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(9, 5, 2), inds=[_ee5449AAIag, _ee5449AAIah, k22], tags={I22, PSI0}),backend=numpy, dtype=complex128, data=array([[[-9.99299350e-01+0.00000000e+00j,\n", + " -6.31517207e-03-3.26103683e-02j],\n", + " [ 4.26443455e-05-2.73868169e-05j,\n", + " -1.25938140e-03-6.99863547e-04j],\n", + " [-1.29306476e-04+5.11391868e-05j,\n", + " 2.26017563e-03+1.15027429e-03j],\n", + " [-9.66653880e-04+3.48512087e-04j,\n", + " 1.50788703e-02+7.71686879e-03j],\n", + " [ 5.26677236e-05-1.93088262e-05j,\n", + " -8.50837117e-04-5.05965843e-04j]],\n", + "\n", + " [[ 3.41867867e-02+0.00000000e+00j,\n", + " -2.55958324e-01-9.50665018e-01j],\n", + " [-1.47423848e-02-4.13826044e-02j,\n", + " 2.81892469e-03-4.06242492e-03j],\n", + " [ 1.71222380e-02+1.50804995e-02j,\n", + " 1.07327542e-03+2.11778528e-02j],\n", + " [-3.18687394e-04+1.28240223e-02j,\n", + " 1.75018545e-02+1.61512839e-01j],\n", + " [-9.56373064e-04-1.78922779e-03j,\n", + " -6.75452089e-04-8.13808304e-03j]],\n", + "\n", + " [[-1.52005263e-03+0.00000000e+00j,\n", + " 1.43963618e-02+3.78688933e-02j],\n", + " [-4.21561907e-01-9.03929965e-01j,\n", + " 2.72431000e-02-1.61793691e-02j],\n", + " [-2.70982480e-02-3.63002238e-02j,\n", + " 9.78075152e-04-3.89270239e-03j],\n", + " [-6.10728509e-03-1.22133827e-02j,\n", + " -3.14808803e-03-1.68056666e-02j],\n", + " [ 3.01152531e-04+6.36484867e-04j,\n", + " 3.58711813e-04+1.01841596e-03j]],\n", + "\n", + " [[ 1.10714668e-03+0.00000000e+00j,\n", + " -8.93728096e-03-1.98651588e-02j],\n", + " [ 3.33671807e-02+2.82636960e-02j,\n", + " -2.16265828e-03-3.53315890e-05j],\n", + " [-8.74076055e-01-4.80840413e-01j,\n", + " 1.47910557e-02-2.58580119e-02j],\n", + " [ 2.78142352e-02+1.63159357e-02j,\n", + " 1.28878294e-02+1.71543130e-02j],\n", + " [-1.15217602e-03-7.80714740e-04j,\n", + " -8.61908051e-04-7.98202659e-04j]],\n", + "\n", + " [[-3.46152254e-03+0.00000000e+00j,\n", + " -1.45498557e-02-2.86385076e-03j],\n", + " [-1.22485053e-02-1.59814861e-03j,\n", + " 8.56456339e-03+3.44022223e-03j],\n", + " [ 2.77629595e-02+1.27652669e-03j,\n", + " -2.14943735e-02-5.87100744e-03j],\n", + " [ 9.72825094e-01+6.25201174e-02j,\n", + " -1.61926623e-01-2.69286331e-02j],\n", + " [ 1.43254715e-01+1.91794415e-02j,\n", + " 8.18656308e-03+7.86562653e-03j]],\n", + "\n", + " [[-1.16497785e-03+0.00000000e+00j,\n", + " -6.90177630e-03-1.78445695e-03j],\n", + " [-1.88455727e-03+4.68050159e-04j,\n", + " 9.78407948e-04-3.37965445e-05j],\n", + " [ 4.37329198e-03-1.30586695e-03j,\n", + " -2.37444926e-03-2.88395559e-03j],\n", + " [ 1.32526877e-01-3.15204023e-02j,\n", + " -6.19353739e-02-1.75354417e-02j],\n", + " [-9.78758251e-01+1.34952092e-01j,\n", + " 9.74924060e-03-3.05464902e-02j]],\n", + "\n", + " [[ 1.46488030e-02+0.00000000e+00j,\n", + " 1.63918130e-01-1.26918929e-03j],\n", + " [-1.13268943e-02-2.63667661e-03j,\n", + " -1.22260914e-01-5.34185448e-02j],\n", + " [ 2.22700850e-02+4.41063293e-04j,\n", + " 1.21745149e-01+1.12012730e-04j],\n", + " [ 1.71774304e-01+3.76785681e-03j,\n", + " 9.40752831e-01+1.42014775e-01j],\n", + " [-3.79176609e-02+1.79369541e-02j,\n", + " -5.37236073e-02-1.75976848e-02j]],\n", + "\n", + " [[-5.87168955e-04+0.00000000e+00j,\n", + " -1.81844172e-02-1.75902667e-03j],\n", + " [ 1.90660249e-02-2.62876102e-02j,\n", + " -8.70344432e-01-4.58197163e-01j],\n", + " [-1.02335304e-03-3.26721225e-03j,\n", + " -1.32908907e-01+6.95317113e-03j],\n", + " [-1.36892546e-02-3.18903354e-04j,\n", + " -1.10885666e-01-2.77013445e-02j],\n", + " [ 4.92799137e-03-1.86952481e-03j,\n", + " 1.20645260e-02+4.31211798e-03j]],\n", + "\n", + " [[-5.12928430e-04+0.00000000e+00j,\n", + " -2.12510658e-03+4.36627537e-03j],\n", + " [-2.74462927e-03-4.94836535e-04j,\n", + " 6.07187367e-04+1.16657061e-01j],\n", + " [ 2.66491023e-02-1.41273070e-02j,\n", + " -5.22645839e-01-8.32043463e-01j],\n", + " [-4.64488827e-03+4.74022608e-03j,\n", + " 5.50617921e-02+1.29710971e-01j],\n", + " [-3.67019664e-03-5.86065946e-03j,\n", + " -6.31004104e-03+2.44352676e-03j]]])
Tensor(shape=(5, 4, 2), inds=[_ee5449AAIah, _ee5449AAIai, k55], tags={I55, PSI0}),backend=numpy, dtype=complex128, data=array([[[ 9.90302217e-01+1.06319363e-08j,\n", + " -1.32841645e-01+3.64651347e-02j],\n", + " [ 1.93279961e-05+1.34281847e-06j,\n", + " 1.04073559e-04-2.19230029e-05j],\n", + " [-4.27725999e-04+1.96802833e-06j,\n", + " -2.85224786e-03+8.11881549e-04j],\n", + " [ 2.70398725e-03+5.51469962e-07j,\n", + " 1.69501759e-02-4.61522807e-03j]],\n", + "\n", + " [[-1.74862168e-02+5.30412511e-06j,\n", + " -1.19115799e-01+3.26620105e-02j],\n", + " [ 9.18595652e-01-3.48678249e-01j,\n", + " -1.09551128e-01+8.00233195e-02j],\n", + " [ 1.86581202e-02-7.52446106e-04j,\n", + " -2.33127384e-03+3.25947102e-04j],\n", + " [ 1.38513944e-03+4.22112467e-04j,\n", + " 1.60634742e-02-4.98110348e-03j]],\n", + "\n", + " [[ 1.36083210e-01+2.06053998e-06j,\n", + " 9.27794919e-01-2.54377009e-01j],\n", + " [ 1.17570278e-01-4.47378931e-02j,\n", + " -1.62439672e-02+1.05996919e-02j],\n", + " [-1.52793708e-01+5.30928052e-03j,\n", + " 2.70478204e-02-7.15681308e-03j],\n", + " [-1.87700997e-02+4.23355853e-04j,\n", + " -1.18560759e-01+3.46951869e-02j]],\n", + "\n", + " [[-2.16592823e-02-1.60436183e-05j,\n", + " -1.45936240e-01+3.98532767e-02j],\n", + " [-1.10950224e-03+3.68585175e-04j,\n", + " 2.99792572e-05-6.05722882e-04j],\n", + " [-9.75418280e-01+3.20615196e-02j,\n", + " 1.08482153e-01-3.23217166e-02j],\n", + " [-9.66226470e-02+2.64195683e-03j,\n", + " 4.31834163e-02-1.24062237e-02j]],\n", + "\n", + " [[-2.13669880e-03-1.21951794e-05j,\n", + " 2.11196878e-02-5.65784320e-03j],\n", + " [ 1.02574226e-03+1.68871118e-04j,\n", + " 7.99029329e-04-7.00195334e-05j],\n", + " [-9.70016452e-02-1.55910799e-03j,\n", + " -1.87259401e-02+4.68857881e-03j],\n", + " [ 9.85503012e-01+2.00081463e-02j,\n", + " 1.29472067e-01-3.67659670e-02j]]])
Tensor(shape=(4, 3, 2), inds=[_ee5449AAIai, _ee5449AAIaj, k5], tags={I5, PSI0}),backend=numpy, dtype=complex128, data=array([[[ 9.97989423e-01-1.68952464e-09j,\n", + " 6.28239570e-02+8.38112227e-03j],\n", + " [ 6.40939381e-06-3.80348749e-06j,\n", + " -1.11982283e-04+4.01112506e-05j],\n", + " [ 8.94306167e-07-2.30201929e-07j,\n", + " -5.92780471e-05-1.35847930e-05j]],\n", + "\n", + " [[-3.64454488e-04+8.19024307e-07j,\n", + " 5.69951395e-03+7.44060086e-04j],\n", + " [ 9.69179163e-01+2.37542722e-01j,\n", + " 6.08870105e-02+2.29074438e-02j],\n", + " [-1.33017683e-04-1.94726584e-06j,\n", + " -1.55509977e-04-1.18234449e-04j]],\n", + "\n", + " [[ 9.81717847e-03-3.62334199e-06j,\n", + " -1.53187199e-01-2.03864349e-02j],\n", + " [ 9.82004093e-04+2.36617329e-04j,\n", + " 3.45677124e-04+1.83356891e-04j],\n", + " [ 9.85561268e-01+3.41355389e-02j,\n", + " 5.86794512e-02+8.99990822e-03j]],\n", + "\n", + " [[-6.26127150e-02+6.07388756e-07j,\n", + " 9.77255997e-01+1.30363989e-01j],\n", + " [-5.53438620e-03-1.41591020e-03j,\n", + " 2.65056456e-04+7.70110093e-04j],\n", + " [ 1.54084104e-01+5.31608713e-03j,\n", + " 1.54810321e-02+3.53028118e-03j]]])
Tensor(shape=(3, 2, 2), inds=[_ee5449AAIaj, _ee5449AAIak, k34], tags={I34, PSI0}),backend=numpy, dtype=complex128, data=array([[[ 0.99578447-2.47805034e-07j, -0.09007306+4.12868757e-03j],\n", + " [-0.00189868+2.37498401e-06j, -0.0166995 +7.78150708e-04j]],\n", + "\n", + " [[ 0.09168285-1.50648068e-05j, 0.97717042-4.47635975e-02j],\n", + " [ 0.04938998-8.02085199e-03j, 0.17931149-8.49338433e-03j]],\n", + "\n", + " [[-0.00269868-3.01903553e-04j, -0.06484672+5.52783116e-03j],\n", + " [ 0.98178507-1.59709108e-01j, 0.07775361-1.73901552e-02j]]])
Tensor(shape=(2, 2), inds=[_ee5449AAIak, k54], tags={I54, PSI0}),backend=numpy, dtype=complex128, data=array([[-0.99591146+6.74047903e-23j, 0.09017207+5.41900732e-03j],\n", + " [-0.09033476+4.09634070e-19j, -0.99411792-5.97428029e-02j]])
" + ], + "text/plain": [ + "TensorNetworkGenVector(tensors=64, indices=127)" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tn = circ.psi\n", + "tn" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "82abd77e", + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " 2024-05-06T15:43:53.799326\n", + " image/svg+xml\n", + " \n", + " \n", + " Matplotlib v3.8.3, https://matplotlib.org/\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "\n" + ], + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "tn.draw(tn.site_tags, node_scale=0.5)" + ] + }, + { + "cell_type": "markdown", + "id": "14fde591", + "metadata": {}, + "source": [ + "To get the non-reindexed and non-retagged MPS you can call [`CircuitPermMPS.get_psi_unordered`](quimb.tensor.circuit.CircuitPermMPS.get_psi_unordered):" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "070dc243", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
MatrixProductState(tensors=64, indices=127, L=64, max_bond=99)
Tensor(shape=(2, 2), inds=[_ee5449AAIZa, k0], tags={I0, PSI0}),backend=numpy, dtype=complex128, data=array([[-0.96560564+4.91419292e-21j, -0.25978125+1.09292731e-02j],\n", + " [ 0.26001106+2.44636224e-18j, -0.96475222+4.05881502e-02j]])
Tensor(shape=(2, 4, 2), inds=[_ee5449AAIZa, _ee5449AAIZb, k1], tags={I1, PSI0}),backend=numpy, dtype=complex128, data=array([[[-9.89303372e-01+1.23025170e-04j,\n", + " 8.54898696e-02+7.46861205e-03j],\n", + " [ 3.96500431e-04+2.40256410e-04j,\n", + " -3.18031447e-03-2.36832173e-03j],\n", + " [ 5.89537414e-03-7.98841896e-07j,\n", + " 5.02510459e-02+4.38490059e-03j],\n", + " [ 3.06292631e-06+4.23537666e-07j,\n", + " 2.13457383e-03+5.52232993e-04j]],\n", + "\n", + " [[-5.90070721e-03-1.68187637e-08j,\n", + " -5.03264018e-02-4.39670209e-03j],\n", + " [-6.62818515e-02-4.04345099e-02j,\n", + " -5.42596518e-03-4.00814468e-03j],\n", + " [ 4.55594022e-05+1.10569728e-05j,\n", + " -2.96553771e-02-2.59957135e-03j],\n", + " [-4.31311107e-04-7.13888109e-05j,\n", + " 3.61644786e-03+9.37287747e-04j]]])
Tensor(shape=(4, 6, 2), inds=[_ee5449AAIZb, _ee5449AAIZc, k2], tags={I2, PSI0}),backend=numpy, dtype=complex128, data=array([[[ 9.98554899e-01-2.25189407e-07j,\n", + " -5.95890904e-03+5.01464087e-02j],\n", + " [-2.43644200e-04-1.40718263e-04j,\n", + " 4.34114360e-03+1.31401406e-03j],\n", + " [ 4.05354378e-05+1.89155010e-05j,\n", + " 1.78152149e-04-3.52247426e-04j],\n", + " [-1.28446178e-03-5.82640521e-04j,\n", + " -1.25399202e-02+1.25006815e-02j],\n", + " [ 9.48535766e-07+1.14036117e-06j,\n", + " -1.62210020e-05-2.13976804e-05j],\n", + " [ 4.51927891e-05+3.53817578e-05j,\n", + " -1.09338720e-03-6.54910547e-04j]],\n", + "\n", + " [[ 3.37186710e-02+5.20108978e-03j,\n", + " 1.95466163e-01-6.03713274e-01j],\n", + " [ 6.42913909e-01+3.91262532e-01j,\n", + " 7.88388087e-02+1.01384238e-02j],\n", + " [-2.20989558e-02-1.34035486e-02j,\n", + " -3.73092672e-03+3.19868403e-03j],\n", + " [ 3.76772110e-03+2.31771726e-03j,\n", + " 5.23161619e-02-1.39082963e-01j],\n", + " [ 4.80568717e-05+5.80009684e-05j,\n", + " -5.07059665e-04-1.70680192e-04j],\n", + " [ 3.12851552e-03+2.20278872e-03j,\n", + " -2.45212052e-02-2.69135702e-03j]],\n", + "\n", + " [[ 8.00220544e-05-3.17172041e-05j,\n", + " -7.43939138e-04+7.41833549e-05j],\n", + " [-3.44595036e-02-6.84580480e-05j,\n", + " 4.42255696e-05-1.70852235e-03j],\n", + " [-9.98217898e-01-1.23696186e-04j,\n", + " 3.44271181e-03-4.80488501e-02j],\n", + " [-2.97167505e-03+1.38837729e-04j,\n", + " 3.16246612e-03-2.73336522e-03j],\n", + " [-2.35862976e-04+7.93011639e-05j,\n", + " 3.53463166e-03-2.26473221e-03j],\n", + " [ 1.23827385e-04+1.02754264e-04j,\n", + " 2.00310121e-03-1.21388605e-03j]],\n", + "\n", + " [[ 2.78797202e-04-2.29082236e-04j,\n", + " -4.22110538e-03+1.14412852e-03j],\n", + " [-9.01122280e-04+1.05905935e-03j,\n", + " 1.34982430e-02-1.72750232e-02j],\n", + " [ 2.54586596e-02+1.81458831e-02j,\n", + " 4.13687346e-01-4.96766714e-01j],\n", + " [-4.82526789e-03+2.23748711e-03j,\n", + " 2.41270973e-02-2.73276083e-02j],\n", + " [-7.53594832e-01-6.55153765e-02j,\n", + " -7.64882211e-02+2.62561863e-02j],\n", + " [ 8.12430391e-03-4.70461780e-04j,\n", + " 1.56971273e-02-1.41164912e-02j]]])
Tensor(shape=(6, 7, 2), inds=[_ee5449AAIZc, _ee5449AAIZd, k3], tags={I3, PSI0}),backend=numpy, dtype=complex128, data=array([[[ 9.99364876e-01-2.98229797e-04j,\n", + " 1.98825776e-02+4.73362135e-03j],\n", + " [-1.26699659e-05+3.94394148e-06j,\n", + " 8.63398293e-04+1.81892908e-05j],\n", + " [-1.31773800e-05-1.28236492e-05j,\n", + " -1.56010831e-03+1.86559806e-03j],\n", + " [ 5.13233119e-04-1.27329801e-04j,\n", + " -2.90309122e-02-1.27935351e-03j],\n", + " [ 1.63998489e-05+9.61381219e-06j,\n", + " 6.35027785e-04+1.01889259e-04j],\n", + " [-5.02874253e-07-2.98673493e-07j,\n", + " 5.44643119e-06+1.29695285e-06j],\n", + " [ 4.54246212e-05-1.37274618e-05j,\n", + " -4.67367137e-04+1.59756679e-04j]],\n", + "\n", + " [[ 1.12118540e-03-2.81134692e-04j,\n", + " 7.41181117e-02-1.52271228e-01j],\n", + " [ 3.81723930e-02+1.09050921e-02j,\n", + " -1.26075536e-03+5.17181683e-03j],\n", + " [-2.81326177e-01-9.30169128e-01j,\n", + " -1.61549523e-02-6.84585693e-02j],\n", + " [-1.56455959e-02+2.50475033e-02j,\n", + " 6.65682469e-02-1.17983118e-01j],\n", + " [ 5.58019703e-03-9.16171079e-03j,\n", + " -2.49610656e-03+2.08956855e-03j],\n", + " [-2.59080634e-05+1.35182989e-05j,\n", + " 4.32395027e-04-1.56866693e-04j],\n", + " [ 3.42344684e-04-1.90747887e-03j,\n", + " -8.61752313e-03+3.13090677e-02j]],\n", + "\n", + " [[-2.02301274e-04+5.72944370e-05j,\n", + " -2.24911325e-04+4.69272041e-03j],\n", + " [ 9.98905704e-01-6.71314823e-04j,\n", + " 2.21029438e-02+4.46187121e-03j],\n", + " [ 2.18528929e-02+3.21467796e-02j,\n", + " 8.31154774e-04+2.45595777e-03j],\n", + " [ 8.28874295e-03-8.83692010e-04j,\n", + " -6.04211371e-03+4.77744073e-03j],\n", + " [-3.40380536e-04+3.41605281e-04j,\n", + " 2.63263696e-03+1.79658404e-05j],\n", + " [-6.16893539e-06+7.37319040e-06j,\n", + " 1.17508539e-03+5.16081202e-04j],\n", + " [-7.97623670e-05+8.35192322e-05j,\n", + " -3.71493914e-04-9.56008914e-04j]],\n", + "\n", + " [[ 1.01430322e-02-5.71008540e-03j,\n", + " -4.82355574e-01+8.80261306e-02j],\n", + " [ 5.50300328e-04+6.79469944e-04j,\n", + " 4.31335811e-03+1.18904391e-03j],\n", + " [ 6.10011499e-02-6.78090008e-02j,\n", + " -1.06783733e-02-1.29974727e-03j],\n", + " [-5.06473795e-02-1.12882344e-03j,\n", + " 3.60193392e-02-5.52250477e-02j],\n", + " [-8.51192939e-01-2.88876742e-03j,\n", + " 1.12794501e-01+2.57317252e-03j],\n", + " [-1.76477220e-04-6.91994511e-05j,\n", + " -9.11679192e-04-3.92973629e-04j],\n", + " [ 9.78819958e-03-5.32334804e-03j,\n", + " 7.35648589e-02-3.57175303e-02j]],\n", + "\n", + " [[-6.69909934e-04+4.23686545e-04j,\n", + " 1.26798773e-02-8.49144132e-03j],\n", + " [ 2.87507915e-03-1.64024193e-03j,\n", + " -1.50699171e-01+4.31432259e-02j],\n", + " [ 5.11650711e-04+7.12295333e-04j,\n", + " -3.75758022e-03-2.66149298e-03j],\n", + " [ 1.64604194e-03+4.81860357e-03j,\n", + " -2.01887562e-02+7.50928235e-03j],\n", + " [-8.93340153e-03+2.03974578e-03j,\n", + " 1.32113704e-02-4.94689158e-03j],\n", + " [ 9.54911576e-01+2.41318275e-01j,\n", + " 6.15775453e-02+2.04851520e-02j],\n", + " [ 7.11939847e-03-5.20360889e-03j,\n", + " -2.83559438e-03+1.10959717e-03j]],\n", + "\n", + " [[-1.79105007e-02+5.95332740e-03j,\n", + " 7.30369824e-01-2.29906598e-01j],\n", + " [-2.05585355e-03-1.65504562e-03j,\n", + " -5.30241391e-03+7.62449514e-03j],\n", + " [-3.57321977e-02+1.26677346e-01j,\n", + " -8.87714460e-02-3.39779847e-01j],\n", + " [-1.40354418e-02+2.46177279e-02j,\n", + " -1.66671085e-01-5.77719217e-02j],\n", + " [-4.48472492e-01+2.40183122e-02j,\n", + " 7.99672161e-02-1.58431923e-01j],\n", + " [-2.12267261e-02-1.07135235e-02j,\n", + " -4.35309154e-04+3.65147968e-04j],\n", + " [ 2.53152225e-03-7.22604936e-03j,\n", + " -8.27912644e-02-5.72415195e-04j]]])
Tensor(shape=(7, 10, 2), inds=[_ee5449AAIZd, _ee5449AAIZe, k4], tags={I4, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(10, 14, 2), inds=[_ee5449AAIZe, _ee5449AAIZf, k5], tags={I5, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(14, 17, 2), inds=[_ee5449AAIZf, _ee5449AAIZg, k6], tags={I6, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(17, 18, 2), inds=[_ee5449AAIZg, _ee5449AAIZh, k7], tags={I7, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(18, 23, 2), inds=[_ee5449AAIZh, _ee5449AAIZi, k8], tags={I8, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(23, 27, 2), inds=[_ee5449AAIZi, _ee5449AAIZj, k9], tags={I9, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(27, 27, 2), inds=[_ee5449AAIZj, _ee5449AAIZk, k10], tags={I10, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(27, 30, 2), inds=[_ee5449AAIZk, _ee5449AAIZl, k11], tags={I11, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(30, 28, 2), inds=[_ee5449AAIZl, _ee5449AAIZm, k12], tags={I12, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(28, 33, 2), inds=[_ee5449AAIZm, _ee5449AAIZn, k13], tags={I13, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(33, 35, 2), inds=[_ee5449AAIZn, _ee5449AAIZo, k14], tags={I14, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(35, 36, 2), inds=[_ee5449AAIZo, _ee5449AAIZp, k15], tags={I15, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(36, 49, 2), inds=[_ee5449AAIZp, _ee5449AAIZq, k16], tags={I16, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(49, 43, 2), inds=[_ee5449AAIZq, _ee5449AAIZr, k17], tags={I17, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(43, 63, 2), inds=[_ee5449AAIZr, _ee5449AAIZs, k18], tags={I18, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(63, 65, 2), inds=[_ee5449AAIZs, _ee5449AAIZt, k19], tags={I19, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(65, 72, 2), inds=[_ee5449AAIZt, _ee5449AAIZu, k20], tags={I20, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(72, 72, 2), inds=[_ee5449AAIZu, _ee5449AAIZv, k21], tags={I21, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(72, 82, 2), inds=[_ee5449AAIZv, _ee5449AAIZw, k22], tags={I22, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(82, 66, 2), inds=[_ee5449AAIZw, _ee5449AAIZx, k23], tags={I23, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(66, 75, 2), inds=[_ee5449AAIZx, _ee5449AAIZy, k24], tags={I24, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(75, 77, 2), inds=[_ee5449AAIZy, _ee5449AAIZz, k25], tags={I25, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(77, 86, 2), inds=[_ee5449AAIZz, _ee5449AAIaA, k26], tags={I26, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(86, 88, 2), inds=[_ee5449AAIaA, _ee5449AAIaB, k27], tags={I27, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(88, 95, 2), inds=[_ee5449AAIaB, _ee5449AAIaC, k28], tags={I28, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(95, 92, 2), inds=[_ee5449AAIaC, _ee5449AAIaD, k29], tags={I29, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(92, 98, 2), inds=[_ee5449AAIaD, _ee5449AAIaE, k30], tags={I30, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(98, 90, 2), inds=[_ee5449AAIaE, _ee5449AAIaF, k31], tags={I31, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(90, 85, 2), inds=[_ee5449AAIaF, _ee5449AAIaG, k32], tags={I32, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(85, 82, 2), inds=[_ee5449AAIaG, _ee5449AAIaH, k33], tags={I33, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(82, 87, 2), inds=[_ee5449AAIaH, _ee5449AAIaI, k34], tags={I34, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(87, 88, 2), inds=[_ee5449AAIaI, _ee5449AAIaJ, k35], tags={I35, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(88, 82, 2), inds=[_ee5449AAIaJ, _ee5449AAIaK, k36], tags={I36, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(82, 82, 2), inds=[_ee5449AAIaK, _ee5449AAIaL, k37], tags={I37, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(82, 95, 2), inds=[_ee5449AAIaL, _ee5449AAIaM, k38], tags={I38, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(95, 99, 2), inds=[_ee5449AAIaM, _ee5449AAIaN, k39], tags={I39, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(99, 96, 2), inds=[_ee5449AAIaN, _ee5449AAIaO, k40], tags={I40, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(96, 80, 2), inds=[_ee5449AAIaO, _ee5449AAIaP, k41], tags={I41, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(80, 85, 2), inds=[_ee5449AAIaP, _ee5449AAIaQ, k42], tags={I42, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(85, 74, 2), inds=[_ee5449AAIaQ, _ee5449AAIaR, k43], tags={I43, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(74, 68, 2), inds=[_ee5449AAIaR, _ee5449AAIaS, k44], tags={I44, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(68, 68, 2), inds=[_ee5449AAIaS, _ee5449AAIaT, k45], tags={I45, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(68, 71, 2), inds=[_ee5449AAIaT, _ee5449AAIaU, k46], tags={I46, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(71, 63, 2), inds=[_ee5449AAIaU, _ee5449AAIaV, k47], tags={I47, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(63, 60, 2), inds=[_ee5449AAIaV, _ee5449AAIaW, k48], tags={I48, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(60, 56, 2), inds=[_ee5449AAIaW, _ee5449AAIaX, k49], tags={I49, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(56, 48, 2), inds=[_ee5449AAIaX, _ee5449AAIaY, k50], tags={I50, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(48, 44, 2), inds=[_ee5449AAIaY, _ee5449AAIaZ, k51], tags={I51, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(44, 37, 2), inds=[_ee5449AAIaZ, _ee5449AAIaa, k52], tags={I52, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(37, 30, 2), inds=[_ee5449AAIaa, _ee5449AAIab, k53], tags={I53, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(30, 25, 2), inds=[_ee5449AAIab, _ee5449AAIac, k54], tags={I54, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(25, 20, 2), inds=[_ee5449AAIac, _ee5449AAIad, k55], tags={I55, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(20, 16, 2), inds=[_ee5449AAIad, _ee5449AAIae, k56], tags={I56, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(16, 12, 2), inds=[_ee5449AAIae, _ee5449AAIaf, k57], tags={I57, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(12, 9, 2), inds=[_ee5449AAIaf, _ee5449AAIag, k58], tags={I58, PSI0}),backend=numpy, dtype=complex128, data=...
Tensor(shape=(9, 5, 2), inds=[_ee5449AAIag, _ee5449AAIah, k59], tags={I59, PSI0}),backend=numpy, dtype=complex128, data=array([[[-9.99299350e-01+0.00000000e+00j,\n", + " -6.31517207e-03-3.26103683e-02j],\n", + " [ 4.26443455e-05-2.73868169e-05j,\n", + " -1.25938140e-03-6.99863547e-04j],\n", + " [-1.29306476e-04+5.11391868e-05j,\n", + " 2.26017563e-03+1.15027429e-03j],\n", + " [-9.66653880e-04+3.48512087e-04j,\n", + " 1.50788703e-02+7.71686879e-03j],\n", + " [ 5.26677236e-05-1.93088262e-05j,\n", + " -8.50837117e-04-5.05965843e-04j]],\n", + "\n", + " [[ 3.41867867e-02+0.00000000e+00j,\n", + " -2.55958324e-01-9.50665018e-01j],\n", + " [-1.47423848e-02-4.13826044e-02j,\n", + " 2.81892469e-03-4.06242492e-03j],\n", + " [ 1.71222380e-02+1.50804995e-02j,\n", + " 1.07327542e-03+2.11778528e-02j],\n", + " [-3.18687394e-04+1.28240223e-02j,\n", + " 1.75018545e-02+1.61512839e-01j],\n", + " [-9.56373064e-04-1.78922779e-03j,\n", + " -6.75452089e-04-8.13808304e-03j]],\n", + "\n", + " [[-1.52005263e-03+0.00000000e+00j,\n", + " 1.43963618e-02+3.78688933e-02j],\n", + " [-4.21561907e-01-9.03929965e-01j,\n", + " 2.72431000e-02-1.61793691e-02j],\n", + " [-2.70982480e-02-3.63002238e-02j,\n", + " 9.78075152e-04-3.89270239e-03j],\n", + " [-6.10728509e-03-1.22133827e-02j,\n", + " -3.14808803e-03-1.68056666e-02j],\n", + " [ 3.01152531e-04+6.36484867e-04j,\n", + " 3.58711813e-04+1.01841596e-03j]],\n", + "\n", + " [[ 1.10714668e-03+0.00000000e+00j,\n", + " -8.93728096e-03-1.98651588e-02j],\n", + " [ 3.33671807e-02+2.82636960e-02j,\n", + " -2.16265828e-03-3.53315890e-05j],\n", + " [-8.74076055e-01-4.80840413e-01j,\n", + " 1.47910557e-02-2.58580119e-02j],\n", + " [ 2.78142352e-02+1.63159357e-02j,\n", + " 1.28878294e-02+1.71543130e-02j],\n", + " [-1.15217602e-03-7.80714740e-04j,\n", + " -8.61908051e-04-7.98202659e-04j]],\n", + "\n", + " [[-3.46152254e-03+0.00000000e+00j,\n", + " -1.45498557e-02-2.86385076e-03j],\n", + " [-1.22485053e-02-1.59814861e-03j,\n", + " 8.56456339e-03+3.44022223e-03j],\n", + " [ 2.77629595e-02+1.27652669e-03j,\n", + " -2.14943735e-02-5.87100744e-03j],\n", + " [ 9.72825094e-01+6.25201174e-02j,\n", + " -1.61926623e-01-2.69286331e-02j],\n", + " [ 1.43254715e-01+1.91794415e-02j,\n", + " 8.18656308e-03+7.86562653e-03j]],\n", + "\n", + " [[-1.16497785e-03+0.00000000e+00j,\n", + " -6.90177630e-03-1.78445695e-03j],\n", + " [-1.88455727e-03+4.68050159e-04j,\n", + " 9.78407948e-04-3.37965445e-05j],\n", + " [ 4.37329198e-03-1.30586695e-03j,\n", + " -2.37444926e-03-2.88395559e-03j],\n", + " [ 1.32526877e-01-3.15204023e-02j,\n", + " -6.19353739e-02-1.75354417e-02j],\n", + " [-9.78758251e-01+1.34952092e-01j,\n", + " 9.74924060e-03-3.05464902e-02j]],\n", + "\n", + " [[ 1.46488030e-02+0.00000000e+00j,\n", + " 1.63918130e-01-1.26918929e-03j],\n", + " [-1.13268943e-02-2.63667661e-03j,\n", + " -1.22260914e-01-5.34185448e-02j],\n", + " [ 2.22700850e-02+4.41063293e-04j,\n", + " 1.21745149e-01+1.12012730e-04j],\n", + " [ 1.71774304e-01+3.76785681e-03j,\n", + " 9.40752831e-01+1.42014775e-01j],\n", + " [-3.79176609e-02+1.79369541e-02j,\n", + " -5.37236073e-02-1.75976848e-02j]],\n", + "\n", + " [[-5.87168955e-04+0.00000000e+00j,\n", + " -1.81844172e-02-1.75902667e-03j],\n", + " [ 1.90660249e-02-2.62876102e-02j,\n", + " -8.70344432e-01-4.58197163e-01j],\n", + " [-1.02335304e-03-3.26721225e-03j,\n", + " -1.32908907e-01+6.95317113e-03j],\n", + " [-1.36892546e-02-3.18903354e-04j,\n", + " -1.10885666e-01-2.77013445e-02j],\n", + " [ 4.92799137e-03-1.86952481e-03j,\n", + " 1.20645260e-02+4.31211798e-03j]],\n", + "\n", + " [[-5.12928430e-04+0.00000000e+00j,\n", + " -2.12510658e-03+4.36627537e-03j],\n", + " [-2.74462927e-03-4.94836535e-04j,\n", + " 6.07187367e-04+1.16657061e-01j],\n", + " [ 2.66491023e-02-1.41273070e-02j,\n", + " -5.22645839e-01-8.32043463e-01j],\n", + " [-4.64488827e-03+4.74022608e-03j,\n", + " 5.50617921e-02+1.29710971e-01j],\n", + " [-3.67019664e-03-5.86065946e-03j,\n", + " -6.31004104e-03+2.44352676e-03j]]])
Tensor(shape=(5, 4, 2), inds=[_ee5449AAIah, _ee5449AAIai, k60], tags={I60, PSI0}),backend=numpy, dtype=complex128, data=array([[[ 9.90302217e-01+1.06319363e-08j,\n", + " -1.32841645e-01+3.64651347e-02j],\n", + " [ 1.93279961e-05+1.34281847e-06j,\n", + " 1.04073559e-04-2.19230029e-05j],\n", + " [-4.27725999e-04+1.96802833e-06j,\n", + " -2.85224786e-03+8.11881549e-04j],\n", + " [ 2.70398725e-03+5.51469962e-07j,\n", + " 1.69501759e-02-4.61522807e-03j]],\n", + "\n", + " [[-1.74862168e-02+5.30412511e-06j,\n", + " -1.19115799e-01+3.26620105e-02j],\n", + " [ 9.18595652e-01-3.48678249e-01j,\n", + " -1.09551128e-01+8.00233195e-02j],\n", + " [ 1.86581202e-02-7.52446106e-04j,\n", + " -2.33127384e-03+3.25947102e-04j],\n", + " [ 1.38513944e-03+4.22112467e-04j,\n", + " 1.60634742e-02-4.98110348e-03j]],\n", + "\n", + " [[ 1.36083210e-01+2.06053998e-06j,\n", + " 9.27794919e-01-2.54377009e-01j],\n", + " [ 1.17570278e-01-4.47378931e-02j,\n", + " -1.62439672e-02+1.05996919e-02j],\n", + " [-1.52793708e-01+5.30928052e-03j,\n", + " 2.70478204e-02-7.15681308e-03j],\n", + " [-1.87700997e-02+4.23355853e-04j,\n", + " -1.18560759e-01+3.46951869e-02j]],\n", + "\n", + " [[-2.16592823e-02-1.60436183e-05j,\n", + " -1.45936240e-01+3.98532767e-02j],\n", + " [-1.10950224e-03+3.68585175e-04j,\n", + " 2.99792572e-05-6.05722882e-04j],\n", + " [-9.75418280e-01+3.20615196e-02j,\n", + " 1.08482153e-01-3.23217166e-02j],\n", + " [-9.66226470e-02+2.64195683e-03j,\n", + " 4.31834163e-02-1.24062237e-02j]],\n", + "\n", + " [[-2.13669880e-03-1.21951794e-05j,\n", + " 2.11196878e-02-5.65784320e-03j],\n", + " [ 1.02574226e-03+1.68871118e-04j,\n", + " 7.99029329e-04-7.00195334e-05j],\n", + " [-9.70016452e-02-1.55910799e-03j,\n", + " -1.87259401e-02+4.68857881e-03j],\n", + " [ 9.85503012e-01+2.00081463e-02j,\n", + " 1.29472067e-01-3.67659670e-02j]]])
Tensor(shape=(4, 3, 2), inds=[_ee5449AAIai, _ee5449AAIaj, k61], tags={I61, PSI0}),backend=numpy, dtype=complex128, data=array([[[ 9.97989423e-01-1.68952464e-09j,\n", + " 6.28239570e-02+8.38112227e-03j],\n", + " [ 6.40939381e-06-3.80348749e-06j,\n", + " -1.11982283e-04+4.01112506e-05j],\n", + " [ 8.94306167e-07-2.30201929e-07j,\n", + " -5.92780471e-05-1.35847930e-05j]],\n", + "\n", + " [[-3.64454488e-04+8.19024307e-07j,\n", + " 5.69951395e-03+7.44060086e-04j],\n", + " [ 9.69179163e-01+2.37542722e-01j,\n", + " 6.08870105e-02+2.29074438e-02j],\n", + " [-1.33017683e-04-1.94726584e-06j,\n", + " -1.55509977e-04-1.18234449e-04j]],\n", + "\n", + " [[ 9.81717847e-03-3.62334199e-06j,\n", + " -1.53187199e-01-2.03864349e-02j],\n", + " [ 9.82004093e-04+2.36617329e-04j,\n", + " 3.45677124e-04+1.83356891e-04j],\n", + " [ 9.85561268e-01+3.41355389e-02j,\n", + " 5.86794512e-02+8.99990822e-03j]],\n", + "\n", + " [[-6.26127150e-02+6.07388756e-07j,\n", + " 9.77255997e-01+1.30363989e-01j],\n", + " [-5.53438620e-03-1.41591020e-03j,\n", + " 2.65056456e-04+7.70110093e-04j],\n", + " [ 1.54084104e-01+5.31608713e-03j,\n", + " 1.54810321e-02+3.53028118e-03j]]])
Tensor(shape=(3, 2, 2), inds=[_ee5449AAIaj, _ee5449AAIak, k62], tags={I62, PSI0}),backend=numpy, dtype=complex128, data=array([[[ 0.99578447-2.47805034e-07j, -0.09007306+4.12868757e-03j],\n", + " [-0.00189868+2.37498401e-06j, -0.0166995 +7.78150708e-04j]],\n", + "\n", + " [[ 0.09168285-1.50648068e-05j, 0.97717042-4.47635975e-02j],\n", + " [ 0.04938998-8.02085199e-03j, 0.17931149-8.49338433e-03j]],\n", + "\n", + " [[-0.00269868-3.01903553e-04j, -0.06484672+5.52783116e-03j],\n", + " [ 0.98178507-1.59709108e-01j, 0.07775361-1.73901552e-02j]]])
Tensor(shape=(2, 2), inds=[_ee5449AAIak, k63], tags={I63, PSI0}),backend=numpy, dtype=complex128, data=array([[-0.99591146+6.74047903e-23j, 0.09017207+5.41900732e-03j],\n", + " [-0.09033476+4.09634070e-19j, -0.99411792-5.97428029e-02j]])
" + ], + "text/plain": [ + "MatrixProductState(tensors=64, indices=127, L=64, max_bond=99)" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mps = circ.get_psi_unordered()\n", + "mps" + ] + }, + { + "cell_type": "markdown", + "id": "aca4c00c", + "metadata": {}, + "source": [ + "The current qubit ordering is stored in `circ.qubits` and so the mapping of qubits to the physical sites of this MPS can be calculated like so:" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "0d9d4399-7247-4623-bafc-cdf4f9f068ea", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{0: 0,\n", + " 1: 43,\n", + " 2: 6,\n", + " 3: 11,\n", + " 4: 35,\n", + " 5: 61,\n", + " 6: 9,\n", + " 7: 8,\n", + " 8: 22,\n", + " 9: 45,\n", + " 10: 10,\n", + " 11: 7,\n", + " 12: 50,\n", + " 13: 23,\n", + " 14: 47,\n", + " 15: 17,\n", + " 16: 18,\n", + " 17: 33,\n", + " 18: 55,\n", + " 19: 15,\n", + " 20: 14,\n", + " 21: 20,\n", + " 22: 59,\n", + " 23: 24,\n", + " 24: 39,\n", + " 25: 54,\n", + " 26: 58,\n", + " 27: 53,\n", + " 28: 1,\n", + " 29: 36,\n", + " 30: 56,\n", + " 31: 21,\n", + " 32: 28,\n", + " 33: 29,\n", + " 34: 62,\n", + " 35: 44,\n", + " 36: 49,\n", + " 37: 3,\n", + " 38: 19,\n", + " 39: 40,\n", + " 40: 38,\n", + " 41: 42,\n", + " 42: 32,\n", + " 43: 13,\n", + " 44: 34,\n", + " 45: 52,\n", + " 46: 37,\n", + " 47: 31,\n", + " 48: 2,\n", + " 49: 25,\n", + " 50: 16,\n", + " 51: 46,\n", + " 52: 30,\n", + " 53: 41,\n", + " 54: 63,\n", + " 55: 60,\n", + " 56: 12,\n", + " 57: 5,\n", + " 58: 27,\n", + " 59: 26,\n", + " 60: 51,\n", + " 61: 48,\n", + " 62: 4,\n", + " 63: 57}" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "{q: circ.qubits.index(q) for q in range(circ.N)}" + ] + }, + { + "cell_type": "markdown", + "id": "70fb6d07-966d-4301-aac5-c141218255d5", + "metadata": {}, + "source": [ + "## Using a GPU or other backends\n", + "\n", + "We can make use of GPUs or other accelerated backends by simply supplying a function that converts the initial tensors and gates to the desired backend. Here we'll use the `torch` backend, with single precision complex tensors on the GPU:" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "bafcc105-db76-4096-8258-15ed8bbdf573", + "metadata": {}, + "outputs": [], + "source": [ + "import torch\n", + "\n", + "def to_backend(x):\n", + " return torch.tensor(x, dtype=torch.complex64, device=\"cuda\")" + ] + }, + { + "cell_type": "markdown", + "id": "31845123", + "metadata": {}, + "source": [ + "We can then attempt a deeper circuit:" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "6e2dfcf5-5a6c-4fc9-9f6f-6022b4f3dda7", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "max_bond=1021, error~=0.272: 100%|##########| 1440/1440 [04:32<00:00, 5.28it/s] \n" + ] + } + ], + "source": [ + "circ = qtn.CircuitPermMPS.from_gates(\n", + " # add 5 more layers of gates\n", + " gen_gates(depth=15),\n", + " cutoff=1e-6,\n", + " # impose a hard bond dimension limit\n", + " max_bond=1024,\n", + " to_backend=to_backend,\n", + " progbar=True,\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "96b57bcb", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
MatrixProductState(tensors=64, indices=127, L=64, max_bond=1021)
Tensor(shape=(2, 2), inds=[_ee5449AAOLe, k0], tags={I0, PSI0}),backend=numpy, dtype=complex64, data=array([[ 0.9983962 -2.4160619e-12j, 0.05661165-2.2753939e-04j],\n", + " [ 0.05426549-1.6130317e-02j, -0.9558608 +2.8831422e-01j]],\n", + " dtype=complex64)
Tensor(shape=(2, 4, 2), inds=[_ee5449AAOLe, _ee5449AAOLf, k1], tags={I1, PSI0}),backend=numpy, dtype=complex64, data=array([[[ 7.7327287e-01+5.0316368e-05j, 2.9520956e-01-8.8291168e-02j],\n", + " [ 5.4402752e-03-1.9685170e-03j, 2.0104591e-03+1.3598918e-03j],\n", + " [ 3.5645809e-02-1.0156715e-02j, -7.7668592e-02+4.9348943e-02j],\n", + " [-1.9088853e-05+8.4765641e-05j, -1.1393003e-03+2.5979981e-03j]],\n", + "\n", + " [[-1.8195353e-02-5.5630808e-03j, 4.3439422e-02-2.0239682e-05j],\n", + " [ 1.3819507e-01+1.3002556e-02j, -4.8184745e-02+9.4910311e-03j],\n", + " [-3.8507774e-03-1.3798841e-03j, -8.1839124e-03+3.2541296e-03j],\n", + " [ 7.3562181e-03-5.2499613e-03j, 1.5762348e-02-1.9997459e-02j]]],\n", + " dtype=complex64)
Tensor(shape=(4, 8, 2), inds=[_ee5449AAOLf, _ee5449AAOLg, k2], tags={I2, PSI0}),backend=numpy, dtype=complex64, data=array([[[ 9.65503395e-01-6.24093518e-05j,\n", + " 1.27870753e-01+5.06331213e-02j],\n", + " [-2.85760239e-02-1.74251888e-02j,\n", + " 1.29419908e-01+1.73371539e-01j],\n", + " [-1.09223300e-03+4.41109471e-04j,\n", + " 2.88077854e-02-8.31278134e-03j],\n", + " [-7.34475470e-05-4.35846632e-05j,\n", + " -5.93354693e-04-2.79356118e-05j],\n", + " [-5.69504191e-05-1.40986886e-04j,\n", + " 2.35484098e-03-7.11532123e-03j],\n", + " [ 9.05690104e-06+2.25640106e-05j,\n", + " 9.91513298e-06+1.42679771e-03j],\n", + " [-1.51727136e-05+2.90976709e-06j,\n", + " -9.16214849e-05-6.31183793e-04j],\n", + " [ 9.70417659e-07-2.36888377e-06j,\n", + " 6.67575150e-05-9.99647636e-06j]],\n", + "\n", + " [[-9.62790996e-02-1.96330324e-02j,\n", + " 1.68201745e-01+1.18223600e-01j],\n", + " [-1.75099984e-01-1.32427067e-01j,\n", + " 1.27981111e-01+2.63560146e-01j],\n", + " [ 7.46928990e-01-4.62884784e-01j,\n", + " -5.34077510e-02+9.36575700e-03j],\n", + " [-1.56331956e-02-3.50264693e-03j,\n", + " 3.77325993e-03+5.84915979e-03j],\n", + " [-1.99147244e-03+2.05459911e-02j,\n", + " -9.52859223e-02+1.66833609e-01j],\n", + " [-8.48183932e-04-1.99627713e-03j,\n", + " 2.27941643e-03-2.81634666e-02j],\n", + " [-5.17894863e-04+3.75765783e-04j,\n", + " 4.13420494e-04+2.19803937e-02j],\n", + " [ 4.15622198e-05-8.21295398e-05j,\n", + " -2.48569471e-04-2.65523733e-04j]],\n", + "\n", + " [[ 6.55877404e-03+2.02565541e-04j,\n", + " -1.50606185e-02-3.60905821e-03j],\n", + " [-3.57695576e-03+5.11151366e-03j,\n", + " -1.22154588e-02-1.84163228e-02j],\n", + " [ 2.38998961e-02-2.12305393e-02j,\n", + " 1.70809124e-02-5.50840283e-03j],\n", + " [ 9.62923229e-01+3.97307873e-02j,\n", + " 1.08321451e-01+4.75455038e-02j],\n", + " [ 1.79808505e-03+2.88563133e-05j,\n", + " -9.23177321e-03-3.19200717e-02j],\n", + " [ 4.05790890e-03-1.47284307e-02j,\n", + " -5.20761795e-02+7.01392666e-02j],\n", + " [-1.78163610e-02-1.88486855e-02j,\n", + " 8.04139450e-02+1.97150201e-01j],\n", + " [-2.54203391e-04+1.86174875e-04j,\n", + " -8.48475657e-03+4.81064635e-04j]],\n", + "\n", + " [[ 1.69700421e-02+1.96229722e-02j,\n", + " -1.64815653e-02-5.42362295e-02j],\n", + " [ 4.36677889e-04+3.33948135e-02j,\n", + " 1.27511369e-02-7.09232241e-02j],\n", + " [ 4.61609997e-02+7.38830259e-03j,\n", + " -1.12159401e-02-1.30335167e-02j],\n", + " [-4.25221361e-02-3.20323221e-02j,\n", + " 4.70296927e-02+8.24957490e-02j],\n", + " [ 1.72839314e-01-1.09057598e-01j,\n", + " -2.31497958e-02-3.64471320e-03j],\n", + " [ 6.26528084e-01-6.17887557e-01j,\n", + " -1.48330048e-01+5.07801361e-02j],\n", + " [ 8.46826583e-02+2.81011552e-01j,\n", + " -1.88223645e-02+8.45388398e-02j],\n", + " [ 2.43712552e-02+2.31450843e-03j,\n", + " 1.72249600e-01+1.01709284e-01j]]], dtype=complex64)
Tensor(shape=(8, 15, 2), inds=[_ee5449AAOLg, _ee5449AAOLh, k3], tags={I3, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(15, 25, 2), inds=[_ee5449AAOLh, _ee5449AAOLi, k4], tags={I4, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(25, 37, 2), inds=[_ee5449AAOLi, _ee5449AAOLj, k5], tags={I5, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(37, 53, 2), inds=[_ee5449AAOLj, _ee5449AAOLk, k6], tags={I6, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(53, 72, 2), inds=[_ee5449AAOLk, _ee5449AAOLl, k7], tags={I7, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(72, 91, 2), inds=[_ee5449AAOLl, _ee5449AAOLm, k8], tags={I8, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(91, 103, 2), inds=[_ee5449AAOLm, _ee5449AAOLn, k9], tags={I9, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(103, 117, 2), inds=[_ee5449AAOLn, _ee5449AAOLo, k10], tags={I10, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(117, 146, 2), inds=[_ee5449AAOLo, _ee5449AAOLp, k11], tags={I11, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(146, 186, 2), inds=[_ee5449AAOLp, _ee5449AAOLq, k12], tags={I12, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(186, 196, 2), inds=[_ee5449AAOLq, _ee5449AAOLr, k13], tags={I13, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(196, 247, 2), inds=[_ee5449AAOLr, _ee5449AAOLs, k14], tags={I14, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(247, 317, 2), inds=[_ee5449AAOLs, _ee5449AAOLt, k15], tags={I15, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(317, 337, 2), inds=[_ee5449AAOLt, _ee5449AAOLu, k16], tags={I16, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(337, 384, 2), inds=[_ee5449AAOLu, _ee5449AAOLv, k17], tags={I17, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(384, 410, 2), inds=[_ee5449AAOLv, _ee5449AAOLw, k18], tags={I18, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(410, 464, 2), inds=[_ee5449AAOLw, _ee5449AAOLx, k19], tags={I19, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(464, 504, 2), inds=[_ee5449AAOLx, _ee5449AAOLy, k20], tags={I20, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(504, 600, 2), inds=[_ee5449AAOLy, _ee5449AAOLz, k21], tags={I21, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(600, 721, 2), inds=[_ee5449AAOLz, _ee5449AAOMA, k22], tags={I22, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(721, 796, 2), inds=[_ee5449AAOMA, _ee5449AAOMB, k23], tags={I23, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(796, 856, 2), inds=[_ee5449AAOMB, _ee5449AAOMC, k24], tags={I24, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(856, 856, 2), inds=[_ee5449AAOMC, _ee5449AAOMD, k25], tags={I25, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(856, 886, 2), inds=[_ee5449AAOMD, _ee5449AAOME, k26], tags={I26, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(886, 916, 2), inds=[_ee5449AAOME, _ee5449AAOMF, k27], tags={I27, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(916, 991, 2), inds=[_ee5449AAOMF, _ee5449AAOMG, k28], tags={I28, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(991, 1021, 2), inds=[_ee5449AAOMG, _ee5449AAOMH, k29], tags={I29, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(1021, 1006, 2), inds=[_ee5449AAOMH, _ee5449AAOMI, k30], tags={I30, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(1006, 916, 2), inds=[_ee5449AAOMI, _ee5449AAOMJ, k31], tags={I31, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(916, 750, 2), inds=[_ee5449AAOMJ, _ee5449AAOMK, k32], tags={I32, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(750, 750, 2), inds=[_ee5449AAOMK, _ee5449AAOML, k33], tags={I33, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(750, 766, 2), inds=[_ee5449AAOML, _ee5449AAOMM, k34], tags={I34, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(766, 721, 2), inds=[_ee5449AAOMM, _ee5449AAOMN, k35], tags={I35, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(721, 706, 2), inds=[_ee5449AAOMN, _ee5449AAOMO, k36], tags={I36, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(706, 563, 2), inds=[_ee5449AAOMO, _ee5449AAOMP, k37], tags={I37, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(563, 537, 2), inds=[_ee5449AAOMP, _ee5449AAOMQ, k38], tags={I38, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(537, 507, 2), inds=[_ee5449AAOMQ, _ee5449AAOMR, k39], tags={I39, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(507, 493, 2), inds=[_ee5449AAOMR, _ee5449AAOMS, k40], tags={I40, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(493, 429, 2), inds=[_ee5449AAOMS, _ee5449AAOMT, k41], tags={I41, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(429, 371, 2), inds=[_ee5449AAOMT, _ee5449AAOMU, k42], tags={I42, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(371, 351, 2), inds=[_ee5449AAOMU, _ee5449AAOMV, k43], tags={I43, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(351, 346, 2), inds=[_ee5449AAOMV, _ee5449AAOMW, k44], tags={I44, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(346, 311, 2), inds=[_ee5449AAOMW, _ee5449AAOMX, k45], tags={I45, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(311, 273, 2), inds=[_ee5449AAOMX, _ee5449AAOMY, k46], tags={I46, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(273, 267, 2), inds=[_ee5449AAOMY, _ee5449AAOMZ, k47], tags={I47, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(267, 235, 2), inds=[_ee5449AAOMZ, _ee5449AAOMa, k48], tags={I48, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(235, 186, 2), inds=[_ee5449AAOMa, _ee5449AAOMb, k49], tags={I49, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(186, 164, 2), inds=[_ee5449AAOMb, _ee5449AAOMc, k50], tags={I50, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(164, 134, 2), inds=[_ee5449AAOMc, _ee5449AAOMd, k51], tags={I51, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(134, 110, 2), inds=[_ee5449AAOMd, _ee5449AAOMe, k52], tags={I52, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(110, 84, 2), inds=[_ee5449AAOMe, _ee5449AAOMf, k53], tags={I53, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(84, 79, 2), inds=[_ee5449AAOMf, _ee5449AAOMg, k54], tags={I54, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(79, 62, 2), inds=[_ee5449AAOMg, _ee5449AAOMh, k55], tags={I55, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(62, 45, 2), inds=[_ee5449AAOMh, _ee5449AAOMi, k56], tags={I56, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(45, 31, 2), inds=[_ee5449AAOMi, _ee5449AAOMj, k57], tags={I57, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(31, 23, 2), inds=[_ee5449AAOMj, _ee5449AAOMk, k58], tags={I58, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(23, 14, 2), inds=[_ee5449AAOMk, _ee5449AAOMl, k59], tags={I59, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(14, 7, 2), inds=[_ee5449AAOMl, _ee5449AAOMm, k60], tags={I60, PSI0}),backend=numpy, dtype=complex64, data=...
Tensor(shape=(7, 4, 2), inds=[_ee5449AAOMm, _ee5449AAOMn, k61], tags={I61, PSI0}),backend=numpy, dtype=complex64, data=array([[[ 9.96236980e-01+2.4070632e-08j, 7.89629221e-02+3.4836203e-02j],\n", + " [ 7.85438053e-04+1.3493551e-03j, 3.86000465e-06-7.7864886e-03j],\n", + " [-3.07907067e-05+4.1298550e-05j, -1.74091445e-04-6.0549745e-04j],\n", + " [-6.33264517e-06+1.0163743e-05j, 8.19765701e-05-1.7924360e-05j]],\n", + "\n", + " [[ 2.91674002e-03-1.8520071e-03j, -2.98597179e-02+6.3157629e-04j],\n", + " [-9.50842917e-01+2.9104754e-01j, -9.70625728e-02+2.7532874e-02j],\n", + " [ 1.01774577e-02+5.3521578e-04j, -5.00710274e-04+1.4484661e-03j],\n", + " [ 7.69868784e-05+8.8001480e-06j, -1.44594989e-04+1.1705145e-04j]],\n", + "\n", + " [[ 6.95380266e-04-8.6132996e-03j, -4.66696434e-02+8.6333320e-02j],\n", + " [-2.67639733e-03-1.2591273e-02j, 1.15524465e-02-2.3635915e-03j],\n", + " [ 1.44219860e-01-9.8215419e-01j, 3.19165848e-02-5.9365232e-02j],\n", + " [-6.82235579e-04-5.4200133e-04j, 2.50299089e-03+3.6452424e-03j]],\n", + "\n", + " [[ 5.20012304e-02+6.8666242e-02j, -2.26194963e-01-9.5790952e-01j],\n", + " [ 2.18018163e-02+1.7246410e-02j, -8.19127113e-02+7.9877868e-02j],\n", + " [-5.40758595e-02-8.2671881e-02j, -3.53236636e-03-1.3851826e-02j],\n", + " [-2.06969329e-04-7.2022912e-04j, 4.10932611e-04+1.9045428e-05j]],\n", + "\n", + " [[ 2.16604420e-03-3.1289419e-06j, -1.13828696e-01-8.6599207e-03j],\n", + " [ 4.76607047e-02+8.9024976e-02j, -4.17614192e-01-8.9195538e-01j],\n", + " [ 5.02990745e-03+1.6479675e-03j, -5.72904162e-02-3.5829116e-02j],\n", + " [ 2.92633139e-02-3.6426760e-02j, -1.88175717e-03-5.2322319e-04j]],\n", + "\n", + " [[-1.11391593e-04+3.7153200e-06j, 3.29019409e-03-3.2021434e-03j],\n", + " [-4.63805255e-03-3.5727155e-04j, 4.38987799e-02+5.6419009e-03j],\n", + " [-4.19351680e-04+2.8612893e-03j, 1.31152254e-02-3.3428535e-02j],\n", + " [-3.55564982e-01-9.2888469e-01j, -2.18382608e-02-8.3493821e-02j]],\n", + "\n", + " [[ 1.12551101e-03+6.4542535e-04j, -6.73710834e-03-1.3146271e-02j],\n", + " [-1.34523027e-03+5.2274307e-03j, 2.15623397e-02-6.3469239e-02j],\n", + " [-3.88851315e-02-5.6240056e-02j, 2.51932204e-01+9.5996392e-01j],\n", + " [-2.12617535e-02-1.9569127e-02j, -6.76252022e-02-1.3219890e-02j]]],\n", + " dtype=complex64)
Tensor(shape=(4, 2, 2), inds=[_ee5449AAOMn, _ee5449AAOMo, k62], tags={I62, PSI0}),backend=numpy, dtype=complex64, data=array([[[ 0.92607856-9.8399801e-07j, 0.31903595-2.0143587e-02j],\n", + " [-0.07055734-4.4627250e-03j, 0.1875915 -1.9815541e-06j]],\n", + "\n", + " [[-0.37172192-1.2331456e-04j, 0.7954943 -5.0294854e-02j],\n", + " [-0.00233152-2.0734944e-04j, 0.47589502+6.9912453e-04j]],\n", + "\n", + " [[ 0.05932834-1.2505287e-04j, 0.20936982-1.4789319e-02j],\n", + " [ 0.926834 +5.4938756e-02j, -0.30063716+1.9048782e-03j]],\n", + "\n", + " [[ 0.01609367-2.0553790e-02j, -0.26616517+3.8415003e-01j],\n", + " [ 0.2447539 -2.7028224e-01j, 0.50008726-6.3076097e-01j]]],\n", + " dtype=complex64)
Tensor(shape=(2, 2), inds=[_ee5449AAOMo, k63], tags={I63, PSI0}),backend=numpy, dtype=complex64, data=array([[ 0.97433376-1.7703654e-12j, -0.22317576-2.9436558e-02j],\n", + " [ 0.22466111-1.4189258e-02j, 0.9720776 +6.6268601e-02j]],\n", + " dtype=complex64)
" + ], + "text/plain": [ + "MatrixProductState(tensors=64, indices=127, L=64, max_bond=1021)" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mps = circ.get_psi_unordered()\n", + "# convert back to numpy\n", + "mps.apply_to_arrays(lambda x: x.cpu().numpy())\n", + "mps" + ] + }, + { + "cell_type": "markdown", + "id": "7cbd2b1b", + "metadata": {}, + "source": [ + "The MPS circuit simulators track the current orthogonality center so as to avoid uneccessary canonicalizations. However with only single precision this can be a meaninfully lossy assumption, meaning the global norm might be slightly different to that estimated above. We can check that here:" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "13961a6f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'cur_orthog': (1, 1)}" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "circ.gate_opts[\"info\"]" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "795db222-c4d5-43c2-abd7-ba93348b3544", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 2 4 8 15 25 37 53 72 91 103 117 146 186 196 247 317 337 384 410 464 5 \n", + "... >─●─●─●──●──●──●──●──●──●━━━●━━━●━━━●━━━●━━━●━━━●━━━●━━━●━━━●━━━●━━━●━ ...\n", + " │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ \n", + " ... \n", + " 04 600 721 796 856 856 886 916 991 1021 1006 916 750 750 766 721 706 5 \n", + "... ━━●━━━●━━━●━━━●━━━●━━━●━━━●━━━●━━━●━━━━●━━━━●━━━●━━━●━━━●━━━●━━━●━━━●━ ...\n", + " │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ \n", + " ... \n", + " 63 537 507 493 429 371 351 346 311 273 267 235 186 164 134 110 84 79 6 \n", + "... ━━●━━━●━━━●━━━●━━━●━━━●━━━●━━━●━━━●━━━●━━━●━━━●━━━●━━━●━━━●━━━●──●──●─ ...\n", + " │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ \n", + " ... \n", + " 2 45 31 23 14 7 4 2 \n", + " ─●──●──●──<──<─<─<─<\n", + " │ │ │ │ │ │ │ │\n" + ] + } + ], + "source": [ + "mps.show()" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "60a1dd99", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.2729898095130906" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1 - abs(mps.norm())**2" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "torch", + "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.11.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/tensor-circuit.ipynb b/docs/tensor-circuit.ipynb index 426f9825..5661b105 100644 --- a/docs/tensor-circuit.ipynb +++ b/docs/tensor-circuit.ipynb @@ -69273,9 +69273,9 @@ ], "metadata": { "kernelspec": { - "display_name": "Python [conda env:py311]", + "display_name": "Python 3 (ipykernel)", "language": "python", - "name": "conda-env-py311-py" + "name": "python3" }, "language_info": { "codemirror_mode": { @@ -69287,7 +69287,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.3" + "version": "3.11.8" } }, "nbformat": 4, diff --git a/quimb/tensor/circuit.py b/quimb/tensor/circuit.py index f2818dd5..52175f80 100644 --- a/quimb/tensor/circuit.py +++ b/quimb/tensor/circuit.py @@ -1031,11 +1031,7 @@ def _apply_controlled_gate_mps(psi, gate, tags=None, **gate_opts): def _apply_controlled_gate_htn( - psi, - gate, - tags=None, - propagate_tags="register", - **gate_opts + psi, gate, tags=None, propagate_tags="register", **gate_opts ): assert propagate_tags == "register" @@ -1212,6 +1208,13 @@ def qubits(self, qubits): else: self._qubits = tuple(qubits) + @property + def total_qubit_count(self): + nq = len(self._qubits) + if self._controls: + nq += len(self._controls) + return nq + @property def controls(self): return self._controls @@ -1644,6 +1647,36 @@ def from_openqasm2_url(cls, url, **circuit_opts): qc.apply_gates(info["gates"]) return qc + @classmethod + def from_gates(cls, gates, N=None, progbar=False, **kwargs): + """Generate a ``Circuit`` instance from a sequence of gates. + + Parameters + ---------- + gates : sequence[Gate] or sequence[tuple] + The sequence of gates to apply. + N : int, optional + The number of qubits. If not given, will be inferred from the + gates. + progbar : bool, optional + Whether to show a progress bar. + kwargs + Supplied to the ``Circuit`` constructor. + """ + if N is None: + gates = tuple(gates) + + N = 0 + for gate in gates: + if gate.qubits: + N = max(N, max(gate.qubits) + 1) + if gate.controls: + N = max(N, max(gate.controls) + 1) + + qc = cls(N, **kwargs) + qc.apply_gates(gates, progbar=progbar) + return qc + def _init_state(self, N, dtype="complex128"): return TN_from_sites_computational_state( site_map={i: "0" for i in range(N)}, dtype=dtype @@ -1756,16 +1789,21 @@ def apply_gate_raw( gate = Gate.from_raw(U, where, controls=controls, round=gate_round) self._apply_gate(gate, **gate_opts) - def apply_gates(self, gates, **gate_opts): + def apply_gates(self, gates, progbar=False, **gate_opts): """Apply a sequence of gates to this tensor network quantum circuit. Parameters ---------- - gates : list[list[str]] + gates : Sequence[Gate] or Sequence[Tuple] The sequence of gates to apply. gate_opts Supplied to :meth:`~quimb.tensor.circuit.Circuit.apply_gate`. """ + if progbar: + from ..utils import progbar as _progbar + + gates = _progbar(gates) + for gate in gates: if isinstance(gate, Gate): self._apply_gate(gate, **gate_opts) @@ -3753,6 +3791,12 @@ class CircuitMPS(Circuit): psi0 : TensorNetwork1DVector, optional The initial state, assumed to be ``|00000....0>`` if not given. The state is always copied and the tag ``PSI0`` added. + max_bond : int, optional + The maximum bond dimension to truncate to when applying gates, if any. + This is simply a shortcut for setting ``gate_opts['max_bond']``. + cutoff : float, optional + The singular value cutoff to use when truncating the state. + This is simply a shortcut for setting ``gate_opts['cutoff']``. gate_opts : dict, optional Default options to pass to each gate, for example, "max_bond" and "cutoff" etc. @@ -3797,7 +3841,10 @@ class CircuitMPS(Circuit): def __init__( self, N=None, + *, psi0=None, + max_bond=None, + cutoff=1e-10, gate_opts=None, gate_contract="auto-mps", **circuit_opts, @@ -3805,6 +3852,8 @@ def __init__( gate_opts = ensure_dict(gate_opts) gate_opts.setdefault("contract", gate_contract) gate_opts.setdefault("propagate_tags", False) + gate_opts.setdefault("max_bond", max_bond) + gate_opts.setdefault("cutoff", cutoff) # this is used to pass around the canonical form gate_opts.setdefault("info", {}) @@ -3817,6 +3866,30 @@ def __init__( def _init_state(self, N, dtype="complex128"): return MPS_computational_state("0" * N, dtype=dtype) + def apply_gates(self, gates, progbar=False, **gate_opts): + if progbar: + from ..utils import progbar as _progbar + + gates = tuple(gates) + gates = _progbar(gates, total=len(gates)) + gates.set_description( + f"max_bond={self._psi.max_bond()}, " + f"error~={self.error_estimate():.3g}" + ) + + for gate in gates: + if isinstance(gate, Gate): + self._apply_gate(gate, **gate_opts) + else: + self.apply_gate(*gate, **gate_opts) + + if progbar and (gate.total_qubit_count >= 2): + # these don't change for single qubit gates + gates.set_description( + f"max_bond={self._psi.max_bond()}, " + f"error~={self.error_estimate():.3g}" + ) + @property def psi(self): # no squeeze so that bond dims of 1 preserved @@ -3842,8 +3915,19 @@ def get_psi_reverse_lightcone(self, where, keep_psi0=False): return self.psi def fidelity_estimate(self): - """Estimate the fidelity of the current state based on its norm, which - tracks how much the state has been truncated. + r"""Estimate the fidelity of the current state based on its norm, which + tracks how much the state has been truncated: + + .. math:: + + \tilde{F} = + \left| \langle \psi | \psi \rangle \right|^2 + \approx + \left|\langle \psi_\mathrm{ideal} | \psi \rangle\right|^2 + + See Also + -------- + error_estimate """ cur_orthog = self.gate_opts["info"].get("cur_orthog", None) @@ -3851,7 +3935,21 @@ def fidelity_estimate(self): return abs(self._psi.norm()) ** 2 cmin, cmax = cur_orthog - return abs(self._psi[cmin : cmax + 1].norm()) ** 2 + return abs(self._psi[cmin : cmax + 1].norm(tags=all)) ** 2 + + def error_estimate(self): + r"""Estimate the error in the current state based on the norm of the + discarded part of the state: + + .. math:: + + \epsilon = 1 - \tilde{F} + + See Also + -------- + fidelity_estimate + """ + return 1 - self.fidelity_estimate() class CircuitPermMPS(CircuitMPS): @@ -3877,7 +3975,7 @@ def __init__( gate_opts.setdefault("contract", gate_contract) # this is used to pass around the canonical form gate_opts.setdefault("info", {}) - super().__init__(N, psi0, gate_opts, **circuit_opts) + super().__init__(N, psi0=psi0, gate_opts=gate_opts, **circuit_opts) # keep track of the current qubit ordering self.qubits = list(range(self.N))