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

Permute all variables of the Steane code #114

Merged
merged 6 commits into from
Jan 2, 2025
Merged
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
51 changes: 31 additions & 20 deletions python/quantum-pecos/src/pecos/qeclib/steane/steane_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,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 @@ -283,7 +281,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 @@ -306,7 +304,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 @@ -324,7 +322,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 @@ -347,7 +345,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),
)

# End Experimental: ------------------------------------
Expand All @@ -370,19 +368,17 @@ def cz(self, target: Steane):

def m(self, meas_basis: str, log: Bit | None = None):
"""Destructively measure the logical qubit in some Pauli basis."""
block = Block(
MeasDecode(
q=self.d,
meas_basis=meas_basis,
meas=self.raw_meas,
log_raw=self.log_raw,
log=self.log,
syn_meas=self.syn_meas,
pf_x=self.pf_x,
pf_z=self.pf_z,
last_raw_syn_x=self.last_raw_syn_x,
last_raw_syn_z=self.last_raw_syn_z,
),
block = MeasDecode(
q=self.d,
meas_basis=meas_basis,
meas=self.raw_meas,
log_raw=self.log_raw,
log=self.log,
syn_meas=self.syn_meas,
pf_x=self.pf_x,
pf_z=self.pf_z,
last_raw_syn_x=self.last_raw_syn_x,
last_raw_syn_z=self.last_raw_syn_z,
Comment on lines -373 to +381
Copy link
Author

Choose a reason for hiding this comment

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

This is just some minor cleanup that comes for the ride in this PR

)
if log is not None:
block.extend(log.set(self.log))
Expand Down Expand Up @@ -419,3 +415,18 @@ def qec(self, flag_bit: Bit | None = None):
if flag_bit is not None:
block.extend(If(self.flags != 0).Then(flag_bit.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
Loading