GithubHelp home page GithubHelp logo

yaleqc / qtcodes Goto Github PK

View Code? Open in Web Editor NEW
89.0 89.0 41.0 75.11 MB

Qiskit Topological Codes

Home Page: https://yaleqc.com/qtcodes/reference/qtcodes/

License: Apache License 2.0

Jupyter Notebook 98.80% Python 1.20%
decoder ibm qiskit qiskit-tutorial quantum-computing quantum-error-correction surface-code topological-quantum-computation

qtcodes's People

Contributors

1ucian0 avatar aaronhouseholder avatar allenator avatar amirebrahimi avatar gaya3-mv avatar jazzych avatar jeffreyjgong avatar liuhenry avatar mtreinish avatar muirheadmaster avatar paniash avatar phionx avatar quantumjim avatar shraggy avatar zhenghaoding avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

qtcodes's Issues

[pip] add dev pip extra, update README and notebooks

We want to make it as easy as possible to contribute to qtcodes. This issue is to implement installation tooling to improve the developer experience.

As @amirebrahimi brought up, we can use the -e pip flag to create editable installs.

So, let's:

  • update the README to reflect this method of installing qtcodes for development
  • remove the sys.path.append from our notebooks, as we can just use editable installs instead
  • add a dev extra that installs generally unnecessary dependencies (like Jupyter Lab) to set up an environment with all the dependencies needed by developers

[TCirc] Allow topological registers/circuits to hold qubits of different types and sizes

Let's allow users to create topological circuits composed of logical qubits of different types and sizes.

Here are some steps to guide you in this task:

  1. Create a new branch on this repo named "feature/49/generalize-tcirc-qubit-type". Please regularly merge changes from master into this branch as you work on this task to keep the branch up to date.
  2. Start by reading circ.py to see how TopologicalRegister and TopologicalCircuit stores and manipulates a set of topological qubits.
  3. Begin by allowing TopologicalRegister to store logical qubits of different types, and then test that single logical qubit gates work as expected on circuits composed of logical qubits of different types.
  4. Then, get the parity measurement based cx gate (already implemented for same type qubits) to work between logical qubits of different types.
  5. Track/demonstrate your changes in a Jupyter Notebook stored under tutorials/.
  6. Add unittests to tests/.
  7. Once you have completed the above steps and there are no obvious bugs/broken code, please make a PR to merge your branch changes into master.
  8. After getting reviewed and undergoing changes, the PR will be merged into master.

(Very Rough) Estimated Time: 2-3 weeks

Other things to keep in mind:

  1. Please use the black python formatter (tutorial using vscode).
  2. Please add typing hints and docstrings to any new code you write and wherever you find these missing.

[Rep] Add support for phase-flip-protected repetition code qubits

As detailed in #65 (which aims to close #60 ), it should be relatively straight forward to enable the creation of repetition code qubits that are protected against Z flips, instead of the usual X (bit) flip protection.

We were briefly chatting about a (phase-flip-protected) repetition qubit protected against Z flips. On a related note, we could allow users to pass in "d": (1,3), "phase-flip-protected": True to RepetitionQubit when they want to create a phase-flip-protected repetition qubit. And, in the case where a user just sends in "d": (1,3) without setting "phase-flip-protected": True, we can raise a warning stating that the user is creating a phase-flip-protected repetition qubit instead of a possibly desired bit-flip-protected repetition qubit.
To enable this phase-flip-protected functionality, I believe we will just need to modify this parameter validation and add some tests.

Steps:

  • Modify the parameter validation in circuits/repetition.py
  • Modify the parameter validation in fitters/repetition.py
  • Add tests to tests/rep.py

[TCirc] Update default params

Use string constants for tcirc types (e.g. "XZZX"). Also add params validation and default values method to override.

[Test] Add basic tests

Let's add some basic unit, integration, and E2E tests for fitters and circuits.

