Skip to content

Commit

Permalink
Fix qasm output for bitmasked measurements (#4756)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
daxfohl authored Dec 14, 2021
1 parent ac5b7ca commit ce1a242
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions cirq-core/cirq/circuits/qasm_output_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions cirq-core/cirq/ops/measurement_gate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_(
Expand Down

0 comments on commit ce1a242

Please sign in to comment.