def _stim_append_measurement_gate(circuit: stim.Circuit, gate: cirq.MeasurementGate, targets: List[int]): for i, b in enumerate(gate.invert_mask): if b: targets[i] = stim.target_inv(targets[i]) circuit.append_operation("M", targets)
def _stim_conversion_(self, edit_circuit: stim.Circuit, edit_measurement_key_lengths: List[Tuple[str, int]], targets: Sequence[int], **kwargs): edit_measurement_key_lengths.append(("custom", 2)) edit_circuit.append_operation("M", [stim.target_inv(targets[0])]) edit_circuit.append_operation("M", [targets[0]]) edit_circuit.append_operation("DETECTOR", [stim.target_rec(-1)])
def test_circuit_append_operation(): c = stim.Circuit() with pytest.raises(IndexError, match="Gate not found"): c.append_operation("NOT_A_GATE", [0]) with pytest.raises(IndexError, match="even number of targets"): c.append_operation("CNOT", [0]) with pytest.raises(IndexError, match="doesn't take"): c.append_operation("X", [0], 0.5) with pytest.raises(IndexError, match="invalid flags"): c.append_operation("X", [stim.target_inv(0)]) with pytest.raises(IndexError, match="invalid flags"): c.append_operation("X", [stim.target_x(0)]) with pytest.raises(IndexError, match="lookback"): stim.target_rec(0) with pytest.raises(IndexError, match="lookback"): stim.target_rec(1) with pytest.raises(IndexError, match="lookback"): stim.target_rec(-2**30) assert stim.target_rec(-1) is not None assert stim.target_rec(-15) is not None c.append_operation("X", [0]) c.append_operation("X", [1, 2]) c.append_operation("X", [3]) c.append_operation("CNOT", [0, 1]) c.append_operation("M", [0, stim.target_inv(1)]) c.append_operation("X_ERROR", [0], 0.25) c.append_operation("CORRELATED_ERROR", [stim.target_x(0), stim.target_y(1)], 0.5) c.append_operation("DETECTOR", [stim.target_rec(-1)]) c.append_operation( "OBSERVABLE_INCLUDE", [stim.target_rec(-1), stim.target_rec(-2)], 5) assert str(c).strip() == """ X 0 1 2 3 CX 0 1 M 0 !1 X_ERROR(0.25) 0 E(0.5) X0 Y1 DETECTOR rec[-1] OBSERVABLE_INCLUDE(5) rec[-1] rec[-2] """.strip()