@.ai-instructions/profiles/tier-a.md @.ai-instructions/modules/jax.md @.ai-instructions/modules/pandas.md @.ai-instructions/modules/dags.md
GETTSIM (German Taxes and Transfers SIMulator) is a Python microsimulation model for the German tax and transfer system. It enables research applications from dynamic programming models to detailed microsimulation studies.
The core computation engine is provided by ttsim-backend. GETTSIM contains the policy
definitions, parameters, and tests specific to Germany.
Never work around limitations in ttsim-backend; any such changes should be made there.
# Run all tests
pixi run -e py314-jax tests -n 7
# Run a single test file
pixi run -e py314-jax tests src/gettsim/tests_germany/test_policy_cases.py
# Run tests for a specific policy area (by test ID pattern)
pixi run -e py314-jax tests -k "kindergeld"
# Type checking (runs as the ty / ty-jax pre-commit hooks)
pixi run prek run ty --all-files
pixi run prek run ty-jax --all-files
# Quality checks (linting, formatting)
pixi run prek run --all-files
# Build documentation
pixi run docsBefore finishing any task that modifies code, always run these two verification steps in order:
pixi run prek run --all-files(quality checks: ty / ty-jax type checking, linting, formatting, yaml, etc.)pixi run -e py314-jax tests -n 7(full test suite)
src/gettsim/germany/- Policy implementations organized by area (einkommensteuer, kindergeld, bürgergeld, etc.)src/gettsim/tests_germany/policy_cases/- Test cases organized by policy area and datesrc/gettsim/tt/- Re-exports from ttsim-backend (decorators, types)
-
Interface DAG: High-level orchestration connecting inputs to outputs via
main(). Key concepts:policy_date: Date for which the policy environment is set uppolicy_environment: Functions/parameters relevant at the policy dateinput_data: User-provided data (via DataFrame + mapper or direct pytree)tt_targets: Which outputs to computeresults: Final outputs in user-requested format
-
TT DAG: The core computation layer. Contains policy functions that operate on data columns.
gettsim.main() is the single entry point. Users specify:
main_targetormain_targets: What to compute (useMainTargetfor autocompletion)policy_date_str: Date for the policy environment (ISO formatYYYY-MM-DD)input_data: User data (viaInputDatahelper classes)tt_targets: Which tax/transfer outputs to compute (viaTTTargets)
from gettsim import InputData, MainTarget, TTTargets, main
outputs_df = main(
main_target=MainTarget.results.df_with_mapper,
policy_date_str="2025-01-01",
input_data=InputData.df_and_mapper(df=inputs_df, mapper=inputs_map),
tt_targets=TTTargets(tree=targets_tree),
)Policy functions use decorators from gettsim.tt:
@policy_function(start_date="2023-01-01", leaf_name="betrag_m")
def betrag_ohne_staffelung_m(anzahl_ansprüche: int, satz: float) -> float:
return satz * anzahl_ansprücheKey decorators:
@policy_function- Main policy calculation functions with date ranges (start_date,end_date,leaf_name)@policy_input- Input column definitions (no implementation body)@param_function- Functions that transform raw parameters into usable forms@agg_by_p_id_function- Aggregation functions by person ID (e.g., summing children's claims to parent)@agg_by_group_function- Aggregation functions by group (e.g., sum to household level)@group_creation_function- Functions that create group IDs (e.g., fg_id, bg_id)
Additional @policy_function parameters:
vectorization_strategy="not_required"- For functions that operate on full columns usingxnprounding_spec=RoundingSpec(...)- Optional rounding (GEP 5)fail_msg_if_included="..."- Error message if function is included in DAG (for unimplemented periods)
Auto-aggregation: If my_col exists and my_col_hh is requested, a sum aggregation
is auto-generated.
Time conversion: Automatic conversion between _y, _q, _m, _w, _d suffixes
using these factors relative to year: 1, 4, 12, 365.25/7, 365.25.
Policy parameters are in YAML files alongside the Python code. Each parameter has:
- Date-keyed values (e.g.,
2023-01-01:) - Metadata:
name(de/en),description(de/en),unit,reference_period,type - Legal references in each date entry
- Schema:
docs/geps/params-schema.json
Parameter types:
scalar- Single value (accessed viavaluekey)dict- Homogeneous dictionary with string/int keyspiecewise_constant,piecewise_linear,piecewise_quadratic,piecewise_cubic- Forpiecewise_polynomialfunctionbirth_year_based_phase_inout,birth_month_based_phase_inout- Age threshold lookups by birth cohortrequire_converter- Complex structures needing a@param_functionconverter
@policy_function(
rounding_spec=RoundingSpec(
base=0.0001,
direction="nearest", # or "up", "down"
reference="§76g SGB VI Abs. 4 Nr. 4",
),
start_date="2021-01-01",
)
def höchstbetrag_m(...) -> float: ...- German for policy-specific code (law names: Kindergeld, Bürgergeld, Einkommensteuer)
- English for infrastructure code
- UTF-8 characters allowed (ä, ö, ü, ß)
- Directory structure defines namespaces (e.g.,
germany/kindergeld/→ namespacekindergeld) - Within a namespace, use local names:
betrag_m,satz - Cross-namespace references use qualified names with double underscores:
arbeitslosengeld_2__einkommen_m_bg betragis the convention for monetary amounts of a tax/transfer
Time units (appear before aggregation):
_y(year),_q(quarter),_m(month),_w(week),_d(day)
Aggregation levels:
_sn(Steuernummer - tax unit)_hh(Haushalt - household)_fg(Familiengemeinschaft)_bg(Bedarfsgemeinschaft)_eg(Einsatzgemeinschaft)_ehe(Ehegemeinschaft)
Example: arbeitslosengeld_2__betrag_m_bg = monthly ALG2 amount at Bedarfsgemeinschaft
level
p_id- Primary person identifier (required)[x]_id- Group identifiers (e.g.,hh_id,bg_id) - same value for all group membersp_id_[y]- Person-to-person pointers (e.g.,p_id_elternteil_1,p_id_empfänger). Value -1 = no link.
Tests use YAML files in tests_germany/policy_cases/{area}/{date}/:
inputs:
provided:
alter: [35, 35, 12]
p_id: [0, 1, 2]
hh_id: [0, 0, 0]
# Nested paths use double underscore in code, but nested dicts in YAML
kindergeld:
in_ausbildung: [false, false, true]
p_id_empfänger: [-1, -1, 0]
outputs:
kindergeld:
betrag_m: [250, 0, 0]Functions must follow these rules for automatic vectorization:
- Ternaries: For a single assignment depending on one condition, prefer a ternary
(
out = 1 if x > 1 else 0) — vectorization converts it toxnp.where. Use statementif/elif/elsefor nested or multi-branch logic. - If-else blocks: Only one operation per branch, no return inside single if (must have else)
- Function calls:
sum,any,allrequire iterable arguments;min,maxtake exactly 2 args or 1 iterable - No elif after else: Use nested if-else instead
from gettsim.tt import (
# Decorators
policy_function,
policy_input,
param_function,
agg_by_group_function,
agg_by_p_id_function,
group_creation_function,
# Types
AggType, # SUM, COUNT, MEAN, MAX, MIN, ANY, ALL
RoundingSpec,
ConsecutiveIntLookupTableParamValue,
PiecewisePolynomialParamValue,
# Functions
piecewise_polynomial,
join, # For person-to-person lookups
get_consecutive_int_lookup_table_param_value,
get_piecewise_parameters,
intervals_to_thresholds,
merge_piecewise_intervals,
PiecewisePolynomialInterval,
)The GETTSIM Enhancement Protocols define conventions:
- GEP 0: Purpose and process for GEPs
- GEP 1: Naming conventions (identifiers, German names, time/unit suffixes)
- GEP 2: Internal data representation (1-d arrays, group identifiers, person pointers)
- GEP 3: Parameters of the taxes and transfers system (YAML structure, types)
- GEP 4: DAG-based computational backend (core architecture)
- GEP 5: Optional rounding via
RoundingSpec - GEP 6: Unified architecture (namespaces, qualified names,
start_date/end_date) - GEP 7: User interface (
main()function,MainTarget, input/output handling)