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

Fix exception when sampling with post-selection #844

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions glue/sample/src/sinter/_decoding/_stim_then_decode_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ def sample(self, max_shots: int) -> AnonTaskStats:
raise ValueError("predictions.dtype != np.uint8")
if len(predictions.shape) != 2:
raise ValueError("len(predictions.shape) != 2")
if predictions.shape[0] != num_shots:
raise ValueError("predictions.shape[0] != num_shots")
if predictions.shape[0] != num_shots - num_discards_1:
raise ValueError("predictions.shape[0] != num_shots - num_discards_1")
if predictions.shape[1] < actual_obs.shape[1]:
raise ValueError("predictions.shape[1] < actual_obs.shape[1]")
if predictions.shape[1] > actual_obs.shape[1] + 1:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import collections

import numpy as np
import stim

from sinter._data import Task
from sinter._decoding._decoding_vacuous import VacuousDecoder
from sinter._decoding._stim_then_decode_sampler import \
classify_discards_and_errors
classify_discards_and_errors, _CompiledStimThenDecodeSampler


def test_classify_discards_and_errors():
Expand Down Expand Up @@ -190,3 +193,23 @@ def test_classify_discards_and_errors():
num_obs=13,
) == (0, 1)
assert counter == collections.Counter(["obs_mistake_mask=_________E___"])

def test_detector_post_selection():
circuit = stim.Circuit("""
X_ERROR(1) 0
M 0
DETECTOR rec[-1]
""")
sampler = _CompiledStimThenDecodeSampler(
decoder=VacuousDecoder(),
task = Task(
circuit=circuit,
detector_error_model=circuit.detector_error_model(),
postselection_mask=np.array([1], dtype=np.uint8),
),
count_observable_error_combos=False,
count_detection_events=False,
tmp_dir=None
)
result = sampler.sample(max_shots=1)
assert result.discards == 1