I am starting a quantum error correction (QEC) project and I would like to invest some time at the outset familiarizing myself with a nice software library that can be used to simulate different codes. I am aware of two publicly-available candidate libraries, qecsim and Stim. From their documentations, both seem likely to be very useful software tools that can be easily adapted to suit a wide array of research problems. However, as someone who is just get started, it would be nice to understand the key differences between these two libraries so that I could pick one to focus on initially - for example, are there computations that one library can do but not the other?

  • 1
    $\begingroup$ @Mauricio I think it's a bit early to point people at qiskit qec. The first line in the readme is "WARNING: qiskit-qec is still in the early stages of development". Give them time to get it to where they want it! $\endgroup$ Sep 1, 2022 at 20:57

1 Answer 1


Probably the biggest difference between qecsim and stim is that qecsim is stabilizer-focused whereas stim is circuit-focused.

In qecsim, a code is defined as a set of stabilizers. For example, it exposes a class RotatedPlanarCode which inherits from the class StabilizerCode which has methods like .stabilizers. Simulations are then based on adding noise to the qubits used by the stabilizers, determining which stabilizers flipped, and running a decoder to explain those flips. To define a new code, you create a new child class of StabilizerCode with different stabilizers (etc). This makes using the library initially simple, but it also effectively makes it very inconvenient to do things like simulate time dynamics where the stabilizer measurements are decomposed into a circuit. It's also much more difficult to work with codes that inherently have time dynamics, like the bacon-shor code and the honeycomb code, or even just doing a logical operation to a vanilla stabilizer code.

In stim, there's no built-in notion of a stabilizer code. There are some utilities like stim.PauliString/stim.Tableau/stim.TableauSimulator that enable you to operate on stabilizers in complex ways, but ultimately the closest you can get to just-define-a-stabilizer-code is to create a stim.Circuit that measures the code's stabilizers. The simplest possible experiment would be to measure the stabilizers twice, with some noise instructions in between, and detector annotations asserting the measurements should agree. This makes getting started harder, because you are responsible for more of the "this is a code" context, but it also won't get in your way when you start doing anything that's not just-a-stabilizer-code.

Probably the next most significant difference is speed.

Stim is thousands of times faster than qecsim. For example, Stim samples any depolarizing error at gigahertz rates by using various SIMD tricks but qecsim is stuck at megahertz rates because it's doing string operations with each random sample. I haven't actually measured this, but I would bet things that run in seconds using stim would take hours to finish when using the qecsim equivalent.

In summary... I would say qecsim is more beginner friendly, whereas stim is more power user friendly. You'll get started faster with qecsim but you'll get further with stim.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.