Skip to content

add mqt.qecc for color code decoders #25

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 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CondaPkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ python = ">=3.10"
numpy = ""
scipy = ""
pymatching = ""
ldpc = ">=2.2.8"
ldpc = ""
sinter = ">=1.14"
stim = ">=1.14"
stim = ">=1.14"
mqt-qecc = ">=1.9.0"
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,64 @@ julia> syndrome = PyArray(H)*error .% 2

julia> decoding = bpd.decode(np.array(syndrome))
Python: array([0, 1, 0])
```

## `mqt.qecc`

The python mqt.qecc module is immediately available:

```
julia> using PyQDecoders

julia> PyQDecoders.mqt_qecc
Python: <module 'mqt_qecc' from ...>
```

Running the example from `mqt_qecc`'s original Readme:

```
julia> using PyQDecoders: np, mqt_qecc;

julia> H = [[1, 0, 0, 1, 0, 1, 1], [0, 1, 0, 1, 1, 0, 1], [0, 0, 1, 0, 1, 1, 1]];

julia> code = mqt_qecc.Code(H, H);

julia> UFHeuristic = mqt_qecc.UFHeuristic;

julia> decoder = mqt_qecc.UFHeuristic();

julia> decoder.set_code(code);

julia> sample_iid_pauli_err = mqt_qecc.sample_iid_pauli_err;

julia> x_err = sample_iid_pauli_err(code.n, 0.05);

julia> decoder.decode(code.get_x_syndrome(x_err));

julia> result = decoder.result;

julia> residual_err = np.array(x_err) .⊻ np.array(result.estimate);

julia> is_stabilizer = code.is_x_stabilizer(residual_err);

julia> println("Is residual error a stabilizer? ", is_stabilizer);
```

LightsOut decoder for color codes

```
julia> using PyQDecoders: np, mqt_qecc, cc_decoder;

julia> side_length = 3;

julia> lattice = mqt_qecc.codes.HexagonalColorCode(side_length);

julia> problem = cc_decoder.LightsOut(lattice.faces_to_qubits, lattice.qubits_to_faces);

julia> problem.preconstruct_z3_instance();

julia> lights = [true, false, false];

julia> switches, constr_time, solve_time = problem.solve(lights)
Python: ([0, 1, 0, 0, 0, 0, 0], 0.06688149999990856, 0.001489878000029421)
```
4 changes: 4 additions & 0 deletions src/PyQDecoders.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const np = PythonCall.pynew()
const pm = PythonCall.pynew()
const ldpc = PythonCall.pynew()
const ldpccodes = PythonCall.pynew()
const mqt_qecc = PythonCall.pynew()
const cc_decoder = PythonCall.pynew()

function __init__()
PythonCall.pycopy!(sp, PythonCall.pyimport("scipy"))
Expand All @@ -15,6 +17,8 @@ function __init__()
PythonCall.pycopy!(pm, PythonCall.pyimport("pymatching"))
PythonCall.pycopy!(ldpc, PythonCall.pyimport("ldpc"))
PythonCall.pycopy!(ldpccodes, PythonCall.pyimport("ldpc.codes"))
PythonCall.pycopy!(mqt_qecc, PythonCall.pyimport("mqt.qecc"))
PythonCall.pycopy!(cc_decoder, PythonCall.pyimport("mqt.qecc.cc_decoder.decoder"))
end

end # module
Loading