Skip to content

Test: interface submodule - #208

Merged
kzsigmond merged 21 commits into
mainfrom
108-test-interface-submodule
Jun 4, 2026
Merged

Test: interface submodule#208
kzsigmond merged 21 commits into
mainfrom
108-test-interface-submodule

Conversation

@kzsigmond

Copy link
Copy Markdown
Contributor

This pull request introduces several improvements and bug fixes to the fanpy.interface.fanci.alias and related PyCI interface code, with a strong focus on input validation, type safety, and enhanced test coverage. The most significant changes include stricter type and value checks in the Alias class, improvements to interface consistency, and the addition of comprehensive unit tests for legacy, pyci and alias functionality.

Input validation and error handling improvements:

  • Added explicit type and value checks in the Alias class constructor and __call__ method to ensure probability vectors are numpy arrays, within the valid range, and 1D (with flattening and warning if not). The __call__ method now checks that n is an integer within valid bounds.
  • Improved error handling in the fanpy_ham and pyci_ham property setters in fanpy/interface/pyci.py to raise clear TypeErrors when input types are invalid.

Interface and documentation consistency:

  • Updated the mask parameter in fanpy/interface/fanci/pyci.py from a list to a np.ndarray of bools, with updated docstrings to clarify its usage for freezing parameters.
  • Fixed a bug in test instance creation for PyCI objects by ensuring the mask is correctly sized and of boolean type.

Testing enhancements:

  • Added a new test module tests/test_interface_fanci_alias.py with comprehensive unit tests for the Alias class, covering input validation, warnings, and output correctness.
  • Refactored and expanded tests in tests/test_interface_fanci_legacy.py and tests/test_interface_fanci_pyci.py
  • Added a tests/interface_utils.py module with reusable fake classes for testing, improving test isolation and maintainability.

** Note on test coverage **

  • legacy.py does not cover the ProjectedSchrodingerLegacyFanci class individually. This is because this class is equivalent to the pyci FanCI class.
  • pyscf_tools.py has a lower test coverage because the localization function is not well documented, and may have a bug in it. Therefore, we are just testing the easiest case for localization.
  • legacy.py & pyci.py: we are testing the most common inputs for the objective class. There are no additional masks, norm_det is set to the default, etc. These are features, we do not actively use, so testing them later should suffice. Especially since the test coverage now is significantly higher.

@kzsigmond kzsigmond linked an issue May 28, 2026 that may be closed by this pull request
@kzsigmond kzsigmond self-assigned this May 28, 2026
@kzsigmond kzsigmond added the test unit tests, integration tests, etc. label May 28, 2026
@kzsigmond
kzsigmond requested a review from rugwed-lokhande May 28, 2026 14:40
@kzsigmond kzsigmond added this to the v2.0.0 milestone May 28, 2026
@kzsigmond
kzsigmond merged commit 13d0e5b into main Jun 4, 2026
3 checks passed
@kzsigmond
kzsigmond deleted the 108-test-interface-submodule branch June 4, 2026 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test unit tests, integration tests, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test: interface submodule

2 participants