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

Include ability to plot all decoding objects in one QEC round + misc. improvements #23

Merged
merged 19 commits into from
May 9, 2022

Conversation

ilan-tz
Copy link
Collaborator

@ilan-tz ilan-tz commented May 4, 2022

Context for changes

  • Improvements:
    • New function draw_mwpm_decoding in the viz module.
    • New draw and drawing_opts argument to the correct function in the decoder module.
    • Change name of label_cubes drawing argument in syndrome_plot to label_stabilizers.
    • Populate node labels of virtual boundary points in the matching graph.
    • Matching graphs can be plotted even with non-NetworkX backends.

Example usage and tests

See the decoding.py example, e.g.

dw = {
    "show_nodes": True,
    "color_nodes": node_colors,
    "label": None,
    "legend": True,
    "title": True,
    "display_axes": True,
    "label_stabilizers": True,
    "label_boundary": False,
    "label_edges": False,
    }

c = dec.correct(
    code=RHG_code,
    decoder=decoder,
    weight_options=weight_options,
    sanity_check=True,
    draw=True,
    drawing_opts=dw,
    )

(New part is the last two arguments).

Performance results justifying changes

  • Not Applicable

Workflow actions and tests

  • Not Applicable

Expected benefits and drawbacks

Expected benefits:

  • Before, user had to extract the decoding objects (stabilizer graph, matching graph, and the matching) from the code and decoder and manually include, e.g. indices for the stabilizers. Now, this can be done with a simple argument to the correct function, which saves time and considerably simplifies the decoding.py example.
  • User is now able to plot the decoding objects in sync with the decoding procedure. This means they are able to associate the result of the error correction to the appearance and properties of the decoding objects, which aids with understanding and debugging.
  • In the decoding example, node labels were not populated for virtual nodes in the matching graph, since these nodes are not of the form of a tuple (x, y, z), but rather ((x, y, z), i), where i denotes the excitation number. This has been fixed, so that the labels are displayed appropriately.
  • Before, user had to convert matching graphs to NetworkX to plot them. Now, this is automatically done when the draw method of MatchingGraph is called (such a problem had already been resolved for stabilizer graphs).

Possible drawbacks:

  • Visualization functionality had been moved to the viz.py file so as not to crowd the rest of the code and to avoid having to import plotting tools unnecessarily. These changes add a matplotlib import statement and calls to viz functions inside correct, which negates some of the benefit of completely separating decoding and plotting. However, matplotlib is only imported if the draw argument is set to True, and nothing else happens in correct other than a one-line function call.
  • The user has limited control of the individual drawing options to the various functions called by draw_mwpm_decoding. For example, settings to the stabilizer and matching graph drawings are the same.
  • Setting label_stabilizers or label_boundary to True in the drawing options individually turn on/off the stabilizer or boundary labels for the syndrome plot, but turn both of them on/off of the stabilizer and matching graphs.

Related Github issues

  • Not Applicable

Checklist and integration statements

  • My Python and C++ codes follow the coding and commenting styles of this project as indicated by existing files. Specifically, the changes conform to given black, docformatter and pylint configurations.
  • I have performed a self-review of these changes, checked my code, and corrected misspellings to the best of my capacity. I have checked the codefactor score in the active branch and ensured it remains at A level. I also confirm that I have already merged other branches into this branch as required.
  • I have added context for corresponding changes in documentation and README.md as needed.
  • I have added new workflow CI tests for corresponding changes, ensuring codecoverage 90% or better, and these pass locally for me.
  • I have updated CHANGELOG.md following the template. I recognize that the developers may revisit CHANGELOG.md and the versioning, and create a Special Release including my changes.

- Add function "draw_mwpm_decoding" to viz.py, which, in one go, plots the stabilizer graph, matching graph, and the syndrome.
- Add a draw option to "correct" in decoder.py that calls on draw_mwpm_decoding.
- Simplify the decoding example considerably thanks to the previous changes. This also allows the user to plot the decoding objects that correspond to a given round of error correction rather than a separate one, assisting with debugging.
@codecov
Copy link

codecov bot commented May 4, 2022

Codecov Report

Merging #23 (f7da2c8) into main (c155cf9) will decrease coverage by 0.06%.
The diff coverage is 86.66%.

@@            Coverage Diff             @@
##             main      #23      +/-   ##
==========================================
- Coverage   95.70%   95.63%   -0.07%     
==========================================
  Files          32       32              
  Lines        1815     1811       -4     
==========================================
- Hits         1737     1732       -5     
- Misses         78       79       +1     
Impacted Files Coverage Δ
flamingpy/utils/viz.py 83.13% <80.00%> (-6.05%) ⬇️
flamingpy/_version.py 100.00% <100.00%> (ø)
flamingpy/decoders/decoder.py 99.18% <100.00%> (+0.02%) ⬆️
flamingpy/decoders/mwpm/matching.py 100.00% <100.00%> (+3.17%) ⬆️
flamingpy/examples/decoding.py 100.00% <100.00%> (ø)
flamingpy/codes/surface_code.py 95.85% <0.00%> (+1.55%) ⬆️
flamingpy/codes/graphs/stabilizer_graph.py 95.26% <0.00%> (+4.87%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c155cf9...f7da2c8. Read the comment docs.

- Change label cubes drawing argument to label stabilizers
- Add label edges argument to draw_mwpm_decoding for allowing user to turn off edge weight labels
- Allow user to turn off node labels on decoding graphs depending on label_stabilizers and label_boundary drawing arguments supplied to draw_mwpm_decoding
If the matching graph is not a networkx graph and yet user wants to draw it, first convert to a networkx graph
Before they were not displaying properly, since the node labels dictionary had tuples (x, y, z) for the boundary points, whereas in the matching graph they are of the form ((x, y, z), i), where i indicated the excitation number
@ilan-tz ilan-tz marked this pull request as ready for review May 4, 2022 21:46
@ilan-tz ilan-tz requested a review from sduquemesa May 4, 2022 21:47
@ilan-tz ilan-tz changed the title Include ability to plot all decoding object in one QEC round Include ability to plot all decoding objects in one QEC round + misc. improvements May 4, 2022
Copy link
Contributor

@sduquemesa sduquemesa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ilan-tz! This contribution indeed simplifies the code for the decoding example. Just left some simple questions, other than that this looks good from my side. We'll wait for other reviewers comments.

One thing we can improve after merging is having all functions and methods that plot something return the figure and axis. This can be taken care of on PR #20 if we merge this one first.

flamingpy/examples/decoding.py Outdated Show resolved Hide resolved
flamingpy/examples/decoding.py Outdated Show resolved Hide resolved
@nariman87
Copy link
Contributor

We should try to ideally improve the slightly-reduced codecov score before merging this into the main (this is due to poorly-tested viz.py but can be compensated by improving other codes).

@nariman87 nariman87 merged commit e07ed84 into main May 9, 2022
@nariman87 nariman87 deleted the decoding-plot branch May 9, 2022 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants