pytpg 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. pytpg-0.5.0/.github/workflows/ci.yml +53 -0
  2. pytpg-0.5.0/.github/workflows/publish.yml +84 -0
  3. pytpg-0.5.0/.gitignore +13 -0
  4. pytpg-0.5.0/CONTRIBUTING.md +37 -0
  5. pytpg-0.5.0/LICENSE +21 -0
  6. pytpg-0.5.0/PKG-INFO +211 -0
  7. pytpg-0.5.0/README.md +176 -0
  8. pytpg-0.5.0/docs/architecture.md +179 -0
  9. pytpg-0.5.0/docs/release.md +52 -0
  10. pytpg-0.5.0/docs/specification/README.md +23 -0
  11. pytpg-0.5.0/docs/specification/evolution.md +81 -0
  12. pytpg-0.5.0/docs/specification/graph.md +85 -0
  13. pytpg-0.5.0/docs/specification/gymnasium-integration.md +89 -0
  14. pytpg-0.5.0/docs/specification/instructions-and-programs.md +86 -0
  15. pytpg-0.5.0/docs/specification/learners-teams-actions.md +50 -0
  16. pytpg-0.5.0/docs/specification/multi-agent.md +94 -0
  17. pytpg-0.5.0/docs/specification/mutation.md +64 -0
  18. pytpg-0.5.0/docs/specification/object-model.md +57 -0
  19. pytpg-0.5.0/docs/specification/open-questions.md +98 -0
  20. pytpg-0.5.0/docs/specification/research-infrastructure.md +103 -0
  21. pytpg-0.5.0/docs/specification/stateful-memory.md +98 -0
  22. pytpg-0.5.0/examples/evolve_bandit.py +42 -0
  23. pytpg-0.5.0/examples/evolve_cartpole.py +61 -0
  24. pytpg-0.5.0/examples/manual_graph.py +63 -0
  25. pytpg-0.5.0/examples/manual_team.py +42 -0
  26. pytpg-0.5.0/examples/multiagent_control.py +80 -0
  27. pytpg-0.5.0/examples/reproducible_experiment.py +38 -0
  28. pytpg-0.5.0/examples/stateful_delayed_signal.py +76 -0
  29. pytpg-0.5.0/pyproject.toml +74 -0
  30. pytpg-0.5.0/src/pytpg/__init__.py +7 -0
  31. pytpg-0.5.0/src/pytpg/adapters/__init__.py +43 -0
  32. pytpg-0.5.0/src/pytpg/adapters/errors.py +40 -0
  33. pytpg-0.5.0/src/pytpg/adapters/gymnasium.py +360 -0
  34. pytpg-0.5.0/src/pytpg/adapters/gymnasium_evaluation.py +231 -0
  35. pytpg-0.5.0/src/pytpg/callbacks/__init__.py +16 -0
  36. pytpg-0.5.0/src/pytpg/callbacks/base.py +104 -0
  37. pytpg-0.5.0/src/pytpg/callbacks/logging.py +52 -0
  38. pytpg-0.5.0/src/pytpg/config.py +197 -0
  39. pytpg-0.5.0/src/pytpg/core/__init__.py +45 -0
  40. pytpg-0.5.0/src/pytpg/core/_validation.py +9 -0
  41. pytpg-0.5.0/src/pytpg/core/action.py +44 -0
  42. pytpg-0.5.0/src/pytpg/core/graph.py +160 -0
  43. pytpg-0.5.0/src/pytpg/core/identifiers.py +22 -0
  44. pytpg-0.5.0/src/pytpg/core/instruction.py +99 -0
  45. pytpg-0.5.0/src/pytpg/core/learner.py +27 -0
  46. pytpg-0.5.0/src/pytpg/core/program.py +27 -0
  47. pytpg-0.5.0/src/pytpg/core/team.py +60 -0
  48. pytpg-0.5.0/src/pytpg/evaluation/__init__.py +20 -0
  49. pytpg-0.5.0/src/pytpg/evaluation/evaluator.py +52 -0
  50. pytpg-0.5.0/src/pytpg/evaluation/statistics.py +222 -0
  51. pytpg-0.5.0/src/pytpg/evaluation/toy.py +102 -0
  52. pytpg-0.5.0/src/pytpg/evolution/__init__.py +81 -0
  53. pytpg-0.5.0/src/pytpg/evolution/_ids.py +51 -0
  54. pytpg-0.5.0/src/pytpg/evolution/engine.py +227 -0
  55. pytpg-0.5.0/src/pytpg/evolution/errors.py +25 -0
  56. pytpg-0.5.0/src/pytpg/evolution/genome.py +186 -0
  57. pytpg-0.5.0/src/pytpg/evolution/initialization.py +129 -0
  58. pytpg-0.5.0/src/pytpg/evolution/mutation/__init__.py +35 -0
  59. pytpg-0.5.0/src/pytpg/evolution/mutation/_utils.py +59 -0
  60. pytpg-0.5.0/src/pytpg/evolution/mutation/base.py +90 -0
  61. pytpg-0.5.0/src/pytpg/evolution/mutation/defaults.py +119 -0
  62. pytpg-0.5.0/src/pytpg/evolution/mutation/instruction.py +137 -0
  63. pytpg-0.5.0/src/pytpg/evolution/mutation/learner.py +176 -0
  64. pytpg-0.5.0/src/pytpg/evolution/mutation/team.py +162 -0
  65. pytpg-0.5.0/src/pytpg/evolution/population.py +123 -0
  66. pytpg-0.5.0/src/pytpg/evolution/reproduction.py +124 -0
  67. pytpg-0.5.0/src/pytpg/evolution/rng.py +38 -0
  68. pytpg-0.5.0/src/pytpg/evolution/selection.py +78 -0
  69. pytpg-0.5.0/src/pytpg/experiment.py +140 -0
  70. pytpg-0.5.0/src/pytpg/memory/__init__.py +34 -0
  71. pytpg-0.5.0/src/pytpg/memory/_validation.py +48 -0
  72. pytpg-0.5.0/src/pytpg/memory/base.py +123 -0
  73. pytpg-0.5.0/src/pytpg/memory/errors.py +16 -0
  74. pytpg-0.5.0/src/pytpg/memory/history.py +53 -0
  75. pytpg-0.5.0/src/pytpg/memory/null.py +33 -0
  76. pytpg-0.5.0/src/pytpg/memory/register.py +104 -0
  77. pytpg-0.5.0/src/pytpg/memory/stateful.py +142 -0
  78. pytpg-0.5.0/src/pytpg/metadata.py +129 -0
  79. pytpg-0.5.0/src/pytpg/multiagent/__init__.py +31 -0
  80. pytpg-0.5.0/src/pytpg/multiagent/_validation.py +102 -0
  81. pytpg-0.5.0/src/pytpg/multiagent/codec.py +82 -0
  82. pytpg-0.5.0/src/pytpg/multiagent/controller.py +159 -0
  83. pytpg-0.5.0/src/pytpg/multiagent/errors.py +30 -0
  84. pytpg-0.5.0/src/pytpg/multiagent/independent.py +191 -0
  85. pytpg-0.5.0/src/pytpg/multiagent/model.py +74 -0
  86. pytpg-0.5.0/src/pytpg/multiagent/shared.py +197 -0
  87. pytpg-0.5.0/src/pytpg/py.typed +1 -0
  88. pytpg-0.5.0/src/pytpg/runtime/__init__.py +84 -0
  89. pytpg-0.5.0/src/pytpg/runtime/_model.py +115 -0
  90. pytpg-0.5.0/src/pytpg/runtime/config.py +40 -0
  91. pytpg-0.5.0/src/pytpg/runtime/errors.py +70 -0
  92. pytpg-0.5.0/src/pytpg/runtime/executor.py +176 -0
  93. pytpg-0.5.0/src/pytpg/runtime/graph_runtime.py +244 -0
  94. pytpg-0.5.0/src/pytpg/runtime/graph_validation.py +368 -0
  95. pytpg-0.5.0/src/pytpg/runtime/inference.py +46 -0
  96. pytpg-0.5.0/src/pytpg/runtime/inspection.py +116 -0
  97. pytpg-0.5.0/src/pytpg/runtime/operators.py +135 -0
  98. pytpg-0.5.0/src/pytpg/runtime/registers.py +60 -0
  99. pytpg-0.5.0/src/pytpg/runtime/team_runtime.py +76 -0
  100. pytpg-0.5.0/src/pytpg/seed.py +48 -0
  101. pytpg-0.5.0/src/pytpg/serialization/__init__.py +57 -0
  102. pytpg-0.5.0/src/pytpg/serialization/_validation.py +71 -0
  103. pytpg-0.5.0/src/pytpg/serialization/checkpoint.py +392 -0
  104. pytpg-0.5.0/src/pytpg/serialization/errors.py +25 -0
  105. pytpg-0.5.0/src/pytpg/serialization/graph.py +317 -0
  106. pytpg-0.5.0/src/pytpg/serialization/io.py +74 -0
  107. pytpg-0.5.0/src/pytpg/serialization/rng.py +104 -0
  108. pytpg-0.5.0/tests/adapters/test_gymnasium_adapter.py +239 -0
  109. pytpg-0.5.0/tests/adapters/test_gymnasium_evaluation.py +326 -0
  110. pytpg-0.5.0/tests/core/test_model.py +74 -0
  111. pytpg-0.5.0/tests/evolution/test_engine.py +268 -0
  112. pytpg-0.5.0/tests/evolution/test_initialization.py +109 -0
  113. pytpg-0.5.0/tests/evolution/test_mutation.py +303 -0
  114. pytpg-0.5.0/tests/evolution/test_population_selection.py +132 -0
  115. pytpg-0.5.0/tests/memory/test_memory.py +179 -0
  116. pytpg-0.5.0/tests/memory/test_stateful_runtime.py +202 -0
  117. pytpg-0.5.0/tests/multiagent/test_codec_model.py +77 -0
  118. pytpg-0.5.0/tests/multiagent/test_independent_runtime.py +169 -0
  119. pytpg-0.5.0/tests/multiagent/test_shared_control.py +140 -0
  120. pytpg-0.5.0/tests/research/test_callbacks_statistics.py +126 -0
  121. pytpg-0.5.0/tests/research/test_checkpoint_resume.py +197 -0
  122. pytpg-0.5.0/tests/research/test_config_seed_metadata.py +149 -0
  123. pytpg-0.5.0/tests/research/test_graph_serialization.py +136 -0
  124. pytpg-0.5.0/tests/research/test_research_validation.py +274 -0
  125. pytpg-0.5.0/tests/runtime/test_executor.py +228 -0
  126. pytpg-0.5.0/tests/runtime/test_graph_runtime.py +200 -0
  127. pytpg-0.5.0/tests/runtime/test_graph_validation.py +158 -0
  128. pytpg-0.5.0/tests/runtime/test_inspection.py +88 -0
  129. pytpg-0.5.0/tests/runtime/test_operators.py +98 -0
  130. pytpg-0.5.0/tests/runtime/test_registers.py +44 -0
  131. pytpg-0.5.0/tests/runtime/test_team_runtime.py +149 -0
  132. pytpg-0.5.0/tests/test_architecture.py +115 -0
  133. pytpg-0.5.0/tests/test_distribution.py +69 -0
  134. pytpg-0.5.0/tests/test_imports.py +246 -0
