Skip to content

Commit cc28567

Browse files
authored
Permute all variables of the Steane code (#114)
* permute all variables of the Steane code * more descriptive docstring * compute the swap of CRegs * minor cleanup * fix bug * formatting fix
1 parent 3e2ef42 commit cc28567

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

python/quantum-pecos/src/pecos/qeclib/steane/steane_class.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def nonft_t_tel(self, aux: Steane):
285285
aux.cx(self),
286286
self.mz(self.t_meas),
287287
If(self.t_meas == 1).Then(aux.x(), aux.sz()),
288-
Permute(self.d, aux.d),
288+
self.permute(aux),
289289
)
290290

291291
def t_tel(
@@ -308,7 +308,7 @@ def t_tel(
308308
aux.cx(self),
309309
self.mz(self.t_meas),
310310
If(self.t_meas == 1).Then(aux.x(), aux.sz()), # SZ/S correction.
311-
Permute(self.d, aux.d),
311+
self.permute(aux),
312312
)
313313

314314
def nonft_tdg_tel(self, aux: Steane):
@@ -326,7 +326,7 @@ def nonft_tdg_tel(self, aux: Steane):
326326
aux.cx(self),
327327
self.mz(self.tdg_meas),
328328
If(self.tdg_meas == 1).Then(aux.x(), aux.szdg()),
329-
Permute(self.d, aux.d),
329+
self.permute(aux),
330330
)
331331

332332
def tdg_tel(
@@ -349,7 +349,7 @@ def tdg_tel(
349349
aux.cx(self),
350350
self.mz(self.tdg_meas),
351351
If(self.t_meas == 1).Then(aux.x(), aux.szdg()), # SZdg/Sdg correction.
352-
Permute(self.d, aux.d),
352+
self.permute(aux),
353353
)
354354

355355
def t_cor(
@@ -495,3 +495,18 @@ def qec(self, flag: Bit | None = None):
495495
if flag is not None:
496496
block.extend(If(self.flags != 0).Then(flag.set(1)))
497497
return block
498+
499+
def permute(self, other: Steane):
500+
"""Permute this code block (including both quantum and classical registers) with another."""
501+
block = Block(
502+
Permute(self.d, other.d),
503+
Permute(self.a, other.a),
504+
)
505+
for var_a, var_b in zip(self.vars, other.vars):
506+
if isinstance(var_a, CReg):
507+
block.extend(
508+
var_a.set(var_a ^ var_b),
509+
var_b.set(var_b ^ var_a),
510+
var_a.set(var_a ^ var_b),
511+
)
512+
return block

0 commit comments

Comments
 (0)