cogant.gnn
The cogant.gnn package builds, formats, and validates Generalized Notation Notation packages. The on-disk artifact is produced by GNNPackageBuilder; GNNValidator produces a 0–100 score and an error/warning table.
Package
cogant.gnn
GNN formatting, export, package building, validation, and execution modules.
Emits GNN markdown and JSON representations with all sections in canonical order. Builds complete GNN packages, validates them, and executes the generative model.
ExecutionTrace
dataclass
Posterior beliefs and the subsequent action-conditioned prediction.
Source code in py/cogant/gnn/execution.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
from_record(record, labels)
classmethod
Attach axis labels without inferring semantics from their spelling.
Source code in py/cogant/gnn/execution.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
to_dict()
Return JSON-ready copies so consumers cannot mutate the trace.
Source code in py/cogant/gnn/execution.py
43 44 45 46 47 48 49 50 51 52 53 54 55 | |
GNNJSONExporter
Exports GNN models to machine-readable JSON format with stable IDs.
Source code in py/cogant/gnn/json_export.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 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 728 729 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 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 | |
__init__(program_graph, state_space_model, process_model, semantic_mappings)
Initialize the exporter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
program_graph
|
ProgramGraph
|
The program graph. |
required |
state_space_model
|
StateSpaceModel
|
The state space model. |
required |
process_model
|
ProcessModel
|
The process model. |
required |
semantic_mappings
|
dict[str, Any]
|
Semantic mappings dictionary. |
required |
Source code in py/cogant/gnn/json_export.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
export()
Export the complete GNN model as a JSON-serializable dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary ready for JSON serialization. |
Source code in py/cogant/gnn/json_export.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 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 | |
export_to_string(indent=2)
Export the model to a JSON string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indent
|
int | None
|
Number of spaces for indentation, or None for compact. |
2
|
Returns:
| Type | Description |
|---|---|
str
|
JSON string. |
Source code in py/cogant/gnn/json_export.py
192 193 194 195 196 197 198 199 200 201 202 203 | |
GNNMarkdownFormatter
Bases: _UpstreamSectionsMixin, _MetadataSectionsMixin, _StructuralSectionsMixin, _DynamicsSectionsMixin, _SemanticSectionsMixin
Formats complete GNN models to canonical markdown with all sections.
The emitted markdown is simultaneously an upstream-valid GNN model
(accepted by the generalized-notation-notation 4.x validator)
(containing ## GNNSection, ## GNNVersionAndFlags,
## ModelName, ## StateSpaceBlock, ## Connections,
## InitialParameterization, ## Equations, ## Time,
## ActInfOntologyAnnotation, ## ModelParameters, ## Footer,
and ## Signature) and a COGANT-extended bundle with
richer metadata, provenance, Markov blanket, and validation
sections appended below the upstream header.
Source code in py/cogant/gnn/formatter/base.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 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 | |
__init__(program_graph, state_space_model, process_model, semantic_mappings)
Initialize the formatter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
program_graph
|
ProgramGraph
|
The program graph. |
required |
state_space_model
|
StateSpaceModel
|
The state space model. |
required |
process_model
|
ProcessModel
|
The process model. |
required |
semantic_mappings
|
dict[str, Any]
|
Semantic mappings dictionary. |
required |
Source code in py/cogant/gnn/formatter/base.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
format()
Format the complete GNN model as markdown.
Returns:
| Type | Description |
|---|---|
str
|
Formatted markdown string. |
Source code in py/cogant/gnn/formatter/base.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
format_section(section_name)
Format a specific section.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
section_name
|
str
|
Name of the section. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Formatted section or None. |
Source code in py/cogant/gnn/formatter/base.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
GNNMatrices
Derives GNN A/B/C/D matrices from COGANT analysis artifacts.
The matrices are computed once on construction-time demand via the
compute_* methods. Callers that need all four at once should use
:meth:to_dict or :meth:to_gnn_markdown_block.
Source code in py/cogant/gnn/matrices.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 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 728 729 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 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 | |
n_actions
property
Number of action dimensions.
Zero is a valid dimension for a degenerate empty state space. The matrix exporter preserves that fact instead of inventing an action dimension, which keeps the declared dimensions consistent with the compiled state-space model.
n_obs
property
Number of observation dimensions.
n_states
property
Number of hidden-state dimensions.
__init__(graph, mappings, state_space)
Initialize the matrix deriver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
The program graph with nodes and edges. |
required |
mappings
|
Any
|
Semantic mappings; accepted as either a |
required |
state_space
|
StateSpaceModel
|
The compiled state space model. |
required |
Source code in py/cogant/gnn/matrices.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 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 | |
compute_A()
Compute the likelihood matrix A[n_obs x n_states].
A[i][j] = P(observation_i | hidden_state_j).
Derivation
For each observation i, find the set of hidden-state
nodes that it directly reads (READS/OBSERVES edges from the
observation's node). Those direct reads receive a high
probability mass; all other states share the residual mass
uniformly. Columns are then normalized so each hidden state
defines a distribution over observations.
Source code in py/cogant/gnn/matrices.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 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 | |
compute_B()
Compute the transition tensor B[n_states x n_states x n_actions].
B[next][cur][action] = P(next_state | current_state, action).
Derivation
For each action k, find the hidden-state nodes that it
WRITES/MUTATES. Those destinations become high-probability
successors of every current state; otherwise the transition
defaults to an identity (stay) move. Every column
(cur, action) is normalized so that it sums to 1.0.
Truncation
When n_states² × n_actions would exceed _MAX_B_ENTRIES
(default 5 M), the state space is reduced to the top-K
highest-degree nodes so that the tensor fits in memory and
serializes in reasonable time. The kept states stay in their
original A/D order, so B index j is full state
self._b_kept_state_indices[j]. The truncation is recorded
in self._b_truncated, self._b_n_states_full,
self._b_n_states_kept and self._b_kept_state_indices,
and surfaced in :meth:to_dict under the "truncation" key.
This approximation is a principal submatrix of the full B
restricted to the most structurally important state nodes.
Source code in py/cogant/gnn/matrices.py
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 | |
compute_C()
Compute the log-preference vector C[n_obs].
Derivation
Each observation receives a log-preference derived from the confidence scores of CONSTRAINT/PREFERENCE mappings whose graph fragments intersect with the observation's node set. Preferences with CONSTRAINT kind contribute a positive preference (the constraint describes a desired observation); absent any matching constraint, C defaults to 0.0 (neutral).
Source code in py/cogant/gnn/matrices.py
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 | |
compute_D()
Compute the initial prior D[n_states].
Derivation
If any hidden state has an explicit default_value or an
attached CONFIGURATION node with a value, concentrate mass
on that state. Otherwise return a uniform prior. The vector
always sums to 1.0.
Source code in py/cogant/gnn/matrices.py
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 | |
to_dict()
Return a JSON-serializable dict of all four matrices.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
``{"A": ..., "B": ..., "C": ..., "D": ..., "shapes": ..., |
dict[str, Any]
|
"dimensions": ..., "truncation": ...}`` |
dict[str, Any]
|
The |
dict[str, Any]
|
occurred; otherwise it is a dict with: |
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
declared as |
dict[str, Any]
|
while |
Source code in py/cogant/gnn/matrices.py
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 728 729 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 | |
to_gnn_markdown_block()
Format the matrices as a GNN-compatible markdown block.
Emits AII-style sections with rows=, cols=, depth=
bracket headers. This block is additive to the existing
StateSpaceBlock / InitialParameterization sections; it is
meant to be embedded as a COGANT extension.
Source code in py/cogant/gnn/matrices.py
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 | |
to_plain_dict()
Export matrices as plain Python lists for JSON serialization.
Unlike :meth:to_dict, this method guarantees all values are plain
Python lists/floats with no numpy arrays or other special types.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dict with keys "A", "B", "C", "D" containing the matrices |
dict[str, Any]
|
as plain Python lists. Additional keys include "n_states", |
dict[str, Any]
|
"n_obs", "n_actions" for shape information, and metadata like |
dict[str, Any]
|
"b_truncated" if the B tensor was truncated. |
Source code in py/cogant/gnn/matrices.py
902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 | |
validate()
Validate dimensional consistency across A/B/C/D matrices.
Checks that all four matrices have the expected shapes and that stochastic constraints are satisfied (column sums for A, column sums for B slices, sum for D).
Returns:
| Type | Description |
|---|---|
list[str]
|
A list of validation issues. Empty list means all matrices |
list[str]
|
are dimensionally consistent and satisfy stochastic constraints. |
Source code in py/cogant/gnn/matrices.py
888 889 890 891 892 893 894 895 896 897 898 899 900 | |
validate_shapes()
Validate that all four matrices have the expected shapes.
Returns:
| Type | Description |
|---|---|
bool
|
|
list[str]
|
were found. |
Source code in py/cogant/gnn/matrices.py
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 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 | |
GNNModelRunner
Own a validated GNN snapshot and its most recent model rollout.
Observations are modes of A times the incoming belief, not measurements of source program execution. Actions minimize one-step risk-plus-ambiguity expected free energy.
Source code in py/cogant/gnn/runner.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
generate_execution_report(trace=None)
Describe matrix inference without claiming program or control success.
Source code in py/cogant/gnn/runner.py
92 93 94 95 96 97 98 99 100 101 102 | |
load_package(package_dir)
Load complete model.gnn.md matrices; invalidate stale state on failure.
Source code in py/cogant/gnn/runner.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
run(steps=10)
Execute 1 to 10,000 steps; invalid input fails without a success report.
Source code in py/cogant/gnn/runner.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
run_with_profiling(num_steps=10, num_trials=1)
Measure complete inference runs; each trial restarts from exported D.
Source code in py/cogant/gnn/runner.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
GNNPackageBuilder
Builds a complete, self-contained GNN model package.
Source code in py/cogant/gnn/package.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 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 728 729 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 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 | |
__init__(graph, state_space, process_model, mappings, config=None)
Initialize the GNN package builder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
state_space
|
StateSpaceModel
|
State space model. |
required |
process_model
|
ProcessModel
|
Process model. |
required |
mappings
|
dict[str, Any]
|
Semantic mappings. |
required |
config
|
dict[str, Any] | None
|
Optional configuration dictionary. |
None
|
Source code in py/cogant/gnn/package.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
build(output_dir)
Build the complete GNN package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
str
|
Directory to create the package in. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Manifest dictionary with package metadata and checksums. |
Source code in py/cogant/gnn/package.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 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 | |
GNNValidator
Validates a GNN package against the GNN specification.
Source code in py/cogant/gnn/validator.py
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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 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 728 729 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 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 | |
__init__()
Initialize validator.
Source code in py/cogant/gnn/validator.py
237 238 239 240 241 242 243 244 245 246 | |
generate_validation_badge(result)
Generate SVG validation badge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
ValidationResult
|
Validation result. |
required |
Returns:
| Type | Description |
|---|---|
str
|
SVG string. |
Source code in py/cogant/gnn/validator.py
855 856 857 858 859 860 861 862 863 864 865 | |
validate_markdown(markdown)
Validate GNN markdown structure.
Checks both the COGANT-extended canonical sections
(## Model Metadata, ## Source Coverage, ## Markov
Blanket, etc.) and the upstream GNN 2.0.0 required headers
(## GNNSection, ## StateSpaceBlock, ## Connections,
## InitialParameterization, ## Equations, ## Time,
## ActInfOntologyAnnotation, ## ModelParameters, etc.). Upstream section
checks are ordered: they must appear in the spec-mandated
order at the TOP of the file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
markdown
|
str
|
Markdown content. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of errors (empty if valid). |
Source code in py/cogant/gnn/validator.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | |
validate_matrices(matrices_json)
Validate the AII Active Inference matrix block.
Checks presence and shape of the A/B/C/D matrices emitted by
:class:cogant.gnn.matrices.GNNMatrices. The matrices must
satisfy:
- A: shape
[n_obs x n_states], columns sum to 1.0. - B: shape
[n_states x n_states x n_actions]; whentruncation.appliedis set (large-repo top-K cut, see :meth:cogant.gnn.matrices.GNNMatrices.compute_B) the state axes aren_states_keptandtruncation.kept_state_indicesmust name those states on the full A/D axis. - C: length equal to
n_obs. - D: length equal to
n_states, sums to 1.0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrices_json
|
dict[str, Any]
|
Dict of the form
|
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of errors (empty if matrices are well-formed). |
Source code in py/cogant/gnn/validator.py
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 | |
validate_package(package_dir, *, upstream_gnn=None)
Validate a GNN package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_dir
|
str
|
Path to the package directory. |
required |
upstream_gnn
|
bool | None
|
When True, run the Active Inference Institute
|
None
|
Returns:
| Type | Description |
|---|---|
ValidationResult
|
ValidationResult object. |
Source code in py/cogant/gnn/validator.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | |
validate_provenance(provenance_json)
Validate provenance structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provenance_json
|
dict[str, Any]
|
Provenance JSON. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of errors (empty if valid). |
Source code in py/cogant/gnn/validator.py
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 | |
validate_state_space(state_space_json)
Validate state space structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_space_json
|
dict[str, Any]
|
State space JSON. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of errors (empty if valid). |
Source code in py/cogant/gnn/validator.py
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 | |
ValidationResult
Result of a GNN package validation.
Source code in py/cogant/gnn/validator.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 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 | |
warnings
property
Current public view of non-fatal validation advisories.
__init__(valid=False, errors=None, warnings=None, score=0.0, advisories=None, capabilities=None, artifact_digests=None, dimensions=None)
Initialize validation result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
valid
|
bool
|
Whether package is valid. |
False
|
errors
|
list[str] | None
|
List of error messages. |
None
|
warnings
|
list[str] | None
|
List of warning messages. |
None
|
score
|
float
|
Validation score 0-100. |
0.0
|
Source code in py/cogant/gnn/validator.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
badge_svg()
Generate SVG badge.
Source code in py/cogant/gnn/validator.py
165 166 167 168 169 170 171 172 173 | |
to_dict()
Convert to dictionary.
Source code in py/cogant/gnn/validator.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
to_markdown()
Generate a human-readable markdown report.
Returns:
| Type | Description |
|---|---|
str
|
A markdown string containing a formatted report of the |
str
|
validation result, including scores, errors, warnings, |
str
|
and section breakdowns. |
Source code in py/cogant/gnn/validator.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 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 | |
Package builder
cogant.gnn.package
GNN package builder — creates a complete, self-contained GNN model package.
Builds a package with: - manifest.json: metadata and checksums - model.gnn.md: canonical GNN markdown - model.gnn.json: machine-readable model - state_space.json: detailed state space - observations.json: observation modalities - actions.json: actions and policies - transitions.json: transition structure - preferences.json: preferences and constraints - factors.json: factorization structure - provenance.json: full provenance chain - ontology.json: ontology mappings - diagrams/: mermaid diagrams - visualizations/: HTML visualizations
GNNPackageBuilder
Builds a complete, self-contained GNN model package.
Source code in py/cogant/gnn/package.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 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 728 729 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 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 | |
__init__(graph, state_space, process_model, mappings, config=None)
Initialize the GNN package builder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
Program graph. |
required |
state_space
|
StateSpaceModel
|
State space model. |
required |
process_model
|
ProcessModel
|
Process model. |
required |
mappings
|
dict[str, Any]
|
Semantic mappings. |
required |
config
|
dict[str, Any] | None
|
Optional configuration dictionary. |
None
|
Source code in py/cogant/gnn/package.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
build(output_dir)
Build the complete GNN package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_dir
|
str
|
Directory to create the package in. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Manifest dictionary with package metadata and checksums. |
Source code in py/cogant/gnn/package.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 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 | |
Matrix builder
Builds the A / B / C / D generative-model matrices from the rule output and the Markov blanket.
cogant.gnn.matrices
GNN A/B/C/D matrix derivation from program graph and semantic mappings.
Implements the four core probabilistic matrices required by the Active Inference Institute (AII) upstream Generalized Notation Notation (GNN) specification:
- A — likelihood matrix
P(o | s)(observation given hidden state), shape[n_obs x n_states]. Columns sum to 1.0 (column-stochastic per AII/pymdp convention: for each fixed hidden states, the distribution over observation outcomessum_o P(o | s) == 1). - B — transition tensor
P(s' | s, a)(next state given current state and action), shape[n_states x n_states x n_actions]. For each action slice, columns sum to 1.0 (column-stochastic per AII convention). - C — log-preference vector over observations, shape
[n_obs]. Positive values indicate preferred observations, negative values indicate aversive observations. This is NOT a probability — it is a log-preference in the sense of the Friston expected-free-energy functional. - D — initial prior over hidden states, shape
[n_states]. Entries sum to 1.0.
These matrices are derived deterministically from the COGANT program
graph (ProgramGraph), the extracted semantic mappings
(SemanticMapping), and the compiled state space (StateSpaceModel)
without any external numerical dependencies. COGANT cannot in general
recover the ground-truth parameters of an Active Inference model from
arbitrary source code, so the derivation uses principled heuristics:
- A comes from READS/OBSERVES edges between observation nodes and hidden-state nodes.
- B comes from WRITES/MUTATES edges from action nodes to hidden-state nodes.
- C comes from CONSTRAINT/PREFERENCE mapping confidence scores.
- D comes from CONFIGURATION nodes and any initial-value metadata.
All arithmetic uses plain Python lists — numpy is intentionally not a
dependency of this module.
GNNMatrices
Derives GNN A/B/C/D matrices from COGANT analysis artifacts.
The matrices are computed once on construction-time demand via the
compute_* methods. Callers that need all four at once should use
:meth:to_dict or :meth:to_gnn_markdown_block.
Source code in py/cogant/gnn/matrices.py
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 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 728 729 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 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 | |
n_actions
property
Number of action dimensions.
Zero is a valid dimension for a degenerate empty state space. The matrix exporter preserves that fact instead of inventing an action dimension, which keeps the declared dimensions consistent with the compiled state-space model.
n_obs
property
Number of observation dimensions.
n_states
property
Number of hidden-state dimensions.
__init__(graph, mappings, state_space)
Initialize the matrix deriver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
ProgramGraph
|
The program graph with nodes and edges. |
required |
mappings
|
Any
|
Semantic mappings; accepted as either a |
required |
state_space
|
StateSpaceModel
|
The compiled state space model. |
required |
Source code in py/cogant/gnn/matrices.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 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 | |
compute_A()
Compute the likelihood matrix A[n_obs x n_states].
A[i][j] = P(observation_i | hidden_state_j).
Derivation
For each observation i, find the set of hidden-state
nodes that it directly reads (READS/OBSERVES edges from the
observation's node). Those direct reads receive a high
probability mass; all other states share the residual mass
uniformly. Columns are then normalized so each hidden state
defines a distribution over observations.
Source code in py/cogant/gnn/matrices.py
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 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 | |
compute_B()
Compute the transition tensor B[n_states x n_states x n_actions].
B[next][cur][action] = P(next_state | current_state, action).
Derivation
For each action k, find the hidden-state nodes that it
WRITES/MUTATES. Those destinations become high-probability
successors of every current state; otherwise the transition
defaults to an identity (stay) move. Every column
(cur, action) is normalized so that it sums to 1.0.
Truncation
When n_states² × n_actions would exceed _MAX_B_ENTRIES
(default 5 M), the state space is reduced to the top-K
highest-degree nodes so that the tensor fits in memory and
serializes in reasonable time. The kept states stay in their
original A/D order, so B index j is full state
self._b_kept_state_indices[j]. The truncation is recorded
in self._b_truncated, self._b_n_states_full,
self._b_n_states_kept and self._b_kept_state_indices,
and surfaced in :meth:to_dict under the "truncation" key.
This approximation is a principal submatrix of the full B
restricted to the most structurally important state nodes.
Source code in py/cogant/gnn/matrices.py
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 | |
compute_C()
Compute the log-preference vector C[n_obs].
Derivation
Each observation receives a log-preference derived from the confidence scores of CONSTRAINT/PREFERENCE mappings whose graph fragments intersect with the observation's node set. Preferences with CONSTRAINT kind contribute a positive preference (the constraint describes a desired observation); absent any matching constraint, C defaults to 0.0 (neutral).
Source code in py/cogant/gnn/matrices.py
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 | |
compute_D()
Compute the initial prior D[n_states].
Derivation
If any hidden state has an explicit default_value or an
attached CONFIGURATION node with a value, concentrate mass
on that state. Otherwise return a uniform prior. The vector
always sums to 1.0.
Source code in py/cogant/gnn/matrices.py
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 | |
to_dict()
Return a JSON-serializable dict of all four matrices.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
``{"A": ..., "B": ..., "C": ..., "D": ..., "shapes": ..., |
dict[str, Any]
|
"dimensions": ..., "truncation": ...}`` |
dict[str, Any]
|
The |
dict[str, Any]
|
occurred; otherwise it is a dict with: |
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
|
dict[str, Any]
|
declared as |
dict[str, Any]
|
while |
Source code in py/cogant/gnn/matrices.py
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 728 729 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 | |
to_gnn_markdown_block()
Format the matrices as a GNN-compatible markdown block.
Emits AII-style sections with rows=, cols=, depth=
bracket headers. This block is additive to the existing
StateSpaceBlock / InitialParameterization sections; it is
meant to be embedded as a COGANT extension.
Source code in py/cogant/gnn/matrices.py
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 | |
to_plain_dict()
Export matrices as plain Python lists for JSON serialization.
Unlike :meth:to_dict, this method guarantees all values are plain
Python lists/floats with no numpy arrays or other special types.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dict with keys "A", "B", "C", "D" containing the matrices |
dict[str, Any]
|
as plain Python lists. Additional keys include "n_states", |
dict[str, Any]
|
"n_obs", "n_actions" for shape information, and metadata like |
dict[str, Any]
|
"b_truncated" if the B tensor was truncated. |
Source code in py/cogant/gnn/matrices.py
902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 | |
validate()
Validate dimensional consistency across A/B/C/D matrices.
Checks that all four matrices have the expected shapes and that stochastic constraints are satisfied (column sums for A, column sums for B slices, sum for D).
Returns:
| Type | Description |
|---|---|
list[str]
|
A list of validation issues. Empty list means all matrices |
list[str]
|
are dimensionally consistent and satisfy stochastic constraints. |
Source code in py/cogant/gnn/matrices.py
888 889 890 891 892 893 894 895 896 897 898 899 900 | |
validate_shapes()
Validate that all four matrices have the expected shapes.
Returns:
| Type | Description |
|---|---|
bool
|
|
list[str]
|
were found. |
Source code in py/cogant/gnn/matrices.py
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 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 | |
Runner
cogant.gnn.runner
Execute a package's declared matrices through the shared categorical kernel.
ExecutionTrace
dataclass
Posterior beliefs and the subsequent action-conditioned prediction.
Source code in py/cogant/gnn/execution.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | |
from_record(record, labels)
classmethod
Attach axis labels without inferring semantics from their spelling.
Source code in py/cogant/gnn/execution.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
to_dict()
Return JSON-ready copies so consumers cannot mutate the trace.
Source code in py/cogant/gnn/execution.py
43 44 45 46 47 48 49 50 51 52 53 54 55 | |
GNNModelRunner
Own a validated GNN snapshot and its most recent model rollout.
Observations are modes of A times the incoming belief, not measurements of source program execution. Actions minimize one-step risk-plus-ambiguity expected free energy.
Source code in py/cogant/gnn/runner.py
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
generate_execution_report(trace=None)
Describe matrix inference without claiming program or control success.
Source code in py/cogant/gnn/runner.py
92 93 94 95 96 97 98 99 100 101 102 | |
load_package(package_dir)
Load complete model.gnn.md matrices; invalidate stale state on failure.
Source code in py/cogant/gnn/runner.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
run(steps=10)
Execute 1 to 10,000 steps; invalid input fails without a success report.
Source code in py/cogant/gnn/runner.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
run_with_profiling(num_steps=10, num_trials=1)
Measure complete inference runs; each trial restarts from exported D.
Source code in py/cogant/gnn/runner.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
Validator
cogant.gnn.validator
GNN validator — validates a GNN package against the GNN specification.
Checks: - All required files present - JSON valid and well-formed - Markdown has all canonical sections in correct order - State space well-formed and connected - No orphan references - Checksums match - Provenance complete
GNNCapabilityError
Bases: RuntimeError
Raised when an explicitly requested validator capability is unavailable.
Source code in py/cogant/gnn/validator.py
25 26 27 28 | |
GNNValidator
Validates a GNN package against the GNN specification.
Source code in py/cogant/gnn/validator.py
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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 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 728 729 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 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 | |
__init__()
Initialize validator.
Source code in py/cogant/gnn/validator.py
237 238 239 240 241 242 243 244 245 246 | |
generate_validation_badge(result)
Generate SVG validation badge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
ValidationResult
|
Validation result. |
required |
Returns:
| Type | Description |
|---|---|
str
|
SVG string. |
Source code in py/cogant/gnn/validator.py
855 856 857 858 859 860 861 862 863 864 865 | |
validate_markdown(markdown)
Validate GNN markdown structure.
Checks both the COGANT-extended canonical sections
(## Model Metadata, ## Source Coverage, ## Markov
Blanket, etc.) and the upstream GNN 2.0.0 required headers
(## GNNSection, ## StateSpaceBlock, ## Connections,
## InitialParameterization, ## Equations, ## Time,
## ActInfOntologyAnnotation, ## ModelParameters, etc.). Upstream section
checks are ordered: they must appear in the spec-mandated
order at the TOP of the file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
markdown
|
str
|
Markdown content. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of errors (empty if valid). |
Source code in py/cogant/gnn/validator.py
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 | |
validate_matrices(matrices_json)
Validate the AII Active Inference matrix block.
Checks presence and shape of the A/B/C/D matrices emitted by
:class:cogant.gnn.matrices.GNNMatrices. The matrices must
satisfy:
- A: shape
[n_obs x n_states], columns sum to 1.0. - B: shape
[n_states x n_states x n_actions]; whentruncation.appliedis set (large-repo top-K cut, see :meth:cogant.gnn.matrices.GNNMatrices.compute_B) the state axes aren_states_keptandtruncation.kept_state_indicesmust name those states on the full A/D axis. - C: length equal to
n_obs. - D: length equal to
n_states, sums to 1.0.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrices_json
|
dict[str, Any]
|
Dict of the form
|
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of errors (empty if matrices are well-formed). |
Source code in py/cogant/gnn/validator.py
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 | |
validate_package(package_dir, *, upstream_gnn=None)
Validate a GNN package.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
package_dir
|
str
|
Path to the package directory. |
required |
upstream_gnn
|
bool | None
|
When True, run the Active Inference Institute
|
None
|
Returns:
| Type | Description |
|---|---|
ValidationResult
|
ValidationResult object. |
Source code in py/cogant/gnn/validator.py
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | |
validate_provenance(provenance_json)
Validate provenance structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provenance_json
|
dict[str, Any]
|
Provenance JSON. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of errors (empty if valid). |
Source code in py/cogant/gnn/validator.py
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 | |
validate_state_space(state_space_json)
Validate state space structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state_space_json
|
dict[str, Any]
|
State space JSON. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of errors (empty if valid). |
Source code in py/cogant/gnn/validator.py
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 | |
ValidationResult
Result of a GNN package validation.
Source code in py/cogant/gnn/validator.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 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 | |
warnings
property
Current public view of non-fatal validation advisories.
__init__(valid=False, errors=None, warnings=None, score=0.0, advisories=None, capabilities=None, artifact_digests=None, dimensions=None)
Initialize validation result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
valid
|
bool
|
Whether package is valid. |
False
|
errors
|
list[str] | None
|
List of error messages. |
None
|
warnings
|
list[str] | None
|
List of warning messages. |
None
|
score
|
float
|
Validation score 0-100. |
0.0
|
Source code in py/cogant/gnn/validator.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
badge_svg()
Generate SVG badge.
Source code in py/cogant/gnn/validator.py
165 166 167 168 169 170 171 172 173 | |
to_dict()
Convert to dictionary.
Source code in py/cogant/gnn/validator.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
to_markdown()
Generate a human-readable markdown report.
Returns:
| Type | Description |
|---|---|
str
|
A markdown string containing a formatted report of the |
str
|
validation result, including scores, errors, warnings, |
str
|
and section breakdowns. |
Source code in py/cogant/gnn/validator.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 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 | |
JSON export
cogant.gnn.json_export
GNN JSON exporter for machine-readable output.
Emits machine-readable JSON with IDs that are stable across sections and serialises every model component (graph, state space, process model, semantic mappings) in a single nested document.
GNNJSONExporter
Exports GNN models to machine-readable JSON format with stable IDs.
Source code in py/cogant/gnn/json_export.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 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 728 729 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 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 | |
__init__(program_graph, state_space_model, process_model, semantic_mappings)
Initialize the exporter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
program_graph
|
ProgramGraph
|
The program graph. |
required |
state_space_model
|
StateSpaceModel
|
The state space model. |
required |
process_model
|
ProcessModel
|
The process model. |
required |
semantic_mappings
|
dict[str, Any]
|
Semantic mappings dictionary. |
required |
Source code in py/cogant/gnn/json_export.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
export()
Export the complete GNN model as a JSON-serializable dictionary.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary ready for JSON serialization. |
Source code in py/cogant/gnn/json_export.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 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 | |
export_to_string(indent=2)
Export the model to a JSON string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indent
|
int | None
|
Number of spaces for indentation, or None for compact. |
2
|
Returns:
| Type | Description |
|---|---|
str
|
JSON string. |
Source code in py/cogant/gnn/json_export.py
192 193 194 195 196 197 198 199 200 201 202 203 | |
export_for_pymdp(bundle)
Export matrices in pymdp-compatible format.
Takes a GNN bundle containing A, B, C, D matrices and exports them in a format compatible with the PyMDP library, with matrices as JSON-serializable lists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bundle
|
dict[str, Any]
|
The GNN bundle dict containing matrices and metadata. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dict with keys "A", "B", "C", "D" containing the matrices |
dict[str, Any]
|
in pymdp format, plus metadata about shapes and truncation. |
Source code in py/cogant/gnn/json_export.py
938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 | |
export_summary(bundle)
Export a compact summary of the GNN bundle.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bundle
|
dict[str, Any]
|
The GNN bundle dict. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A compact dict with key metadata and matrix shapes suitable |
dict[str, Any]
|
for quick inspection. |
Source code in py/cogant/gnn/json_export.py
980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 | |
Upstream bridge
Thin facades to the optional, commit-pinned generalized-notation-notation package (cogant[upstream], GNN v5.1.0 release), which installs the top-level gnn package. COGANT callers should not import gnn directly: the bridge enforces GNN >= 4.0 and upstream ownership of gnn, keeps the heavy import lazy, and maps the facades onto the upstream GNN >= 4 API (validate_gnn_syntax, validate_gnn_source, check_gnn_file_structure). Use the re-exported symbols on cogant.gnn (run_upstream_validate_gnn, parse_upstream_model_gnn_md, run_upstream_pipeline, …) or the additional helpers in cogant.gnn.upstream_bridge (see py/cogant/gnn/AGENTS.md).
cogant.gnn.upstream_bridge
Integration with the Active Inference Institute generalized-notation-notation package.
The PyPI distribution name is generalized-notation-notation; since GNN 4.x
the installed wheel ships the top-level gnn package (the GNN 2.x
src.gnn import surface was removed upstream). This is an optional
COGANT extra (cogant[upstream]); the bridge requires GNN >= 4.0, whose
public API uses validate_gnn_syntax / validate_gnn_source /
check_gnn_file_structure (the GNN 2.x validate_gnn* aliases were
deleted upstream).
Upstream is CC-BY-NC-SA-4.0; see LICENSES.md at the package root.
All call sites use lazy importlib loading so importing cogant does not
eagerly initialize JAX/PyTorch until a bridge function runs.
Enable upstream validation explicitly with COGANT_ENABLE_UPSTREAM_GNN=1 or
the validator/pipeline/CLI option.
DEFAULT_SKIP_STEPS = frozenset({1, 2, 11, 12})
module-attribute
Steps suppressed by default (see the module docstring for rationale).
1_setup— upstream environment provisioning (mutates the caller's environment when run from an installed wheel).2_tests— upstream repository test suite (not shipped in the wheel).11_render— framework-specific simulation code generation.12_execute— runs the rendered simulations (heavy optional deps).
DEFAULT_VALIDATION_LEVEL = 'standard'
module-attribute
Upstream ValidationLevel used by :func:run_upstream_validate_gnn.
MIN_UPSTREAM_MAJOR = 4
module-attribute
Oldest upstream major release whose public API this bridge targets.
UPSTREAM_DISTRIBUTION = 'generalized-notation-notation'
module-attribute
PyPI distribution that provides the upstream gnn package.
UPSTREAM_IMPORT_NAME = 'gnn'
module-attribute
Top-level import package shipped by the upstream wheel (GNN >= 4.0).
UPSTREAM_STEP_SCRIPTS = ('0_template.py', '1_setup.py', '2_tests.py', '3_gnn.py', '4_model_registry.py', '5_type_checker.py', '6_validation.py', '7_export.py', '8_visualization.py', '9_advanced_viz.py', '10_ontology.py', '11_render.py', '12_execute.py', '13_llm.py', '14_ml_integration.py', '15_audio.py', '16_analysis.py', '17_integration.py', '18_security.py', '19_research.py', '20_website.py', '21_mcp.py', '22_gui.py', '23_report.py', '24_intelligent_analysis.py')
module-attribute
Canonical 25 numbered scripts in the upstream pipeline (steps 0 → 24).
Indexed by step number: UPSTREAM_STEP_SCRIPTS[3] == "3_gnn.py".
UpstreamGNNValidation
dataclass
Outcome of calling upstream validate_gnn_syntax on markdown content.
Source code in py/cogant/gnn/upstream_bridge/__init__.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
UpstreamPipelineConfig
dataclass
Inputs for :func:run_upstream_pipeline.
Attributes:
| Name | Type | Description |
|---|---|---|
target_dir |
Path
|
Directory containing the GNN markdown model (the COGANT
|
output_dir |
Path
|
Upstream output root (per-step sub-directories plus
|
only_steps |
list[int] | None
|
Restrict execution to these step indices. |
skip_steps |
list[int]
|
Step indices to drop. Defaults to
:data: |
frameworks |
str
|
Forwarded to upstream |
llm_model |
str | None
|
|
timesteps |
int
|
Forwarded to upstream |
verbose |
bool
|
Forwarded to upstream |
skip_llm |
bool
|
Forwarded to upstream |
timeout_s |
float
|
Bridge-level wall-clock ceiling for the invocation. |
Source code in py/cogant/gnn/upstream_bridge/pipeline.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | |
UpstreamPipelineResult
dataclass
Aggregated outcome of an upstream pipeline run.
Attributes:
| Name | Type | Description |
|---|---|---|
available |
bool
|
|
steps |
list[UpstreamStepResult]
|
Per-step results in execution order. |
executed |
list[int]
|
Step indices requested from upstream plus any it
auto-included (see |
skipped |
list[int]
|
Step indices that did not run. |
total_duration_s |
float
|
Wall-clock duration of the upstream invocation. |
output_dir |
str | None
|
Absolute path to the upstream output root. |
target_dir |
str | None
|
Absolute path to the GNN package directory used as input. |
error |
str | None
|
Bridge-level error (e.g. |
upstream_status |
str | None
|
Upstream |
run_id |
str | None
|
Upstream invocation ID ( |
auto_included |
list[int]
|
Steps upstream ran as declared prerequisites of the requested steps although the caller did not request them. |
Source code in py/cogant/gnn/upstream_bridge/pipeline.py
238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 | |
success_rate
property
Fraction of executed steps that succeeded; 0.0 for empty runs.
UpstreamStepResult
dataclass
Outcome of running a single upstream pipeline step.
Attributes:
| Name | Type | Description |
|---|---|---|
step_index |
int
|
Step number (0..24). |
script |
str
|
Script filename (e.g. |
status |
str
|
Upstream-reported status string
( |
success |
bool
|
|
duration_s |
float
|
Wall-clock duration in seconds. |
exit_code |
int
|
Subprocess exit code ( |
memory_delta_mb |
float
|
Resident-memory growth observed by upstream. |
output_dir |
str | None
|
Absolute path to the per-step output directory, when known. |
error |
str | None
|
Free-form error message when |
Source code in py/cogant/gnn/upstream_bridge/pipeline.py
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 | |
get_upstream_gnn_format_enum()
Return GNNFormat enum class from upstream.
Source code in py/cogant/gnn/upstream_bridge/__init__.py
344 345 346 347 | |
get_upstream_parsing_system()
Return a new GNNParsingSystem instance.
Source code in py/cogant/gnn/upstream_bridge/__init__.py
338 339 340 341 | |
is_upstream_gnn_available()
Return True if the upstream gnn package (GNN >= 4.0) imports successfully.
Source code in py/cogant/gnn/upstream_bridge/__init__.py
149 150 151 152 153 154 155 | |
json_safe(obj)
Best-effort JSON-serializable view of an upstream return value.
Source code in py/cogant/gnn/upstream_bridge/__init__.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | |
parse_upstream_model_gnn_md(package_dir)
Parse model.gnn.md inside a COGANT GNN package directory; JSON-safe summary.
Returns {"path", "parse"} on success. When the optional
cogant[upstream] extra is not installed (an expected configuration)
returns {"path", "error", "available": False} and logs only at debug
level; a genuine upstream parse failure returns {"path", "error"} and
logs a warning with the traceback.
Source code in py/cogant/gnn/upstream_bridge/__init__.py
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | |
resolve_steps(only, skip)
Return the ordered list of step indices to execute.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
only
|
list[int] | None
|
When set, restrict to these step indices (preserving canonical
order). When |
required |
skip
|
list[int] | None
|
Step indices to drop after applying |
required |
Returns:
| Type | Description |
|---|---|
list[int]
|
Sorted list of integers in |
Examples:
>>> resolve_steps(None, [11, 12])
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24]
>>> resolve_steps([3, 5, 7], None)
[3, 5, 7]
>>> resolve_steps([3, 5, 7], [5])
[3, 7]
Source code in py/cogant/gnn/upstream_bridge/pipeline.py
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 | |
run_upstream_pipeline(cfg)
Execute the configured subset of upstream pipeline steps.
Issues one python -m gnn.main --only-steps … invocation against a
staged copy of the package's GNN markdown, then reads per-step outcomes
from the upstream run summary. One failing step does not abort the run
(upstream continues past non-critical failures); bridge-level problems —
timeout, a crashed invocation, a missing summary — are reported per
requested step with status TIMEOUT / BRIDGE_ERROR and on
:attr:UpstreamPipelineResult.error. The upstream console log is written
to <output_dir>/upstream_pipeline.log and the bridge summary to
<output_dir>/upstream_pipeline_summary.json.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cfg
|
UpstreamPipelineConfig
|
Pipeline configuration. |
required |
Returns:
| Type | Description |
|---|---|
UpstreamPipelineResult
|
class: |
UpstreamPipelineResult
|
per requested step. |
Source code in py/cogant/gnn/upstream_bridge/pipeline.py
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 728 729 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 | |
run_upstream_validate_gnn(markdown, *, validation_level=DEFAULT_VALIDATION_LEVEL)
Run upstream validate_gnn_syntax on GNN markdown.
Upstream gnn.validate_gnn_syntax delegates to the formal
schema_validator pipeline: every required section must be present with
substantive content, and (at standard and above) connection endpoints
must reference declared variables. The markdown is staged to a temporary
.gnn.md file so the verdict never depends on upstream's
path-versus-content probe of the input string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
markdown
|
str
|
GNN markdown document. |
required |
validation_level
|
str
|
Upstream |
DEFAULT_VALIDATION_LEVEL
|
Source code in py/cogant/gnn/upstream_bridge/__init__.py
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 | |
upstream_discover_files(root)
Call upstream discover_gnn_files.
Source code in py/cogant/gnn/upstream_bridge/__init__.py
271 272 273 274 | |
upstream_generate_report(*args, **kwargs)
Call upstream generate_gnn_report.
Source code in py/cogant/gnn/upstream_bridge/__init__.py
297 298 299 300 | |
upstream_module_info(*args, **kwargs)
Call upstream get_module_info.
Source code in py/cogant/gnn/upstream_bridge/__init__.py
309 310 311 312 | |
upstream_parse_file(path)
Call upstream parse_gnn_file.
Source code in py/cogant/gnn/upstream_bridge/__init__.py
265 266 267 268 | |
upstream_parse_formal(*args, **kwargs)
Call upstream parse_gnn_formal.
Source code in py/cogant/gnn/upstream_bridge/__init__.py
326 327 328 329 | |
upstream_process_directory(input_dir, output_dir, **kwargs)
Call upstream process_gnn_directory.
Source code in py/cogant/gnn/upstream_bridge/__init__.py
277 278 279 280 281 282 283 284 | |
upstream_process_directory_lightweight(input_dir, output_dir, **kwargs)
Call upstream process_gnn_directory_lightweight.
Source code in py/cogant/gnn/upstream_bridge/__init__.py
287 288 289 290 291 292 293 294 | |
upstream_process_multi_format(input_dir, output_dir, log=None, **kwargs)
Call upstream process_gnn_multi_format (may import upstream pipeline helpers).
Source code in py/cogant/gnn/upstream_bridge/__init__.py
315 316 317 318 319 320 321 322 323 | |
upstream_validate_file_content(content, *, is_content=True)
Call upstream validate_gnn_source (path or raw content).
Source code in py/cogant/gnn/upstream_bridge/__init__.py
251 252 253 254 255 256 257 258 259 260 261 262 | |
upstream_validate_markdown(markdown)
Alias for :func:run_upstream_validate_gnn.
Source code in py/cogant/gnn/upstream_bridge/__init__.py
246 247 248 | |
upstream_validate_structure(*args, **kwargs)
Call upstream check_gnn_file_structure (GNN 2.x validate_gnn_structure).
Source code in py/cogant/gnn/upstream_bridge/__init__.py
303 304 305 306 | |
upstream_validate_syntax_formal(*args, **kwargs)
Call upstream validate_gnn_syntax (GNN 2.x validate_gnn_syntax_formal).
Source code in py/cogant/gnn/upstream_bridge/__init__.py
332 333 334 335 | |
upstream_version()
Return the upstream gnn.__version__ if available.
Source code in py/cogant/gnn/upstream_bridge/__init__.py
158 159 160 161 162 163 164 165 | |
Examples
Every public symbol exported by cogant.gnn (GNNPackageBuilder, GNNValidator, the matrix builder, the runner, the JSON exporter, and upstream bridge helpers) is exercised by the following references:
- Zoo:
examples/zoo/01_simple_state/— produces the smallest valid on-disk package (1 hidden state, 0 observations). - Zoo:
examples/zoo/04_pomdp_minimal/— produces a complete A / B / C / D quadruple via the matrix builder. - Zoo:
examples/zoo/12_full_pomdp/— full validator score = 100 / 100 reference. - Cookbook: Recipe 14: Validating a hand-written GNN against AII spec —
GNNValidatorwalk-through. - Cookbook: Recipe: Interpret GNN output — reading A / B / C / D from a real bundle.
- Tutorial: Tutorial 5: Reading the A / B / C / D matrices — full narrative on the matrix builder + validator.