-
Notifications
You must be signed in to change notification settings - Fork 121
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
Pytype fixes #740
Pytype fixes #740
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import abc | ||
from typing import Tuple, Union | ||
|
||
import pathlib | ||
|
||
import numpy as np | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
import pathlib | ||
from typing import TYPE_CHECKING | ||
|
||
from sinter._decoding_decoder_class import Decoder, CompiledDecoder | ||
|
||
|
||
if TYPE_CHECKING: | ||
import numpy as np | ||
import pymatching | ||
import stim | ||
|
||
|
||
class PyMatchingCompiledDecoder(CompiledDecoder): | ||
def __init__(self, matcher: 'pymatching.Matching'): | ||
self.matcher = matcher | ||
|
@@ -10,12 +19,15 @@ def decode_shots_bit_packed( | |
*, | ||
bit_packed_detection_event_data: 'np.ndarray', | ||
) -> 'np.ndarray': | ||
return self.matcher.decode_batch( | ||
result = self.matcher.decode_batch( | ||
shots=bit_packed_detection_event_data, | ||
bit_packed_shots=True, | ||
bit_packed_predictions=True, | ||
return_weights=False, | ||
) | ||
if isinstance(result, tuple): | ||
return result[0] # pymatching returned predictions and weights | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this ever actually executed, it would be a bug. Raise an exception, or do a cast. |
||
return result | ||
|
||
|
||
class PyMatchingDecoder(Decoder): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -361,7 +361,7 @@ def test_decode_fails_correctly(decoder: str, force_streaming: Optional[bool]): | |
with open(d / 'bad_dets.b8', 'wb') as f: | ||
f.write(b'!') | ||
|
||
if 'vacuous' not in decoder: | ||
if 'vacuous' not in decoder and decoder_obj is not None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should assert it's not none instead of disabling the testing of the decoder that wasn't. |
||
with pytest.raises(Exception): | ||
decoder_obj.decode_via_files( | ||
num_shots=1, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary to change? Because these methods are in the external API, I prefer to name the types how users would use them ("sinter.Task" instead of just "Task").