Skip to content

Refactor/refactor AlphaPeel - #292

Merged
XingerTang merged 57 commits into
AlphaGenes:develfrom
XingerTang:refactor/refactor-AlphaPeel
Aug 7, 2026
Merged

XingerTang merged 57 commits into
AlphaGenes:develfrom
XingerTang:refactor/refactor-AlphaPeel

Conversation

@XingerTang

@XingerTang XingerTang commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Related Issue

Closes #78
Closes #147
Closes #172
Closes #178
Closes #258
Working...

What changed

  • Call modules of functional tests directly instead of building, installing, and running with an OS command
  • Check directly against the error message and warning message in the functional tests
  • Improve the readability of the functional test file
  • Use ValueError instead of printing error messages
  • Add instructions for functional tests memory profiling and coverage report generation
  • Simplify the accuracy test so that it only runs minimal
  • Provide separate full performance benchmarking in utility files.
  • Provide visualization of the full benchmarking report.

Working...

Bigger picture of the full plan

  • Modification on tests:

    • For functional tests:
      • Call modules directly instead of build and install and run with OS command
      • It would enable:
        • memory profiling
        • function-wise runtime profiling
        • test coverage report
        • more informative debugging information when test failed
        • catch errors and warnings easier than the other way
    • Keep the accuracy tests as the current build and install approach to test by platform and distribution
    • Update accuracy test table as AlphaImpute2
  • Refactor the reassignment of argument options in AlphaPeel to remove warnings raised because of the unsynced arguments retrieval.

  • Remove unused/commented code

  • Replace single-letter variable names with more informative names

  • Add comments and docstrings when applicable

  • Memory optimisation

    • Background: For a 2MB genotype input, the PeelingInfo would take 174MB
    • By reviewing the current most memory-demanding data, several improvements can make:
      • PointSeg is used a temporary holder of segregation probabilities of one single individual, no necessity to allocate it an nInd x 4 x nLoci array.
      • Similar case but a little bit more complicated situation may apply to family terms:
        • posteriorSire_new
        • posteriorDam_new
        • posteriorSire_minusFam
        • posteriorDam_minusFam
      • There are several variables of int64 type, int64 is too large than what we need
  • Move the functions that are jit-compilable to jit

  • Explore multi-processing solution on HPC

Why this change

  • Refactoring the code

Working...

Submodule changes

Notes / Risks

Working...

@XingerTang
XingerTang marked this pull request as draft July 7, 2026 17:57
@XingerTang

Copy link
Copy Markdown
Contributor Author

Coverage report of the functional test:

coverage report -m
Name                                            Stmts   Miss  Cover   Missing
-----------------------------------------------------------------------------
conftest.py                                       104     33    68%   10-18, 23-33, 58-71, 150-151, 198
src/tinypeel/Peeling/Peeling.py                   268    240    10%   31-243, 268-274, 292-303, 324-332, 352-360, 370-382, 412-427, 446-452, 471-477, 490-512, 525-542, 565-641
src/tinypeel/Peeling/PeelingIO.py                 173     68    61%   24-84, 151-152, 183, 191, 214, 267-285, 430-433, 447-450, 463-487
src/tinypeel/Peeling/PeelingInfo.py               211     74    65%   54, 153, 210-213, 232-235, 269, 289-300, 366-383, 391-434, 446-458, 470-482
src/tinypeel/Peeling/PeelingUpdates.py            191     74    61%   35, 54, 75, 77, 88, 90, 95, 113-135, 153-164, 261, 279, 336-344, 397-400, 413-437, 462-466, 503-509, 524-547, 560-564, 576
src/tinypeel/Peeling/version.py                     2      0   100%
src/tinypeel/tinyhouse/HaplotypeOperations.py      59     42    29%   6-8, 16-22, 31-39, 44-46, 51-54, 59-63, 68-73, 78-85
src/tinypeel/tinyhouse/InputOutput.py             343    156    55%   15, 42-62, 70-71, 76-77, 87-88, 98-106, 114-122, 243-258, 262-284, 308-309, 327-328, 331-340, 343, 357-358, 368-370, 415-416, 438-446, 453-454, 458-459, 481-482, 485-486, 510-567, 576-577, 590-604, 610-633, 639-642, 646-655, 659-666, 698, 700
src/tinypeel/tinyhouse/MultiThreadIO.py            78     44    44%   9-10, 15-16, 21-47, 52, 56-63, 97-105, 122-138, 151
src/tinypeel/tinyhouse/Pedigree.py                778    350    55%   45-48, 107, 110, 120-137, 143, 199, 212-214, 292, 300-310, 313-337, 342-363, 366, 402-408, 411-418, 422-427, 434, 437, 447-451, 483, 501-512, 530-557, 560-567, 665, 675, 677, 680-708, 722, 728, 732, 740, 767-789, 795-798, 805-824, 829-849, 855-872, 883-938, 981, 986-987, 1009-1021, 1091, 1097, 1104, 1116-1138, 1146, 1154-1159, 1176-1177, 1181, 1185-1186, 1193-1199, 1212, 1215-1226, 1229-1237, 1240-1244, 1247-1252, 1255-1264, 1270-1279, 1283-1294, 1298-1307, 1310, 1315-1317, 1322-1325, 1330-1332, 1337-1340, 1345-1348
src/tinypeel/tinyhouse/ProbMath.py                251    115    54%   35-55, 65, 67, 95-96, 106-140, 145-147, 152-164, 176-211, 215-254, 260-262, 267-270, 275-278, 283-289
src/tinypeel/tinypeel.py                          286     50    83%   97, 113-119, 146-149, 165-168, 300-327, 350-362, 812-813, 845, 849-855, 886-891, 899
tests/functional_tests/run_func_test.py           527      2    99%   79, 177
-----------------------------------------------------------------------------
TOTAL                                            3271   1248    62%

