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: [email protected]

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

Reply via email to