viiccwen opened a new pull request, #807:
URL: https://github.com/apache/mahout/pull/807

   ### Purpose of PR
   
   Improve error handling in `QuMat.__init__()` to provide clear and helpful 
error messages when `backend_config` is missing required keys (`backend_name` 
or `backend_options`). 
   
   Previously, the code would raise a generic `KeyError` without clear 
indication of what was missing or how to fix it, making debugging difficult for 
users.
   
   ### Related Issues or PRs
   
   resolve #800 
   
   ### Changes Made
   
   <!-- Please mark one with an "x"   -->
   
   - [x] Bug fix
   - [ ] New feature
   - [ ] Refactoring
   - [ ] Documentation
   - [x] Test
   - [ ] CI/CD pipeline
   - [ ] Other
   
   ### Breaking Changes
   
   <!-- Does this PR introduce a breaking change? -->
   
   - [ ] Yes
   - [x] No
   
   ### Changes Summary
   
   **Code Changes:**
   - Added validation in `QuMat.__init__()` to check if `backend_config` is a 
dictionary
   - Added validation to check for required keys (`backend_name` and 
`backend_options`) before accessing them
   
   **Test Changes:**
   - Added `TestBackendConfigValidation` class in `test_create_circuit.py`
   - Added tests for invalid type (non-dictionary config)
   - Added tests for missing `backend_name` key
   - Added tests for missing `backend_options` key
   
   **Before:**
   ```python
   # Would raise: KeyError: 'backend_name' (not helpful)
   qumat = QuMat({"backend_options": {...}})
   ```
   
   **After:**
   ```python
   # Raises: KeyError: "backend_config is missing required key 'backend_name'. 
   #          Please provide a backend name (e.g., 'qiskit', 'cirq', 
'amazon_braket')"
   qumat = QuMat({"backend_options": {...}})
   ```
   
   ### Checklist
   
   <!-- Please mark each item with an "x" when complete -->
   
   <!-- If not all items are complete, please open this as a **Draft PR**.
   
   Once all requirements are met, mark as ready for review. -->
   
   - [x] Added or updated unit tests for all changes
   - [x] Added or updated documentation for all changes (updated docstring)
   - [x] Successfully built and ran all unit tests or manual tests locally
   - [ ] PR title follows "MAHOUT-XXX: Brief Description" format (if related to 
an issue)
   - [x] Code follows ASF guidelines
   ```


-- 
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