@gregorgorjanc gregorgorjanc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good/ok

@XingerTang

Copy link
Copy Markdown
Contributor Author

Functional tests memory profiling - this is not very informative, as the Numba function can be called at any part of the run:

======================================================================================= MEMRAY REPORT =======================================================================================
Allocation results for tests/functional_tests/run_func_test.py::TestClass::test_out_id_only at the high watermark

         📦 Total memory allocated: 90.3MiB
         📏 Total allocations: 899
         📊 Histogram of allocation sizes: | ▂█▂▁|
         🥇 Biggest allocating functions:
                - __call__:/Users/xtang3/anaconda3/envs/phase/lib/python3.11/site-packages/llvmlite/binding/ffi.py:197 -> 19.6MiB
                - __call__:/Users/xtang3/anaconda3/envs/phase/lib/python3.11/site-packages/llvmlite/binding/ffi.py:197 -> 4.6MiB
                - __call__:/Users/xtang3/anaconda3/envs/phase/lib/python3.11/site-packages/llvmlite/binding/ffi.py:197 -> 4.3MiB
                - _to_string:/Users/xtang3/anaconda3/envs/phase/lib/python3.11/site-packages/llvmlite/ir/values.py:549 -> 2.5MiB
                - __call__:/Users/xtang3/anaconda3/envs/phase/lib/python3.11/site-packages/llvmlite/binding/ffi.py:197 -> 2.1MiB


Allocation results for tests/functional_tests/run_func_test.py::TestClass::test_files at the high watermark

         📦 Total memory allocated: 52.2MiB
         📏 Total allocations: 3811
         📊 Histogram of allocation sizes: |  █  |
         🥇 Biggest allocating functions:
                - _compile_bytecode:<frozen importlib._bootstrap_external>:729 -> 2.9MiB
                - __call__:/Users/xtang3/anaconda3/envs/phase/lib/python3.11/site-packages/llvmlite/binding/ffi.py:197 -> 2.2MiB
                - __call__:/Users/xtang3/anaconda3/envs/phase/lib/python3.11/site-packages/llvmlite/binding/ffi.py:197 -> 2.1MiB
                - _compile_bytecode:<frozen importlib._bootstrap_external>:729 -> 1.1MiB
                - updatecache:/Users/xtang3/anaconda3/envs/phase/lib/python3.11/linecache.py:137 -> 1.1MiB


Allocation results for tests/functional_tests/run_func_test.py::TestClass::test_est at the high watermark

         📦 Total memory allocated: 9.4MiB
         📏 Total allocations: 482
         📊 Histogram of allocation sizes: | ▁█▄ |
         🥇 Biggest allocating functions:
                - __call__:/Users/xtang3/anaconda3/envs/phase/lib/python3.11/site-packages/llvmlite/binding/ffi.py:197 -> 1.2MiB
                - _icmp:/Users/xtang3/anaconda3/envs/phase/lib/python3.11/site-packages/llvmlite/ir/builder.py:575 -> 1.0MiB
                - init_first_block:/Users/xtang3/anaconda3/envs/phase/lib/python3.11/site-packages/numba/core/interpreter.py:1519 -> 1.0MiB
                - __init__:/Users/xtang3/anaconda3/envs/phase/lib/python3.11/site-packages/llvmlite/ir/instructions.py:464 -> 1.0MiB
                - generic:/Users/xtang3/anaconda3/envs/phase/lib/python3.11/site-packages/numba/core/typing/npydecl.py:97 -> 1.0MiB


