Skip to content

docs(ti): Phase L implementation plans for ti library-ization#6

Merged
k-yoshimi merged 2 commits into
developfrom
docs/ti-library-plans
Apr 18, 2026
Merged

docs(ti): Phase L implementation plans for ti library-ization#6
k-yoshimi merged 2 commits into
developfrom
docs/ti-library-plans

Conversation

@k-yoshimi
Copy link
Copy Markdown
Owner

@k-yoshimi k-yoshimi commented Apr 18, 2026

Phase L plans for the ti module (impurity transport). 8 sub-phases (L-0..L-7) modeled on tr Phase L design (PR #3). L-0 includes regression-test infrastructure (no Phase 0 for ti yet). Tests mandatory; existing ti binary preserved; libtiapi.so added as new target. See individual plan files for details.


Note

Low Risk
Documentation-only change adding detailed implementation plans; no runtime, build, or test behavior is modified in this PR.

Overview
Adds a new set of TI library-ization plan documents (docs/superpowers/plans/2026-04-18-ti-library-L0..L7*.md) describing the proposed work to build TI regression baselines, split ti/Makefile source groups, add a C ABI (ti_api/ti_state) and parameter registry, build libtiapi.so, introduce a Python tilib wrapper, and integrate 4-layer tests plus documentation/examples.

This PR only introduces plans/documentation; it does not implement any of the described code or test changes.

Reviewed by Cursor Bugbot for commit 78ad1e2. Bugbot is set up for automated code reviews on this repo. Configure here.

@k-yoshimi
Copy link
Copy Markdown
Owner Author

@cursor review

8 sub-phases (L-0..L-7) modeled on the tr Phase L design, adapted for the ti
(impurity transport) module. L-0 sets up regression-test infrastructure since
ti has no Phase 0 yet. Tests mandatory in every sub-phase (4-layer pattern).
Existing ti executable preserved; libtiapi.so added as new build target.
Comment thread docs/superpowers/plans/2026-04-18-ti-library-L2-c-abi-foundation.md
@k-yoshimi
Copy link
Copy Markdown
Owner Author

Pre-merge review (parent agent + code-reviewer agent)

PR を draft 化 します。merge 前に以下の修正が必要です。

Critical (compile-blocking)

  • L-2 ti_api.f90USE plinit, ONLY: pl_init および USE equnit, ONLY: eq_init を使用するが、両モジュールの存在を verify するステップなし。MODINCLUDE は path(-I../pl/mod -I../eq/mod)のみで、モジュール名が正しい保証なし。Fallback section は equnit 不在時の対処を述べるが plinit には言及なし。
  • L-3 ti_param_registry.f90USE plcomm, ONLY: ..., PM, ... だが、実際の ticomm.f90:5USE plcomm, pm=>pa(rename)。プランは rename を完全に無視。PMplcomm で本当にその名前で export されているか未検証。フラジャイル。
  • L-0 Task 3 Step 1 の grep pattern DEALLOCATE(v) は実コード IF(ALLOCATED(v)) DEALLOCATE(v) (tiexec.f90:43) にマッチしない。verify-step が silent fail し agent worker をミスリード。

Major

  • L-1 classification table が tinclass.f90 / ticdbm.f90SRCS_CORE 候補に列挙だが、実 Makefile SRCS には両方とも不在。後続 Step 3 verification と矛盾。
  • L-0 Task 4: ti_min.in が namelist + R\nQ\n を一緒に stdin 流す invocation pattern を未検証。ti バイナリの実 menu loop 仕様確認なし。Task 6 Step 6 で fail すれば 4-9 全タスク手戻り。
  • L-2 ti_run_cINTEGER, SAVE :: prepped = 0 を使用。ti_finalize_c でリセットしないので、L-6 sweep test が Tilib() を per-cell 作成すると 2 回目以降 ti_prep が呼ばれない。完全に sweep が壊れる。

Minor

修正方針

  • L-2 で plinit/equnit モジュール存在確認 grep step を Task 3 前に追加
  • L-3 で plcomm の rename に対応(USE plcomm, pa=>pm 等)または USE を見直し
  • L-0 grep pattern を IF\(ALLOCATED\(v\)\) DEALLOCATE\(v\) に修正
  • L-1 classification table から tinclass/ticdbm を除外(または excluded を明示)
  • L-2 ti_finalize_cprepped = 0 にリセット、または SAVE を排除

修正後 gh pr ready で draft 解除して再レビューします。

@k-yoshimi k-yoshimi marked this pull request as draft April 18, 2026 06:21
@k-yoshimi k-yoshimi marked this pull request as ready for review April 18, 2026 06:48
@k-yoshimi
Copy link
Copy Markdown
Owner Author

@cursor review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 78ad1e2. Configure here.

@k-yoshimi k-yoshimi merged commit c39410a into develop Apr 18, 2026
1 check passed
k-yoshimi added a commit that referenced this pull request Apr 18, 2026
Implements ti L-0 per docs/superpowers/plans/2026-04-18-ti-library-L0-baseline.md
(merged in PR #6, c39410a). Mirrors the tr Phase 0 dump+compare pattern.

Changes:
- ti/tiregress.f90: env-guarded high-precision dump module. Writes
  ti_regress.dat (1PE24.16 format) only when TI_REGRESS_DUMP=1; normal
  runs are unaffected.
- ti/tiexec.f90: 1-line USE + 1-line CALL hook in ti_exec, immediately
  after IF(ALLOCATED(v)) DEALLOCATE(v) and before RETURN.
- ti/Makefile: tiregress.f90 added to SRCS before tiexec.f90; dependency
  rule for tiregress.o + updated dep for tiexec.o.
- test_run/scripts/extract_ti_metrics.py: parses ti_regress.dat into the
  common scalars + scalars_int + profile JSON schema.
- test_run/scripts/compare_metrics.py: generalized to dispatch list-vs-
  float per profile dict key at runtime, so the same script handles both
  tr (RN/RT lists, AJ/QP scalars) and ti (RNA/RTA/RUA lists, RBP/RQP/
  RJP/ZEFF/BETA/BETAP scalars). Adds scalars_int exact-match path. tr
  test suite still passes.
- test_run/scripts/check_regression.sh: optional leading "--module ti"
  flag. Default tr (backward compatible). Dispatches the right
  extract_*_metrics.py + dump filename per module.
- test_run/run_tests.sh: get_binary registers ti -> ti/ti, exports
  TI_REGRESS_DUMP=1 for ti tests, and invokes check_regression.sh
  --module ti on success. Renames the local "tr_env" array to "mod_env".
- test_run/inputs/ti_{min,ar,w}.in: 3 namelist inputs with R\nQ\n menu
  trailer. ti_min uses NSMAX=1 (no impurities). ti_ar/ti_w use ID_NS=10
  (ADAS) for Ar / W respectively.
- test_run/test_definitions.conf: registers ti_min, ti_ar, ti_w as
  ti-module tests with no dependencies.
- test_run/scripts/tests/test_extract_ti_metrics.py +
  test_compare_metrics_ti.py + fixtures/sample_ti_regress.dat: 6 new
  unittest cases covering scalars/profile parsing, schema dispatch, and
  scalars_int exact-match drift detection. All 17 unittests pass
  (8 existing tr + 3 new ti extract + 3 new ti compare + 3 existing tr
  extract).

Plan deviations:
- ti_min.in drops AD0/AK0/AV0/DK0/DKS (not in current /TI/ namelist;
  plan Step 3 anticipated this and explicitly documents the fallback
  minimal form used here).

KNOWN BLOCKER (baselines not generated in this PR):
- This worktree's sandbox blocks execution of the freshly-built ti
  binary, so test_run/baselines/ti_*/metrics.json could not be produced
  here. The Fortran source compiles cleanly (tiregress.o + tiexec.o
  build, ti binary links) once a local ../mtxp/make.mtxp ships
  LIB_MTX_MUMPS as well as the open-adas xxdata_11 vendor sources, both
  of which are environment prerequisites outside this PR's scope.
  Baselines should be generated and committed in a follow-up once a
  build host with ADAS data is available:

      ./run_tests.sh ti_min ti_ar ti_w
      for c in ti_min ti_ar ti_w; do
          ./scripts/check_regression.sh --module ti "$c" \
              "$(pwd)/test_output/$c" "$(pwd)/baselines" 1e-10 \
              --generate-baseline
      done
      git add test_run/baselines/ti_{min,ar,w}/metrics.json

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@k-yoshimi k-yoshimi deleted the docs/ti-library-plans branch April 18, 2026 15:42
k-yoshimi added a commit that referenced this pull request May 11, 2026
…follow-up) (#193)

* docs(spec): TOT AJRFT triangle backfill design (#191)

Expands #191 scope beyond the issue's literal text (regress mirror only)
to cover the full TOT C ABI + Python wrapper triangle. Codex design-stage
review (2026-05-12) surfaced the gap: TR-side PR #187 added AJRFT to the
tr_state_c + tr_api + trlib triangle, but the parallel TOT triangle was
untouched — meaning the L-7b-i `EXTERNAL_DRIVEN_I → tr → AJRFT` pipeline
has zero coverage at the TOT exit even after the regress-mirror work is
done. Verify-only on acceptance #6 is only defensible after the TOT
triangle is closed.

12 modification points across 3 commits:
- C1: tot_state.f90 + tot_api.h + tot_api.f90 + _ffi.py + state.py +
      test_ffi.py + TOT_STATE_ABI_VERSION 2 (mirrors PR #187 ABI block)
- C2: totregress.f90 + extract_tot_metrics.py + 2 baseline regens on
      clavius (mirrors TR commit 24b1b12)
- C3: sample_tot_regress.dat + test_extract_tot_metrics.py
      (mirrors TR commit d17f71e)

Self-reviewed: corrected §4.1.3 (tot_api.f90 reaches AJRFT via
trstate%, not direct TRCOMM USE) and §5 commit-ordering rationale
(commits are functionally independent; ordered for PR #187 parity).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(spec): apply Codex spec-file review fixes (#191)

Second Codex review pass on the design spec (post-commit 1df5493)
surfaced HIGH + MED + LOW findings. All verified against live tree
and incorporated.

HIGH:
- §4.1.2 (tot_api.h ABI version placement): the comment "after line 9"
  was inside the header /* ... */ block (lines 8-32). Corrected to
  "between #define TOT_MAX_NSMAX (line 35) and enum tot_error (line
  37+)" with explicit sample content mirroring tr_api.h:27-38.

MED:
- §4.3.1 sample_tot_regress.dat line off-by-one (9 → 8); AJT= is on
  line 8 between WPT= (7) and Q0= (9).
- §4.1.6 expanded: TR PR #187 added a test_size_matches_header_math
  test (test_ffi.py:70-85) that asserts ctypes.sizeof(TrStateC)
  matches header math. Mirror this for TOT — name-only assertIn
  alone misses misplaced-field bugs that the sizeof check catches.
- §4.1.7 new subsection (components 6a-6d): 4 user-facing surfaces
  hard-code the 13-scalar count and become stale once SCALAR_FIELDS
  grows to 14 — python/totlib/README.md, tot_mcp/server.py, and en/ja
  sphinx state.md. Folded into C1 to keep the scalar-count narrative
  self-consistent.
- §5 commit-dependency claim corrected: C3 actually depends on C2.
  Without C2's SCALAR_KEYS addition, the extractor's allowlist filters
  AJRFT out before C3's assertIn assertion can see it. Ordering
  C1 → C2 → C3 is now stated as functional, not just review parity.

LOW:
- §4.1.6 field-order in test_has_expected_fields locked to end of
  tuple (after "QP") so a future sizeof/offset check can't disagree
  with the name list.

Spec scope grows from 12 → 16 modification points; commit shape
unchanged (3 commits) but C1 now carries 10 components (6 ABI/wrapper
+ 4 docs-parity).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(spec): apply Codex round-3 spec review fixes (#191)

Round-3 Codex review on `87734400` surfaced an incomplete doc sweep
in §4.1.7 (4 → 12 hardcoded "13 scalars" references), a missing test
verification path for docs, and two LOW polish items.

MED:
- §4.1.7 reframed as a "doc-parity sweep" with 12 known hits (was 4):
  added totlib.py:319 (get_state docstring), server.py:831 (second hit
  beyond the schema description), en/state.md body line 37, en/
  applications.md:154, ja/state.md table row :102, ja/index.md:32,
  ja/applications.md:151, tot-library/architecture.md:116. Now driven
  by a single explicit grep + verification table.
- §7.4 added: post-impl grep returns 0 TOT-side hits + sphinx
  `make html` smoke-build catches markup errors in the new table rows.
- §5 commit-shape row C1 updated: components now "1, 2, 3, 4, 5, 6, 6a
  (doc sweep, 12 lines across 9 files)".

LOW:
- §4.1.2 sample ABI comment block adds the in-tree-consumers/build-
  system sentence from `tr_api.h:30-32` (faithful TR mirror).
- §8 risk table: added doc-drift + sphinx-markup risk rows.

Scope claim revised: 13 modification points + 1 doc-sweep (12 lines
across 9 files) + ABI bump + 3 commits. Group 1 = 6 ABI/wrapper +
1 doc sweep. Commit shape (3 commits) unchanged.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(spec): apply Codex round-4 spec review fixes (#191)

Round-4 Codex review on 5128997 returned PASS on checks 1-5 and
surfaced ONE MED finding.

MED:
- python/totlib/tests/test_totlib.py:135-185 (TestTotStateFromC)
  hardcodes a populated TotStateC instance + asserts a subset of
  scalars; the existing test silently passes when AJRFT is added to
  _fields_ because the field defaults to 0.0 and is never asserted.
  This silently loses coverage on the TotStateC -> TotState.from_c
  -> scalars["AJRFT"] round-trip.

Fix: new §4.1.8 (component 6b) prescribes two paired edits:
  - _populated_state sets s.AJRFT = 1.5
  - test_from_c_slices_correctly asserts st.scalars["AJRFT"] == 1.5

This is analogous to TR's d17f71e for the extractor, applied to the
totlib from_c round-trip path. Folded into C1 (same triangle as
_ffi.py + state.py).

Also updated §4 header (14 modification points), §4.1 header
(7 components + 1 doc sweep), §5 commit-shape C1 row, §7.1 to
include the new TestTotStateFromC pytest invocation, and §10.4
reviewer trail.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(spec): apply Codex round-5 spec review fixes (#191)

Round-5 Codex confirms diminishing returns: checks on §1-3, §6, §9,
§10, and cross-section consistency mostly PASS. Found:

MED:
- §6 acceptance-mapping line 423 still listed components "1-6 + 6a-6d"
  — stale from R2 before §4.1.7 was consolidated into a single 6a
  (doc sweep) and §4.1.8 added 6b (test_totlib round-trip). Updated
  to "1-6 + 6a + 6b".

LOW:
- §4.1 line 88 prose "All six components are interdependent" was
  stale after 6a + 6b were added — rewrote to clarify that 1-6 form
  the ABI triangle (interdependent) while 6a and 6b are co-shipped
  to keep narrative/coverage in lockstep.
- §6 reviewer-history sentence said "four user-facing scalar-count
  surfaces" — stale from R2; rewrote to reflect the R3 expansion
  to 12 hits across 9 files plus R4's §4.1.8 addition.

§10.4 reviewer trail updated with R5 entry. R5 also surfaces a META
finding (issue #191 body should be updated before C1 lands to
reflect the expanded scope) — tracked as a manual user task, not
spec content.

Per Codex: no other material findings. §3 non-goal still defensible,
§9 out-of-scope still consistent, §10 memory refs still relevant,
no stale component counts elsewhere (grep clean).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(plan): TOT AJRFT triangle backfill implementation plan (#191)

1014-line bite-sized task plan for the spec
`docs/superpowers/specs/2026-05-12-tot-ajrft-triangle-design.md`
(HEAD 3c2da8e). Breaks the 3-commit workflow into ~25 numbered
tasks across 4 phases:

- Pre-flight (worktree + toolchain sanity)
- Phase C1 (12 tasks): TDD-style C ABI + Python wrapper + 12-line
  doc sweep + test_ffi sizeof + test_totlib round-trip
- Phase C2 (6 tasks): regress code + 2 baseline regens on clavius
  (SSH workflow detailed)
- Phase C3 (3 tasks): extractor fixture + unit-test assertion
- Phase F (5 tasks): pre-push gate (parallel reviewers + REVIEW_OK
  marker) + push + PR create

Each task lists exact files + line ranges + before/after code
snippets + verification command + expected output. Acceptance
checklist at end cross-references issue #191 items 1-6 to plan
tasks.

Self-review: spec coverage complete (each §4 component maps to
1+ tasks), zero placeholders, names consistent across tasks.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* feat(tot): add AJRFT to tot_state ABI + Python wrapper (#191 / PR #187 follow-up)

Mirror of PR #187's TR-side AJRFT triangle on the TOT orchestrator
struct. Closes the totlib pipeline path of issue #191's L-7b-i
invisibility class (the regress-dump path is closed by C2/C3).

C ABI:
- tot/tot_state.f90: append REAL(C_DOUBLE) :: AJRFT at end of struct
- tot/tot_api.h: add #define TOT_STATE_ABI_VERSION 2 + matching
  double AJRFT field; ABI version comment block mirrors tr_api.h:27-38
- tot/tot_api.f90: add zero-init + copy-from-trstate%AJRFT lines

Python wrapper:
- python/totlib/_ffi.py: ("AJRFT", c_double) at end of TotStateC._fields_
- python/totlib/state.py: "AJRFT" in SCALAR_FIELDS, docstring 13 -> 14

Tests:
- python/totlib/tests/test_ffi.py: AJRFT in test_has_expected_fields
  + new test_size_matches_header_math (mirrors TR test_ffi.py:70-85,
  adjusted for 7 ints with 28/32 byte padding tolerance)
- python/totlib/tests/test_totlib.py: TestTotStateFromC._populated_state
  sets s.AJRFT = 1.5; test_from_c_slices_correctly asserts it
  round-trips through TotState.from_c (mirrors d17f71e's
  test_extract_tr_metrics.py treatment, applied to the from_c path)

Doc parity sweep (12 lines / 9 files):
- python/totlib/totlib.py, README.md
- python/mcp-servers/tot_mcp/server.py (x2 lines)
- docs/sphinx/modules/tot/en/{state,applications}.md
- docs/sphinx/modules/tot/ja/{state,applications,index}.md
- docs/tot-library/architecture.md
All bump "13 scalars" -> "14 scalars (incl. AJRFT)" and add AJRFT
row to scalar tables where present.

Post-impl grep returns 0 TOT-side hardcoded "13 scalars" hits.
Sphinx HTML smoke-build succeeds.

Spec: docs/superpowers/specs/2026-05-12-tot-ajrft-triangle-design.md

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* test+tot: backfill AJRFT in regression dump (#191 / PR #187 follow-up)

Mirrors TR-side commit 24b1b12, applied to the TOT regress path:
- tot/totregress.f90: AJRFT in USE TRCOMM list + WRITE line between
  AJT and Q0 (inside the TR_OK guard, so AJRFT is dumped only when
  TR's allocatable arrays are present, matching the existing scalars)
- test_run/scripts/extract_tot_metrics.py: "AJRFT" in SCALAR_KEYS

Baselines (tot_demo2014_short, tot_ht6m_short) will be regenerated
on clavius and added in a follow-up commit/amend (see spec §4.2.3/4).
Without the regen, ./test_run/run_tests.sh would fail at the schema
comparison because the new tot_regress.dat has AJRFT and the cached
baseline does not.

Spec: docs/superpowers/specs/2026-05-12-tot-ajrft-triangle-design.md §4.2

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* test: backfill AJRFT in extractor unit-test fixture (#191)

Mirrors the TR-side commit d17f71e (`test: backfill AJRFT in
extractor unit-test fixture (PR #187 follow-up)`): the TOT
extractor's unit-test fixture is the analogous third paired
artefact, and without it future copy-paste of sample_tot_regress.dat
as a "what does a real dump look like" reference would silently
omit AJRFT, recreating the asymmetry class this PR is closing.

Depends on C2 (commit 6dec5cd), which already wired AJRFT into
totregress.f90's WRITE block and extract_tot_metrics.py's
SCALAR_KEYS — so the extractor already knows the key; this commit
only locks it into the unit-test fixture.

- Adds AJRFT=0.0E+00 line after AJT in sample_tot_regress.dat
- Adds `assert "AJRFT" in data["scalars"]` and value-equals-0.0
  assertion to test_extracts_tr_scalars so the fixture stays locked

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(tr): backfill stale 13->14 scalar references (PR #187 follow-on)

PR #187 (e049a1e, 2026-05-02) added AJRFT to the tr_state_c C ABI
+ Python wrapper but missed the docs/MCP-schema strings that hard-code
the 13-scalar count. The asymmetry surfaced when this PR's TOT-side
doc sweep asserted "TrState has the same 14 scalars as TotState",
contradicting TR's own docs that still said 13.

8 stale references fixed across 5 files:
- docs/sphinx/modules/tr/en/state.md (heading + body line + add table row)
- docs/sphinx/modules/tr/ja/state.md (heading + body line + add table row)
- docs/sphinx/modules/tr/en/design.md (single line bump)
- docs/sphinx/modules/tr/ja/design.md (single line bump)
- python/mcp-servers/tr_mcp/server.py (schema string + docstring)

Post-impl grep returns 0 TR-side stale hits.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

* docs(presentations): backfill 13->14 in trlib slide builder + cached md (#191)

Final cumulative grep after C4 surfaced 3 residual "13 個" hits in
docs/presentations/ that escape the sphinx modules sweep:
- _build_trlib_usage.py:590 (TrState.scalars enumeration string)
- _build_trlib_usage.py:653 (speaker notes string)
- 2026-04-20-trlib-python-usage.md:191 (cached speaker notes)

While the markdown file is date-stamped, both files are git-tracked
active reference content (the .py is a re-runnable slide builder;
the .md is browsed as current trlib usage doc). Codex post-push
review (2026-05-12) flagged these as merge blockers for the same
reason C4 fixed the sphinx/MCP sweep — readers comparing TOT vs TR
get inconsistent counts otherwise.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant