Skip to content
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

Add Steane-type and teleportation-based QEC for the Steane code #115

Merged
merged 28 commits into from
Jan 7, 2025
Merged
Changes from 20 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
33f6f5d
draft steane_qec
perlinm Dec 16, 2024
d34ce75
fix qec_steane_z
perlinm Dec 16, 2024
a837422
factor out permute changes to another PR
perlinm Dec 16, 2024
710b0ff
factor out Steane.m cleanup to another PR
perlinm Dec 16, 2024
2743142
set flag bit correctly
perlinm Dec 16, 2024
566d266
add qec_steane_.*tel templates
perlinm Dec 16, 2024
f39c31b
fix Steane.qec_steane_tel
perlinm Dec 17, 2024
95c6891
permute all qubits for teleportation
perlinm Dec 17, 2024
661cd65
formatting fixes
perlinm Dec 17, 2024
b6c1fb2
formatting fixes
perlinm Dec 17, 2024
548f216
formatting fix
perlinm Dec 17, 2024
e7bbed0
formatting fix
perlinm Dec 17, 2024
e6077e1
no need to permute ancillas
perlinm Dec 17, 2024
622b2d2
minor rearrangement
perlinm Dec 17, 2024
4d665ce
fix teleportation-based QEC
perlinm Dec 17, 2024
b864193
fix typo
perlinm Dec 17, 2024
0e8ae1d
maybe fix classical registers in teleportation-based QEC
perlinm Dec 17, 2024
4c64865
two flag bits for Steane.qec_tel
perlinm Dec 17, 2024
3cee0b9
add warnings
perlinm Dec 17, 2024
b1ab651
rename flag_bit --> flag, in agreement with elsewhere in the repo
perlinm Dec 17, 2024
45ebaf9
minor cleanup
perlinm Dec 17, 2024
70af9a5
minor renaming
perlinm Dec 18, 2024
cc910d7
standardize docstring
perlinm Dec 18, 2024
9a59086
fix If statement
perlinm Dec 20, 2024
0eaffcc
maybe fix Steane QEC and an incorrect type hint
perlinm Dec 21, 2024
cc99d12
fix typo
perlinm Dec 21, 2024
87c739b
fix warning typo
perlinm Dec 25, 2024
ef393bb
Merge branch 'development' into steane-qec
perlinm Jan 2, 2025
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
164 changes: 158 additions & 6 deletions python/quantum-pecos/src/pecos/qeclib/steane/steane_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
from typing import TYPE_CHECKING
from warnings import warn

