Skip to content

Commit

Permalink
tidy product_state_as_mps utility function
Browse files Browse the repository at this point in the history
  • Loading branch information
bartandrews committed Nov 14, 2024
1 parent dc7d07f commit 2e1777c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions python/ffsim/tenpy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ def product_state_as_mps(bitstring: tuple[str, str]) -> MPS:
The product state as an MPS.
"""

# unpack bitstrings
string_a, string_b = bitstring

# extract norb
assert len(bitstring[0]) == len(bitstring[1])
norb = len(bitstring[0])
assert len(string_a) == len(string_b)
norb = len(string_a)

# merge bitstrings
up_sector = list(bitstring[0].replace("1", "u"))
down_sector = list(bitstring[1].replace("1", "d"))
product_state = list(map(lambda x, y: x + y, up_sector, down_sector))
up_sector = string_a.replace("1", "u")
down_sector = string_b.replace("1", "d")
product_state = [a + b for a, b in zip(up_sector, down_sector)]

# relabel using TeNPy SpinHalfFermionSite convention
for i, site in enumerate(product_state):
Expand Down

0 comments on commit 2e1777c

Please sign in to comment.