Skip to content

Commit 023775e

Browse files
hmgaudeckerclaude
andauthored
Use om.Constraints throughout. (#86)
* Refactor model configuration to use frozen dataclasses instead of dicts Introduce strongly-typed dataclasses for model configuration: - Dimensions, Labels, Anchoring, EstimationOptions, TransitionInfo - FactorEndogenousInfo, EndogenousFactorsInfo This improves type safety and enables IDE autocompletion while keeping user-facing model_dict as a plain dictionary. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Use frozendict for immutable dict fields in dataclasses Replace dict fields with frozendict in frozen dataclasses to ensure true immutability: - Labels.aug_periods_to_periods - Labels.aug_stages_to_stages - Anchoring.outcomes - TransitionInfo.param_names, individual_functions, function_names - EndogenousFactorsInfo.aug_periods_to_aug_period_meas_types, factor_info 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Ignore ty false positive. * Return ProcessedModel dataclass from process_model() instead of dict Update process_model() to return a ProcessedModel frozen dataclass and update all consumers to use attribute access instead of dict access. This provides: - Better type safety with explicit typed fields - Immutability via frozen dataclass - IDE autocomplete support - Clear documentation of the model structure 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Rename FactorEndogenousInfo to FactorInfo 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Ensure complete typing in src/skillmodels. * Require Python 3.14 before fixing type annotations. * Move TESTS_DIR -> TEST_DATA_DIR, which points to a subdirectory of src so that config.TEST_DATA_DIR is valid also for skillmodels the package (as opposed to the project). * Fix more linting issues. * Make ruff rules much stricter. * Further tighten type annotations. Fix a missing run-time annotation of NDArray. * Move unsafe_fixes = false from .pre-commit config to pyproject. * Fix query in data simulation. * More fixes to imports, add test. * Use more tuples in place of lists to prevent errors. * Fix typing. * Dataclasses for user input. * Simplify. * Use modern rng everywhere. * Update CLAUDE.md * Get rid of if TYPE_CHECKING blocks * Update hooks and clean up * Call by name throughout. * Autogenerated docs, harmonised hooks / project configuration. * Get rid of model_dict. * Replace yaml model specifications by ModelSpec-s. * Next shot at fixing pickling. * Add improved output formatting. * Add variance decompositions. * Fix variance decomposition to use aug_period instead of period. The filtered_states DataFrame and params index both use aug_period as the period identifier, not period. This fixes KeyError when calling decompose_measurement_variance. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Fix diagnostic_plots double-processing of debug data. debug_loglike already returns processed debug data (it calls process_debug_data internally). Remove the redundant second call to process_debug_data which was causing AttributeError when trying to iterate over already-processed DataFrames. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Review comments 1: single EstimationOptions; improved dataclasses with all defaults set right there; get rid of remaining mutable types being passed around. * Review comments on docs; tighten typing of Mapping to MappingProxyType where we could do so. * Back to general implementation of ensure_containers_are_immutable. * Small fixes. * Latest boilerplate version. * Make optimagic a package dependency. * Latest boilerplate. * Make jupyterbook and pytask required deps. * Use dags 0.5.0 dev branch. * Update CLAUDE.md with complete API docs and actual application usage Document all 14 public exports, get_maximization_inputs return dict, ProcessedModel attributes, frequently used internal APIs, all 7 transition functions, and ModelSpec builder methods — based on how the package is actually used in skane-struct-bw and health-cognition. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * Increase test coverage to close to 100%. * Fix bugs caught by review agent. * Call ty environment 'type-checking'. * Require dags 0.5, bump pandas, numpy and hooks, fix resulting issues. * Remove suppression of deprecation warning, which is unnecessary in Pandas 3.0 * Make ruff stricter. * Update boilerplate. * Update ty and remove a couple of unused-ignores. * Rename _sel to select_by_loc; fix stale docstring Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Allow passing states directly to get_transition_plots (health-cognition use case). * Use optimagic constraints directly. Need a wrapper because we are setting values on FixedConstraints. * Fix FixedConstraintWithValue.loc type and test expectations Remove list from loc type union, convert callers to tuple(). Update anchoring test expectations from list to tuple. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Validate not-None input directly. * Simplify API by setting .selectors via .loc in __post_init__ * Require dags 0.5.1 * Fix aug_period/period bug in transition equation visualization The viz code assumed states DataFrames always have `aug_period` as a column, but pre-computed states (e.g. from health-cognition) may carry `period` in the index instead. Add `_normalize_states_columns` to promote index levels and rename `period` → `aug_period` when needed. Also document the period vs aug_period convention in CLAUDE.md. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * Remove aug_periods from public-facing functions. * Previous commit was too greedy. * Use pixi 0.66 in CI; prek autoupdate. * CHORE: Approximation-tolerant floating point comparisons, remove pandas in-place operations. * Get rid of unnecessary block-comments. --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e965395 commit 023775e

8 files changed

Lines changed: 385 additions & 555 deletions

File tree

CLAUDE.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ simulate_dataset() → Simulate states (with optional policy effects)
9393
computation using Kalman filtering. The debug variant is not jitted and returns
9494
intermediate results (residuals, contributions, filtered states).
9595
- **constraints.py**: Generates parameter constraints (bounds, equalities from stagemap,
96-
fixed values) for optimization. Exports `get_constraints_dicts()`,
97-
`constraints_dicts_to_om()`, `enforce_fixed_constraints()`, `add_bounds()`.
96+
fixed values) for optimization. Exports `get_constraints()`,
97+
`enforce_fixed_constraints()`, `add_bounds()`, `FixedConstraintWithValue`.
9898
- **parse_params.py**: Converts flat parameter vectors to structured model parameters.
9999
Exports `create_parsing_info()` and `parse_params()`.
100100
- **params_index.py**: Builds the `pd.MultiIndex` for the params DataFrame via
@@ -194,7 +194,8 @@ These are not in `__all__` but are imported directly by application projects:
194194
- `skillmodels.process_model.process_model` — central to all application code
195195
- `skillmodels.types.ProcessedModel`, `EndogenousFactorsInfo`
196196
- `skillmodels.decorators.register_params` — essential for custom transition functions
197-
- `skillmodels.constraints.constraints_dicts_to_om`, `enforce_fixed_constraints`
197+
- `skillmodels.constraints.get_constraints`, `enforce_fixed_constraints`,
198+
`FixedConstraintWithValue`, `select_by_loc`
198199
- `skillmodels.utilities.extract_factors`, `update_parameter_values`
199200
- `skillmodels.process_data.pre_process_data`
200201
- `skillmodels.correlation_heatmap.get_measurements_corr`, `get_quasi_scores_corr`,

pixi.lock

Lines changed: 112 additions & 114 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ classifiers = [
2929
]
3030
dynamic = [ "version" ]
3131
dependencies = [
32-
"dags>=0.5",
32+
"dags>=0.5.1",
3333
"jax>=0.9",
3434
"jupyter-book>=2",
3535
"kaleido>=1.2",

0 commit comments

Comments
 (0)