Skip to content

Commit cc2e715

Browse files
committed
Enhance tests for the utility functions
1 parent 1c0c8d2 commit cc2e715

File tree

2 files changed

+583
-0
lines changed

2 files changed

+583
-0
lines changed

tests/__init__.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
"""
2+
Test Suite for Hadamard Random Forest (HRF) Quantum State Tomography Library
3+
4+
This test module provides comprehensive testing for the HRF quantum state tomography library,
5+
which implements efficient reconstruction of real-valued quantum states using random forests
6+
over hypercube graphs. The library achieves exponential speedup (from O(4^n) to O(n) circuits)
7+
compared to traditional quantum state tomography methods.
8+
9+
Test Module Structure
10+
====================
11+
12+
The test suite is organized into three main modules, each testing different components
13+
of the HRF library:
14+
15+
1. test_random_forest.py (20 tests)
16+
- Tests core graph theory algorithms for hypercube spanning trees
17+
- Validates uniform random tree generation using optimized algorithms
18+
- Tests majority voting and sign reconstruction mechanisms
19+
- Covers path finding and weight calculation functions
20+
- Ensures reproducibility through random seed management
21+
22+
2. test_sample.py (35 tests)
23+
- Tests quantum circuit generation for Hadamard measurements
24+
- Validates sampling from both simulators and real quantum hardware
25+
- Tests M3 error mitigation integration with IBM Quantum backends
26+
- Covers statevector reconstruction from measurement data
27+
- Tests hardware-specific circuit transpilation and optimization
28+
29+
3. test_utils.py (24 tests)
30+
- Tests quantum entanglement measures (logarithmic negativity)
31+
- Validates quantum magic quantification (stabilizer entropy)
32+
- Tests quantum state overlap calculations (SWAP test)
33+
- Covers mathematical utilities for partial transpose and trace norm
34+
- Tests Pauli operator generation and conversion functions
35+
36+
Testing Methodology
37+
===================
38+
39+
Unit Testing Framework:
40+
- Built on Python's unittest framework with pytest integration
41+
- Total of 79 tests covering ~90% of the codebase functionality
42+
- Includes both unit tests and integration tests
43+
44+
Mock Testing Strategy:
45+
- Extensive use of unittest.mock for quantum hardware operations
46+
- Mocked IBM Quantum backends to avoid actual hardware calls during CI
47+
- Simulated measurement results for deterministic testing
48+
49+
Reproducibility:
50+
- Fixed random seeds (typically 42 or 999) for deterministic test results
51+
- Controlled random state generation for quantum states and parameters
52+
- Consistent test environments across different platforms
53+
54+
Test Coverage Areas:
55+
- Algorithmic correctness of hypercube graph operations
56+
- Quantum circuit construction and transpilation
57+
- Hardware noise simulation and error mitigation
58+
- Mathematical accuracy of quantum information measures
59+
- Edge cases and error handling
60+
61+
Quality Assurance Features:
62+
- Warning suppression for external library deprecations (mthree, Qiskit)
63+
- Numerical stability testing with small floating-point values
64+
- Input validation and error handling verification
65+
- Performance testing for large qubit counts (up to 10 qubits)
66+
67+
Configuration and Execution
68+
===========================
69+
70+
Test Configuration:
71+
- pytest.ini configures warning filters for clean test output
72+
- Suppresses DeprecationWarnings from mthree and Qiskit dependencies
73+
- Maintains UserWarning and RuntimeWarning visibility for debugging
74+
75+
Running Tests:
76+
```bash
77+
# Run all tests
78+
pytest tests/
79+
80+
# Run with verbose output
81+
pytest tests/ -v
82+
83+
# Run specific test module
84+
pytest tests/test_utils.py
85+
86+
# Run with coverage report
87+
coverage run -m pytest tests/
88+
coverage report
89+
90+
# Run tests for specific functionality
91+
pytest tests/test_sample.py::TestQuantumSampling -v
92+
```
93+
94+
Dependencies for Testing:
95+
- Core: numpy, scipy, networkx, qiskit
96+
- Testing: pytest, unittest.mock, coverage
97+
- Quantum: qiskit-aer, qiskit-ibm-runtime, mthree
98+
- Optional: pygraphviz (for tree visualization tests)
99+
100+
Integration with CI/CD:
101+
- Automated testing on GitHub Actions
102+
- Coverage reporting via coveralls
103+
- Tests run on multiple Python versions and platforms
104+
- Graphviz-dependent tests are conditionally skipped in CI environments
105+
106+
Test Data and Fixtures:
107+
- Uses tutorial notebooks as behavioral references
108+
- Includes known quantum states (Bell states, stabilizer states)
109+
- Validates against theoretical predictions from quantum information theory
110+
- Tests hardware noise models based on IBM Quantum device characteristics
111+
112+
This test suite ensures the reliability, accuracy, and performance of the HRF
113+
quantum state tomography library across various quantum computing platforms
114+
and use cases.
115+
"""

0 commit comments

Comments
 (0)