Skip to content

File layout: target tree and moves #1010

Backlog

Description

@seabbs-bot

This issue records an audit of the file layout on main (ff37dd6), the target layout, and the moves to reach it.
It changes no behaviour, public name or API: files and internal sections move or are renamed, and code moves verbatim.

Audit

Names that do not say what the file holds

  • src/modifiers/builtin.jl (1208 lines) holds four things: how a modifier reads a parameter (param, add_param!, lines 1–196), the Hazard and Floor depletion forms and the shared form helpers (197–510), Redistribute (511–1158) and the linear-step helper _LinearStep (1159–1208).
  • src/couplings/builtin.jl holds the couplings by matrix type (UniformScaling, Diagonal, sparse, dense, TimeVarying); "builtin" says nothing once couplings/batched.jl (Stepwise methods: select strata of a state, shared parameters, batches and the chunked-run contract #928, A cheaper resumed step: the state stays in the run's buffer, a state as one vector, PerStratum histories, and advance! as a proposal #1009) sits beside it.
  • src/interface/declarations.jl holds PieceInterface and its checks, which its own include comment says.
  • src/interface/canonical.jl holds the pure step (step, init, step_pullback); "canonical" is a name from an earlier design.
  • src/interface/roles.jl (1159 lines) holds the roles, the role functions, the modifier traits, the step shapes, the steps by scope and the modifier stages.
  • src/depletion/pool.jl holds Depletion itself, not a pool type.
  • src/shapes/wrappers.jl holds PerStratum, Pairwise, TimeVarying and the kernel storage they wrap; the name matches the docs' word "wrapper" and stays.
  • src/shapes/utils.jl is a grab bag of call-input checks, allocation, number, time and tuple helpers, most of which are not about shapes.
  • src/operators/trace_run.jl holds a call with its trace (_WithTrace).
  • test/unit/pool*.jl (five files) test Depletion; test/unit/builtin_modifiers.jl mirrors the mixed source file; test/unit/interfaces.jl tests PieceInterface; test/unit/dual_ties.jl tests the dual-number helpers; test/unit/snippets.jl is the shared setup that test/ad and test/usecases call setup.jl.
  • test/ad/moved_checks.jl is named after where its items came from; they are Mooncake reverse checks.
  • test/ad/movement.jl tests the rule of Redistribute's movement.
  • test/registry/ holds check scripts that the unit and device runs include; the AD scenario registry itself is test/ADFixtures/src/registry.jl, so "registry" names two things.

Directories whose grouping is unclear

  • src/adjoints/executor.jl holds Serial, Threaded and Parallel, which run every operator loop, forward as well as reverse.
  • src/interface/duals.jl is AD machinery (the local forward-mode derivative); src/adjoints/local.jl holds the rest of the dual-number methods.
  • src/interface/ mixes the extension interface (roles, pure step, trace role, PieceInterface) with printing (show.jl) and convert_floats (precision.jl).
  • Depletion forms live in two directories: Hazard and Floor in src/modifiers/builtin.jl, Truncate in src/depletion/truncate.jl, whose comment (line 93) points back at the first.
  • param and add_param! live in src/modifiers/, while src/parameters/ holds the parameter types that extend them.
  • Change points are spread over src/shapes/wrappers.jl (the type), src/kernels/weights.jl (made dense) and src/parameters/piecewise.jl (the loops); the type must load before the operators, so this stays.
  • test/unit is flat (52 files) and holds checks of committed result files and benchmark scripts (ad_benchmark_results.jl, full_benchmark_results.jl, benchmark_harness.jl, reactant_results.jl, parity.jl) that are not unit tests of src.
  • test/device (scripts), test/cuda and test/opencl (runner environments) are one concept in three directories.
  • test/reactant mixes the runner, its cases, the results (results.tsv, RESULTS.md) and notes (extension.md).
  • benchmark/ is flat with five groups mixed together: the CI suite (benchmarks.jl, run.jl, compare.jl, routes/), the hand-run A/B scripts (ab.jl, harness.jl, verdict.jl, step_pullback_ab.jl, threshold.jl, methods.jl, baselines.jl), the matrix (matrix.jl, matrix_report.jl, reactant_target.jl, bvd_handrule.jl, tutorial_handrule.jl), the docs results (figures.jl, docs_draw.jl, docs_modifier.jl, parity.jl) and the workflow helpers (ad_latest.jl, full_latest.jl, history_fixtures.jl).
  • docs/ root holds page helpers (getting_started_model.jl, performance.jl, performance_page.jl, readme_figure.jl) beside the build files.

Long files with natural seams

  • src/operators/recurrence.jl (2175): type and state; kernel reads and buffer; the call and routing; the run loops; strata-major runs; exponential_history; the one-lag scan.
  • src/operators/convolution.jl (1550): methods; type; the call and layout cache; loops; reverse pass; contributions.
  • src/operators/recurrence_adjoint.jl (1121), src/depletion/flows.jl (1164), src/depletion/pool.jl (1151) and src/interface/roles.jl (1159) each have clear # == sections.
  • test/ad/adjoints.jl (2819), test/unit/adjoints.jl (1805), test/ADFixtures/src/registry.jl (3757) and test/ADFixtures/src/matrix_cases.jl (3257).
  • benchmark/bvd_handrule.jl (1237) and benchmark/tutorial_handrule.jl (1042).

Include order

src/ComposableRecurrences.jl includes shapes, interface, couplings, adjoints, modifiers, parameters, depletion, operators, kernels, then operators/growth.jl, interface/show.jl, interface/precision.jl and adjoints/local.jl one at a time.
Operators, interface and adjoints are each split across the list, so it does not read as the package's structure.

Repository root and stray files

The root holds only standard files.
No tracked file is scratch: every script in benchmark and docs is reached from a Taskfile, a workflow, a test or a page.
docs/benchmarks_notes.md and docs/release_notes_header.jl are package-owned files the managed build reads.

Managed files

No change is wanted in a managed file for this round.

Target layout

src/
  ComposableRecurrences.jl   module, exports and includes in the order below
  docstrings.jl              docstring templates
  precompile.jl              precompile workload
  shapes/                    coefficient wrappers
    wrappers.jl              PerStratum, Pairwise, TimeVarying, kernel storage
  interface/                 what a user's piece implements
    roles.jl                 roles, forward!, pullback!, modifier traits
    step.jl                  the pure step: step, init, step_pullback
    trace.jl                 the trace role
    piece_interface.jl       PieceInterface and its checks
    show.jl                  one-line summaries
    precision.jl             convert_floats
  adjoints/                  routing to the rules and AD helpers
    duals.jl                 the local forward-mode derivative
    adjoints.jl              NoAdjoint, routing, mirrors, test_adjoint
    local.jl                 the pure step inside the rule
  couplings/                 how strata mix
    matrices.jl              couplings by matrix type
  parameters/                how a modifier reads a parameter, and parameter types
    param.jl                 param and add_param!
    derived.jl, recent.jl, piecewise.jl, gather.jl
  modifiers/                 the modifiers other than Depletion
    redistribute.jl, allocate.jl, transform.jl
    linear.jl                a whole-step modifier declared linear
  depletion/                 Depletion, its forms and flows
    forms.jl                 Hazard, Floor, Truncate and shared helpers
    flows.jl                 Share, Split, Flow
    depletion.jl             Depletion
  kernels/                   routes, delays and computed kernels
    routes.jl, delays.jl, lag_maps.jl, weights.jl, walk.jl, computed.jl
  operators/                 the operators and their loops
    executor.jl              Serial, Threaded, Parallel
    recurrence.jl            type, state, kernel reads and the call
    recurrence_run.jl        the run loops, strata-major runs and the scan
    recurrence_adjoint.jl    the reverse pass
    traced.jl                a call with its trace
    convolution.jl, transpose.jl, reverse.jl, pressure.jl, windows.jl,
    rows.jl, growth.jl
  utils.jl                   checks, allocation, number and time helpers
test/
  runtests.jl, item_times.jl, item_times.tsv   runner and item times
  unit/                      one file per source file, same stem
  ad/                        AD backend items, own environment
  results/                   checks of committed results and the scripts that write them
  usecases/                  real models against their original code
  package/                   quality and standards
  device/                    device scripts, with cuda/ and opencl/ runners
  reactant/                  Reactant runner, cases and results
  shared/                    check scripts the unit and device runs include
  ADFixtures/                the AD scenario package
  formatter/, jet/, trim/, downstream/
benchmark/
  benchmarks.jl, run.jl, compare.jl, routes/, results/   the CI suite
  ab/                        hand-run A/B scripts
  matrix/                    the benchmark matrix and its hand rules
  docs/                      the docs' result scripts
  latest/                    workflow helpers that merge results
  wren/                      the Wren comparison
docs/
  make.jl, pages.jl, docs_config.jl and other build files
  helpers/                   page helpers included by pages
  src/                       pages

Moves

This round

Done in #1023 (renames) and #1024 (the modifiers split).

from to reason
src/interface/declarations.jl src/interface/piece_interface.jl says what it holds
src/couplings/builtin.jl src/couplings/matrices.jl says what it holds
src/interface/duals.jl src/adjoints/duals.jl AD machinery
src/modifiers/builtin.jl (parameters, _float_param) src/parameters/param.jl one home for parameters
src/modifiers/builtin.jl (Hazard, Floor, shared) and src/depletion/truncate.jl src/depletion/forms.jl one home for depletion forms
src/modifiers/builtin.jl (Redistribute) src/modifiers/redistribute.jl one modifier per file
src/modifiers/builtin.jl (linear steps) src/modifiers/linear.jl its own concept
parameters include block before the modifiers block modifiers read parameters
test/unit/pool.jl, pool_capacity.jl, pool_flows.jl, pool_moves.jl, pool_split.jl test/unit/depletion.jl, depletion_capacity.jl, depletion_flows.jl, depletion_moves.jl, depletion_split.jl name the tested type
test/unit/builtin_modifiers.jl test/unit/depletion_forms.jl, redistribute.jl, transform.jl, modifiers.jl mirror the source split
test/unit/interfaces.jl test/unit/piece_interface.jl mirror the source
test/unit/dual_ties.jl test/unit/duals.jl mirror the source
test/unit/snippets.jl test/unit/setup.jl same name as in test/ad and test/usecases
test/unit/ad_benchmark_results.jl, full_benchmark_results.jl, benchmark_harness.jl, reactant_results.jl test/results/ad_benchmark.jl, full_benchmark.jl, benchmark_harness.jl, reactant.jl not unit tests of src
test/ad/moved_checks.jl test/ad/mooncake_reverse.jl says what it holds
test/ad/movement.jl test/ad/redistribute.jl names the tested modifier

After these merge

These touch files that #1009, #1008, #1006, #991, #986, #984, #981, #955 or #928 change, or the Julia floor and FFT branches.
#928, #986, #991, #981, #984, #955, #1009 and #1008 have merged.
The docs/helpers/ move is done in #1026.

from to reason
src/interface/canonical.jl src/interface/step.jl says what it holds
src/depletion/pool.jl src/depletion/depletion.jl names the type
src/adjoints/executor.jl src/operators/executor.jl runs forward loops too
src/operators/trace_run.jl src/operators/traced.jl says what it holds
src/shapes/utils.jl src/utils.jl not about shapes
src/operators/recurrence.jl (run loops, strata-major, scan) src/operators/recurrence_run.jl 2175 lines, a clear seam
include order grouped by directory as in the tree reads as the structure
test/unit/parity.jl test/results/parity.jl not a unit test
test/registry/ test/shared/ one meaning for "registry"
test/cuda/, test/opencl/ test/device/cuda/, test/device/opencl/ one home for device runs
test/reactant/extension.md into test/reactant/RESULTS.md one notes file
test/unit recurrence feature files (primary_recurrence.jl, number_history.jl, buffer_depth.jl, ragged.jl, record.jl) test/unit/recurrence_*.jl group by tested source
benchmark/*.jl benchmark/ab/, matrix/, docs/, latest/ group by purpose
docs/getting_started_model.jl, performance.jl, performance_page.jl, readme_figure.jl docs/helpers/ apart from build files

Internal types without the leading underscore

A last mechanical pull request, once the open pull requests on src have merged, drops the leading underscore from internal structs and type aliases.
The package marks its public names with public, so a type is internal by not being on that list.
Internal functions keep their underscore.
Another session is redesigning the union aliases and wrappers, so an alias it removes needs no rename.

Clashes and near clashes:

  • _Pressure would clash with the public role Pressure; it becomes PressureOperator.
  • _Checked would shadow the unexported module Base.Checked; it becomes ArgsChecked.
  • The type-design session removes _ParamInput, _Param, _BuiltinForm and the extensions' copies of _IEEEFloat and _Inert (the extensions import _Inert and use Base.IEEEFloat), and turns _ExponentForm and _LagMap into the abstract types ExponentForm and LagMap; those rows are not in the table.
  • The batching pull request renames the public Gather(p, rows) to Grouped(p, groups) and makes Batched internal, so _GatheredKernel and _GatheredRows become GroupedKernel and GroupedRows.
    _Gathered, a convolution read strategy, is unrelated to Gather and keeps the name Gathered.
  • _Shared (Enzyme extension) matches the name of a type defined in a forward! docstring example; doctests run in their own module, so this does not clash.
from to kind file
_ADLeaves ADLeaves struct adjoints/adjoints.jl
_Adapted Adapted alias ext KernelAbstractions
_AllocateImports AllocateImports struct modifiers/allocate.jl
_AnyRagged AnyRagged alias shapes/wrappers.jl
_Arithmetic Arithmetic alias kernels/weights.jl
_ArrayCoefficient ArrayCoefficient alias kernels/weights.jl
_ArrayKernel ArrayKernel alias operators/growth.jl
_ArrayStack ArrayStack struct adjoints/executor.jl
_BatchArray BatchArray alias couplings/batched.jl
_BoundRecent BoundRecent struct parameters/recent.jl
_Buffered Buffered struct operators/convolution.jl
_CPUArray CPUArray alias shapes/utils.jl
_CPUMatrix CPUMatrix alias adjoints/local.jl
_Chained Chained struct operators/recurrence.jl
_Checked ArgsChecked struct shapes/utils.jl
_Chunk Chunk struct adjoints/executor.jl
_ChunkFailed ChunkFailed struct adjoints/executor.jl
_Coefficient Coefficient alias kernels/weights.jl
_Columns Columns struct shapes/wrappers.jl
_Computed Computed alias kernels/weights.jl
_ComputedConvolution ComputedConvolution alias kernels/computed.jl
_ComputedKernel ComputedKernel alias kernels/weights.jl
_Contributions Contributions struct operators/convolution.jl
_ConvLoop ConvLoop struct adjoints/executor.jl
_ConvolutionFlat ConvolutionFlat struct operators/convolution.jl
_Count Count alias depletion/flows.jl
_CountLike CountLike alias depletion/flows.jl
_Counts Counts alias depletion/flows.jl
_Current Current struct adjoints/executor.jl
_DenseMirror DenseMirror alias adjoints/adjoints.jl
_DenseMixed DenseMixed alias operators/growth.jl
_DenseTimeVarying DenseTimeVarying alias operators/convolution.jl
_Depleting Depleting alias depletion/pool.jl
_DerivedArg DerivedArg struct kernels/weights.jl
_DeviceKernel DeviceKernel alias adjoints/adjoints.jl
_DeviceMovement DeviceMovement alias operators/recurrence_adjoint.jl
_DevicePressureCache DevicePressureCache alias ext GPUArrays
_DeviceReadyConvolution DeviceReadyConvolution alias operators/convolution.jl
_Distinct Distinct struct ext Enzyme
_DrawFrom DrawFrom struct depletion/pool.jl
_DrawInto DrawInto struct depletion/pool.jl
_Drawing Drawing alias depletion/pool.jl
_Drawless Drawless alias depletion/pool.jl
_Drop Drop struct depletion/forms.jl
_FFTCall FFTCall alias ext Mooncake
_FFTFloat FFTFloat alias ext FFTW
_FixedKernel FixedKernel alias operators/convolution.jl
_Flat Flat struct shapes/wrappers.jl
_FloatDual FloatDual alias adjoints/local.jl
_Floats Floats alias ext Enzyme
_FlowCount FlowCount alias depletion/flows.jl
_FlowForm FlowForm alias depletion/flows.jl
_FlowHazard FlowHazard alias depletion/flows.jl
_Flowing Flowing alias depletion/pool.jl
_Flows Flows alias depletion/pool.jl
_From From struct operators/recurrence.jl
_FusedSteps FusedSteps struct ext GPUArrays
_Gathered Gathered struct operators/convolution.jl
_GatheredKernel GroupedKernel alias kernels/gathered.jl
_GatheredRows GroupedRows struct kernels/gathered.jl
_Group Group struct operators/recurrence.jl
_HardTruncate HardTruncate alias depletion/forms.jl
_InKernel InKernel struct parameters/recent.jl
_Inert Inert alias ext Enzyme,ext Mooncake
_Infix Infix alias interface/show.jl
_KeptPartials KeptPartials alias kernels/walk.jl
_KernelBlock KernelBlock struct kernels/weights.jl
_KernelMatrix KernelMatrix alias ext Mooncake
_KernelStrata KernelStrata struct ext Reactant
_KernelTable KernelTable alias kernels/lag_maps.jl
_KernelWeights KernelWeights struct kernels/computed.jl
_LagScratch LagScratch struct kernels/weights.jl
_LagWalk LagWalk struct kernels/walk.jl
_LayoutCache LayoutCache struct operators/convolution.jl
_Leafless Leafless alias shapes/utils.jl
_LinearStep LinearStep struct modifiers/linear.jl
_LocalRoute LocalRoute struct adjoints/local.jl
_LocalTag LocalTag alias adjoints/duals.jl
_Marker Marker alias operators/recurrence.jl
_MassVector MassVector alias ext Mooncake
_MaybeTraced MaybeTraced alias ext Reactant
_Moved Moved struct depletion/flows.jl
_Movement Movement struct modifiers/redistribute.jl
_Named Named struct depletion/flows.jl
_NoHazard NoHazard alias depletion/flows.jl
_NoModifier NoModifier struct interface/canonical.jl
_NoPiecewise NoPiecewise alias ext GPUArrays
_NoRecord NoRecord struct kernels/walk.jl
_NoTrace NoTrace struct operators/trace_run.jl
_NormalisedKernel NormalisedKernel alias kernels/computed.jl
_OldestFirstPairwise OldestFirstPairwise struct shapes/wrappers.jl
_OldestFirstPiecewise OldestFirstPiecewise struct parameters/piecewise.jl
_OnePool OnePool alias depletion/pool.jl
_Ones Ones struct parameters/recent.jl
_Operand Operand alias parameters/derived.jl
_Owned Owned struct adjoints/executor.jl
_PairwiseKernel PairwiseKernel alias shapes/wrappers.jl
_ParamSlots ParamSlots struct adjoints/executor.jl
_Piecewise Piecewise struct shapes/wrappers.jl
_PiecewiseBuffer PiecewiseBuffer struct parameters/piecewise.jl
_PiecewiseCoupling PiecewiseCoupling alias parameters/piecewise.jl
_Placed Placed struct depletion/flows.jl
_PlainRenewal PlainRenewal alias operators/growth.jl
_PointDraw PointDraw alias depletion/pool.jl
_Pointwise Pointwise alias depletion/pool.jl
_PointwiseCoupling PointwiseCoupling alias operators/recurrence.jl
_Population Population alias depletion/pool.jl
_Pressure PressureOperator struct operators/pressure.jl
_Queue Queue struct depletion/forms.jl
_Ragged Ragged struct shapes/wrappers.jl
_RecurrenceFlat RecurrenceFlat struct operators/recurrence.jl
_Reversed Reversed struct operators/reverse.jl
_ReversedPairwise ReversedPairwise alias operators/recurrence_adjoint.jl
_RouteBuffers RouteBuffers struct kernels/routes.jl
_RouteKernels RouteKernels struct kernels/routes.jl
_Routes Routes struct kernels/routes.jl
_Row Row struct interface/canonical.jl
_RowAt RowAt struct parameters/recent.jl
_RowParameter RowParameter alias operators/select.jl
_RowsKernel RowsKernel alias kernels/gathered.jl
_RunLoop RunLoop struct adjoints/executor.jl
_ScalarStack ScalarStack struct adjoints/executor.jl
_Scan Scan struct operators/recurrence.jl
_ScanOut ScanOut alias ext Enzyme
_ScanPullback ScanPullback struct ext Mooncake
_Seeded Seeded alias adjoints/duals.jl
_SeededRow SeededRow struct adjoints/local.jl
_Shared Shared struct ext Enzyme
_SharedTable SharedTable alias kernels/lag_maps.jl
_Single Single struct adjoints/executor.jl
_SingleForm SingleForm alias depletion/flows.jl
_Slot Slot struct adjoints/executor.jl
_SoftTruncate SoftTruncate alias depletion/forms.jl
_SparseArg SparseArg alias ext Enzyme
_SparseSteps SparseSteps struct ext GPUArrays
_SplitFlow SplitFlow alias depletion/flows.jl
_SplitRows SplitRows struct operators/rows.jl
_StackRows StackRows struct operators/rows.jl
_Stacked Stacked struct adjoints/executor.jl
_StackedBlock StackedBlock struct adjoints/executor.jl
_StepLoop StepLoop struct adjoints/executor.jl
_StepTag StepTag struct adjoints/duals.jl
_StrataMajorCoupling StrataMajorCoupling alias operators/recurrence.jl
_StrataMajorOp StrataMajorOp alias operators/recurrence.jl
_StrataSegments StrataSegments alias parameters/piecewise.jl
_StrataTable StrataTable alias kernels/lag_maps.jl
_Summarised Summarised alias interface/show.jl
_SurvivalScratch SurvivalScratch struct kernels/weights.jl
_TVColumns TVColumns alias operators/recurrence.jl
_TVCoupling TVCoupling alias couplings/matrices.jl
_TVMatrix TVMatrix alias operators/recurrence.jl
_TVPerStratum TVPerStratum alias operators/recurrence.jl
_TVPiecewise TVPiecewise alias parameters/piecewise.jl
_TableIncrements TableIncrements alias kernels/lag_maps.jl
_TableMapped TableMapped alias kernels/lag_maps.jl
_TimeArray TimeArray alias ext Mooncake
_TimeAxis TimeAxis alias kernels/weights.jl
_TimeFixed TimeFixed alias operators/reverse.jl
_ToStratum ToStratum struct depletion/forms.jl
_TracePressures TracePressures struct operators/recurrence.jl
_TraceSink TraceSink struct operators/trace_run.jl
_TracedImports TracedImports alias modifiers/allocate.jl
_TracedOperand TracedOperand alias ext Reactant
_TracedPressure TracedPressure alias operators/recurrence_adjoint.jl
_TracedRecord TracedRecord alias operators/trace_run.jl
_TracedValue TracedValue alias ext Reactant
_TransformTag TransformTag struct adjoints/duals.jl
_TransposedConvolution TransposedConvolution struct operators/transpose.jl
_VectorSegments VectorSegments alias parameters/piecewise.jl
_WalkBack WalkBack struct kernels/walk.jl
_WalkScratch WalkScratch struct kernels/walk.jl
_WindowSums WindowSums struct operators/windows.jl
_WithState WithState struct operators/recurrence.jl
_WithTrace WithTrace struct operators/trace_run.jl

Generated by Claude Code

Activity

  1. seabbs-bot commented on Dec 2, 2026

    @seabbs-bot
    CollaboratorAuthor

    Paused. Merged: #1023, #1024, #1026, #1028, #1029.
    Pushed, not yet checked, no PR open:

    • layout/moves-2: adjoints/executor.jl → operators/executor.jl, depletion/pool.jl → depletion/depletion.jl, test/cuda and test/opencl → test/device/; its test run was stopped mid-way.
    • docs/internal-{parameters,modifiers,depletion,couplings,adjoints,interface,ext}: internal docstrings, each verified code-identical to main.
      Next: (1) run the full suite and docs build on layout/moves-2, then open its PR; (2) run the quality items on each docstring branch and one full suite and docs build on their merge, then open one PR per directory; (3) document the remaining internals in operators/, kernels/computed.jl, interface/roles.jl and canonical.jl, and executor.jl once their PRs merge, and drop the parity.jl and recurrence-test moves from this issue (they would mislabel the files).

    Generated by Claude Code

  2. seabbs-bot commented on Dec 4, 2026

    @seabbs-bot
    CollaboratorAuthor

    Status against main at d1f52c3

    Done:

    Remaining:

    Only the last item touches the public surface. The file moves can follow the release.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions