From 5300945964b6e7dfa1779a51c66006e975ae6c65 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sun, 16 Mar 2025 11:24:43 +0500 Subject: [PATCH 1/3] add pecos --- CondaPkg.toml | 3 ++- README.md | 50 +++++++++++++++++++++++++++++++++++++++++++++- src/PyQDecoders.jl | 2 ++ 3 files changed, 53 insertions(+), 2 deletions(-) diff --git a/CondaPkg.toml b/CondaPkg.toml index a8db9b1..30cae58 100644 --- a/CondaPkg.toml +++ b/CondaPkg.toml @@ -7,4 +7,5 @@ scipy = "" pymatching = "" ldpc = ">=2.2.8" sinter = ">=1.14" -stim = ">=1.14" \ No newline at end of file +stim = ">=1.14" +quantum-pecos = ">=0.2.0" diff --git a/README.md b/README.md index d64107b..53e5567 100644 --- a/README.md +++ b/README.md @@ -99,4 +99,52 @@ julia> syndrome = PyArray(H)*error .% 2 julia> decoding = bpd.decode(np.array(syndrome)) Python: array([0, 1, 0]) -``` \ No newline at end of file +``` + +## `pecos` + + +The python pecos module is immediately available: + +``` +julia> using PyQDecoders + +julia> PyQDecoders.pecos +Python: +``` + +Running the example from `pecos`'s [original example](https://quantum-pecos.readthedocs.io/en/latest/api_guide/decoders.html) +on 2D version of minimum-weight-perfect-matching decoder: + +``` +julia> using PyQDecoders: pecos + +julia> depolar = pecos.error_gens.DepolarGen(model_level="code_capacity"); + +julia> surface = pecos.qeccs.Surface4444(distance=3); + +julia> logic = pecos.circuits.LogicalCircuit(); + +julia> logic.append(surface.gate("ideal init |0>")); + +julia> logic.append(surface.gate("I", num_syn_extract=1)); + +julia> circ_runner = pecos.circuit_runners.Standard(seed=1); + +julia> state = pecos.simulators.SparseSim(surface.num_qudits); + +julia> decode = pecos.decoders.MWPM2D(surface).decode; + +julia> meas, err = circ_runner.run(state, logic, error_gen=depolar, error_params=Dict("p" => 0.1)); + +julia> print("Measurement outcomes (syndrome):", meas) +Measurement outcomes (syndrome):{(1, 0, 7): {3: 1, 5: 1, 15: 1}} + +julia> print("Errors introduced:", err) +Errors introduced:{(1, 0, 0): {'after': QuantumCircuit(params={'circuit_type': 'faults'}, ticks=[{'Z': {4}, 'X': {10}}])}} + +julia> recovery_circuit = decode(meas); + +julia> print("Recovery circuit from MWPM2D decoder:", recovery_circuit) +Recovery circuit from MWPM2D decoder:QuantumCircuit([{'Z': {4}, 'X': {10}}]) +``` diff --git a/src/PyQDecoders.jl b/src/PyQDecoders.jl index 570fbca..7d98218 100644 --- a/src/PyQDecoders.jl +++ b/src/PyQDecoders.jl @@ -7,6 +7,7 @@ const np = PythonCall.pynew() const pm = PythonCall.pynew() const ldpc = PythonCall.pynew() const ldpccodes = PythonCall.pynew() +const pecos = PythonCall.pynew() function __init__() PythonCall.pycopy!(sp, PythonCall.pyimport("scipy")) @@ -15,6 +16,7 @@ function __init__() PythonCall.pycopy!(pm, PythonCall.pyimport("pymatching")) PythonCall.pycopy!(ldpc, PythonCall.pyimport("ldpc")) PythonCall.pycopy!(ldpccodes, PythonCall.pyimport("ldpc.codes")) + PythonCall.pycopy!(pecos, PythonCall.pyimport("pecos")) end end # module From 097dec7ce001f126797a0ff40d69676303c59ac7 Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sun, 16 Mar 2025 11:26:27 +0500 Subject: [PATCH 2/3] undo one space --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 53e5567..43f7269 100644 --- a/README.md +++ b/README.md @@ -103,7 +103,6 @@ Python: array([0, 1, 0]) ## `pecos` - The python pecos module is immediately available: ``` From 1da51c2bc748f5b4aee76528391719c3642add6f Mon Sep 17 00:00:00 2001 From: Fe-r-oz Date: Sun, 16 Mar 2025 11:43:26 +0500 Subject: [PATCH 3/3] add pecosdecoders to call pecos.decoders as well --- README.md | 4 ++-- src/PyQDecoders.jl | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 43f7269..28a7158 100644 --- a/README.md +++ b/README.md @@ -116,7 +116,7 @@ Running the example from `pecos`'s [original example](https://quantum-pecos.read on 2D version of minimum-weight-perfect-matching decoder: ``` -julia> using PyQDecoders: pecos +julia> using PyQDecoders: pecos, pecosdecoders julia> depolar = pecos.error_gens.DepolarGen(model_level="code_capacity"); @@ -132,7 +132,7 @@ julia> circ_runner = pecos.circuit_runners.Standard(seed=1); julia> state = pecos.simulators.SparseSim(surface.num_qudits); -julia> decode = pecos.decoders.MWPM2D(surface).decode; +julia> decode = pecosdecoders.MWPM2D(surface).decode; julia> meas, err = circ_runner.run(state, logic, error_gen=depolar, error_params=Dict("p" => 0.1)); diff --git a/src/PyQDecoders.jl b/src/PyQDecoders.jl index 7d98218..3cd43d0 100644 --- a/src/PyQDecoders.jl +++ b/src/PyQDecoders.jl @@ -8,6 +8,7 @@ const pm = PythonCall.pynew() const ldpc = PythonCall.pynew() const ldpccodes = PythonCall.pynew() const pecos = PythonCall.pynew() +const pecosdecoders = PythonCall.pynew() function __init__() PythonCall.pycopy!(sp, PythonCall.pyimport("scipy")) @@ -17,6 +18,7 @@ function __init__() PythonCall.pycopy!(ldpc, PythonCall.pyimport("ldpc")) PythonCall.pycopy!(ldpccodes, PythonCall.pyimport("ldpc.codes")) PythonCall.pycopy!(pecos, PythonCall.pyimport("pecos")) + PythonCall.pycopy!(pecosdecoders, PythonCall.pyimport("pecos.decoders")) end end # module