shiavm006 opened a new issue, #632:
URL: https://github.com/apache/mahout/issues/632

   
   ### Description
   
   The `execute_circuit()` function in `qiskit_backend.py` uses an incorrect 
check to determine if measurements already exist in the circuit. It checks 
`circuit.cregs` (classical registers) instead of checking if measurements are 
actually present. This causes duplicate measurements to be added every time 
`execute_circuit()` is called multiple times on the same circuit, corrupting 
the circuit state and producing incorrect results.
   
   ### Steps to Reproduce
   
   1. Create a circuit and apply some gates:on
   qumat = QuMat(backend_config)
   qumat.create_empty_circuit(2)
   qumat.apply_hadamard_gate(0)
   qumat.apply_cnot_gate(0, 1)
   2. Execute the circuit multiple times:
   results1 = qumat.execute_circuit()  # First execution - adds measurements
   results2 = qumat.execute_circuit()  # Second execution - ADDS DUPLICATE 
MEASUREMENTS!3. Observe that the circuit now has duplicate measurement 
operations
   
   ### Expected Behavior
   
   The circuit should check if measurements already exist using the proper 
Qiskit API (e.g., checking circuit data for measurement operations) and only 
add measurements once, even if `execute_circuit()` is called multiple times.
   
   ### Actual Behavior
   
   Current code in `qumat/qiskit_backend.py` lines 90-91:
   if not circuit.cregs:
       circuit.measure_all()This checks for classical registers (`cregs`), not 
measurements. Since `measure_all()` automatically creates classical registers, 
the check `not circuit.cregs` will always be True on the first call, but may 
incorrectly evaluate on subsequent calls, leading to duplicate measurements.
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to