Repository navigation
Native structure and bound structs (PR-5) - #770
Merged
Merged
Conversation
…tor/native-structure-seam
refuse<Error>(parts...) and concat(parts...) (include/solprop_native/ refuse.hpp) replace the hand-built `"..." + std::to_string(n) + "..."` messages. Numbers keep std::to_string's text, so every message is byte-identical. The march's and the watch's own policy helpers are named refuse_policy so that they no longer shadow it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3
include/solprop_native/build.hpp holds cuda, hip, device, host and openmp as inline constexpr bools. The #if blocks whose branches both compile in every build become constants or if constexpr: the crossing's device test, the real-signal switch, the register plane, the host pack layout, the Adams block width, the accepted-step fence, the band league and four host-only eligibility predicates. Blocks that name a device- or host-only facility keep their #if. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3
dispatch_among<Values...> and dispatch_width<First, Last> (include/solprop_native/dispatch.hpp) turn a run-time extent into a compile-time one through a forced-inline comparison chain, which the compilers fold back into the switch. They replace the band filter's half-width ladder, the modal projection's lane ladder and the device Adams prediction's and element's width ladders. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3
A private member template, GeneralState::with_team(function, arguments...), opens the workspace's CPU team scope and invokes the workspace's member on it; the 66 forwarders that opened the scope by hand become one call each. It is defined and instantiated in general.cpp alone, so the pImpl stays the firewall that keeps the workspace class from the strict units. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3
clang-tidy's readability-avoid-return-with-void-value: the three void overloads no longer return their member's void, and with_team, which returns whatever its member returns, says why it may. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3
native::Problem's 161 fields are grouped into sub-aggregates (dims, grid, spatial, flux, stepper, linear, absorber, transform, kerr, plasma, raman, general, flow, dispersive), every access renamed mechanically. The extension binds them with nb::class_ (FieldFamily with nb::enum_): a scalar field reads and writes as itself, a vector field as an exact NumPy array, float64, complex128, uint64 or bool, C-contiguous, of a declared rank where its count is laid out beside it, refused otherwise with the field's name. Problem::validate() keeps problem_from's presence and extent rules and their messages, and the CPU execution and FFT planning records still cross as dicts. The adapter's _lower(problem, request, plan) fills the structs in place of _native_problem's dict and its payload helpers; a lowering of 851 problems from the native test suites matched the old dict field for field, bit for bit, before the old path was removed. Tests address the struct fields instead of dict keys, with every assertion and match kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3
The bound struct's fields read and write the same types, so the stub declares each as an attribute instead of a property and its setter. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3
scripts/problem_stub.py keeps stubgen's setter types as plain attributes, so strict pyright reads the adapter's assignments as before; the lint stage checks that the committed section is fresh. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3
A pure move: kernels.hpp holds the shared device helpers and types, workspace.hpp the class (its constructor now out of line in setup.cpp), and checks, setup, trial (the hot set, one unit), statistics and state hold the members. The helpers move from an unnamed namespace to solprop_native::general, found through a using-directive. Both headers refuse inclusion from the strict units, which CMake now marks with SOLPROP_NATIVE_STRICT_TU; the licence test follows the helpers' files. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3
GeneralWorkspace's 339-line close() becomes a destructor that fences: every plan is declared after the views it is built on, and the execution instances after the pools, so member destruction releases them in the order close() did. GeneralState::close() destroys the workspace, and with_team refuses a closed state, in place of the workspace's 40 require_open() calls; the noexcept readers read nothing once closed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3
The general modal source, the coupled flow, the three dispersive responses and the far-field pass were only ever closed by their owner's close() or their own destructor: each destructor now fences and lets its members go (plans are declared after the views they are built on), and their close(), closed_ flags and closed refusals go. DispersiveWeights keeps its default destructor. Two native tests no longer close a part by hand before it leaves scope. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3
Each entry sums its views' elements times their own element size, and the host problem arrays are listed by the problem's nested groups: the same numbers (every entry but the measured plan growth is unchanged on the benchmark cases), without a multiplier per view to keep in step. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3
With close() destroying the workspace, a closed GeneralState reads nothing: the dispersive test asserts the refusal where it asserted a zero row (Python's bound state already refused the read once closed). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3
require_general_problem becomes six checks by concern, the separable geometry's extents and finiteness rules as tables; allocate() hands its separable, low-storage, statistics, Raman, transform, forward-row, absorber, plasma, split-step and part allocations to members; plan() its transverse, Raman and split-step plans; statistics() its energy, windowed energy, intensity and plasma passes, with the absent offset and the device team aliases at file scope. Moves only: the order of every check, allocation and kernel is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3
The two hot kernels above it, adams_exponential_trial and team_band_plasma_column, and the module's binding table carry a NOLINT with their reason; the hot ones wait for an A/B before any split. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3
From the native-deep coverage run's unexecuted functions, those with no caller in any source, header, test or #if branch: the bindings' field_family (left unused by the bound Problem, and a -Wunused-function error under -Werror), GeneralModalSource::delayed_fft_provider, CoupledFlowAction::n_sections and full_route, and the device graph region's replays, captures and disabled readers with the two counters only they read. Every other unexecuted function has a caller: a device branch, solprop's own tests through the bindings, or a native test entry point. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3
The coverage source record and its configure dependencies globbed src/*.cpp and include/*.hpp alone, so an edit to kernels.hpp or workspace.hpp left the record unchanged; it now takes the source digest's set. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3
The bound problem kept a field's elements alone, so Problem::validate checked raman_undamped, raman_tensor_weights, rate_coefficients and the envelope rules by size, and the fixed terms not at all: a transposed table with the right element count passed. The bindings now record the shape each Linear, Plasma and Raman array arrives with, and validate holds it to the layout its counts give, with the old messages (the fixed terms rank two or three, their leading extent the term count). The adapter lays the fixed terms out as (n_terms, rows, n_omega) again, as before the bound problem. Each restored check has a test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3
The build-facts change had made adams_block `build::device ? 1 : adams_lane_width`, but adams_lane_width exists only on a host build, so CUDA and HIP refused it, and HIP then refused every device use of the non-constant block. It is the #if constant it was. The two device-only width dispatches in the elementwise Adams trial go back to their switches as well: the CUDA compile of this file also failed inside nvcc, and device-only code is not compiled before CI. The host build is unchanged (bitwise on the benchmark cases). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3
With trial.cpp fixed, CUDA 12.8's front end refused bindings.cpp: array_of's return type and two aliases relied on C++20's implicit typename, and nvcc took ExactArray<Element> for an incomplete type. Each carries its typename again, with a NOLINT naming why. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
jtravs
marked this pull request as ready for review
November 12, 2026 17:26
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
jtravs
added a commit
that referenced
this pull request
Nov 12, 2026
Brings in #770, #768 and #774 (main 33172a5). The TDSE changes of this branch move with #768's split of simulation.py: the numpy_ref-only rule of _admit_tdse_execution is gone from driver/settings.py, and driver/tdse_run.py takes the stop flag to the binding, the installed provider's revision for the consistency gate, no provider_pin in the archive context, and auto resolving to native. ADR-077 keeps main's text with ADR-078's amendment note; layers.svg is redrawn with docs/dev/figures/build.py. A docstring line in test_tdse_hacc_installed.py is rewrapped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR-5 of the lean-codebase plan: the native helpers, the bound problem struct and the workspace forwarders (first half), then the split of
general.cpp,close()by destruction, the decomposition of long cold functions and the dead-code removal (second half, steps 4–7, below). Stacked onfeature/two-backends-binary64, withchore/native-toolingmerged in. It will be retargeted tomainlater.Maintainer decision (2026-11-12): keep the bound
Problem, but do not bind the other structs (march, watch, Runge-Kutta, session, transverse and stage tables stay dicts) and do not splitNB_MODULEfor its own sake: binding turned out not to save lines. What remains is aimed at real line reduction and structure.What changed
refuse<Error>(parts...)andconcat(parts...)(include/solprop_native/refuse.hpp) replace about 40 hand-built"..." + std::to_string(n)refusals. Every message keeps its exact text.include/solprop_native/build.hppdefinescuda,hip,device,hostandopenmp. Where both branches compile in every build,#ifblocks become constants orif constexpr. Blocks that name device-only or host-only facilities keep their#if, and so does the Adams flow guard that nvcc needs.dispatch_amonganddispatch_width(include/solprop_native/dispatch.hpp) replace the fourswitchladders: the band filter, the modal projection lanes, and the device Adams prediction and element.GeneralState::with_team(&GeneralWorkspace::f, args...)replaces the bodies of the 66 forwarders that opened the CPU team scope by hand. The declarations stay, because the pImpl keeps the workspace class out of the strict units.native::Problem's 161 fields are nested in 14 groups: dims, grid, spatial, flux, stepper, linear, absorber, transform, kerr, plasma, raman, general, flow and dispersive. Each group is bound withnb::class_, andFieldFamilywithnb::enum_.Problem::validate()holdsproblem_from's presence and extent rules, with the same messages._lower(problem, request, plan)replaces_native_problem, its dict and its payload helpers.match=was removed and no tolerance changed.Hot-path commits (for the A/B)
41f53f3cdispatch_width: the band filter (host and device), the modal projection lanes, and the device Adams prediction and element.9b6eec2fbuild facts: the Adams block width, the accepted-step fence and the band league. The others are cold predicates.f7f5ddc2with_team: everyGeneralStatecall,trial_stepand the Adams trials included, goes throughstd::invoke.2da322d9bound problem: a mechanical rename ofproblem_.xtoproblem_.group.xthroughoutgeneral.cpp, kernels included.d8d3af10refuse: the cold throw branches of the stage-table and z-table lookups and ofprepare_trial.Every commit is meant to give bitwise-identical results,
field_difference0.Sizes
tools/size_report.pycoverssrc/solprop, which this PR does not touch. Fornative/(git diff --shortstatfrom the base: 40 files, +4839 / −4316):src,include,tests/native)_core.pyiThe plan's savings are not reached yet. Most of them were to come from the part of step 2 that this PR leaves open (below).
Not done (step 2 remainder, now dropped by the decision above)
nb::class_, in place of the*_fromand*_todict conversions. Their dicts are produced and read in solprop as well as in the adapter.NB_MODULEintobind_state.cpp,bind_session.cppandbind_build.cpp.BoundStatelambdas into.def(&BoundState::f, nb::call_guard<...>()). Most lambdas convert NumPy inputs before releasing the GIL, so they first need an exact-array argument type._core.pyiwithnanobind.stubgen: while most of the seam is untyped dicts, a generated stub would type them as baredictand break strict typing in the adapter. The bound problem's part is now generated (second half, below).Second half: structure (steps 4–7)
Stub (
ae3918f9).native/scripts/problem_stub.pywrites theFieldFamily/Problempart of_core.pyifromnanobind.stubgen, keeping each setter's type as a plain attribute so strict pyright reads the adapter's assignments as before; the lint stage runs it with--check. The output equals the hand-written section (only the markers were added).Split (
bea5d7b9).src/general.cpp(18.3k lines) becomessrc/general/:kernels.hpp(device helpers, kernel functors, view and plan types),workspace.hpp(the class), andchecks.cpp,setup.cpp(constructor, allocate, upload, plans, ledger),trial.cpp(the hot set in one unit: trials, stages, responses, band and envelope plasma, Adams, low storage, split step),statistics.cpp(statistics, monitor and edge readings) andstate.cpp(transfers,GeneralState). A pure move (the line multiset is unchanged apart from namespace lines,inlineon eight shared plain helpers and the out-of-line constructor). The helpers leave the unnamed namespace forsolprop_native::general, found through a using-directive, because the class's fields and member signatures name them across units. Both headers#errorunderSOLPROP_NATIVE_STRICT_TU, which CMake now sets on the ten strict sources (one list for the definition and the-ffp-contract=offoption). No function moved between strict and contracting units: the strict sources are untouched andsrc/general/holds no strict namespace;ci/check_strict_fma.pyon the built extension: 173 strict functions, none fused. The licence test now names the helpers' new files (it had silently skipped them).Destruction (
13aa7a63,1fa55177,ed006584).GeneralWorkspace::close()(339 lines) becomes~GeneralWorkspace() { execution_space_.fence(); }. Audit: all 37 plan constructions name only views declared before the plan, so each plan is destroyed before its views, and the execution instances are declared after the pools.GeneralState::close()destroys the workspace;with_teamrefuses a closed state, replacing 40require_open()calls; the noexcept readers read nothing once closed. The same applies toGeneralModalSource,CoupledFlowAction, the three dispersive responses,DispersiveWeightsandFarFieldPass: each destructor fences, and theirclose(),closed_and closed refusals go (they were only closed by their owner). Behaviour change: a closedGeneralStatenow refusesmemory_ledger()instead of returning zeros; Python's bound state already refused it once closed, and one GoogleTest assertion follows.Ledger (
bf847391).bytes(views...)andreserved(vectors...)replace the per-view multipliers; host problem arrays are listed byProblemgroup. Every ledger entry is unchanged on the 21 benchmark configurations except the measured plan heap growth.Long functions (
2ccc83b3,6966802e).require_general_problembecomes six checks by concern, the separable geometry's extents and finiteness rules as tables (order and messages unchanged);allocate()(914 lines) hands eleven blocks to members;plan()its transverse, Raman and split-step plans;statistics()its energy, windowed-energy, intensity and plasma passes.readability-function-sizeis on atLineThreshold: 300. Left whole withNOLINTNEXTLINE(readability-function-size):adams_exponential_trialandteam_band_plasma_column(hot path, split pending an A/B) andNB_MODULE(the module's one binding table).Dead C++ (
4cc6908f). Of the run 43171495302 coverage report's unexecuted functions, every one but these has a caller in some build (device branches, solprop's tests through the bindings, native test entry points). Deleted:field_familyinbindings.cpp(unused since the bound problem; a-Wunused-functionerror under-Werror),GeneralModalSource::delayed_fft_provider,CoupledFlowAction::n_sectionsandfull_route, and the device graph region'sreplays()/captures()/disabled()readers with the two counters only they read.Review fixes (
b9f8f9a5,a7874a8c,aefa7d03,bb3eca14). The coverage build's source record now hashessrc/general/'s headers. The bound problem had loosenedproblem_from's layout checks to size checks: the bindings now record eachLinear,PlasmaandRamanarray's shape andProblem::validateholds it to its counts again (fixed terms rank two or three withn_phi_terms/n_prefactor_termsrows;raman_undamped(n_terms, 2 n_to);raman_tensor_weights(n_terms, 2);rate_coefficients(4, n_intervals); envelope rules(n_channels, 4, 512)), with the old messages, and the adapter lays the fixed terms out as(n_terms, rows, n_omega)as before. Each restored check has a test that a transposed or miscounted table with the right element count is refused by name. The stub says array fields are copied in and out. The open documents point atsrc/general/.Hot-TU commits (second half, for the A/B)
bea5d7b9the split: the hot set keeps one unit, but the shared helpers change linkage (unnamed namespace tosolprop_native::general) and cold members leave the hot unit.6ed5a296whitespace inkernels.hpponly.13aa7a63removesrequire_open()from 24trial.cppentry points (the check moves toGeneralState::with_team).1fa55177removes closed-state branches fromGeneralModalSource::evaluate/set_weights/combineandCoupledFlowAction::set_trial/form_actions/set_actions/actions_to_host.4cc6908fremoves two counter increments from the device graph region's replay and capture paths.6966802eadds only NOLINT comments totrial.cpp.2ccc83b3,bf847391,ed006584,ba70b224,464c2ad9are cold or comments.Bitwise check here: 21 configurations (11 benchmark cases, default and RK, 0.1 of their length, 4 threads) hashed final fields and statistics after each step: identical to the base build at every step, with
SOLPROP_FFTW_PLAN=estimate SOLPROP_CALIBRATION=off. Withoutestimate, rebuilding the unchanged base gave differentargon_blueshift_envelopeandkerr_beam_192fields: their measured FFTW plans are re-chosen per build, so afield_differenceof 0 on envelope cases needs estimated (or shared) plans.Line counts per step (
native/)srcincludetests/native.py_core.pyiscripts/*.pyccf8d8d5)464c2ad9)The decomposition adds function headers and comments; the real savings are the destructors (about −680). The plan's 3.5–5.5k C++ is not reached: most of it was to come from binding the other structs, which the decision above drops.
Verification, first half (Mac, Apple Clang via Homebrew LLVM, editable Release build, OpenMP CPU)
-n 4:test_api_contract,test_backend,test_envelope_plasma,test_mixtures,test_execution,test_band_plasma,test_session_failure,test_dispersive,test_free,test_envelope_statistics_refusal,test_coupled_flow,test_general_modal,test_radial,test_planning,test_raman_tailandtest_batch.tests/backends, also with-n 4: low storage, planar, far field, every statistic, dispersive Kerr, held plasma, node chunk, phi moments, z table, stage tables, march admission, rk/march traces, widths. Flow sessions and marches, resume history and helpers fromtests/driverandtests/test_helpers.pyran too.ruff, the native pyright configuration (0 errors) andclang-format.clang-tidyon the changed sources. One finding was fixed in its own commit.test_public_surface_is_exact: an uncommitted tree gives a.dYYYYMMDDversion suffix.test_response_column_boundary_preserves_full_and_tail_windows[19]: it fails the same way onmainhere.if constexprfacts are compiled on devices for the first time in the device-compile lanes.Verification, second half (Mac, Homebrew Clang 23.1, editable Release build with IPO, OpenMP CPU)
check_build()fresh;check_strict_fma.pyclean.-n 4:test_api_contract,test_backend,test_session_failure,test_general_modal,test_coupled_flow,test_dispersive,test_planning,test_store,test_envelope_statistics_refusal,test_band_statistics_per_node,test_free,test_radial; parity modules: every statistic, planar statistics, edge reading, widths, far field (three), dispersive routes, low storage, held plasma, floating-point licence, march and RK rows.-Werror): 235 passed, 8 skipped.clang-tidy(full) on every changed source; the function-size check alone over every native source and test;clang-format,ruff.test_public_surface_is_exact(the editable versions differ by commit).🤖 Generated with Claude Code
https://claude.ai/code/session_01HAYtF5P9QqEd3HQx3WJkA3