Skip to content

Commit

Permalink
Weighting decoding graphs (#427)
Browse files Browse the repository at this point in the history
* Update decoding_graph.py

Allowing the user to provide costume weights for DecodingGraph.weight_syndrome_graph() as a new argument "error_probs".
- counts is not a required argument anymore
- error_probs is also not required and overridden by counts if both of them are provided
- at least one of the above arguments should be specified to avoid NotImplementedError

* Update decoding_graph.py

Allowing the user to provide costume weights for DecodingGraph.weight_syndrome_graph() as a new argument "error_probs".
- counts is not a required argument anymore
- error_probs is also not required and overridden by counts if both of them are provided
- at least one of the above arguments should be specified to avoid NotImplementedError

* Update decoding_graph.py

* Update decoding_graph.py

linting

* Update decoding_graph.py

remove self-assigning variable

* Update decoding_graph.py
  • Loading branch information
hetenyib authored Mar 13, 2024
1 parent 34403b4 commit d61cb32
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/qiskit_qec/decoders/decoding_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,22 +303,32 @@ def get_error_probs(
else:
return error_probs

def weight_syndrome_graph(self, counts, method: str = METHOD_SPITZ):
def weight_syndrome_graph(
self, counts: dict = None, method: str = METHOD_SPITZ, error_probs: dict = None
):
"""Generate weighted syndrome graph from result counts.
Args:
counts (dict): Counts dictionary of the results used to calculate
the weights.
method (string): Method to used for calculation. Supported
methods are 'spitz' (default) and 'naive'.
error_probs (dict): probability that the syndrome contains the node pair
of a given edge. Overridden by counts if both are given.
Additional information:
Uses `counts` to estimate the probability of the errors that
create the pairs of nodes in graph. The edge weights are then
replaced with the corresponding -log(p/(1-p).
"""

error_probs = self.get_error_probs(counts, method=method)
if counts:
error_probs = self.get_error_probs(counts, method=method)
elif not error_probs:
raise NotImplementedError(
"No information provided to reweight the graph."
+ "Specify either counts or error_probs."
)

boundary_nodes = []
for n, node in enumerate(self.graph.nodes()):
Expand Down

0 comments on commit d61cb32

Please sign in to comment.