From ce1a242204f4bdc4e6c6b7770d6d05bbb5476b54 Mon Sep 17 00:00:00 2001 From: Dax Fohl Date: Tue, 14 Dec 2021 15:26:36 -0800 Subject: [PATCH] Fix qasm output for bitmasked measurements (#4756) Our invert mask only affects the stored value of the measurement, not the qubit itself. So in the qasm we need to un-invert the qubit after measurement. --- cirq-core/cirq/circuits/qasm_output_test.py | 1 + cirq-core/cirq/ops/measurement_gate.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/cirq-core/cirq/circuits/qasm_output_test.py b/cirq-core/cirq/circuits/qasm_output_test.py index 4fd0891a1a8..4264b65530d 100644 --- a/cirq-core/cirq/circuits/qasm_output_test.py +++ b/cirq-core/cirq/circuits/qasm_output_test.py @@ -494,6 +494,7 @@ def filter_unpredictable_numbers(text): measure q[1] -> m_multi[0]; x q[2]; // Invert the following measurement measure q[2] -> m_multi[1]; +x q[2]; // Undo the inversion measure q[3] -> m_multi[2]; // Dummy operation diff --git a/cirq-core/cirq/ops/measurement_gate.py b/cirq-core/cirq/ops/measurement_gate.py index db46c8b7eaf..ffde4399ae0 100644 --- a/cirq-core/cirq/ops/measurement_gate.py +++ b/cirq-core/cirq/ops/measurement_gate.py @@ -181,6 +181,8 @@ def _qasm_(self, args: 'cirq.QasmArgs', qubits: Tuple['cirq.Qid', ...]) -> Optio if inv: lines.append(args.format('x {0}; // Invert the following measurement\n', qubit)) lines.append(args.format('measure {0} -> {1:meas}[{2}];\n', qubit, self.key, i)) + if inv: + lines.append(args.format('x {0}; // Undo the inversion\n', qubit)) return ''.join(lines) def _quil_(