Skip to content

Commit 22a4290

Browse files
Improve argument structure in Detectors.from_layouts (#392)
1 parent 5e9781b commit 22a4290

File tree

6 files changed

+21
-19
lines changed

6 files changed

+21
-19
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ from surface_sim.experiments.rot_surface_code_css import memory_experiment
4040
# prepare the layout, model, and detectors objects
4141
layout = rot_surface_code(distance=3)
4242
model = CircuitNoiseModel(layout.qubit_inds)
43-
detectors = Detectors(layout.anc_qubits, frame="pre-gate")
43+
detectors = Detectors.from_layouts(layout)
4444
4545
# create a memory experiment
4646
NUM_ROUNDS = 10
@@ -91,7 +91,7 @@ circuit = stim.Circuit(
9191
9292
layouts = unrot_surface_codes(circuit.num_qubits, distance=3)
9393
model = CircuitNoiseModel.from_layouts(*layouts)
94-
detectors = Detectors.from_layouts("pre-gate", *layouts)
94+
detectors = Detectors.from_layouts(*layouts, frame="pre-gate")
9595
9696
model.setup.set_var_param("prob", 1e-3)
9797

surface_sim/detectors/detectors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ def __init__(
8484
@classmethod
8585
def from_layouts(
8686
cls: type[Detectors],
87-
frame: str,
8887
*layouts: Layout,
88+
frame: str = "pre-gate",
8989
include_gauge_dets: bool = False,
9090
) -> "Detectors":
9191
"""Creates a ``Detectors`` object using the information from the layouts.

tests/experiments/test_arbitrary_experiment.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ def test_experiment_from_schedule():
155155
"""
156156
)
157157
model = NoiselessModel.from_layouts(*layouts)
158-
detectors = Detectors.from_layouts("pre-gate", *layouts)
158+
detectors = Detectors.from_layouts(*layouts, frame="pre-gate")
159159

160160
schedule = schedule_from_circuit(circuit, layouts, gate_to_iterator)
161161
experiment = experiment_from_schedule(
@@ -199,7 +199,9 @@ def test_experiment_from_schedule_no_gauge_detectors():
199199
"""
200200
)
201201
model = NoiselessModel.from_layouts(*layouts)
202-
detectors = Detectors.from_layouts("pre-gate", *layouts, include_gauge_dets=False)
202+
detectors = Detectors.from_layouts(
203+
*layouts, frame="pre-gate", include_gauge_dets=False
204+
)
203205

204206
schedule = schedule_from_circuit(circuit, layouts, gate_to_iterator)
205207
experiment = experiment_from_schedule(
@@ -223,7 +225,7 @@ def test_module_2_operations_in_detectors():
223225
layouts = unrot_surface_codes(2, distance=3)
224226
model = CircuitNoiseModel.from_layouts(*layouts)
225227
model.setup.set_var_param("prob", 1e-3)
226-
detectors = Detectors.from_layouts("pre-gate", *layouts)
228+
detectors = Detectors.from_layouts(*layouts, frame="pre-gate")
227229

228230
circuit = stim.Circuit(
229231
"""
@@ -265,7 +267,7 @@ def test_noiseless_decorator():
265267
layouts = unrot_surface_codes(2, distance=3)
266268
model = CircuitNoiseModel.from_layouts(*layouts)
267269
model.setup.set_var_param("prob", 1e-3)
268-
detectors = Detectors.from_layouts("pre-gate", *layouts)
270+
detectors = Detectors.from_layouts(*layouts, frame="pre-gate")
269271

270272
noisy_schedule = [
271273
[
@@ -295,7 +297,7 @@ def test_noiseless_decorator():
295297
layouts = unrot_surface_codes(2, distance=3)
296298
model = CircuitNoiseModel.from_layouts(*layouts)
297299
model.setup.set_var_param("prob", 1e-3)
298-
detectors = Detectors.from_layouts("pre-gate", *layouts)
300+
detectors = Detectors.from_layouts(*layouts, frame="pre-gate")
299301

300302
noiseless_schedule = [
301303
[

tests/experiments/test_templates.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ def test_repeated_cnot_experiments():
628628
for layouts, repeated_cnot_experiment in TESTS:
629629
layout_c, layout_t = layouts
630630
model = NoiselessModel.from_layouts(*layouts)
631-
detectors = Detectors.from_layouts("post-gate", *layouts)
631+
detectors = Detectors.from_layouts(*layouts, frame="post-gate")
632632

633633
# standard experiment in both basis
634634
for rot_basis in [True, False]:
@@ -666,7 +666,7 @@ def test_repeated_cnot_experiments():
666666

667667
# build for some specific detectors
668668
detectors = Detectors.from_layouts(
669-
"post-gate", *layouts, include_gauge_dets=True
669+
*layouts, frame="post-gate", include_gauge_dets=True
670670
)
671671
circuit = repeated_cnot_experiment(
672672
model=model,
@@ -696,7 +696,7 @@ def test_repeated_cnot_experiments():
696696

697697
# without gauge detectors
698698
detectors = Detectors.from_layouts(
699-
"post-gate", *layouts, include_gauge_dets=False
699+
*layouts, frame="post-gate", include_gauge_dets=False
700700
)
701701
circuit = repeated_cnot_experiment(
702702
model=model,
@@ -750,7 +750,7 @@ def test_repeated_s_injection_experiment():
750750
for layouts, repeated_s_injection_experiment in TESTS:
751751
layout, layout_anc = layouts
752752
model = NoiselessModel.from_layouts(*layouts)
753-
detectors = Detectors.from_layouts("post-gate", *layouts)
753+
detectors = Detectors.from_layouts(*layouts, frame="post-gate")
754754

755755
# standard experiment in both basis
756756
for rot_basis in [True, False]:
@@ -786,7 +786,7 @@ def test_repeated_s_injection_experiment():
786786

787787
# build for some specific detectors
788788
detectors = Detectors.from_layouts(
789-
"post-gate", *layouts, include_gauge_dets=True
789+
*layouts, frame="post-gate", include_gauge_dets=True
790790
)
791791
circuit = repeated_s_injection_experiment(
792792
model=model,
@@ -823,7 +823,7 @@ def test_repeated_s_injection_experiment():
823823

824824
# without gauge detectors
825825
detectors = Detectors.from_layouts(
826-
"post-gate", *layouts, include_gauge_dets=False
826+
*layouts, frame="post-gate", include_gauge_dets=False
827827
)
828828
circuit = repeated_s_injection_experiment(
829829
model=model,

tests/experiments/test_templates_mid_cycle.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def test_repeated_cnot_experiments():
113113
for layouts, repeated_cnot_experiment in TESTS:
114114
layout_c, layout_t = layouts
115115
model = NoiselessModel.from_layouts(*layouts)
116-
detectors = Detectors.from_layouts("post-gate", *layouts)
116+
detectors = Detectors.from_layouts(*layouts, frame="post-gate")
117117

118118
# standard experiment in both basis
119119
for rot_basis in [True, False]:
@@ -151,7 +151,7 @@ def test_repeated_cnot_experiments():
151151

152152
# build for some specific detectors
153153
detectors = Detectors.from_layouts(
154-
"post-gate", *layouts, include_gauge_dets=True
154+
*layouts, frame="post-gate", include_gauge_dets=True
155155
)
156156
circuit = repeated_cnot_experiment(
157157
model=model,
@@ -181,7 +181,7 @@ def test_repeated_cnot_experiments():
181181

182182
# without gauge detectors
183183
detectors = Detectors.from_layouts(
184-
"post-gate", *layouts, include_gauge_dets=False
184+
*layouts, frame="post-gate", include_gauge_dets=False
185185
)
186186
circuit = repeated_cnot_experiment(
187187
model=model,

tests/test_readme_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def test_readme_example_memory_experiment():
77
# prepare the layout, model, and detectors objects
88
layout = rot_surface_code(distance=3)
99
model = CircuitNoiseModel(layout.qubit_inds)
10-
detectors = Detectors(layout.anc_qubits, frame="pre-gate")
10+
detectors = Detectors.from_layouts(layout)
1111

1212
# create a memory experiment
1313
NUM_ROUNDS = 10
@@ -60,7 +60,7 @@ def test_readme_example_arbitrary_circuit():
6060

6161
layouts = unrot_surface_codes(circuit.num_qubits, distance=3)
6262
model = CircuitNoiseModel.from_layouts(*layouts)
63-
detectors = Detectors.from_layouts("pre-gate", *layouts)
63+
detectors = Detectors.from_layouts(*layouts, frame="pre-gate")
6464

6565
model.setup.set_var_param("prob", 1e-3)
6666

0 commit comments

Comments
 (0)