Unit Test: is a type of software testing where individual units or components of a software are tested. The purpose is to validate that each unit of the software code performs as expected.

Integration Test: is the phase in software testing in which individual software modules are combined and tested as a group

E2E Test: End-to-end testing verifies that your software works correctly from the beginning to the end of a particular user flow. It replicates expected user behavior and various usage scenarios to ensure that your software works as whole.

Resources:

[Surface][Circuit] Encode rotated surface code with arbitrary width and height

Let's generalize the square rotated surface code encoder to a rectangular rotated surface code encoder.

Here are some steps to guide you in this task:

  1. Create a new branch on this repo named "feature/28/rectangular-surface-code". Please regularly merge changes from master into this branch as you work on this task to keep the branch up to date.
  2. Start by reading through rotated_surface.py, xxzz.py and xzzx.py and notice where self.params["d"] is used and relied upon. In this task, you will primarily change these files.
  3. Update the call-sites of XXZZQubit and XZZXQubit to use XXZZSquareQubit and XZZXSquareQubit, which can be subclasses of the now more general XXZZQubit and XZZXQubit rectangular rotated surface code classes.
  4. It may be possible to have RepetitionQubit extend from XXZZQubit (or at least RotatedQubit), as the Repetition code can be thought of as a very slim surface code. (Moved to #60)
  5. Track/demonstrate your changes in a Jupyter Notebook stored under tutorials/.
  6. Add unittests to tests/.
  7. Once you have completed the above steps and there are no obvious bugs/broken code, please make a PR to merge your branch changes into master.
  8. After getting reviewed and undergoing changes, the PR will be merged into master.

(Very Rough) Estimated Time: 2-3 weeks

Other things to keep in mind:

  1. Please use the black python formatter (tutorial using vscode).
  2. Please add typing hints and docstrings to any new code you write and wherever you find these missing.

Achieve threshold on XXZZ Decoder

The physics error rate below which larger surface codes become better is called the threshold.
We hope to show this crossing of logical error rates of different sized surface codes in simulation.

Migrate to Qiskit 1.0

I'm making this issue because this project is part of the Qiskit ecosystem.

As of June 2024, we're introducing a requirement that all projects are compatible with Qiskit 1.0. New users will be using Qiskit 1.0 and we want to make sure any projects we guide them to work straight away.

See our migration guide. and let me know if you need any support (such as answering questions about Qiskit or code review). With Qiskit's new stability policy, this should be the last change needed for a while.

In June, we will test out your project and remove it if it doesn't work with Qiskit 1.0. This includes cases in which we can't get the project working because the documentation is lacking. We do value your project so let me know if you need any help migrating or have any other concerns.

[Test] Add testing for lattice readout path

Background

If an error occurs after the final round of stabilization and before the logical readout, then we can incur a logical error. To combat this issue, we have introduced the concept of lattice readout, where we readout every single data qubit, each along a particular readout axis. Then, we can extract a single set of syndrome measurements and logical readout from that lattice readout. For example, if we wish to perform logical Z readout, then we use lattice readout to extract Z syndrome measurements and logical Z readout from lattice readout.

Task

We want to add tests, similar to those in tests/rotated_surface.py but using lattice_readout_z in place of:

qubit.stabilize()
qubit.readout_z() 

Stretch

We can also add tests to address logical X readout paths for both lattice readout (lattice_readout_x) and normal logical readout (readout_x).

[tcirc][CNOT] Implement protected CNOT gate between surface code qubits of the same type

We leverage the parity measurement to implement a CNOT between surface code qubits, as shown below.

Screen Shot 2021-11-28 at 2 50 16 AM

While we use a surface code ancilla, our parity measurements are not topologically protected. For example, we use CNOTs conditioned by data (physical) qubits in the top rows of two surface code qubits and targeting a single external physical qubit. Then, we measure the external physical qubit to perform a logical ZZ parity measurement between two surface code qubits. This external physical qubit is not topologically protected and could, however, undergo bit flip errors.

Instead, let's follow Ref. [1] and implement a parity measurement of the form:

Screen Shot 2021-11-28 at 2 56 28 AM

Here are some concrete steps towards completing this task:

  • Implement a ZZ parity measurement between two RotatedQubit qubits of the same type and same size using the top rows of each qubit.
    • This may involve defining an abstract method ToplogicalQubit.zz and implementing at the level of XXZZQubit (circuits/xxzz.py) and XZZXQubit (circuits/xzzx.py). Since the repetition code extends XXZZQubit, it does not need to be changed.
  • Do the same as above for a XX parity measurement, using the left-most columns of each qubit.
  • Deprecate the TopologicalQubit.cx method and all of its implementations, as this unprotected CNOT uses a single external qubit as a control (target) on a surface code target (control) qubit. With the new protected CNOT gates, we should not need this method at all.
  • Update the tcirc notebook(s) accordingly to demo your changes.

Refs:
[1] https://arxiv.org/pdf/1709.02318.pdf

[Graphvis] Graph plotting is not working with python 3.6

I tried to run the code in the tutorial https://github.com/yaleqc/qtcodes/blob/master/tutorials/xxzz/2-fitters.ipynb
In the decoder.draw(G) Command - it is using Graphviz, which seems to make trouble with python 3.6.
I get this error:
FileNotFoundError: [WinError 2] "fdp" not found in path.
Which is tried to be solved in https://stackoverflow.com/questions/22698227/python-installation-issues-with-pygraphviz-and-graphviz
They y mention the fact that it is making troubles with python 3.5 and above

[non-clifford] Implement magic state initialization and T Gate

To realized fault-tolerant universal quantum computation using topological QEC, we must implement a non-Clifford gate. Here, we aim to implement the T gate and initialization for the magic state needed for the T gate.

  • Add a reset_magic_T abstract method to circuits/rotated_surface.py , similar to reset_x. Then, implement this for the XZZX and XXZZ surface codes.
  • Add a T abstract method to circuits/rotated_surface.py, similar to the x method. Then, implement this for the XZZX and XXZZ surface codes.

Note. We want these implementations to be fault-tolerant, meaning that this state initialization and gate are not vulnerable to single qubit errors on any qubit involved. However, this doesn't seem possible as of now. In practice, this is why people propose magic state distillation.

decoder returns error with noise models

This is great work, and I'm testing it for integration with other projects within qiskit. When noise models of significant amplitude are used, for example using the test harness (3_testing_and_noise_models), the decoder returns an error. Here is an example:

for i in range(10):
    print("====Run", i, "====")
    full_loop(code, decoder1, decoder2, noise_model=get_noise(0.1))
    print("=============", "\n")

returns different errors each time it is executed, but they all point to the same point in fitters.py:

====Run 0 ====
Raw readout: {'111101110 01001011 01010010 01011000': 1}
Parsed X: [(2, 2.5, 1.5)]
Parsed Z: [(0, 0.5, 0.5), (0, 0.5, 2.5), (0, 1.5, -0.5), (1, 1.5, -0.5), (1, 1.5, 1.5), (2, 0.5, 2.5), (2, 1.5, -0.5)]
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-10-1dab31d2f569> in <module>
      1 for i in range(10):
      2     print("====Run", i, "====")
----> 3     full_loop(code, decoder1, decoder2, noise_model=get_noise(0.1))
      4     print("=============", "\n")

<ipython-input-5-e58737e1f698> in full_loop(code, decoder1, decoder2, noise_model)
     26             matching_graph = decoder.matching_graph(error_graph,'Z')
     27             matches = decoder.matching(matching_graph,'Z')
---> 28             _, paths = decoder.make_error_graph(X_errors, "Z")
     29             flips_z = decoder.calculate_qubit_flips(matches, paths,'Z')
     30         else:

~/code/qiskit_surface_codes/surface_code/fitters.py in make_error_graph(self, nodes, error_key, err_prob)
    320                 error_graph.add_node(
    321                     node,
--> 322                     virtual=virtual_dict[node],
    323                     pos=(node[2], -node[1]),
    324                     time=time_dict[node],

KeyError: (2, 2.5, 1.5)

The code in this instance had d, T = 3, 3 and that location is valid (it is the bottom-most X-syndrome qubit).

This error doesn't show up when noise models are disabled.

[RFC] Refactor the XXZZ Decoder

The code is a bit messy right now, let's refactor the XXZZ decoder in an attempt to debug it and achieve threshold as detailed in #17 .

Refactoring includes:

  • docstrings
  • satisfy pylint
  • simplification of methods
  • potential speed-ups

[simulator] Try speeding up the simulator

There are several potential ways to speed up benchmarking simulations.

  • Currently, we are inserting identity gates where we want errors, which forces us to use an optimization level of 0 thus preventing additional optimizations in the rest of the circuit. Instead, we can insert the Krauss error operators directly.
  • It may be faster to use density matrix simulation and then use that to measure the average value of the desired measurement operator (say logical Z readout) as follows, Tr(rho * measurement_operator).
  • We should look into why adding single qubit gates on the same qubit drastically increases simulation time. This may be because circuit depth is increasing with each addition gate on the same qubit.

[Misc] Encapsulate logical gates in custom gates

It would help with visualization I think if we encapsulate logical X, Y, Z and stabilize with custom gates, so that circuit visualizations are more reasonable. Then, if a user wants to decompose the circuit further they can to see the same circuit visualizations that we currently have.

[simulator] Look up decoding simulation works on linux distro but not on OSx

The simulation tutorials/rep/2-fitters-lookup.ipynb requires errors being inserted between the stabilizer measurements to produce a lookup table of possible results. This works on elementary OS, but not on OSx.

Expected Result (elementary OS):

Screen Shot 2021-11-11 at 2 14 39 PM

Incorrect Result (Mac OSx):
Screen Shot 2021-11-11 at 2 14 55 PM

This is probably an issue with the aer_simulator.

Transpile logical circuits to topological QEC code circuits

Qiskit has a transpiler, which can transform and optimize circuits via various passes. Passes can be run individually if instantiated as such or can be included in different PassManagers as a default.

The idea here is that we can create a PassManager to make use of qtcodes to take a standard Qiskit circuit and transpile it to a qtcode circuit. Ideally, qtcodes could inject the Pass into Qiskit upon initialization, but if that is not possible, then perhaps we can define a custom PassManager on the qtcodes side that can be used when one wants to transpile a standard circuit to an error-correcting one.

One of the unique features of a pass is that it can consider the actual hardware when performing the pass operation. This feature can be used to transpile a standard circuit into a qtcode circuit that can run on actual hardware. An error could be thrown if that is not possible based on the coupling map or the number of qubits available.

There may be some overlap between this task and #63 or perhaps one can be used by the other.

inconsistent results from the tutorial

Hi all,

I am new to to qec code and I apologize for any inconvenience .

I was running the tutorial of XXZZ benchmark, but what I got was different than the figures showed in the tutorial.
surface_perf1.pdf
surface_perf2.pdf

I have checked the d_3_T_1.npz and make sure it is loaded by TopologicalBenchmark. The results remain the same.

Thanks for the help!

[Fitters] Benchmark look-up table decoding

Implement look-up table benchmarking tool, and generate similar graphs. Also, it would be interesting to compare both the efficiency and efficacy of look-up table vs graph decoding.

[RepCode] Extend RepetitionQubit from XXZZQubit

Extend RepetitionQubit from XXZZQubit (or at least RotatedQubit), as the Repetition code can be thought of as a very slim surface code. This would follow the work from #27 and #28.

Add a RepetitionPhaseQubit as well as a "row" repetition code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.