You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mahout.apache.org by "shiavm006 (via GitHub)" <gi...@apache.org> on 2025/11/13 07:17:31 UTC

[I] [Bug] No qubit index validation allows out of bounds access causing cryptic backend errors [mahout]

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

   ### Description
   None of the gate application methods in `qumat.py` validate that qubit indices are within valid bounds (0 to num_qubits-1). This allows users to apply gates to non-existent qubits, causing cryptic backend-specific errors instead of clear validation messages at the frontend layer.
   
   ### Steps to Reproduce
   1. Create a 2-qubit circuit: `qumat.create_empty_circuit(2)`
   2. Try to apply a gate to qubit index 5 (out of bounds): `qumat.apply_hadamard_gate(5)`
   3. Try to apply a gate to negative index: `qumat.apply_cnot_gate(-1, 0)`
   4. Observe backend-specific cryptic errors instead of clear validation
   
   ### Expected Behavior
   Qumat should validate qubit indices at the frontend layer and raise clear `ValueError` or `IndexError` with descriptive messages like:
   ValueError: qubit index 5 out of range for circuit with 2 qubits (valid range: 0-1)
   
   
   ### Actual Behavior
   **Current code** (example from `apply_hadamard_gate` in `qumat/qumat.py` lines 94-105):
   def apply_hadamard_gate(self, qubit_index):
       """Apply a Hadamard gate to the specified qubit."""
       self._ensure_circuit_initialized()
       self.backend_module.apply_hadamard_gate(self.circuit, qubit_index)
       #No validation that 0 <= qubit_index < self.num_qubits**Backend-specific errors** that result:
   - **Qiskit**: `CircuitError: "Index 5 out of range for size 2"`
   - **Cirq**: May create new LineQubit silently or crash during execution
   - **Braket**: Backend-specific validation errors
   


-- 
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: dev-unsubscribe@mahout.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] No qubit index validation allows out of bounds access causing cryptic backend errors [mahout]

Posted by "guan404ming (via GitHub)" <gi...@apache.org>.
guan404ming closed issue #624: [Bug] No qubit index validation  allows out of bounds access causing cryptic backend errors
URL: https://github.com/apache/mahout/issues/624


-- 
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: dev-unsubscribe@mahout.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [Bug] No qubit index validation allows out of bounds access causing cryptic backend errors [mahout]

Posted by "guan404ming (via GitHub)" <gi...@apache.org>.
guan404ming commented on issue #624:
URL: https://github.com/apache/mahout/issues/624#issuecomment-3528766842

   Nice catch, to add validation for this sounds like a great idear.


-- 
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: dev-unsubscribe@mahout.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org