Skip to content

Tutorial: Decoding Quantum Errors on the Steane code with Belief Propagation & Catalyst #1371

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

Open
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

beitom
Copy link

@beitom beitom commented May 14, 2025

Title: Decoding Quantum Errors on the Steane code with Belief Propagation & Catalyst

Summary:
This tutorial walks you through a simplified error correction cycle using the Steane $[[7,1,3]]$
code. You’ll encode a logical qubit, introduce noise, extract syndromes, and apply decoding using
two different strategies: a simple lookup table and a belief propagation (BP) decoder. Both decoders
are implemented in JAX and JIT-compiled by Catalyst, allowing everything to run inside a single
@qml.qjit circuit.

Relevant references:

Possible Drawbacks:
The tutorial uses a simplified noise model (code capacity) where errors occur only once. Real-world quantum computers have errors at every step (circuit-level noise), which creates a much more complex decoding challenge involving errors in space and time.

Related GitHub Issues:
N/A


If you are writing a demonstration, please answer these questions to facilitate the marketing process.

GOALS — Why are we working on this now?

I work on fault tolerant compilation of quantum circuits which involves making classical decoding algorithms run alongside quantum circuit with measurements and feedforward operations. Catalyst is a great new technology to enable these kinds of high performance hybrid quantum-classical workflows essential for quantum error correction.

AUDIENCE — Who is this for?

  • Quantum computing researchers interested in QEC.
  • Developers working with Pennylane and Catalyst on hybrid workflows for QEC.
  • Educators teaching stabilizer codes or decoding techniques.

KEYWORDS — What words should be included in the marketing post?

quantum error correction, css code, hybrid quantum-classical, belief propagation decoding, JAX, Catalyst

  • Which of the following types of documentation is most similar to your file?
    (more details here note this requires a Xanadu email to view)
  • Tutorial
  • Demo
  • How-to

Notes:

suggested thumbail is to make a graphic of the Steane code in it's usual triangle layout
image

The hero image should have some theme of quantum/classical QEC circuits my idea is roughly this where S is the syndrome and R is the recovery operator:

image

[sc-93094]

Co-authored-by: Paul Finlay <50180049+doctorperceptron@users.noreply.github.com>
Copy link

github-actions bot commented May 14, 2025

Thank you for opening this pull request.

You can find the built site at this link.

Deployment Info:

  • Pull Request ID: 1371
  • Deployment SHA: adb8368d058862231593afac8acfc143dadcff36
    (The Deployment SHA refers to the latest commit hash the docs were built from)

Note: It may take several minutes for updates to this pull request to be reflected on the deployed site.

@daniela-angulo daniela-angulo self-assigned this Jun 17, 2025
Copy link
Contributor

@daniela-angulo daniela-angulo left a comment

Choose a reason for hiding this comment

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

This is a great demo! Excellent work.
I left comments to clarify a few points and suggestions to make it cleaner.

#
# In the final section of this demo we will compute the average performance of our Steane code error
# correction circuit for a range of possible error rates. We’ll define logical error rates by
# comparing the state vector from our noisy simulation to with the clean state vector ``sv_clean`` of
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# comparing the state vector from our noisy simulation to with the clean state vector ``sv_clean`` of
# comparing the state vector from our noisy simulation with the clean state vector ``sv_clean`` of



######################################################################
# Simulate 1000x noisy shots for several noise levels, we’ll use ``jax.vmap`` to efficiently map our
Copy link
Contributor

Choose a reason for hiding this comment

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

what do we mean by 1000x noisy? can it be written in plain words or more clearly?

Comment on lines 1148 to 1152
# In this tutorial, we’ve successfully built, simulated, and decoded a simple quantum error correction
# cycle using the Steane code. We’ve demonstrated encoding a logical qubit, introduced errors through
# noise simulation, and performed error correction using stabilizer measurements combined with
# classical decoding. The performance was benchmarked by measuring the logical versus physical error
# rates.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# In this tutorial, we’ve successfully built, simulated, and decoded a simple quantum error correction
# cycle using the Steane code. We’ve demonstrated encoding a logical qubit, introduced errors through
# noise simulation, and performed error correction using stabilizer measurements combined with
# classical decoding. The performance was benchmarked by measuring the logical versus physical error
# rates.
# In this tutorial, we successfully built, simulated, and decoded a simple quantum error correction
# cycle using the Steane code. We demonstrated encoding a logical qubit, introduced errors through
# noise simulation, and performed error correction using stabilizer measurements combined with
# classical decoding. Performance was benchmarked by measuring the logical versus physical error
# rates.

