Skip to content

[QDP] [Test] Add and refactor NumPy encoding tests #823

@viiccwen

Description

@viiccwen

Summary

Add and refactor NumPy encoding tests in test_numpy.py to improve maintainability and add 2D array batch encoding test coverage.

Use Case

The NumPy encoding tests were lacked coverage for 2D array batch encoding scenarios. This refactoring:

  1. Adds 2D array testing - Ensures batch encoding works correctly for 2D NumPy arrays
  2. Follows pytest best practices - Removes unnecessary if __name__ == "__main__": blocks
  3. Improves maintainability - Uses helper functions and parameterized tests for cleaner code

Proposed Implementation

  1. Added 2D array batch encoding tests

    • Extended test_encode_numpy_array() to test both 1D (single sample) and 2D (batch) arrays
    • Tests various batch sizes and qubit configurations
  2. Code cleanup

    • Removed redundant if __name__ == "__main__": block (pytest handles test discovery automatically)
    • Removed unnecessary print statements
    • Fixed tests to only test implemented encoding methods (amplitude, not angle/basis)
  3. Test coverage

    • NumPy file format encoding (.npy files)
    • 1D NumPy array encoding (single sample)
    • 2D NumPy array encoding (batch)
    • Different precision settings (float32, float64)
    • Error handling (wrong dtype, unsupported dimensions)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions