Skip to content

Phase 2b: rename grids/shocks packages and process leaf classes#362

Closed
hmgaudecker wants to merge 5 commits into
refactor/phase-2-api-reorganisationfrom
refactor/phase-2b-grids-processes-rename
Closed

Phase 2b: rename grids/shocks packages and process leaf classes#362
hmgaudecker wants to merge 5 commits into
refactor/phase-2-api-reorganisationfrom
refactor/phase-2b-grids-processes-rename

Conversation

@hmgaudecker
Copy link
Copy Markdown
Member

Stacked on top of #361 (Phase 2). Merge #359#360#361 → this in order.

Summary

Land the internal restructure Phase 2 (#361) deferred to keep itself reviewable: rename the lcm/grids/ and lcm/shocks/ packages to leading-underscore (private), rename the _ShockGrid* ABCs to _ProcessGrid*, rename the is_shock/shock_names/ShockName derived names to is_process/process_names/ProcessName, and rename the seven leaf process classes themselves so lcm/api/processes.py becomes a plain re-export.

lcm_examples/ updated in-tree to use the new names. Downstream user code (outside this repo) will be handled separately by the user.

Four commits

Step What
A a47402b git mv lcm/grids → lcm/_grids. Sed-rewrite from lcm.grids / import lcm.grids / lcm.grids. across src and tests.
B 591e955 git mv lcm/shocks → lcm/_processes. Rename internal ABCs _ShockGrid_ProcessGrid, _ShockGridIID_ProcessGridIID, _ShockGridAR1_ProcessGridAR1. Drop from lcm import shocks from lcm/__init__.py and the "shocks" entry from __all__. Update lcm_examples/precautionary_savings.py and lcm_examples/mahler_yum_2024/_model.py to use top-level from lcm import UniformIIDProcess, RouwenhorstAR1Process, ... (instead of the old lcm.shocks.iid.Uniform / lcm.shocks.ar1.Rouwenhorst bare-attribute access).
C 2e3e974 VariableInfo.is_shockis_process. Variables.shock_namesprocess_names. typing.ShockNametyping.ProcessName. Plus the matching non_shock_names local-var and test-function-name renames.
D ee357b5 Rename the seven leaf classes in _processes/iid.py and _processes/ar1.py: UniformUniformIIDProcess, NormalNormalIIDProcess, LogNormalLogNormalIIDProcess, NormalMixtureNormalMixtureIIDProcess, TauchenTauchenAR1Process, RouwenhorstRouwenhorstAR1Process, TauchenNormalMixtureTauchenNormalMixtureAR1Process. api/processes.py drops its as ... aliases — plain re-export. Tests that used lcm._processes.iid.X qualified access switch to top-level imports.

End state

  • Public surface: from lcm import UniformIIDProcess, TauchenAR1Process, ... (unchanged from Phase 2; the alias indirection is now removed).
  • Internal infra: lcm._grids/ and lcm._processes/ are the only homes for grid / process implementation. Both packages signal "private" via the leading underscore.
  • No more lcm.shocks namespace. No more is_shock / shock_names / ShockName identifiers in source.

What's NOT in this PR

  • Downstream user code outside this repo. Per the user's note, "I will take care of the downstream code elsewhere." Migration guide for downstream:
    • from lcm.shocks.iid import Uniformfrom lcm import UniformIIDProcess
    • from lcm.shocks.ar1 import Tauchenfrom lcm import TauchenAR1Process
    • from lcm.grids import ... continues to work but should switch to from lcm import ... for public classes (the _grids package is now private).
    • info.is_shockinfo.is_process on VariableInfo instances.
    • variables.shock_namesvariables.process_names on Variables instances.

Test plan

  • pixi run -e tests-cpu tests -n 7 — 1001 passed, 10 skipped (unchanged)
  • pixi run ty — all checks pass
  • prek run --all-files — all hooks pass
  • Public-import smoke test:
    python from lcm import UniformIIDProcess, TauchenAR1Process, RouwenhorstAR1Process
  • Verify Phase 2 (Split pylcm into a public lcm/ package and a private _lcm/ package #361) is merged before merging this PR

🤖 Generated with Claude Code

hmgaudecker and others added 5 commits May 19, 2026 08:30
`lcm/grids/` is internal grid infrastructure (ABCs, validators,
coordinate helpers, the leaf classes whose user-facing copies live
in `lcm/api/grids.py`). The leading underscore signals "private —
don't import from user code"; users keep reaching for grid classes
through `from lcm import LinSpacedGrid` or `from lcm.api.grids
import LinSpacedGrid`.

Pure rename via `git mv` to preserve blame. Sed-rewrite of `from
lcm.grids` / `import lcm.grids` / `lcm.grids.` across src and tests.
Update docstring references in `api/grids.py` and `api/categorical.py`.

Step A of `Phase 2 — api Reorganisation.md`'s deferred internal
restructure.

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

`lcm/shocks/` is internal process infrastructure (the `_ShockGrid`
ABC hierarchy plus the seven leaf distribution / discretization
classes). The leading underscore matches the `lcm/_grids/` rename
from step A — these are private packages users shouldn't reach into
directly.

Renames:
- `lcm/shocks/` → `lcm/_processes/`
- `_ShockGrid` → `_ProcessGrid`
- `_ShockGridIID` → `_ProcessGridIID`
- `_ShockGridAR1` → `_ProcessGridAR1`

Sed-rewrite of `from lcm.shocks` / `import lcm.shocks` /
`lcm.shocks.` and the three internal class names across src, tests,
and lcm_examples. `lcm/__init__.py` drops `from lcm import shocks`
and the `"shocks"` entry from `__all__` — the public surface is now
exclusively `from lcm import UniformIIDProcess` (etc.) via
`api/processes.py`.

`lcm_examples/precautionary_savings.py` and
`lcm_examples/mahler_yum_2024/_model.py` had bare-attribute access
to `lcm.shocks.{iid,ar1}.{Normal,Uniform,Rouwenhorst,Tauchen}`;
those rewrite to top-level imports (`NormalIIDProcess`,
`UniformIIDProcess`, `RouwenhorstAR1Process`, `TauchenAR1Process`)
because `lcm._processes` is private and ruff (rightly) flags the
underscore access. The internal class names themselves
(`Uniform`, `Tauchen`, ...) are renamed in step D; today the
`*Process` names are aliases declared in `api/processes.py`.

Step B of `Phase 2 — api Reorganisation.md`'s deferred internal
restructure.

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

Rename the derived attribute and type-alias names so the codebase
speaks one language: `process` for any stochastic-process state.

- `VariableInfo.is_shock` → `VariableInfo.is_process`
- `Variables.shock_names` → `Variables.process_names`
- `typing.ShockName` → `typing.ProcessName`
- `non_shock_names` local var in `api/regime.py` → `non_process_names`
- `test_shock_names_filters_is_shock` → `test_process_names_filters_is_process`

Sed-rewrite across src and tests.

Step C of `Phase 2 — api Reorganisation.md`'s deferred internal
restructure.

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

Rename the seven user-facing process leaf classes in their
definition files to the canonical `<Distribution><Kind>Process`
names. `api/processes.py` becomes a plain re-export without the
`as ...` aliases. Tests that previously reached for the classes via
`lcm._processes.iid.X` qualified access now import them from the
top-level `lcm` namespace.

Last step of `Phase 2 — api Reorganisation.md`'s deferred internal
restructure.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@review-notebook-app
Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@read-the-docs-community
Copy link
Copy Markdown

@hmgaudecker
Copy link
Copy Markdown
Member Author

Folded into #361 via fast-forward merge — all four Phase 2b commits (steps A, B, C, D) now live on the Phase 2 branch. Phase 2 description updated to cover the full restructure.

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