Skip to content

Commit

Permalink
improve bitstring docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsung committed Jul 15, 2024
1 parent 9292d56 commit e911272
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions python/ffsim/states/bitstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,18 +311,25 @@ def addresses_to_strings(
norb = 3
nelec = (2, 1)
dim = ffsim.dim(norb, nelec)
strings = ffsim.addresses_to_strings(range(dim), norb, nelec)
[format(s, f"06b") for s in strings]
# output:
# ['001011',
# '010011',
# '100011',
# '001101',
# '010101',
# '100101',
# '001110',
# '010110',
# '100110']
strings = ffsim.addresses_to_strings(range(5), norb, nelec)
print(strings) # prints [11, 19, 35, 13, 21]
strings = ffsim.addresses_to_strings(
range(5), norb, nelec, bitstring_type=ffsim.BitstringType.STRING
)
print(strings) # prints ['001011', '010011', '100011', '001101', '010101']
strings = ffsim.addresses_to_strings(
range(5), norb, nelec, bitstring_type=ffsim.BitstringType.BIT_ARRAY
)
print(strings)
# prints
# [[False False True False True True]
# [False True False False True True]
# [ True False False False True True]
# [False False True True False True]
# [False True False True False True]]
Args:
addresses: The state vector addresses to convert to bitstrings.
Expand All @@ -338,6 +345,10 @@ def addresses_to_strings(
If False, then two lists are returned, ``(strings_a, strings_b)``. Note that
the list of alpha strings appears first, that is, on the left.
In the spinless case (when `nelec` is an integer), this argument is ignored.
Returns:
The bitstrings. The type of the output depends on `bitstring_type` and
`concatenate`.
"""
if isinstance(nelec, int):
# Spinless case
Expand Down Expand Up @@ -441,6 +452,9 @@ def strings_to_addresses(
nelec: Either a single integer representing the number of fermions for a
spinless system, or a pair of integers storing the numbers of spin alpha
and spin beta fermions.
Returns:
The state vector addresses, as a Numpy array of integers.
"""
if not len(strings):
return np.array([])
Expand Down

0 comments on commit e911272

Please sign in to comment.