Skip to content

Commit

Permalink
fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
quantumjim authored Feb 1, 2022
1 parent 3858c7a commit 50fadfd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion qiskit_qec/decoders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@

"""Circuits."""

from . import graph_decoder
from . import graph_decoder
31 changes: 21 additions & 10 deletions qiskit_qec/decoders/graph_decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ def _separate_string(self, string):
return separated_string

def string2nodes(self, string, logical="0"):
"""
Generate probabilities of single error events from result counts.
Args:
string (string): Processed results string to convert.
logical (string): Logical value whose results are used.
Returns:
dict: List of nodes corresponding to to the non-trivial
elements in the string.
"""

separated_string = self._separate_string(string)
nodes = []
Expand Down Expand Up @@ -157,7 +166,9 @@ def _make_syndrome_graph(self, results=None):
for j in range(depth):
gate = qc.data[j][0].name
qubits = qc.data[j][1]
errors = ["x", "y", "z"]*(gate not in ['reset', 'measure']) + ["x_id", "x_x"]*(gate=="measure")
errors = ["x", "y", "z"]\
* (gate not in ['reset', 'measure'])\
+ ["x_id", "x_x"]*(gate=="measure")
for error in errors:
for qubit in qubits:
raw_results = {}
Expand Down Expand Up @@ -200,16 +211,17 @@ def get_error_probs(self, results, logical="0", use_old=False):
results (dict): A results dictionary, as produced by the
`process_results` method of the code.
logical (string): Logical value whose results are used.
use_old (bool): Whether to use the old calculation method.
Returns:
dict: Keys are the edges for specific error
events, and values are the calculated probabilities
Additional information:
Uses `results` to estimate the probability of the errors that
create the pairs of nodes specified by the edge.
Calculation done using the method of Spitz, et al.
Default calculation method is that of Spitz, et al.
https://doi.org/10.1002/qute.201800012
"""

if not use_old:

results = results[logical]
Expand Down Expand Up @@ -284,9 +296,9 @@ def get_error_probs(self, results, logical="0", use_old=False):

for node0 in boundary:
error_probs[node0, node0] = 0.5 + (av_v[node0] - 0.5) / prod[node0]

else:

results = results[logical]
shots = sum(results.values())

Expand All @@ -308,7 +320,6 @@ def get_error_probs(self, results, logical="0", use_old=False):

error_probs = {}
for edge in self.S.edge_list():
edge_data = self.S.get_edge_data(edge[0], edge[1])
ratios = []
for elements in [('00', '11'), ('11', '00'),
('01', '10'), ('10', '01')]:
Expand Down Expand Up @@ -522,11 +533,11 @@ def get_logical_prob(self, results, algorithm="matching"):
Warning,
)

for string in corrected_results:
shots += corrected_results[string]
for string, samples in corrected_results.items():
shots += samples
if string[0] != str(log):
incorrect_shots += corrected_results[string]
incorrect_shots += samples

logical_prob[log] = incorrect_shots / shots

return logical_prob
return logical_prob

0 comments on commit 50fadfd

Please sign in to comment.