Make combinatorial model memory safe#69
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1cb05b3ac5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| self.P_vec_work = np.zeros(self.n_TF_rows, dtype=np.float64) | ||
| self.TF_in_work = np.zeros(self.n_TF_rows, dtype=np.float64) | ||
| self.S_cache = np.zeros((self.n_W_rows, self.kin_Kmat.shape[1]), dtype=np.float64) | ||
| self.S_cache = np.zeros(self.n_W_rows, dtype=np.float64) |
There was a problem hiding this comment.
Keep MODEL=2 S-rate exports two-dimensional
In the normal runner path I checked, runner.py calls export_S_rates after optimization for every model; for MODEL==2 that exporter still calls build_S_cache_into(sys.S_cache, ...) and treats sys.S_cache as a (total_sites, n_timebins) matrix before writing S_rates_picked.csv. Changing the cache here to a 1-D current-rate buffer makes combinatorial runs fail during result export rather than producing the expected output, so the exporter needs its own dense matrix or a streaming export path.
Useful? React with 👍 / 👎.
Motivation
Description
networkmodel/models.pyby addingiter_random_transitions_for_sites,count_random_transitions_for_sites, and a guardedbuild_random_transitionsthat only materializes dense arrays for small proteins; the Numbacombinatorial_rhsnow enumerates phosphorylation edges on-the-fly in the same mask/site order.S_cachebuffer innetworkmodel/network.py; the constructor checks2^n_sitesper-protein and totalstate_dimand raises a clearMemoryErrorif unsafe, and the System now populatesS_cachewith the current site rates instead of preallocating a full site×time matrix.networkmodel/simulate.pywith streaming per-site aggregation viacombinatorial_site_signals_streamingand free large temporaries immediately, preserving the returned DataFrame layout and values.networkmodel/backend.pyby removing dependence on global dense transition arrays and generating explicit phosphorylation transitions per protein from localn_states/n_sitesmetadata using JAX-compatible loops, and bound sensitivity retention innetworkmodel/sensitivity.pyso only the configured top curves are kept in memory during collection.tests/test_combinatorial_memory_safe.pyvalidating tiny smoke case, streaming bit extraction against dense for n_sites=2..4, transition-order equivalence, dense-compatibility gating, and the memory guard; update docsdocs/Combinatorial_Model_Memory_Issue.mddescribing implemented behavior and diagnostics.Testing
python -m py_compile(checkednetworkmodel/models.py,networkmodel/network.py,networkmodel/simulate.py,networkmodel/backend.py,networkmodel/sensitivity.py,networkmodel/runner.py); compilation succeeded.PYTHONPATH=. pytest -q tests/test_combinatorial_memory_safe.pyand all tests passed (assertions check numerical equality to tight tolerances, e.g., 1e-12).PYTHONPATH=. pytest -q tests/test_combinatorial_memory_safe.py tests/test_phoskintime_jax_multimodal.py::test_all_modes_detect_losses_objective_optimize_outputs_and_no_fake_missing_data) which passed.PYTHONPATH=. pytest -q) to surface unrelated environmental issues: 145 tests passed, 8 tests failed and 1 skipped; the failures are due to non-combinatorial/environmental factors (test expectations in the localconfig.tomlforn_starts, missing optional plotting/notebook deps and an artifacts directory expectation) and are not caused by the combinatorial memory-safety changes.Codex Task