File size: 1,649 Bytes
9f8cf99 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | """iSWAP-native dynamic surface code circuit builder."""
from __future__ import annotations
from typing import Dict, Optional
from surface_code_in_stem.noise_models import NoiseModel
from .base import DynamicLayout, StimStringBuilder, stabilizer_cycle
def iswap_surface_code(distance: int, rounds: int, p: float, noise_model: Optional[NoiseModel] = None) -> str:
"""Return a Stim circuit string for the iSWAP-native dynamic surface code.
Forward cycles use one orientation ordering while odd cycles reverse it to
mimic the time-reversal pairing described in the paper. The entangling gate
is `ISWAP`, emphasizing compatibility with exchange-based couplers.
"""
layout = DynamicLayout.build(distance)
index_to_coord = {idx: coord for coord, idx in layout.coord_to_index.items()}
builder = StimStringBuilder(coord_lookup=index_to_coord)
builder.qubit_coords()
orientations_fwd = (0, 3, 1, 2)
orientations_rev = tuple(reversed(orientations_fwd))
prev_meas: Dict[tuple[float, float], int] = {}
for cycle in range(rounds):
orient = orientations_fwd if cycle % 2 == 0 else orientations_rev
prev_meas = stabilizer_cycle(
builder,
layout,
p=p,
orientations=orient,
gate="ISWAP",
noise_model=noise_model,
reset_data=False,
measure_data=False,
prev_meas=prev_meas,
)
logical_targets = [layout.coord_to_index[c] for c in layout.datas[:distance]]
logical_meas = builder.measure(logical_targets)
builder.observable(logical_meas)
return builder.build()
|