Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ members = [

[dependency-groups]
dev = [
"nanobind",
"maturin>=1.2,<2.0", # For building (should match build requirements)
"setuptools>=62.6", # Build system
"pre-commit", # Git hooks
Expand Down
16 changes: 14 additions & 2 deletions python/quantum-pecos/src/pecos/qeclib/generic/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def __init__(
paulis: str,
a: Qubit,
out: Bit,
*,
with_barriers: bool = False,
) -> None:
"""Initialize a stabilizer check measurement.

Expand All @@ -50,6 +52,8 @@ def __init__(
Can be a single character (applied to all qubits) or one character per qubit.
a: Ancilla qubit used for the check measurement.
out: Classical bit to store the measurement result.
with_barriers: Whether to insert barrier instructions between operations to prevent
gate reordering. Defaults to False.

Raises:
Exception: If check weight is less than 2.
Expand Down Expand Up @@ -84,12 +88,20 @@ def __init__(
)

for i in range(n):
if with_barriers:
self.extend(
Barrier(a, d[i]), # to preserve order
)

self.extend(
Barrier(a, d[i]), # to preserve order
self.cp(ps[i], a, d[i]),
Barrier(a, d[i]), # to preserve order
)

if with_barriers:
self.extend(
Barrier(a, d[i]), # to preserve order
)

self.extend(
H(a),
Measure(a) > out,
Expand Down
47 changes: 40 additions & 7 deletions python/quantum-pecos/src/pecos/qeclib/generic/check_1flag.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def __init__(
flag: Qubit,
out: Bit,
out_flag: Bit,
*,
with_barriers: bool = False,
) -> None:
"""Initialize a stabilizer check measurement with flag qubit.

Expand All @@ -54,6 +56,8 @@ def __init__(
flag: Flag qubit used to detect hook errors.
out: Classical bit to store the measurement result.
out_flag: Classical bit to store the flag measurement result.
with_barriers: Whether to insert barrier instructions between operations to prevent
gate reordering. Defaults to False.

Raises:
Exception: If check weight is less than 3.
Expand Down Expand Up @@ -83,25 +87,54 @@ def __init__(
Comment(f"Measure check {ops}"),
Prep(a, flag),
H(a),
Barrier(a, d[0]),
)
if with_barriers:
self.extend(
Barrier(a, d[0]),
)
self.extend(
self.cu(ops[0], a, d[0]),
Barrier(a, flag),
)
if with_barriers:
self.extend(
Barrier(a, flag),
)
self.extend(
CX(a, flag),
Barrier(a, flag),
)
if with_barriers:
self.extend(
Barrier(a, flag),
)

for i in range(1, n - 1):
self.extend(
self.cu(ops[i], a, d[i]),
Barrier(a, d[i]), # To preserve order
)
if with_barriers:
self.extend(
Barrier(a, d[i]), # To preserve order
)

if with_barriers:
self.extend(
Barrier(a, flag),
)
self.extend(
Barrier(a, flag),
CX(a, flag),
Barrier(a, flag),
)
if with_barriers:
self.extend(
Barrier(a, flag),
)
self.extend(
self.cu(ops[-1], a, d[-1]),
Barrier(a, d[-1]),
)
if with_barriers:
self.extend(
Barrier(a, d[-1]),
)
self.extend(
H(a),
Measure(a) > out,
Measure(flag) > out_flag,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def __init__(
flag=a[1],
out=out[0],
out_flag=out[1],
with_barriers=True,
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# specific language governing permissions and limitations under the License.

from pecos.qeclib.steane.decoders.lookup import (
FlagLookupQASM,
FlagLookupQASMActiveCorrectionX,
FlagLookupQASMActiveCorrectionZ,
)
Expand Down Expand Up @@ -111,3 +112,89 @@ def __init__(
scratch,
),
)


class ParallelFlagQEC(Block):
"""Defining QEC Block that does adaptive syndrome extraction, decodes, and updates the Paul frame."""

def __init__(
self,
q: QReg,
a: QReg,
flag_x: CReg,
flag_z: CReg,
flags: CReg,
syn_x: CReg,
syn_z: CReg,
last_raw_syn_x: CReg,
last_raw_syn_z: CReg,
syndromes: CReg,
pf_x: Bit,
pf_z: Bit,
scratch: CReg,
) -> None:
"""Initialize ParallelFlagQECActiveCorrection block for error correction.

Args:
q: Data register containing the 7 qubits of the Steane code.
a: Ancilla register for syndrome extraction.
flag_x: Classical register for X stabilizer flags.
flag_z: Classical register for Z stabilizer flags.
flags: Combined flags register.
syn_x: Classical register for X syndromes.
syn_z: Classical register for Z syndromes.
last_raw_syn_x: Previous X syndrome measurements.
last_raw_syn_z: Previous Z syndrome measurements.
syndromes: Classical register for syndrome storage.
pf_x: Pauli frame bit for X errors.
pf_z: Pauli frame bit for Z errors.
scratch: Scratch classical register for intermediate calculations.
"""
super().__init__(
# flagging XZZ checks
ThreeParallelFlaggingXZZ(
q,
a,
flag_x,
flag_z,
flags,
last_raw_syn_x,
last_raw_syn_z,
),
# flagging ZXX checks
If(flags == 0).Then(
ThreeParallelFlaggingZXX(
q,
a,
flag_x,
flag_z,
flags,
last_raw_syn_x,
last_raw_syn_z,
),
),
# Remeasure all the checks unflagged
If(flags != 0).Then(
SixUnflaggedSyn(q, a, syn_x, syn_z),
),
FlagLookupQASM(
basis="X",
syn=syn_x,
syndromes=syndromes,
raw_syn=last_raw_syn_x,
pf=pf_z,
flag=flag_x,
flags=flags,
scratch=scratch,
),
FlagLookupQASM(
basis="Z",
syn=syn_z,
syndromes=syndromes,
raw_syn=last_raw_syn_z,
pf=pf_x,
flag=flag_z,
flags=flags,
scratch=scratch,
),
)
Loading
Loading