Skip to content

Commit

Permalink
Permute all variables of the Steane code (#114)
Browse files Browse the repository at this point in the history
* permute all variables of the Steane code

* more descriptive docstring

* compute the swap of CRegs

* minor cleanup

* fix bug

* formatting fix
  • Loading branch information
perlinm authored Jan 2, 2025
1 parent 3e2ef42 commit cc28567
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions python/quantum-pecos/src/pecos/qeclib/steane/steane_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ def nonft_t_tel(self, aux: Steane):
aux.cx(self),
self.mz(self.t_meas),
If(self.t_meas == 1).Then(aux.x(), aux.sz()),
Permute(self.d, aux.d),
self.permute(aux),
)

def t_tel(
Expand All @@ -308,7 +308,7 @@ def t_tel(
aux.cx(self),
self.mz(self.t_meas),
If(self.t_meas == 1).Then(aux.x(), aux.sz()), # SZ/S correction.
Permute(self.d, aux.d),
self.permute(aux),
)

def nonft_tdg_tel(self, aux: Steane):
Expand All @@ -326,7 +326,7 @@ def nonft_tdg_tel(self, aux: Steane):
aux.cx(self),
self.mz(self.tdg_meas),
If(self.tdg_meas == 1).Then(aux.x(), aux.szdg()),
Permute(self.d, aux.d),
self.permute(aux),
)

def tdg_tel(
Expand All @@ -349,7 +349,7 @@ def tdg_tel(
aux.cx(self),
self.mz(self.tdg_meas),
If(self.t_meas == 1).Then(aux.x(), aux.szdg()), # SZdg/Sdg correction.
Permute(self.d, aux.d),
self.permute(aux),
)

def t_cor(
Expand Down Expand Up @@ -495,3 +495,18 @@ def qec(self, flag: Bit | None = None):
if flag is not None:
block.extend(If(self.flags != 0).Then(flag.set(1)))
return block

def permute(self, other: Steane):
"""Permute this code block (including both quantum and classical registers) with another."""
block = Block(
Permute(self.d, other.d),
Permute(self.a, other.a),
)
for var_a, var_b in zip(self.vars, other.vars):
if isinstance(var_a, CReg):
block.extend(
var_a.set(var_a ^ var_b),
var_b.set(var_b ^ var_a),
var_a.set(var_a ^ var_b),
)
return block

0 comments on commit cc28567

Please sign in to comment.