Skip to content

Commit b41a5d7

Browse files
committed
fix complex Hamiltonians
1 parent 5ff4de7 commit b41a5d7

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

docs/source/tutorial/mpo-mps-quimb.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
" counter[0] += 1\n",
214214
" return pympo.tensors[counter[0] - 1].blocks[0].reduced\n",
215215
"\n",
216-
"qumpo = qtn.MatrixProductOperator.from_fill_fn(mpo_fill_fn, len(pyket.tensors), bond_dim=None, phys_dim=2, shape=\"ludr\")\n",
216+
"qumpo = qtn.MatrixProductOperator.from_fill_fn(mpo_fill_fn, len(pyket.tensors), bond_dim=None, phys_dim=2, shape=\"ldur\")\n",
217217
"qumps = qtn.MatrixProductState.from_fill_fn(mps_fill_fn, len(pympo.tensors), bond_dim=None, phys_dim=2, shape=\"lpr\")\n",
218218
"\n",
219219
"qumps.show()\n",

pyblock2/algebra/io.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@ def from_block2(bmps):
251251
bmps.unload_tensor(i)
252252
mr.deallocate()
253253
r.deallocate()
254+
if i == bmps.n_sites - 1 and tensors[i].rank == 3:
255+
for block in tensors[i].blocks:
256+
block.reduced = block.reduced.reshape(block.reduced.shape[:2])
257+
block.q_labels = block.q_labels[:2]
258+
block.rank = 2
254259
elif (
255260
i == bmps.center and i != 0 and i != bmps.n_sites - 2 and bmps.dot == 2
256261
):

pyblock2/driver/core.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4471,6 +4471,7 @@ def dmrg(
44714471
fused_contraction_multiplication=False,
44724472
fused_contraction_rotation=False,
44734473
lowmem_numerical_transform=False,
4474+
real_density_matrix=False,
44744475
):
44754476
"""
44764477
Perform the ground state and/or excited state Density Matrix
@@ -4604,6 +4605,9 @@ def dmrg(
46044605
lowmem_numerical_transform : bool
46054606
If True, numerical transform will be done with copying to save peak memory.
46064607
Defult is False.
4608+
real_density_matrix : bool
4609+
If True, will use the real part of the density matrix for truncation.
4610+
Should not be used for complex Hamiltonians. Default is False.
46074611
46084612
Returns:
46094613
energy : float|complex or list[float|complex]
@@ -4729,7 +4733,8 @@ def dmrg(
47294733
dmrg.store_seq_data = store_seq_data
47304734
dmrg.iprint = iprint
47314735
dmrg.cutoff = cutoff
4732-
dmrg.trunc_type = dmrg.trunc_type | bw.b.TruncationTypes.RealDensityMatrix
4736+
if real_density_matrix:
4737+
dmrg.trunc_type = dmrg.trunc_type | bw.b.TruncationTypes.RealDensityMatrix
47334738
if kernel is not None:
47344739
# need to keep Python derived class in memory (stored in self)
47354740
self.dmrg_kernel = self.make_kernel(kernel=kernel)

0 commit comments

Comments
 (0)