Allocation results for tests/functional_tests/run_func_test.py::TestClass::test_pheno at the high watermark

         📦 Total memory allocated: 9.0MiB
         📏 Total allocations: 397
         📊 Histogram of allocation sizes: |  █▁ |
         🥇 Biggest allocating functions:
                - __call__:/Users/xtang3/anaconda3/envs/phase/lib/python3.11/site-packages/llvmlite/binding/ffi.py:197 -> 3.4MiB
                - __call__:/Users/xtang3/anaconda3/envs/phase/lib/python3.11/site-packages/llvmlite/binding/ffi.py:197 -> 2.0MiB
                - __call__:/Users/xtang3/anaconda3/envs/phase/lib/python3.11/site-packages/llvmlite/binding/ffi.py:197 -> 604.1KiB
                - __call__:/Users/xtang3/anaconda3/envs/phase/lib/python3.11/site-packages/llvmlite/binding/ffi.py:197 -> 415.7KiB
                - __call__:/Users/xtang3/anaconda3/envs/phase/lib/python3.11/site-packages/llvmlite/binding/ffi.py:197 -> 170.1KiB


Allocation results for tests/functional_tests/run_func_test.py::TestClass::test_sex at the high watermark

         📦 Total memory allocated: 4.2MiB
         📏 Total allocations: 316
         📊 Histogram of allocation sizes: | ▁█▂ |
         🥇 Biggest allocating functions:
                - __call__:/Users/xtang3/anaconda3/envs/phase/lib/python3.11/site-packages/llvmlite/binding/ffi.py:197 -> 2.6MiB
                - __call__:/Users/xtang3/anaconda3/envs/phase/lib/python3.11/site-packages/llvmlite/binding/ffi.py:197 -> 185.3KiB
                - register:/Users/xtang3/anaconda3/envs/phase/lib/python3.11/site-packages/llvmlite/ir/_utils.py:21 -> 128.0KiB
                - __call__:/Users/xtang3/anaconda3/envs/phase/lib/python3.11/site-packages/llvmlite/binding/ffi.py:197 -> 77.2KiB
                - __call__:/Users/xtang3/anaconda3/envs/phase/lib/python3.11/site-packages/llvmlite/binding/ffi.py:197 -> 77.2KiB

@XingerTang

Copy link
Copy Markdown
Contributor Author

Coverage report of the functional test:

coverage report -m
Name                                            Stmts   Miss  Cover   Missing
-----------------------------------------------------------------------------
conftest.py                                       104     33    68%   10-18, 23-33, 58-71, 150-151, 198
src/tinypeel/Peeling/Peeling.py                   268    240    10%   31-243, 268-274, 292-303, 324-332, 352-360, 370-382, 412-427, 446-452, 471-477, 490-512, 525-542, 565-641
src/tinypeel/Peeling/PeelingIO.py                 173     68    61%   24-84, 151-152, 183, 191, 214, 267-285, 430-433, 447-450, 463-487
src/tinypeel/Peeling/PeelingInfo.py               211     74    65%   54, 153, 210-213, 232-235, 269, 289-300, 366-383, 391-434, 446-458, 470-482
src/tinypeel/Peeling/PeelingUpdates.py            191     74    61%   35, 54, 75, 77, 88, 90, 95, 113-135, 153-164, 261, 279, 336-344, 397-400, 413-437, 462-466, 503-509, 524-547, 560-564, 576
src/tinypeel/Peeling/version.py                     2      0   100%
src/tinypeel/tinyhouse/HaplotypeOperations.py      59     42    29%   6-8, 16-22, 31-39, 44-46, 51-54, 59-63, 68-73, 78-85
src/tinypeel/tinyhouse/InputOutput.py             343    156    55%   15, 42-62, 70-71, 76-77, 87-88, 98-106, 114-122, 243-258, 262-284, 308-309, 327-328, 331-340, 343, 357-358, 368-370, 415-416, 438-446, 453-454, 458-459, 481-482, 485-486, 510-567, 576-577, 590-604, 610-633, 639-642, 646-655, 659-666, 698, 700
src/tinypeel/tinyhouse/MultiThreadIO.py            78     44    44%   9-10, 15-16, 21-47, 52, 56-63, 97-105, 122-138, 151
src/tinypeel/tinyhouse/Pedigree.py                778    350    55%   45-48, 107, 110, 120-137, 143, 199, 212-214, 292, 300-310, 313-337, 342-363, 366, 402-408, 411-418, 422-427, 434, 437, 447-451, 483, 501-512, 530-557, 560-567, 665, 675, 677, 680-708, 722, 728, 732, 740, 767-789, 795-798, 805-824, 829-849, 855-872, 883-938, 981, 986-987, 1009-1021, 1091, 1097, 1104, 1116-1138, 1146, 1154-1159, 1176-1177, 1181, 1185-1186, 1193-1199, 1212, 1215-1226, 1229-1237, 1240-1244, 1247-1252, 1255-1264, 1270-1279, 1283-1294, 1298-1307, 1310, 1315-1317, 1322-1325, 1330-1332, 1337-1340, 1345-1348
src/tinypeel/tinyhouse/ProbMath.py                251    115    54%   35-55, 65, 67, 95-96, 106-140, 145-147, 152-164, 176-211, 215-254, 260-262, 267-270, 275-278, 283-289
src/tinypeel/tinypeel.py                          286     50    83%   97, 113-119, 146-149, 165-168, 300-327, 350-362, 812-813, 845, 849-855, 886-891, 899
tests/functional_tests/run_func_test.py           527      2    99%   79, 177
-----------------------------------------------------------------------------
TOTAL                                            3271   1248    62%

