Coder Social home page Coder Social logo

honeycomb_threshold's Introduction

Honeycomb Threshold Estimation

This repository contains code for estimating the threshold of Hasting and Haah's honeycomb code from the paper "Dynamically Generated Logical Qubits".

The code in this repository uses Stim for defining the code as a circuit, and for simulating noisy runs of that circuit. It then decodes those simulated runs using PyMatching (or using an internal decoding tool not included in the repository). Finally, it uses the collected data to produce plots like this one:

example plot

Usage

In a python 3.9+ environment, install the requirements from requirements.txt:

python -m pip install -r requirements.txt

The python file src/main_example.py is by default configured to collect a few data points and then plot them. You can run it in your python environment:

python src/main_example.py

This should create a file test.csv and begin populating it (printing CSV data to the file and also to the console). After a few minutes, it will finish and pop up a plot summarizing the data.

You can get more data by customizing the collect_simulated_experiment_data call from src/main_example.py:

collect_simulated_experiment_data(
    [
        HoneycombLayout(
            noise=p,
            data_width=d * 4,
            data_height=d * 6,
            sub_rounds=30,
            style="EM3_v2",
            obs="H",
        ).as_decoder_problem("pymatching")
        for d in [1, 2]
        for p in [0.001, 0.002, 0.003]
    ],
    out_path="test.csv",
    discard_previous_data=True,
    min_shots=10**3,
    max_shots=10**6,
    min_seen_logical_errors=10**2,
)

And you can plot data from a csv file using the plot_data method from experiment.py:

plot_data(
    read_recorded_data("test.csv"),
    title="LogLog per-sub-round error rates in periodic Honeycomb code under circuit noise",
    show=True)

honeycomb_threshold's People

Contributors

newmanmg avatar strilanc avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

honeycomb_threshold's Issues

Merge parallel edges for PyMatching

The stim detector error model (DEM) format can have multiple error mechanisms with the same targets, however neither networkx.Graph nor PyMatching support parallel edges. When a duplicate edge is added to a networkx.Graph, the old edge data is silently replaced with the new edge data. To workaround this problem, parallel edges should be merged when converting a DEM to a pymatching.Matching object.

One solution is to change the handle_error function in decoder.py. i.e. it could be changed from

    def handle_error(p: float, dets: List[int], frame_changes: List[int]):
        if p == 0:
            return
        if len(dets) == 1:
            dets.append(num_detectors)
        if len(dets) != 2:
            return  # Just ignore correlated error mechanisms (e.g. Y errors / XX errors)
        g.add_edge(*dets, weight=-math.log(p), qubit_id=frame_changes)

to

    def handle_error(p: float, dets: List[int], frame_changes: List[int]):
        if p == 0:
            return
        if len(dets) == 1:
            dets.append(num_detectors)
        if len(dets) != 2:
            return  # Just ignore correlated error mechanisms (e.g. Y errors / XX errors)
        if g.has_edge(*dets):
            edge_data = g.get_edge_data(*dets)
            old_p = edge_data["error_probability"]
            old_frame_changes = edge_data["qubit_id"]
            if set(old_frame_changes) != set(frame_changes):
                raise NotImplementedError()
            p = p * (1 - old_p) + old_p * (1 - p)
            g.remove_edge(*dets)
        g.add_edge(*dets, weight=math.log((1-p)/p), qubit_id=frame_changes, error_probability=p)

(Note that I use log((1-p)/p) for weights, but maybe you prefer to keep -log(p) instead).

In the next PyMatching release, I'll add support to add edges directly to pymatching.Matching rather than relying on NetworkX, and either raise an exception when a parallel edge is added or merge it internally.

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.