Package: qtcodes
qtcodesQiskit Topological CodesInstallationConda users, please make sure toconda install pipbefore running any pip installation if you want to installqtcodesinto your conda environment.qtcodesis published on PyPI. So, to install, simply run:pipinstallqtcodesIf you also want to download the dependencies needed to run optional tutorials, please usepip install qtcodes[dev]orpip install 'qtcodes[dev]'(forzshusers).To check if the installation was successful, run:>>>importqtcodesasqtcBuilding from sourceTo buildqtcodesfrom source, pip install using:gitclonehttps://github.com/yaleqc/qtcodes.gitcdqtcodes
pipinstall--upgrade.If you also want to download the dependencies needed to run optional tutorials, please usepip install --upgrade .[dev]orpip install --upgrade '.[dev]'(forzshusers).Installation for DevsIf you intend to contribute to this project, please installqtcodesin editable mode as follows:gitclonehttps://github.com/yaleqc/qtcodes.gitcdqtcodes
pipinstall-e.[dev]Please usepip install -e '.[dev]'if you are azshuser.Building documentation locallySet yourself up to use the[dev]dependencies. Then, from the command line run:mkdocsbuildMotivationQuantum computation is an inherently noisy process. Scalable quantum computers will require fault-tolerance to implement useful computation. There are many proposed approaches to this, but one promising candidate is the family oftopological quantum error correcting codes.Currently, theqiskit.ignis.verification.topological_codesmodule provides a general framework for QEC and implements one specific example, therepetition code. Qiskit Topological Codes builds out theqtcodesmodule into a diverse family of QEC encoders and decoders, supporting the repetition code, XXXX/ZZZZ (XXZZ) rotated surface code, and the XZZX rotated surface code.Inspired by theQiskit Textbook, we've written a full set ofjupyter notebook tutorialsto demonstrate thecircuit encoders,graph decoders, andbenchmarking toolsthat compose Qiskit Topological Codes. These tutorials both demonstrate the elegance of QEC codes as well as the utility of this package -- please check them out!CodebaseFig 1.Rotated XXXX/ZZZZ (XXZZ) Surface Code. ZZZZ/ZZ syndromes in red, XXXX/XX syndromes in purple, physical errors in green, and syndrome hits in yellow.Topological QEC codes disperse, and thus protect, one quantum bit of logical information across many physical qubits. The classical repetition code distributes 1 bit of logical information across multiple imperfect physical bits (e.g. logical 0 is 000...0 and logical 1 is 111...1). In the classical repetition logical 0 bit, for example, a few physical bits may flip to 1, but the majority will very likely stay in 0, thus preserving the logical 0 bit. Similarly, the surface code protects one logical qubit in a grid of imperfect physical qubits against Pauli errors.Theqtcodesmodule can be broken down intocircuits(encoders) andfitters(decoders). Additionally, unittests can be found intestsand benchmarking tools inqtcodes/tools.The rotated surface code is based on the earlier theoretical idea of atoric code, with periodic boundary conditions instead of open boundary conditions. This has been shown to be largely identical, but embedding a surface code on an actual device is much easier.CircuitsTheqtcodes.circuitssub-module contains classes such asXXZZQubit,XZZXQubit, andRepetitionQubit, which each allow users to construct and manipulate circuits encoding one logical qubit using a particular QEC code.For example, we can create and apply a logical X onto aRepetitionQubitas followsfromqtcodesimportRepetitionQubitqubit=RepetitionQubit({"d":3},"t")qubit.reset_z()qubit.stabilize()qubit.x()qubit.stabilize()qubit.readout_z()qubit.draw(output='mpl',fold=150)qtcodes.circuits.circalso allows users to createTopologicalRegisters (treg: a collection of topological qubits) andTopologicalCircuits (tcirc: a circuit built using a treg), the analog ofQuantumRegisterandQuantumCircuit.We can, for example, create a tcirc and treg out of twoRepetitionQubits.fromqtcodesimportTopologicalRegister,TopologicalCircuittreg=TopologicalRegister(ctypes=[REPETITION,REPETITION],params=[{"d":3},{"d":3}])circ=TopologicalCircuit(treg)circ.x(treg[0])circ.stabilize(treg[1])circ.x(1)circ.draw(output='mpl',fold=500)Learn more about circuits through encoder tutorials such as thisonefor the XXXX/ZZZZ rotated surface code.FittersTopological codes aim to build better (read: less noisy) logical qubits out of many imperfect physical qubits. This improvement is enabled by decoding schemes that can detect and thus correct for errors on a code's constituent physical qubits.The Qiskit Topological Codes package leverages Minimum-Weight Perfect Matching Graph Decoding to efficiently correct logical qubit readout.For example, we can decode the syndrome hits in Fig 1 and fine the most probable error chains (data qubit flips) corresponding to these syndrome hits.#d: surface code side length, T: number of roundsdecoder=RotatedDecoder({"d":5,"T":1})all_syndromes={"X":[(0,1.5,.5),(0,.5,1.5)],"Z":[(0,0.5,0.5),(0,1.5,1.5),(0,1.5,3.5),(0,3.5,3.5)]}matches={}forsyndrome_key,syndromesinall_syndromes.items():print(f"{syndrome_key}Syndrome Graph")error_graph=decoder._make_error_graph(syndromes,syndrome_key)print("Error Graph")decoder.draw(error_graph)matches[syndrome_key]=decoder._run_mwpm(error_graph)matched_graph=decoder._run_mwpm_graph(error_graph)print("Matched Graph")decoder.draw(matched_graph)print(f"Matches:{matches[syndrome_key]}")print("\n===\n")In this way, Qiskit Topological Codes uses graph decoding to find and correct for the most probable set of errors (error chains).The careful reader will notice that connecting syndrome hits in the most probable set of "error chains" does not uniquely specify the underlying physical qubits that underwent physical errors (i.e. there are multiple shortest paths between two syndrome hits). It turns out, by the nuances of how topological codes store  logical information (i.e. codespace), in most cases the exact path across physical qubits doesn't matter when correcting for an error chain. Read more about this in thistutorialon Decoding for XXZZ Qubits!BenchmarkingFinally, the efficiency and efficacy of the Qiskit Topological Codes package is demonstrated through benchmark simulations achieving threshold for the Repetition, XXZZ, and XZZX topological codes. Here, threshold is defined as the maximum physical error rate (i.e. imperfection level of physical qubits) below which larger surface codes perform better than smaller surface codes.Fig. 2By simulating circuits with errors inserted between two rounds of stabilizing measurements, we are able to extract a logical error rate for each code for a given physical error rate (quality of physical qubit) and surface code size. In particular, threshold is shown for the repetition code (left), XXZZ code (center), and XZZX code (right).Explore the benchmarkingtoolsandsimulationsto see how the graphs in Fig. 2 were created.Future DirectionsCheckoutissuesto see what we are working on these days!AcknowledgementsCore Devs:Shantanu Jha,Amir Ebrahimi,Jeffrey GongThanks to our mentorJames Wootton(IBM) for invaluable feedback and support since the inception of this project at the IBM Qiskit - Summer Jam Hackathon 2020.Thanks also toMatthew Treinishfrom theretworkxteam for helping onboard and support this project.Alums:Henry Liu,Shraddha Singh,Will Sun,Andy Ding,Jessie Chen,Aaron Householder,Allen MiReferencesHere's some reading material that we found particularly useful:Presentationslidesandvideoabout this package to the Qiskit Advocate community at the November 2020 Qiskit Advocate Demo Session.Surface Codes: Towards Practical Large-Scale Quantum ComputationStabilizer Codes and Quantum Error CorrectionMulti-path Summation for Decoding 2D Topological CodesQiskit Textbook - Introduction to Quantum Error Correction using Repetition Codes