Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Fix: sz=0 ignored in post selection filter #323

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def create_jw_electron_number_post_selection_filter_fn(
"""

def filter_fn(bits: int) -> bool:
if sz:
if sz is not None:
n_up = bin(bits)[-1:1:-2].count("1")
n_down = bin(bits)[-2:1:-2].count("1")
if n_up - n_down != sz * 2:
Expand All @@ -58,7 +58,7 @@ def create_bk_electron_number_post_selection_filter_fn(
def filter_fn(bits: int) -> bool:
state = ComputationalBasisState(qubit_count, bits=bits)
occ_indices = inv_st_mapper(state)
if sz and occupation_state_sz(occ_indices) != sz:
if sz is not None and occupation_state_sz(occ_indices) != sz:
return False
return len(occ_indices) == n_electrons

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ def test_create_jw_electron_number_post_selection_filter_fn() -> None:
assert not filter_fn(0b1011)
assert not filter_fn(0b11010)

n_electrons = 2
filter_fn = create_jw_electron_number_post_selection_filter_fn(n_electrons, sz=0)
assert not filter_fn(0b00)
assert not filter_fn(0b10)
assert filter_fn(0b11)
assert filter_fn(0b1100)
assert filter_fn(0b1001)
assert not filter_fn(0b101)
assert not filter_fn(0b1111)


def test_create_bk_electron_number_post_selection_filter_fn() -> None:
qubit_count = 10
Expand All @@ -57,6 +67,22 @@ def test_create_bk_electron_number_post_selection_filter_fn() -> None:
assert not filter_fn(0b0010)
assert filter_fn(59)

filter_fn = create_bk_electron_number_post_selection_filter_fn(
qubit_count, n_electrons, sz=0.0
)
assert filter_fn(0b1)
assert filter_fn(0b11)
assert filter_fn(0b101011)
assert filter_fn(0b1011)
assert filter_fn(0b1100)
assert filter_fn(0b100)
assert not filter_fn(0b111)
assert not filter_fn(0b111011)
assert not filter_fn(0b1001011)
assert not filter_fn(0b1000)
assert not filter_fn(0b1000010)
assert not filter_fn(0b1110000100)


def test_create_scbk_electron_number_post_selection_filter_fn() -> None:
qubit_count = 6
Expand Down
Loading