@@ -0,0 +1,53 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ permissions:
8
+ contents: read
9
+
10
+ jobs:
11
+ tests:
12
+ name: Tests (Python ${{ matrix.python-version }})
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ fail-fast: false
16
+ matrix:
17
+ python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
18
+ steps:
19
+ - uses: actions/checkout@v6
20
+ with:
21
+ persist-credentials: false
22
+ - uses: actions/setup-python@v6
23
+ with:
24
+ python-version: ${{ matrix.python-version }}
25
+ cache: pip
26
+ - name: Install package and test dependencies
27
+ run: python -m pip install -e ".[dev,gymnasium]"
28
+ - name: Test (including installed distribution)
29
+ run: python -m pytest
30
+
31
+ quality-release-check:
32
+ name: Quality and release checks
33
+ runs-on: ubuntu-latest
34
+ steps:
35
+ - uses: actions/checkout@v6
36
+ with:
37
+ persist-credentials: false
38
+ - uses: actions/setup-python@v6
39
+ with:
40
+ python-version: "3.14"
41
+ cache: pip
42
+ - name: Install package and development dependencies
43
+ run: python -m pip install -e ".[dev,gymnasium]"
44
+ - name: Lint
45
+ run: python -m ruff check .
46
+ - name: Type check
47
+ run: python -m pyright
48
+ - name: Test (including installed distribution)
49
+ run: python -m pytest
50
+ - name: Build source distribution and wheel
51
+ run: python -m build
52
+ - name: Check distribution metadata
53
+ run: python -m twine check dist/*
@@ -0,0 +1,84 @@
1
+ name: Publish pyTPG
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ push:
6
+ tags:
7
+ - "v*"
8
+
9
+ jobs:
10
+ build:
11
+ name: Build distributions
12
+ runs-on: ubuntu-latest
13
+
14
+ steps:
15
+ - uses: actions/checkout@v6
16
+ with:
17
+ persist-credentials: false
18
+
19
+ - name: Set up Python
20
+ uses: actions/setup-python@v6
21
+ with:
22
+ python-version: "3.x"
23
+
24
+ - name: Install build
25
+ run: python -m pip install build
26
+
27
+ - name: Build distributions
28
+ run: python -m build
29
+
30
+ - name: Store distributions
31
+ uses: actions/upload-artifact@v5
32
+ with:
33
+ name: python-package-distributions
34
+ path: dist/
35
+
36
+ publish-testpypi:
37
+ name: Publish to TestPyPI
38
+ if: github.event_name == 'workflow_dispatch'
39
+ needs:
40
+ - build
41
+ runs-on: ubuntu-latest
42
+
43
+ environment:
44
+ name: testpypi
45
+ url: https://test.pypi.org/p/pytpg
46
+
47
+ permissions:
48
+ id-token: write
49
+
50
+ steps:
51
+ - name: Download distributions
52
+ uses: actions/download-artifact@v6
53
+ with:
54
+ name: python-package-distributions
55
+ path: dist/
56
+
57
+ - name: Publish to TestPyPI
58
+ uses: pypa/gh-action-pypi-publish@release/v1
59
+ with:
60
+ repository-url: https://test.pypi.org/legacy/
61
+
62
+ publish-pypi:
63
+ name: Publish to PyPI
64
+ if: startsWith(github.ref, 'refs/tags/v')
65
+ needs:
66
+ - build
67
+ runs-on: ubuntu-latest
68
+
69
+ environment:
70
+ name: pypi
71
+ url: https://pypi.org/p/pytpg
72
+
73
+ permissions:
74
+ id-token: write
75
+
76
+ steps:
77
+ - name: Download distributions
78
+ uses: actions/download-artifact@v6
79
+ with:
80
+ name: python-package-distributions
81
+ path: dist/
82
+
83
+ - name: Publish to PyPI
84
+ uses: pypa/gh-action-pypi-publish@release/v1
pytpg-0.5.0/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ .coverage
5
+ .pytest_cache/
6
+ .ruff_cache/
7
+ .mypy_cache/
8
+ .pyright/
9
+ .venv/
10
+ build/
11
+ dist/
12
+ htmlcov/
13
+
@@ -0,0 +1,37 @@
1
+ # Contributing
2
+
3
+ pyTPG is specification-first research software. A change to algorithm behavior
4
+ must update the relevant document under `docs/specification/` in the same pull
5
+ request. Tests should assert semantics, not only benchmark performance.
6
+
7
+ Core dependencies must point inward:
8
+
9
+ ```text
10
+ application/environment -> adapter -> training/evolution -> core -> runtime
11
+ ```
12
+
13
+ The core and runtime must not import environment integrations. Optional
14
+ integrations must not become required package dependencies.
15
+
16
+ Before submitting a change, run:
17
+
18
+ ```bash
19
+ ruff check .
20
+ pyright
21
+ pytest
22
+ python -m build
23
+ python -m twine check dist/*
24
+ ```
25
+
26
+ Install development dependencies with `python -m pip install -e ".[dev]"`.
27
+ The distribution test also requires pip and builds an installed-wheel smoke test.
28
+ See [release preparation](docs/release.md) for compatibility and licensing.
29
+
30
+ Milestone 7 intentionally uses a fixed synchronous agent roster. Independent
31
+ controllers isolate live episode state; centralized shared control concatenates
32
+ observations and uses a mixed-radix scalar joint action. Dynamic or turn-based
33
+ rosters, per-agent early termination, PettingZoo integration, partial
34
+ observations, continuous/composite actions, coevolution, credit assignment,
35
+ centralized-training/decentralized-execution, parallel evaluation, persistent
36
+ genealogy, custom-operator schema registration, and serialization migrations
37
+ remain outside this milestone.
pytpg-0.5.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 pyTPG contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
pytpg-0.5.0/PKG-INFO ADDED
@@ -0,0 +1,211 @@
1
+ Metadata-Version: 2.5
2
+ Name: pytpg
3
+ Version: 0.5.0
4
+ Summary: A modular research framework for Tangled Program Graphs
5
+ Project-URL: Homepage, https://github.com/ramsayxiaoshao/pyTPG
6
+ Project-URL: Repository, https://github.com/ramsayxiaoshao/pyTPG
7
+ Project-URL: Documentation, https://github.com/ramsayxiaoshao/pyTPG/tree/main/docs
8
+ Project-URL: Issues, https://github.com/ramsayxiaoshao/pyTPG/issues
9
+ Author: pyTPG contributors
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: evolutionary-computation,reinforcement-learning,tangled-program-graphs
13
+ Classifier: Development Status :: 2 - Pre-Alpha
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.10
23
+ Requires-Dist: numpy>=2.0
24
+ Provides-Extra: dev
25
+ Requires-Dist: build>=1.2; extra == 'dev'
26
+ Requires-Dist: hatchling>=1.26; extra == 'dev'
27
+ Requires-Dist: pyright[nodejs]>=1.1.380; extra == 'dev'
28
+ Requires-Dist: pytest-cov>=5.0; extra == 'dev'
29
+ Requires-Dist: pytest>=8.0; extra == 'dev'
30
+ Requires-Dist: ruff>=0.6; extra == 'dev'
31
+ Requires-Dist: twine>=6.1; extra == 'dev'
32
+ Provides-Extra: gymnasium
33
+ Requires-Dist: gymnasium<2,>=1.0; extra == 'gymnasium'
34
+ Description-Content-Type: text/markdown
35
+
36
+ # pyTPG
37
+
38
+ ## What is TPG?
39
+
40
+ pyTPG is a modular research framework for Tangled Program Graphs
41
+ (TPG). The project is being developed specification-first so that algorithmic
42
+ choices are explicit, testable, and reproducible.
43
+
44
+ The repository currently contains **Milestone 7**: deterministic runtime and
45
+ evolution, reproducible research infrastructure, optional Gymnasium integration,
46
+ episode-scoped stateful TPG, and deterministic multi-agent composition.
47
+
48
+ ## Installation
49
+
50
+ Requires Python 3.10 or newer. After the first public release, install with:
51
+
52
+ ```bash
53
+ pip install pytpg
54
+ ```
55
+
56
+ For development from a checkout:
57
+
58
+ ```bash
59
+ python -m pip install -e ".[dev]"
60
+ ```
61
+
62
+ Install the optional Gymnasium integration with:
63
+
64
+ ```bash
65
+ python -m pip install "pytpg[gymnasium]"
66
+ ```
67
+
68
+ The PyPI distribution and Python import namespace are both `pytpg`.
69
+ The GitHub project name is pyTPG.
70
+
71
+ Code using the previous `tpg` namespace must update imports to `pytpg`;
72
+ no compatibility alias is provided. See [release notes](docs/release.md).
73
+
74
+ ## Minimal example
75
+
76
+ The following manually constructs and executes a one-team TPG graph:
77
+
78
+ ```python
79
+ from pytpg.core import (
80
+ ActionID,
81
+ AtomicAction,
82
+ ConstantOperand,
83
+ InputIndex,
84
+ InputOperand,
85
+ Instruction,
86
+ Learner,
87
+ LearnerID,
88
+ OperatorName,
89
+ Program,
90
+ ProgramID,
91
+ RegisterIndex,
92
+ Team,
93
+ TeamID,
94
+ TPGGraph,
95
+ )
96
+
97
+ instruction = Instruction(
98
+ operator=OperatorName("multiply"),
99
+ destination=RegisterIndex(0),
100
+ operands=(InputOperand(InputIndex(0)), ConstantOperand(2.0)),
101
+ )
102
+ program = Program(ProgramID(0), (instruction,))
103
+ learner = Learner(LearnerID(0), program, AtomicAction(ActionID(0)))
104
+ team = Team(TeamID(0), (learner,))
105
+ graph = TPGGraph((team,), (team.id,))
106
+
107
+ action = graph.act((0.75,))
108
+ assert action == ActionID(0)
109
+ ```
110
+
111
+ For recorded experiments, pass an explicit `GraphRuntime(RuntimeConfig(...))`
112
+ rather than relying on the shape inference provided by `graph.act`.
113
+
114
+ ## Main features
115
+
116
+ - Explicit core concepts rather than trainer-owned dictionaries.
117
+ - Immutable value objects and typed identifiers.
118
+ - Environment-independent core architecture.
119
+ - Extensible operator registry with protected deterministic arithmetic.
120
+ - Strict observation, register, instruction, and operator validation.
121
+ - Stable raw-bid selection with deterministic tie-breaking.
122
+ - Validated Team-reference traversal with cycle and step-limit safety.
123
+ - Graph diagnostics, traversal traces, and structural summaries.
124
+ - Explicit NumPy RNG ownership and fixed-seed reproducibility.
125
+ - Valid connected population initialization and finite scalar evaluation.
126
+ - Stable tournament selection, elitism, and mutation-only reproduction.
127
+ - Eight focused clone-on-write mutation operators with invariant validation.
128
+ - Inspectable parent and mutation records for each offspring generation.
129
+ - Canonical experiment configuration digests and named RNG streams.
130
+ - Structured lifecycle callbacks, standard logging, and generation statistics.
131
+ - Recorded Python/NumPy/package/platform experiment metadata.
132
+ - Versioned JSON graph serialization and evaluated-boundary checkpoints.
133
+ - Exact deterministic continuation without re-evaluating saved fitness.
134
+ - Lazy optional Gymnasium integration with no environment dependency in core.
135
+ - Reproducible multi-episode fitness with common seeds and a hard rollout bound.
136
+ - Strict modern `terminated`/`truncated` handling and Discrete action mapping.
137
+ - Explicit memory reset, snapshot, restore, and atomic update contracts.
138
+ - Null, fixed-register, and oldest-to-newest observation-history memory.
139
+ - Stateful traversal by observation augmentation without duplicated graph logic.
140
+ - Independent and heterogeneous controllers with transactional joint steps.
141
+ - Safe immutable-graph parameter sharing with per-agent episode state.
142
+ - Centralized shared control with mixed-radix heterogeneous joint actions.
143
+
144
+ ## Documentation
145
+
146
+ - [Architecture](docs/architecture.md)
147
+ - [Specification index](docs/specification/README.md)
148
+ - [Open algorithmic questions](docs/specification/open-questions.md)
149
+
150
+ ## Examples
151
+
152
+ Run the manual deterministic-team example with:
153
+
154
+ ```bash
155
+ python examples/manual_team.py
156
+ ```
157
+
158
+ Run the cyclic graph traversal example with:
159
+
160
+ ```bash
161
+ python examples/manual_graph.py
162
+ ```
163
+
164
+ Run a fixed-seed toy evolution with:
165
+
166
+ ```bash
167
+ python examples/evolve_bandit.py
168
+ ```
169
+
170
+ Run, save, load, and resume a reproducible experiment with:
171
+
172
+ ```bash
173
+ python examples/reproducible_experiment.py
174
+ ```
175
+
176
+ After installing the Gymnasium extra, run the small CartPole evolution with:
177
+
178
+ ```bash
179
+ python examples/evolve_cartpole.py
180
+ ```
181
+
182
+ Run the three-step delayed-signal memory example with:
183
+
184
+ ```bash
185
+ python examples/stateful_delayed_signal.py
186
+ ```
187
+
188
+ Run heterogeneous independent and centralized shared control with:
189
+
190
+ ```bash
191
+ python examples/multiagent_control.py
192
+ ```
193
+
194
+ ## Development status
195
+
196
+ Current version: `0.5.0` (Milestone 7, multi-agent TPG, pre-alpha).
197
+
198
+ Run the local checks with:
199
+
200
+ ```bash
201
+ ruff check .
202
+ pyright
203
+ pytest
204
+ python -m build
205
+ ```
206
+
207
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for the development boundaries.
208
+
209
+ ## License
210
+
211
+ MIT licensed. Copyright (c) 2026 pyTPG contributors. See [LICENSE](LICENSE).
pytpg-0.5.0/README.md ADDED
@@ -0,0 +1,176 @@
1
+ # pyTPG
2
+
3
+ ## What is TPG?
4
+
5
+ pyTPG is a modular research framework for Tangled Program Graphs
6
+ (TPG). The project is being developed specification-first so that algorithmic
7
+ choices are explicit, testable, and reproducible.
8
+
9
+ The repository currently contains **Milestone 7**: deterministic runtime and
10
+ evolution, reproducible research infrastructure, optional Gymnasium integration,
11
+ episode-scoped stateful TPG, and deterministic multi-agent composition.
12
+
13
+ ## Installation
14
+
15
+ Requires Python 3.10 or newer. After the first public release, install with:
16
+
17
+ ```bash
18
+ pip install pytpg
19
+ ```
20
+
21
+ For development from a checkout:
22
+
23
+ ```bash
24
+ python -m pip install -e ".[dev]"
25
+ ```
26
+
27
+ Install the optional Gymnasium integration with:
28
+
29
+ ```bash
30
+ python -m pip install "pytpg[gymnasium]"
31
+ ```
32
+
33
+ The PyPI distribution and Python import namespace are both `pytpg`.
34
+ The GitHub project name is pyTPG.
35
+
36
+ Code using the previous `tpg` namespace must update imports to `pytpg`;
37
+ no compatibility alias is provided. See [release notes](docs/release.md).
38
+
39
+ ## Minimal example
40
+
41
+ The following manually constructs and executes a one-team TPG graph:
42
+
43
+ ```python
44
+ from pytpg.core import (
45
+ ActionID,
46
+ AtomicAction,
47
+ ConstantOperand,
48
+ InputIndex,
49
+ InputOperand,
50
+ Instruction,
51
+ Learner,
52
+ LearnerID,
53
+ OperatorName,
54
+ Program,
55
+ ProgramID,
56
+ RegisterIndex,
57
+ Team,
58
+ TeamID,
59
+ TPGGraph,
60
+ )
61
+
62
+ instruction = Instruction(
63
+ operator=OperatorName("multiply"),
64
+ destination=RegisterIndex(0),
65
+ operands=(InputOperand(InputIndex(0)), ConstantOperand(2.0)),
66
+ )
67
+ program = Program(ProgramID(0), (instruction,))
68
+ learner = Learner(LearnerID(0), program, AtomicAction(ActionID(0)))
69
+ team = Team(TeamID(0), (learner,))
70
+ graph = TPGGraph((team,), (team.id,))
71
+
72
+ action = graph.act((0.75,))
73
+ assert action == ActionID(0)
74
+ ```
75
+
76
+ For recorded experiments, pass an explicit `GraphRuntime(RuntimeConfig(...))`
77
+ rather than relying on the shape inference provided by `graph.act`.
78
+
79
+ ## Main features
80
+
81
+ - Explicit core concepts rather than trainer-owned dictionaries.
82
+ - Immutable value objects and typed identifiers.
83
+ - Environment-independent core architecture.
84
+ - Extensible operator registry with protected deterministic arithmetic.
85
+ - Strict observation, register, instruction, and operator validation.
86
+ - Stable raw-bid selection with deterministic tie-breaking.
87
+ - Validated Team-reference traversal with cycle and step-limit safety.
88
+ - Graph diagnostics, traversal traces, and structural summaries.
89
+ - Explicit NumPy RNG ownership and fixed-seed reproducibility.
90
+ - Valid connected population initialization and finite scalar evaluation.
91
+ - Stable tournament selection, elitism, and mutation-only reproduction.
92
+ - Eight focused clone-on-write mutation operators with invariant validation.
93
+ - Inspectable parent and mutation records for each offspring generation.
94
+ - Canonical experiment configuration digests and named RNG streams.
95
+ - Structured lifecycle callbacks, standard logging, and generation statistics.
96
+ - Recorded Python/NumPy/package/platform experiment metadata.
97
+ - Versioned JSON graph serialization and evaluated-boundary checkpoints.
98
+ - Exact deterministic continuation without re-evaluating saved fitness.
99
+ - Lazy optional Gymnasium integration with no environment dependency in core.
100
+ - Reproducible multi-episode fitness with common seeds and a hard rollout bound.
101
+ - Strict modern `terminated`/`truncated` handling and Discrete action mapping.
102
+ - Explicit memory reset, snapshot, restore, and atomic update contracts.
103
+ - Null, fixed-register, and oldest-to-newest observation-history memory.
104
+ - Stateful traversal by observation augmentation without duplicated graph logic.
105
+ - Independent and heterogeneous controllers with transactional joint steps.
106
+ - Safe immutable-graph parameter sharing with per-agent episode state.
107
+ - Centralized shared control with mixed-radix heterogeneous joint actions.
108
+
109
+ ## Documentation
110
+
111
+ - [Architecture](docs/architecture.md)
112
+ - [Specification index](docs/specification/README.md)
113
+ - [Open algorithmic questions](docs/specification/open-questions.md)
114
+
115
+ ## Examples
116
+
117
+ Run the manual deterministic-team example with:
118
+
119
+ ```bash
120
+ python examples/manual_team.py
121
+ ```
122
+
123
+ Run the cyclic graph traversal example with:
124
+
125
+ ```bash
126
+ python examples/manual_graph.py
127
+ ```
128
+
129
+ Run a fixed-seed toy evolution with:
130
+
131
+ ```bash
132
+ python examples/evolve_bandit.py
133
+ ```
134
+
135
+ Run, save, load, and resume a reproducible experiment with:
136
+
137
+ ```bash
138
+ python examples/reproducible_experiment.py
139
+ ```
140
+
141
+ After installing the Gymnasium extra, run the small CartPole evolution with:
142
+
143
+ ```bash
144
+ python examples/evolve_cartpole.py
145
+ ```
146
+
147
+ Run the three-step delayed-signal memory example with:
148
+
149
+ ```bash
150
+ python examples/stateful_delayed_signal.py
151
+ ```
152
+
153
+ Run heterogeneous independent and centralized shared control with:
154
+
155
+ ```bash
156
+ python examples/multiagent_control.py
157
+ ```
158
+
159
+ ## Development status
160
+
161
+ Current version: `0.5.0` (Milestone 7, multi-agent TPG, pre-alpha).
162
+
163
+ Run the local checks with:
164
+
165
+ ```bash
166
+ ruff check .
167
+ pyright
168
+ pytest
169
+ python -m build
170
+ ```
171
+
172
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for the development boundaries.
173
+
174
+ ## License
175
+
176
+ MIT licensed. Copyright (c) 2026 pyTPG contributors. See [LICENSE](LICENSE).