Skip to content

Conversation

@sharminafrose
Copy link

Ensure that the measurement results in the generated output align with the number of classical bits defined in the OpenQASM program.

Summary of changes

In qbraid_qir/qasm3/visitor.py file, the record_output method has been updated to loop over num_clbits instead of num_qubits. Previously, when the number of classical bits was lower than the number of qubits, the generated QIR had an incorrect output configuration.
Example Input: For the following OpenQASM program:
image

Issue:
The generated output QIR incorrectly included two calls to @__quantum__rt__result_record_output, attempting to record a non-existent measurement result:
image

By adjusting the loop to iterate over num_clbits, the generated QIR now correctly matches the number of classical bits, preventing unnecessary or erroneous result recordings.

@TheGupta2012
Copy link
Member

TheGupta2012 commented Mar 17, 2025

Thanks for the contribution @sharminafrose ! When we initially developed the record_output function it was analogous to a method which measures all of the qubits in the quantum program.

  • While your change takes care of one particular case, I believe the correct way to do this would be to make a call to the @__quantum__rt__result_record_output respective to each measurement.
  • This is because, say if num_clbits would be larger than num_qubits OR num measurements are != num_clbits, the calls to record output would not match the actual measurements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants