Skip to content

Conversation

@viiccwen
Copy link
Contributor

@viiccwen viiccwen commented Jan 12, 2026

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

  • Bug fix
  • New feature
  • Refactoring
  • Documentation
  • Test
  • CI/CD pipeline
  • Other

Breaking Changes

  • Yes
  • 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:

# Would raise: KeyError: 'backend_name' (not helpful)
qumat = QuMat({"backend_options": {...}})

After:

# 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

  • Added or updated unit tests for all changes
  • Added or updated documentation for all changes (updated docstring)
  • Successfully built and ran all unit tests or manual tests locally
  • PR title follows "MAHOUT-XXX: Brief Description" format (if related to an issue)
  • Code follows ASF guidelines

- Added checks to ensure `backend_config` is a dictionary and includes required keys: `backend_name` and `backend_options`.
- Updated tests to validate these new error conditions, ensuring appropriate exceptions are raised for invalid configurations.
- Refactored test code to utilize a centralized `get_backend_config` function for cleaner backend configuration retrieval.
@viiccwen
Copy link
Contributor Author

The description of error messages could adjust if there is anything unclear.

@viiccwen viiccwen changed the title [QDP] Improve error messages for missing backend_config keys MAHOUT-744 Improve error messages for missing backend_config keys Jan 12, 2026
@guan404ming guan404ming merged commit 2526ff3 into apache:main Jan 12, 2026
4 checks passed
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.

[Bug] Report a bug to help us improve

2 participants