Skip to content

Commit 0517e83

Browse files
committed
cleanup
1 parent 6c0c0ae commit 0517e83

2 files changed

Lines changed: 22 additions & 17 deletions

File tree

python/qiskit_paulice/checked_circuit.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class CheckedCircuit:
6767
Attributes:
6868
circuit: A quantum circuit containing ``0`` or more spacetime Pauli checks.
6969
target_qubits: Qubit indices of ``circuit`` which were used to entangle the check
70-
qubits to the payload. ``None`` if ``circuit`` contains no checks.
70+
qubits to the payload. Empty if ``circuit`` contains no checks.
7171
check_qubits: Qubit indices of the ancilla qubits in ``circuit``. The ``i``th
7272
check uses ``check_qubits[i]`` to detect errors on ``target_qubits[i]`` and other
7373
qubits in ``check_support[i]``.
@@ -201,15 +201,17 @@ def box(
201201
Raises:
202202
ValueError: ``payload_layers`` does not describe this circuit's payload gates.
203203
ValueError: ``payload_layers`` contains duplicate edges.
204-
ValueError: :attr:`circuit` contains an instruction other than unitary gates,
205-
measurements, and barriers.
204+
ValueError: :attr:`circuit` contains an instruction other than one- and two-qubit
205+
unitary gates, measurements, and barriers.
206206
"""
207207
for instruction in self.circuit.data:
208208
operation = instruction.operation
209-
if not isinstance(operation, Gate) and operation.name not in _NON_GATES:
209+
if operation.name in _NON_GATES:
210+
continue
211+
if not isinstance(operation, Gate) or len(instruction.qubits) > 2:
210212
raise ValueError(
211213
f"'{operation.name}' is not supported: a checked circuit may contain only "
212-
"unitary gates, measurements, and barriers."
214+
"one- and two-qubit unitary gates, measurements, and barriers."
213215
)
214216
options = {**BOXING_DEFAULTS, **kwargs}
215217
return generate_boxing_pass_manager(**options).run(self._stratify(payload_layers))

test/test_checked_circuit.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class TestBox(unittest.TestCase):
211211
"""Tests for ``CheckedCircuit.box``."""
212212

213213
def test_boxes_the_executed_circuit(self):
214-
"""Every entangling gate of the checked circuit -- check gates included -- lands in a box."""
214+
"""Every entangling gate of the checked circuit lands in a box."""
215215
checked, boxed = _checked_example()
216216
ancillas = set(checked.check_qubits)
217217
circuit_edges = [
@@ -229,12 +229,15 @@ def test_boxes_the_executed_circuit(self):
229229
# the check gates are really in there
230230
self.assertTrue(any(set(e) & ancillas for e in boxed_edges))
231231

232-
def test_rejects_non_gate_instructions(self):
233-
"""Anything but unitary gates, measures, and barriers is rejected.
232+
def test_rejects_gates_on_three_or_more_qubits(self):
233+
"""A many-qubit gate is an error: stratification would silently reorder it."""
234+
checked, _ = _checked_example()
235+
checked.circuit.ccx(0, 1, 2)
236+
with self.assertRaisesRegex(ValueError, "ccx"):
237+
checked.box()
234238

235-
Resets alter the check propagation, and control flow can be reordered by
236-
stratification, which tracks qubit wires but not clbit dataflow.
237-
"""
239+
def test_rejects_non_gate_instructions(self):
240+
"""Anything but unitary gates, measures, and barriers is rejected."""
238241
checked, _ = _checked_example()
239242
checked.circuit.reset(0)
240243
with self.assertRaisesRegex(ValueError, "reset"):
@@ -248,15 +251,15 @@ def setUp(self):
248251
self.checked, self.isolated = _checked_example(nq=6, depth=8, seed=4)
249252

250253
def test_same_circuit(self):
251-
"""Isolating check gates only regroups them: same gates, same unitary."""
254+
"""Isolating check gates doesn't change the unitary the circuit implements."""
252255
stripped = self.checked._stratify(None)
253256
self.assertEqual(_gate_counts(self.checked.circuit), _gate_counts(stripped))
254257
original = RemoveBarriers()(self.checked.circuit.remove_final_measurements(inplace=False))
255258
restratified = RemoveBarriers()(stripped.remove_final_measurements(inplace=False))
256259
self.assertEqual(Clifford(original), Clifford(restratified))
257260

258261
def test_each_check_gate_boxed_alone(self):
259-
"""A check box is exactly its one gate: a single edge on a two-qubit box."""
262+
"""A check box is exactly its one gate."""
260263
ancillas = set(self.checked.check_qubits)
261264
saw_check_box = False
262265
for instruction in self.isolated.data:
@@ -270,7 +273,7 @@ def test_each_check_gate_boxed_alone(self):
270273
self.assertTrue(saw_check_box)
271274

272275
def test_unique_layers_is_payload_plus_one_per_check(self):
273-
"""The whole point: two brickwork payload layers plus one unique layer per check."""
276+
"""Ensure checks add one unique layer apiece."""
274277
ancillas = set(self.checked.check_qubits)
275278
payload, check = set(), set()
276279
for edges in _box_edge_sets(self.isolated):
@@ -296,19 +299,19 @@ def test_payload_layers_split_what_packing_would_merge(self):
296299
self.assertEqual(len(set(_box_edge_sets(split))), 2)
297300

298301
def test_rejects_foreign_payload_layers(self):
299-
"""Layers that do not cover the payload's edges are an error, not a mislabelling."""
302+
"""Error on layers that do not cover the payload's edges."""
300303
with self.assertRaises(ValueError):
301304
self.checked.box(payload_layers=_brickwork_layers(4))
302305

303306
def test_rejects_ambiguous_payload_layers(self):
304-
"""An edge sitting in two unique layers has no well-defined boxing."""
307+
"""Error on redundant layers."""
305308
layers = _brickwork_layers(6)
306309
layers[1].add((0, 1))
307310
with self.assertRaises(ValueError):
308311
self.checked.box(payload_layers=layers)
309312

310313
def test_builds_a_samplex(self):
311-
"""The isolated boxing is a working samplomatic circuit."""
314+
"""The boxed circuit is a working samplomatic circuit."""
312315
samplomatic.build(self.isolated)
313316

314317

0 commit comments

Comments
 (0)