Comment on lines 1154 to 1160
# However, our approach had a significant simplifying assumption known as the code capacity model,
# where errors are assumed to occur at only one stage of the circuit, with perfect encoding and
# syndrome extraction otherwise. A more realistic approach—called circuit-level noise—accounts for
# potential errors at every gate and measurement within the circuit. This model significantly
# complicates decoding because it requires mapping every possible error location not only in space but
# also across multiple syndrome measurement rounds, forming a complex space-time hypergraph. Decoding
# then involves interpreting error events over both spatial and temporal dimensions.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# However, our approach had a significant simplifying assumption known as the code capacity model,
# where errors are assumed to occur at only one stage of the circuit, with perfect encoding and
# syndrome extraction otherwise. A more realistic approach—called circuit-level noise—accounts for
# potential errors at every gate and measurement within the circuit. This model significantly
# complicates decoding because it requires mapping every possible error location not only in space but
# also across multiple syndrome measurement rounds, forming a complex space-time hypergraph. Decoding
# then involves interpreting error events over both spatial and temporal dimensions.
# However, our approach relied on a significant simplifying assumption known as the code capacity model,
# where errors are assumed to occur at only one stage of the circuit, with otherwise perfect encoding and
# syndrome extraction. A more realistic approach—called circuit-level noise—accounts for
# potential errors at every gate and measurement within the circuit. This model significantly
# complicates decoding, as it requires mapping every possible error location not only in space but
# also across multiple syndrome measurement rounds, forming a complex space-time hypergraph. Decoding
# then involves interpreting error events over both spatial and temporal dimensions.

Comment on lines 1162 to 1164
# Nevertheless, the fundamental decoding principles explored here, particularly the Belief Propagation
# (BP) algorithm, remain highly relevant. BP is flexible enough to operate effectively on more full
# circuit level decoding hypergraphs.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# Nevertheless, the fundamental decoding principles explored here, particularly the Belief Propagation
# (BP) algorithm, remain highly relevant. BP is flexible enough to operate effectively on more full
# circuit level decoding hypergraphs.
# Nevertheless, the fundamental decoding principles explored here, particularly the Belief Propagation
# algorithm, remain highly relevant. BP is flexible enough to operate effectively on more comprehensive
# circuit-level decoding hypergraphs.

@beitom
Copy link
Author

beitom commented Jul 3, 2025

Thank you for the detailed comments @daniela-angulo I'll start addressing these tomorrow.

Co-authored-by: Daniela Angulo <42325731+daniela-angulo@users.noreply.github.com>
Copy link
Author

@beitom beitom left a comment

Choose a reason for hiding this comment

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

Some comments on dependancies/utility code.

from typing import Optional


def state_vector_to_dict(
Copy link
Author

Choose a reason for hiding this comment

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

@alvaro-at-xanadu this is unrelated utility code for displaying state vectors that ideally could be moved to a resource file if possible

Copy link
Author

Choose a reason for hiding this comment

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

@daniela-angulo is there a way to extract utility code or should we just keep it inline to keep things self contained

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a great question. There is no utility codes. However, the function is quite long and can distract people from the core content of the demo.
The function is to pretty print the state vector, isn't it? Could it be possible to just print it using a simpler function. I know yours renders beautifully, but I am wondering if there is a way in which we can keep things self contained without having a long piece of code that might be distracting. What do you think?

Copy link
Contributor

@daniela-angulo daniela-angulo Jul 7, 2025

Choose a reason for hiding this comment

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

In addition, this is a cool feature and if you would like this to be added to PL, you can request a new feature. See here in How can I contribute? to see the Feature request form.

# the Steane code logical zero state.
#

import pandas as pd
Copy link
Author

Choose a reason for hiding this comment

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

I have a few dependencies not part of the core qml deps

Copy link
Author

Choose a reason for hiding this comment

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

@daniela-angulo not sure where to include extra deps

Copy link
Contributor

Choose a reason for hiding this comment

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

This section is short enough for us to leave it there, I believe.

######################################################################
# A simple utility function to display the state
#
# @TODO can we move this to a utility file (or better yet make it part of pennylane 😁)
Copy link
Author

Choose a reason for hiding this comment

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

Remember to remove this

@beitom
Copy link
Author

beitom commented Jul 4, 2025

This is a great demo! Excellent work. I left comments to clarify a few points and suggestions to make it cleaner.

Everything looks good here please make the changes.

@daniela-angulo
Copy link
Contributor

Hi @beitom
I made the changes that were minor or you had given a form of approval.
There are a few of them still remaining that need your opinion or are more involved/technical that I can't make by myself.
Just in case: I don't need to perform the changes myself. You can also make changes locally on the repo and then commit them if that's something you prefer.
Let me know if I can help with anything and thank you for your time!

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.

4 participants