Coverage report cannot identify the calls to jit-compiled functions.

@XingerTang

XingerTang commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor Author

The original accuracy tests have been split into two parts:

  • Minimalist accuracy test for CI/CD quality check
    • Simplified report so we can focus on the most important values during production
    • Much faster and lighter, so shorter delay for accuracy checks
    • Still use the built distribution version for the OS-wise check
  • Accuracy benchmarking for monitoring the performance of combinations of different options
    • Maximised report to cover as many details as possible
    • Call the modules directly so that it runs faster and captures the debugging info/profiling info better
      • Run by from src.utils import run_full_accuracy_suite as run_full; run_full()

Still under development...

@XingerTang

Copy link
Copy Markdown
Contributor Author

GitHub runner does not support Python 3.7 for ubuntu:

Error: The version '3.7' with architecture 'x64' was not found for Ubuntu 24.04.

for simplicity, just test version 3.9 to 3.13.
(AlphaImpute2 cross version testing is wrong, and requires a fix.)

Comment thread docs/source/usage.rst Outdated
``-n_thread_fam`` controls the number of threads to parallelise accross
families in a generation, while ``-n_thread_loci`` controls the number of threads
to parallelise across loci for each individual. Both options can be used together
to speed up the analysis, but ``-n_thread_fam`` is more efficient than

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
to speed up the analysis, but ``-n_thread_fam`` is more efficient than
to speed up the analysis, but ``-n_thread_fam`` is more impactful than

Comment thread docs/source/usage.rst Outdated
to speed up the analysis, but ``-n_thread_fam`` is more efficient than
``-n_thread_loci`` when the number of loci is small (i.e., less than 3000
per chromosome) and computing resources are limited.
While the ``-n_thread_loci`` option might be more useful if number of CPU cores

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
While the ``-n_thread_loci`` option might be more useful if number of CPU cores
The ``-n_thread_loci`` option might be more useful if number of CPU cores

@gregorgorjanc gregorgorjanc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor suggested edits.

@XingerTang

Copy link
Copy Markdown
Contributor Author

In ef647f0:

  • The section testing_and_profiling is moved from contribute to a separate page
    • Its content has been updated according to the current code behaviour, and new details have been added
  • accuracy_report_comparison.py is added for the comparison of two accu_report

@gregorgorjanc

Copy link
Copy Markdown
Member
  • The section testing_and_profiling is moved from contribute to a separate page

That's a good call @XingerTang! Just ensure you link it up well from contrib/dev page too.

@gregorgorjanc gregorgorjanc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, clear, and detailed instructions @XingerTang !

@gregorgorjanc

Copy link
Copy Markdown
Member
  • The section testing_and_profiling is moved from contribute to a separate page

That's a good call @XingerTang! Just ensure you link it up well from contrib/dev page too.

I see that you have the linking, so all seems in order;)

@XingerTang

Copy link
Copy Markdown
Contributor Author

The remaining things to do would be:

  • Pylint the other Python files
  • Update changelog

@XingerTang
XingerTang marked this pull request as ready for review August 5, 2026 14:39
Comment thread pyproject.toml Outdated
@XingerTang

Copy link
Copy Markdown
Contributor Author

I'm not sure if we should be on the author list or the maintainer list. Could you review that?

@gregorgorjanc

Copy link
Copy Markdown
Member

I'm not sure if we should be on the author list or the maintainer list. Could you review that?

I think your edits are in a good direction and make sense! Groovy;)

Please check with Ros if she would prefer Ros or Rosalind

Ensure you add space before Ros' surname;)

You misspelled alphagenes for Yu.

Best if you put me last in the author order.

@XingerTang
XingerTang force-pushed the refactor/refactor-AlphaPeel branch from 4594857 to e474267 Compare August 7, 2026 11:52
@XingerTang
XingerTang merged commit a539a54 into AlphaGenes:devel Aug 7, 2026
18 checks passed
@XingerTang
XingerTang deleted the refactor/refactor-AlphaPeel branch August 7, 2026 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants