Survey IO¶
A survey is the self-contained HDF5 output of a run: the taxon namespace, the
shared alignment pool, and the per-chart elite archives, bundled in one file.
SurveyPlan describes what to run and round-trips through a TOML plan file.
SurveyRun prepares the shared context and turns the plan into addressable
units of work. Survey holds the result, saves it, and reloads it, and
frame/cloud unpack the elites for downstream analysis.
SurveyPlan
dataclass
¶
A declarative survey: the alignment pool, the charts, and the parameters.
The plan is the same object as the plan file. :meth:from_toml and
:meth:to_toml round-trip it, so a run is reproducible and shareable as one
small text file.
The plan validates its own labels at construction. Every anchor and every
gene must name an entry of sequence_alignments, and a chart must name
three distinct anchors, so a typo raises where the user wrote it.
Attributes:
| Name | Type | Description |
|---|---|---|
sequence_alignments |
dict
|
Label to alignment path. The |
charts |
list[ChartSpec]
|
The charts to survey. |
model |
str
|
Substitution model name, or |
w |
float
|
Topology weight of the tree metric, in [0, 1]. |
description |
str
|
Free text stored with the survey. |
params |
dict
|
Overrides for :class: |
gpu_params |
dict
|
Overrides for :class: |
Source code in src/hifuku/survey_io.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
from_toml
classmethod
¶
Read a plan file.
The file holds description, model and w at the top level, an
[alignments] table of label to path, optional [params] and
[gpu] tables, and one [[charts]] table per chart.
Source code in src/hifuku/survey_io.py
to_toml
¶
Write the plan file that :meth:from_toml reads.
Source code in src/hifuku/survey_io.py
ChartSpec
dataclass
¶
One chart to survey: three anchor labels and the genes to drop onto it.
genes may include labels that are not among anchors: a gene can be
surveyed on a chart it is not a vertex of.
Source code in src/hifuku/survey_io.py
SurveyRun
¶
One prepared survey: the shared context, the work units, and the results.
:meth:prepare builds the namespace, the NJ tree of every alignment and the
AnchorTriangle of every chart before any survey runs, so a bad triangle
on the fourth chart raises in seconds.
prepare is a function of the plan. A worker on another host rebuilds
the same context from the same paths, which AlignmentInfo records with a
SHA-256 digest.
plan = SurveyPlan.from_toml("ncldv.toml")
run = SurveyRun.prepare(plan, device="cuda")
for task in run.tasks:
run.execute(task)
run.survey().save("ncldv.h5")
Source code in src/hifuku/survey_io.py
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 | |
prepare
classmethod
¶
Build the shared context and validate every chart.
backend defaults to the host or device backend that device
names. Inject one to run the orchestration against another engine.
Source code in src/hifuku/survey_io.py
context
¶
The :class:~hifuku.backend.RunContext for one work unit.
Source code in src/hifuku/survey_io.py
execute
¶
Survey one gene on one chart and keep the record.
monitor reaches :func:~hifuku.driver.run_survey, which calls it at
every checkpoint. A monitor that names task receives this task.
Source code in src/hifuku/survey_io.py
survey
¶
Assemble the executed records into a :class:Survey.
A chart holds the genes that ran on it, in the order the plan names them. A gene that no call executed is left out.
Source code in src/hifuku/survey_io.py
SurveyTask
dataclass
¶
One gene surveyed on one chart: the unit of work.
The task holds a chart index, a gene label and a digest. Every field is a string or an integer, so the task round-trips through JSON and travels to another host as data.
digest covers the anchor labels, the gene, its alignment SHA-256, the
model, the metric weight and every run parameter. Two runs that would
produce the same result therefore carry the same key, and a caller resumes
with if task.key() in done: continue.
Source code in src/hifuku/survey_io.py
key
¶
Survey
¶
A survey: a shared taxon namespace, an alignment pool, and charts.
Construct one directly, or with :meth:run. save and load are a
plain, predictable round trip; they always do the same thing and hold no
resume or caching logic (that lives in the caller).
Source code in src/hifuku/survey_io.py
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 | |
metric
property
¶
The cloud-wide tree metric of this survey.
Built from the NJ tree of every alignment in the pool, so analysis over
the whole cloud uses one normalization. A chart carries its own
CBSMetric, whose c_ref and r_ref come from the anchors of
that chart alone, so this is not the metric of any one chart.
run
classmethod
¶
Run every (chart, gene) survey in plan and return the Survey.
This is :class:SurveyRun with the loop written out. Call
SurveyRun directly to watch a run, to skip finished work, or to send
a task to another host.
Source code in src/hifuku/survey_io.py
alignment
¶
archive
¶
EliteArchive for a surveyed gene on a chart (index or Chart).
frame
¶
Tidy frame of every elite niche across all charts and surveys.
Columns: gene, chart, i, j, lam1, lam2, logL, z.
Source code in src/hifuku/survey_io.py
cloud
¶
Union of every elite tree across all charts, each with (gene, chart)
provenance. Returns a list of :class:CloudPoint.
Source code in src/hifuku/survey_io.py
cloud_identity
¶
The (gene, chart, i, j) of every cloud point, in cloud order.
This is what an embedding's rows line up with. :meth:cloud builds the
points in the same order, charts then surveys then niches, so the two
agree by construction.
Source code in src/hifuku/survey_io.py
cloud_digest
¶
SHA-256 over :meth:cloud_identity.
Two runs of one plan give one digest, because the digest covers which niches were filled and not what landed in them. Adding a chart changes it, which is the case that would otherwise misalign a stored embedding.
Source code in src/hifuku/survey_io.py
ordination
¶
The stored embedding with this label.
Source code in src/hifuku/survey_io.py
add_ordination
¶
Keep an embedding of this survey's cloud.
Fills in the point count and the cloud digest, so a later load can tell whether the survey still matches the embedding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X
|
ndarray
|
|
required |
label
|
str
|
A name, unique within this survey. |
required |
method
|
str
|
How the embedding was produced. |
required |
params
|
dict
|
What the method was given. |
None
|
faithfulness
|
Faithfulness
|
The score of this embedding. |
None
|
Returns:
| Type | Description |
|---|---|
Ordination
|
|
Source code in src/hifuku/survey_io.py
save
¶
Write the survey to a schema-v2 HDF5 file.
Source code in src/hifuku/survey_io.py
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 | |
load
classmethod
¶
Reconstruct a Survey from a schema-v2 file (inverse of :meth:save).
Source code in src/hifuku/survey_io.py
645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 | |
Chart
¶
One chart: its AnchorTriangle, the three anchor labels, and the surveys
(one per surveyed gene) run on it.