hybrid_solver_test.py
Here’s a comprehensive documentation for the target file test/solver_tests/hybrid_solver_test.py
:
High-level description
This file contains unit tests for the HybridSolver class in Cassiopeia’s solver module. It tests various aspects of the hybrid solver, including its constructor, cutoff assessment, top-down splitting, and full solving capabilities for different scenarios (small trees, large trees, trees with missing data).
Code Structure
The main class TestHybridSolver
inherits from unittest.TestCase
and contains multiple test methods. It sets up test data in the setUp
method and cleans up in the tearDown
method. The tests cover different aspects of the HybridSolver’s functionality, including its initialization, cutoff assessment, top-down splitting, and full solving capabilities.
Symbols
TestHybridSolver
Description
A test class that inherits from unittest.TestCase
and contains multiple test methods for the HybridSolver class.
Internal Logic
- Sets up test data in
setUp
method - Defines various test methods to check different aspects of HybridSolver
- Cleans up test files in
tearDown
method
find_triplet_structure
Description
A helper function that finds the structure of a triplet in a given tree.
Inputs
Name | Type | Description |
---|---|---|
triplet | tuple | A tuple of three node names |
T | networkx.DiGraph | The tree to analyze |
Outputs
Name | Type | Description |
---|---|---|
structure | str | The structure of the triplet (“ab”, “ac”, “bc”, or ”-“) |
Internal Logic
- Finds ancestors for each node in the triplet
- Compares the number of common ancestors between pairs
- Returns the structure based on which pair has the most common ancestors
TestHybridSolver.setUp
Description
Sets up the test environment by creating test data and initializing HybridSolver instances.
TestHybridSolver.test_constructor
Description
Tests the constructor of the HybridSolver class.
TestHybridSolver.test_cutoff
Description
Tests the cutoff assessment functionality of the HybridSolver.
TestHybridSolver.test_top_down_split_manual
Description
Manually tests the top-down splitting functionality of the HybridSolver.
TestHybridSolver.test_apply_top_solver_small
Description
Tests the application of the top solver on a small dataset.
TestHybridSolver.test_apply_top_solver_large
Description
Tests the application of the top solver on a large dataset.
TestHybridSolver.test_apply_top_solver_missing
Description
Tests the application of the top solver on a dataset with missing data.
TestHybridSolver.test_full_hybrid
Description
Tests the full hybrid solving process on a small dataset.
TestHybridSolver.test_full_hybrid_single_thread
Description
Tests the full hybrid solving process using a single thread.
TestHybridSolver.test_full_hybrid_large
Description
Tests the full hybrid solving process on a large dataset.
TestHybridSolver.test_full_hybrid_maxcut
Description
Tests the full hybrid solving process using the MaxCut greedy solver.
TestHybridSolver.test_full_hybrid_missing
Description
Tests the full hybrid solving process on a dataset with missing data.
TestHybridSolver.test_greedy_over_greedy_maxcut_missing
Description
Tests the hybrid solver using a greedy solver over a greedy MaxCut solver on a dataset with missing data.
Dependencies
Dependency | Purpose |
---|---|
unittest | Provides testing framework |
itertools | Used for generating combinations |
networkx | Used for graph operations |
pandas | Used for data manipulation |
pathlib | Used for file path operations |
cassiopeia | The main package being tested |
gurobipy | Optional dependency for ILP solving |
Error Handling
The tests use assertions provided by the unittest
framework to check for expected behaviors and results. Some tests are skipped if Gurobi is not installed using the @unittest.skipUnless
decorator.
Logging
The tests create log files during execution, which are cleaned up in the tearDown
method.
TODOs
None explicitly mentioned in the code.
This documentation provides a comprehensive overview of the test file for the HybridSolver in Cassiopeia. It covers the main test class, its methods, and the helper function used in the tests. The documentation also includes information about dependencies, error handling, and logging practices used in the test suite.