| 
53 | 53 |     "    if method == \"cluster\":\n",  | 
54 | 54 |     "        gauges = gauges.copy()\n",  | 
55 | 55 |     "        psi.gauge_all_simple_(100, 1e-6, gauges=gauges)\n",  | 
56 |  | -    "        return psi.compute_local_expectation_cluster(\n",  | 
57 |  | -    "            ham.terms,\n",  | 
58 |  | -    "            max_distance=0,\n",  | 
59 |  | -    "            normalized=True,\n",  | 
60 |  | -    "            gauges=gauges,\n",  | 
61 |  | -    "            optimize=\"auto-hq\",\n",  | 
62 |  | -    "        ) / psi.nsites\n",  | 
 | 56 | +    "        return (\n",  | 
 | 57 | +    "            psi.compute_local_expectation_cluster(\n",  | 
 | 58 | +    "                ham.terms,\n",  | 
 | 59 | +    "                max_distance=0,\n",  | 
 | 60 | +    "                normalized=True,\n",  | 
 | 61 | +    "                gauges=gauges,\n",  | 
 | 62 | +    "                optimize=\"auto-hq\",\n",  | 
 | 63 | +    "            )\n",  | 
 | 64 | +    "            / psi.nsites\n",  | 
 | 65 | +    "        )\n",  | 
63 | 66 |     "\n",  | 
64 | 67 |     "    psi = psi.copy()\n",  | 
65 | 68 |     "    if gauges is not None:\n",  | 
 | 
70 | 73 |     "        return psi.compute_local_expectation_exact(ham.terms) / psi.nsites\n",  | 
71 | 74 |     "\n",  | 
72 | 75 |     "    if method == \"boundary\":\n",  | 
73 |  | -    "\n",  | 
74 | 76 |     "        if max_bond is None:\n",  | 
75 |  | -    "            max_bond = max(16, psi.max_bond()**2)\n",  | 
 | 77 | +    "            max_bond = max(16, psi.max_bond() ** 2)\n",  | 
76 | 78 |     "\n",  | 
77 |  | -    "        return psi.compute_local_expectation(\n",  | 
78 |  | -    "            ham.terms,\n",  | 
79 |  | -    "            max_bond=max(16, psi.max_bond()**2),\n",  | 
80 |  | -    "            equalize_norms=1.0,\n",  | 
81 |  | -    "            normalized=True,\n",  | 
82 |  | -    "            layer_tags=None, mode=\"fit-zipup\", bsz=1,\n",  | 
83 |  | -    "        ) / psi.nsites"  | 
 | 79 | +    "        return (\n",  | 
 | 80 | +    "            psi.compute_local_expectation(\n",  | 
 | 81 | +    "                ham.terms,\n",  | 
 | 82 | +    "                max_bond=max(16, psi.max_bond() ** 2),\n",  | 
 | 83 | +    "                equalize_norms=1.0,\n",  | 
 | 84 | +    "                normalized=True,\n",  | 
 | 85 | +    "                layer_tags=None,\n",  | 
 | 86 | +    "                mode=\"fit-zipup\",\n",  | 
 | 87 | +    "                bsz=1,\n",  | 
 | 88 | +    "            )\n",  | 
 | 89 | +    "            / psi.nsites\n",  | 
 | 90 | +    "        )"  | 
84 | 91 |    ]  | 
85 | 92 |   },  | 
86 | 93 |   {  | 
 | 
99 | 106 |    "outputs": [],  | 
100 | 107 |    "source": [  | 
101 | 108 |     "D = 4\n",  | 
102 |  | -    "psi = qtn.PEPS.rand(L, L, D, seed=42, dist=\"uniform\", loc=-1/3)"  | 
 | 109 | +    "psi = qtn.PEPS.rand(L, L, D, seed=42, dist=\"uniform\", loc=-1 / 3)"  | 
103 | 110 |    ]  | 
104 | 111 |   },  | 
105 | 112 |   {  | 
 | 
184 | 191 |    "source": [  | 
185 | 192 |     "def to_backend(x):\n",  | 
186 | 193 |     "    import torch\n",  | 
 | 194 | +    "\n",  | 
187 | 195 |     "    return torch.tensor(x, dtype=torch.float32, device=\"cuda\")\n",  | 
188 | 196 |     "\n",  | 
 | 197 | +    "\n",  | 
189 | 198 |     "psi.apply_to_arrays(to_backend)\n",  | 
190 | 199 |     "ham.apply_to_arrays(to_backend)"  | 
191 | 200 |    ]  | 
 | 
0 commit comments