[Test] Improve Test Coverage for Quantum Gates and Circuit Operations
This issue improves test coverage for Qumat by adding comprehensive unit tests for all quantum gates and circuit operations. Currently, the test suite has basic tests for circuit creation, swap test, and overlap measurement, but lacks dedicated unit tests for individual quantum gates and parameterized circuits.
The Qumat library currently has the following test coverage:
- Basic circuit creation tests (
test_create_circuit.py) - Swap test functionality (
test_swap_test.py) - Overlap measurement (
test_overlap_measurement.py) - Final quantum states comparison (
test_final_quantum_states.py)
However, there are gaps in test coverage:
- No dedicated unit tests for individual quantum gates (Pauli X/Y/Z, Hadamard, rotation gates, etc.)
- No comprehensive tests for parameterized circuits
- Limited error handling tests
- Missing edge case tests
Goal
The goal of this issue is to improve code coverage for qumat/qumat.py by adding comprehensive test files for:
- All single-qubit gates (Pauli X/Y/Z, Hadamard, NOT, rotation gates, U gate)
- All multi-qubit gates (CNOT, Toffoli, SWAP, CSWAP)
- Parameterized circuit operations
- Error handling and edge cases
- Backend consistency across Qiskit, Cirq, and Amazon Braket
Test Files to Create
This issue proposes creating 7 test files below , each focusing on a specific area of functionality. We can discuss with increasing or decreasing test files.
1. test_single_qubit_gates.py
- Pauli X, Y, Z gates
- Hadamard gate
- NOT gate
- U gate (universal single-qubit gate)
- Edge cases for single-qubit gates
2. test_rotation_gates.py
- RX, RY, RZ gates with different angles
- Parameterized rotation gates (using string parameters)
- Parameter binding for rotation gates
- Edge cases for rotation gates
3. test_multi_qubit_gates.py
- CNOT gate
- Toffoli gate
- SWAP gate
- CSWAP gate
4. test_parameterized_circuits.py
- Parameter binding functionality (
bind_parameters()) - Parameterized circuit execution (
execute_circuit(parameter_values)) - Multiple parameterized gates in a single circuit
- Mixing parameterized and non-parameterized gates
- Edge cases for parameterized circuits
5. test_error_handling.py
- Uninitialized circuit errors (all gate operations,
execute_circuit(),draw(),get_final_state_vector()) - Invalid qubit index errors
- Edge cases for error conditions
6. test_edge_cases.py
- Circuit execution edge cases (0 qubits, 1 qubit, large number of qubits, empty circuits)
- Circuit creation edge cases
- Circuit drawing functionality
- Probability calculation functionality (
calculate_prob_zero()) - Edge cases for all operations
7. test_backend_consistency.py
- Consistency tests for all single-qubit gates across Qiskit, Cirq, and Amazon Braket
- Consistency tests for all multi-qubit gates
- Consistency tests for rotation gates
- Consistency tests for parameterized circuits
- Consistency tests for complex circuits
I'm ready to start working on this issue. Please let me know if you have any feedback or suggestions.
Thanks for the suggestion!
Overall it looks good. I think we could merge some of the similar tests, such as the Single-Qubit Gates ones you mentioned, into a single file instead of splitting them into multiple ones. That would make the structure much clearer. Also, I think the edge cases don’t need to be separated from the original test.
You could try implementing these changes, and I can help review them afterward.
@guan404ming thanks for your feedback! 23 files were merged into 7 files.
A little background here- someone started working on testing framework long long ago, and then just sort of dissapeared, so if it seems like testing is half implemented, it's bc it is
A little background here- someone started working on testing framework long long ago, and then just sort of dissapeared, so if it seems like testing is half implemented, it's bc it is
Haha! makes sense now... every project has that unfinished legend. As a true gift to future developers.:)
it's worse, much worse in open source.
Agree.
And in case said person comes back around, I'll add some more color. They started on the testing framework- everyone was busy with other stuff in life- they respectfully let us know that they were going to have to re-focus on some family stuff for a while- we said you're welcome back whenever- and that was the last I heard of them, but let this post show, I think they may still come back again some day.
Maybe one day they’ll come back and be surprised to see the hole they left halfway done has finally been filled. 😃