from pecos.qeclib.steane.decoders.lookup import (
FlagLookupQASMActiveCorrectionX,
FlagLookupQASMActiveCorrectionZ,
)
from pecos.qeclib.steane.gates_sq import paulis, sqrt_paulis
from pecos.qeclib.steane.gates_sq.hadamards import H
from pecos.qeclib.steane.gates_tq import transversal_tq
Expand Down Expand Up @@ -162,9 +166,7 @@ def prep_t_plus_state(
d=self.d,
a=self.a,
out=self.scratch,
reject=self.scratch[
2
], # the first two bits of self.scratch are used by "out"
reject=self.scratch[2], # the first two bits are used by "out"
flag_x=self.flag_x,
flag_z=self.flag_z,
flags=self.flags,
Expand Down Expand Up @@ -400,7 +402,7 @@ def mz(self, log: Bit | None = None):
"""Logical destructive measurement of the logical Z operator."""
return self.m("Z", log=log)

def qec(self, flag_bit: Bit | None = None):
def qec(self, flag: Bit | None = None):
Copy link
Author

@perlinm perlinm Dec 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also renamed flag_bit --> flag in this PR, for consistency with conventions elsewhere in the repo.

block = ParallelFlagQECActiveCorrection(
q=self.d,
a=self.a,
Expand All @@ -416,6 +418,156 @@ def qec(self, flag_bit: Bit | None = None):
pf_z=self.pf_z,
scratch=self.scratch,
)
if flag_bit is not None:
block.extend(If(self.flags != 0).Then(flag_bit.set(1)))
if flag is not None:
block.extend(If(self.flags != 0).Then(flag.set(1)))
return block

def qec_steane(
self,
aux: Steane,
reject_x: Bit | None = None,
reject_z: Bit | None = None,
flag_x: Bit | None = None,
flag_z: Bit | None = None,
rus_limit: int | None = None,
) -> Block:
"""Run a Steane-type error-correction cycle of this code."""
return Block(
self.qec_steane_z(
aux,
reject=reject_z,
flag=flag_z,
rus_limit=rus_limit,
),
self.qec_steane_x(
aux,
reject=reject_x,
flag=flag_x,
rus_limit=rus_limit,
),
)

def qec_steane_z(
self,
aux: Steane,
reject: Bit | None = None,
flag: Bit | None = None,
rus_limit: int | None = None,
) -> Block:
"""Run a Steane-type error-correction cycle for Z stabilizers (X errors)."""
warn("Using experimental feature: qec_steane_z", stacklevel=2)
flag = flag or self.scratch.elems[7]
return Block(
aux.px(reject=reject, rus_limit=rus_limit),
self.cx(aux),
aux.mz(),
If(aux.syn_meas != 0).Then(flag.set(1)),
self.last_raw_syn_z.set(0),
self.pf_x.set(0),
FlagLookupQASMActiveCorrectionZ(
self.d,
aux.syn_meas,
self.syndromes,
self.last_raw_syn_z,
self.pf_x,
flag,
aux.syn_meas,
self.scratch,
),
)

def qec_steane_x(
self,
aux: Steane,
reject: Bit | None = None,
flag: Bit | None = None,
rus_limit: int | None = None,
) -> Block:
"""Run a Steane-type error-correction cycle for X stabilizers (Z errors)."""
warn("Using experimental feature: qec_steane_x", stacklevel=2)
flag = flag or self.scratch.elems[7]
return Block(
aux.pz(reject=reject, rus_limit=rus_limit),
aux.cx(self),
aux.mx(),
If(aux.syn_meas != 0).Then(flag.set(1)),
self.last_raw_syn_x.set(0),
self.pf_z.set(0),
FlagLookupQASMActiveCorrectionX(
self.d,
aux.syn_meas,
self.syndromes,
self.last_raw_syn_x,
self.pf_z,
flag,
aux.syn_meas,
self.scratch,
),
)

def qec_tel(
self,
aux: Steane,
reject_x: Bit | None = None,
reject_z: Bit | None = None,
flag_x: Bit | None = None,
flag_z: Bit | None = None,
rus_limit: int | None = None,
) -> Block:
"""Run a teleportation-based error correction cycle."""
return Block(
self.qec_tel_x(aux, reject_x, flag_x, rus_limit),
self.qec_tel_z(aux, reject_z, flag_z, rus_limit),
)

def qec_tel_x(
self,
aux: Steane,
reject: Bit | None = None,
flag: Bit | None = None,
rus_limit: int | None = None,
) -> Block:
"""Run a teleportation-based error correction cycle for X errors."""
warn("Using experimental feature: qec_tel_x", stacklevel=2)
block = Block(
# teleport
aux.px(reject=reject, rus_limit=rus_limit),
aux.cx(self),
self.mz(),
If(self.log).Then(aux.x()),
Permute(self.d, aux.d),
# update syndromes and pauli frame
self.last_raw_syn_x.set(0),
self.last_raw_syn_z.set(0),
self.syn_z.set(self.syn_meas),
self.pf_x.set(0),
)
if flag is not None:
block.extend(If(self.syn_meas != 0).Then(flag.set(1)))
return block

def qec_tel_z(
self,
aux: Steane,
reject: Bit | None = None,
flag: Bit | None = None,
rus_limit: int | None = None,
) -> Block:
"""Run a teleportation-based error correction cycle for Z errors."""
warn("Using experimental feature: qec_tel_z", stacklevel=2)
block = Block(
# teleport
aux.pz(reject=reject, rus_limit=rus_limit),
self.cx(aux),
self.mx(),
If(self.log).Then(aux.z()),
Permute(self.d, aux.d),
# update syndromes and pauli frame
self.last_raw_syn_x.set(0),
self.last_raw_syn_z.set(0),
self.syn_x.set(self.syn_meas),
self.pf_z.set(0),
)
if flag is not None:
block.extend(If(self.syn_meas != 0).Then(flag.set(1)))
return block
Loading