Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
66e1d71
Got started setting xnp as the backend at runtime.
hmgaudecker Jun 10, 2025
1d914e5
Merge branch 'hierarchical-interface' into set-backend
hmgaudecker Jun 11, 2025
279fc7a
Defer vectorization until the creation of the specialised environment…
hmgaudecker Jun 11, 2025
2527f7a
Improve fixtures.
hmgaudecker Jun 11, 2025
cc98a2d
Convert test_piecewise_polynomial.
hmgaudecker Jun 11, 2025
4f52606
Change order of vectorization and removing tree logic (vectorization …
hmgaudecker Jun 11, 2025
d0bb42e
Change order of vectorization and removing tree logic (vectorization …
hmgaudecker Jun 11, 2025
601c4cf
More updates, getting there.
hmgaudecker Jun 11, 2025
21821a8
Fix tests in METTSIM, adjust calls to piecewise polynomial everywhere…
hmgaudecker Jun 11, 2025
1f18025
Fix usage of numpy/xnp in Lohnsteuer module.
hmgaudecker Jun 12, 2025
d671cf7
Small cleanups and docstrings.
hmgaudecker Jun 12, 2025
1d8afad
Adjust GETTSIM s.t. tests pass.
hmgaudecker Jun 12, 2025
471a151
Almost done removing IS_JAX_INSTALLED, missing the aggregations.
hmgaudecker Jun 12, 2025
86c8d2b
Remove IS_JAX_INSTALLED. For some reason, tests are not working with …
hmgaudecker Jun 12, 2025
c233b4e
Add backend to cached policy env
mj023 Jun 12, 2025
8afc429
Merge branch 'hierarchical-interface' into set-backend
hmgaudecker Jun 13, 2025
d0a147b
Remove lists from possible outputs; make jax tests pass.
hmgaudecker Jun 13, 2025
76dd10e
Add test case for TypeError because of list parameter.
MImmesberger Jun 13, 2025
cebf3f1
Move to jaxtyping, except for aggregation.
hmgaudecker Jun 13, 2025
1e8f558
Rename, we have many more groups than 'hh' now...
hmgaudecker Jun 13, 2025
e3d933d
Got rid of remaining numpy.ndarray type hints.
hmgaudecker Jun 13, 2025
905f28b
Merge branch 'set-backend' of github.com:iza-institute-of-labor-econo…
hmgaudecker Jun 13, 2025
f13ccd5
Cut down on ruff exceptions.
hmgaudecker Jun 13, 2025
141cf48
Further cut down on ruff exceptions.
hmgaudecker Jun 13, 2025
8f9ce34
Apply naming suggestions made by @MImmesberger in #951.
hmgaudecker Jun 13, 2025
c721a37
Rename 'names' -> 'labels'. Sort-of another naming suggestions made b…
hmgaudecker Jun 13, 2025
9868e9f
Perils of git commit -a ...
hmgaudecker Jun 14, 2025
7719e0f
Docstrings, as suggested by @mj023.
hmgaudecker Jun 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import pytest

from ttsim.interface_dag_elements.backend import dnp as ttsim_dnp
from ttsim.interface_dag_elements.backend import xnp as ttsim_xnp


# content of conftest.py
def pytest_addoption(parser):
parser.addoption(
"--backend",
action="store",
default="numpy",
help="The backend to test against (e.g., --backend=numpy --backend=jax)",
)


def pytest_configure(config):
config.addinivalue_line("markers", "skipif_jax: skip test if backend is jax")


@pytest.fixture
def backend(request):
backend = request.config.getoption("--backend")
return backend


@pytest.fixture
def xnp(request):
backend = request.config.getoption("--backend")
return ttsim_xnp(backend)


@pytest.fixture
def dnp(request):
backend = request.config.getoption("--backend")
return ttsim_dnp(backend)

Check warning on line 36 in conftest.py

View check run for this annotation

Codecov / codecov/patch

conftest.py#L35-L36

Added lines #L35 - L36 were not covered by tests


@pytest.fixture(autouse=True)
def skipif_jax(request, backend):
"""Automatically skip tests marked with skipif_jax when backend is jax."""
if request.node.get_closest_marker("skipif_jax") and backend == "jax":
pytest.skip("Cannot run this test with Jax")

Check warning on line 43 in conftest.py

View check run for this annotation

Codecov / codecov/patch

conftest.py#L43

Added line #L43 was not covered by tests
18 changes: 16 additions & 2 deletions pixi.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ python = "3.12.*"
jax = ">=0.4.20"
jaxlib = ">=0.4.20"

[tool.pixi.feature.jax.pypi-dependencies]
jax-datetime = { git = "https://github.com/google/jax-datetime.git" }

[tool.pixi.feature.jax.target.win-64.pypi-dependencies]
jax = { version = ">=0.4.20", extras = ["cpu"] }
jaxlib = ">=0.4.20"
Expand All @@ -165,6 +168,9 @@ types-pytz = "*"
[tool.pixi.feature.test.tasks]
tests = "pytest"

[tool.pixi.feature.jax.tasks]
tests-jax = "pytest --backend=jax"

[tool.pixi.feature.mypy.tasks]
mypy = "mypy --ignore-missing-imports"

Expand Down
11 changes: 11 additions & 0 deletions src/_gettsim/arbeitslosengeld_2/einkommen.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
)

if TYPE_CHECKING:
from types import ModuleType

Check warning on line 17 in src/_gettsim/arbeitslosengeld_2/einkommen.py

View check run for this annotation

Codecov / codecov/patch

src/_gettsim/arbeitslosengeld_2/einkommen.py#L17

Added line #L17 was not covered by tests

from ttsim.interface_dag_elements.typing import RawParam


Expand Down Expand Up @@ -147,12 +149,14 @@
einkommensteuer__einkünfte__aus_nichtselbstständiger_arbeit__bruttolohn_m: float,
nettoquote: float,
parameter_anrechnungsfreies_einkommen_ohne_kinder_in_bg: PiecewisePolynomialParamValue,
xnp: ModuleType,
) -> float:
"""Share of income which remains to the individual."""
return piecewise_polynomial(
x=einkommensteuer__einkünfte__aus_nichtselbstständiger_arbeit__bruttolohn_m,
parameters=parameter_anrechnungsfreies_einkommen_ohne_kinder_in_bg,
rates_multiplier=nettoquote,
xnp=xnp,
)


Expand All @@ -164,6 +168,7 @@
einkommensteuer__anzahl_kinderfreibeträge: int,
parameter_anrechnungsfreies_einkommen_ohne_kinder_in_bg: PiecewisePolynomialParamValue,
parameter_anrechnungsfreies_einkommen_mit_kindern_in_bg: PiecewisePolynomialParamValue,
xnp: ModuleType,
) -> float:
"""Calculate share of income, which remains to the individual since 10/2005.

Expand All @@ -184,32 +189,37 @@
out = piecewise_polynomial(
x=eink_erwerbstätigkeit,
parameters=parameter_anrechnungsfreies_einkommen_mit_kindern_in_bg,
xnp=xnp,
)
else:
out = piecewise_polynomial(
x=eink_erwerbstätigkeit,
parameters=parameter_anrechnungsfreies_einkommen_ohne_kinder_in_bg,
xnp=xnp,
)
return out


@param_function(start_date="2005-01-01")
def parameter_anrechnungsfreies_einkommen_ohne_kinder_in_bg(
raw_parameter_anrechnungsfreies_einkommen_ohne_kinder_in_bg: RawParam,
xnp: ModuleType,
) -> PiecewisePolynomialParamValue:
"""Parameter for calculation of income not subject to transfer withdrawal when
children are not in the Bedarfsgemeinschaft."""
return get_piecewise_parameters(
leaf_name="parameter_anrechnungsfreies_einkommen_ohne_kinder_in_bg",
func_type="piecewise_linear",
parameter_dict=raw_parameter_anrechnungsfreies_einkommen_ohne_kinder_in_bg,
xnp=xnp,
)


@param_function(start_date="2005-10-01")
def parameter_anrechnungsfreies_einkommen_mit_kindern_in_bg(
raw_parameter_anrechnungsfreies_einkommen_mit_kindern_in_bg: RawParam,
raw_parameter_anrechnungsfreies_einkommen_ohne_kinder_in_bg: RawParam,
xnp: ModuleType,
) -> PiecewisePolynomialParamValue:
"""Parameter for calculation of income not subject to transfer withdrawal when
children are in the Bedarfsgemeinschaft."""
Expand All @@ -221,4 +231,5 @@
leaf_name="parameter_anrechnungsfreies_einkommen_mit_kindern_in_bg",
func_type="piecewise_linear",
parameter_dict=updated_parameters,
xnp=xnp,
)
27 changes: 16 additions & 11 deletions src/_gettsim/arbeitslosengeld_2/kindergeldübertrag.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from ttsim.tt_dag_elements import AggType, agg_by_p_id_function, join, policy_function

if TYPE_CHECKING:
from ttsim.config import numpy_or_jax as np
from types import ModuleType

Check warning on line 10 in src/_gettsim/arbeitslosengeld_2/kindergeldübertrag.py

View check run for this annotation

Codecov / codecov/patch

src/_gettsim/arbeitslosengeld_2/kindergeldübertrag.py#L10

Added line #L10 was not covered by tests

import numpy

Check warning on line 12 in src/_gettsim/arbeitslosengeld_2/kindergeldübertrag.py

View check run for this annotation

Codecov / codecov/patch

src/_gettsim/arbeitslosengeld_2/kindergeldübertrag.py#L12

Added line #L12 was not covered by tests


@agg_by_p_id_function(start_date="2005-01-01", agg_type=AggType.SUM)
Expand Down Expand Up @@ -57,9 +59,10 @@
@policy_function(start_date="2005-01-01", vectorization_strategy="not_required")
def kindergeld_zur_bedarfsdeckung_m(
kindergeld_pro_kind_m: float,
kindergeld__p_id_empfänger: np.ndarray, # int
p_id: np.ndarray, # int
) -> np.ndarray: # float
kindergeld__p_id_empfänger: numpy.ndarray, # int
p_id: numpy.ndarray, # int
xnp: ModuleType,
) -> numpy.ndarray: # float
"""Kindergeld that is used to cover the SGB II Regelbedarf of the child.

Even though the Kindergeld is paid to the parent (see function
Expand All @@ -71,10 +74,11 @@

"""
return join(
kindergeld__p_id_empfänger,
p_id,
kindergeld_pro_kind_m,
foreign_key=kindergeld__p_id_empfänger,
primary_key=p_id,
target=kindergeld_pro_kind_m,
value_if_foreign_key_is_missing=0.0,
xnp=xnp,
)


Expand Down Expand Up @@ -119,10 +123,11 @@

@policy_function(start_date="2005-01-01", vectorization_strategy="not_required")
def in_anderer_bg_als_kindergeldempfänger(
p_id: np.ndarray, # int
kindergeld__p_id_empfänger: np.ndarray, # int
bg_id: np.ndarray, # int
) -> np.ndarray: # bool
p_id: numpy.ndarray, # int
kindergeld__p_id_empfänger: numpy.ndarray, # int
bg_id: numpy.ndarray, # int
xnp: ModuleType, # Will become necessary for Jax. # noqa: ARG001
) -> numpy.ndarray: # bool
"""True if the person is in a different Bedarfsgemeinschaft than the
Kindergeldempfänger of that person.
"""
Expand Down
5 changes: 4 additions & 1 deletion src/_gettsim/arbeitslosengeld_2/regelbedarf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
)

if TYPE_CHECKING:
from types import ModuleType

Check warning on line 17 in src/_gettsim/arbeitslosengeld_2/regelbedarf.py

View check run for this annotation

Codecov / codecov/patch

src/_gettsim/arbeitslosengeld_2/regelbedarf.py#L17

Added line #L17 was not covered by tests

from _gettsim.grundsicherung.bedarfe import Regelbedarfsstufen
from ttsim.tt_dag_elements import RawParam

Expand Down Expand Up @@ -450,11 +452,12 @@
def berechtigte_wohnfläche_eigentum(
parameter_berechtigte_wohnfläche_eigentum: RawParam,
wohngeld__max_anzahl_personen: dict[str, int],
xnp: ModuleType,
) -> ConsecutiveInt1dLookupTableParamValue:
"""Berechtigte Wohnfläche für Eigenheim."""
tmp = parameter_berechtigte_wohnfläche_eigentum.copy()
je_weitere_person = tmp.pop("je_weitere_person")
max_anzahl_direkt = tmp.pop("max_anzahl_direkt")
for i in range(wohngeld__max_anzahl_personen["indizierung"] - max_anzahl_direkt):
tmp[i] = tmp[max_anzahl_direkt] + i * je_weitere_person
return get_consecutive_int_1d_lookup_table_param_value(raw=tmp)
return get_consecutive_int_1d_lookup_table_param_value(raw=tmp, xnp=xnp)
10 changes: 9 additions & 1 deletion src/_gettsim/einkommensteuer/abzüge/alter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
)

if TYPE_CHECKING:
from types import ModuleType

Check warning on line 14 in src/_gettsim/einkommensteuer/abzüge/alter.py

View check run for this annotation

Codecov / codecov/patch

src/_gettsim/einkommensteuer/abzüge/alter.py#L14

Added line #L14 was not covered by tests

from ttsim.tt_dag_elements import ConsecutiveInt1dLookupTableParamValue


Expand Down Expand Up @@ -94,6 +96,7 @@
@param_function(start_date="2005-01-01")
def altersentlastungsquote_gestaffelt(
raw_altersentlastungsquote_gestaffelt: dict[str | int, int | float],
xnp: ModuleType,
) -> ConsecutiveInt1dLookupTableParamValue:
"""Convert the raw parameters for the age-based tax deduction allowance to a dict."""
spec = raw_altersentlastungsquote_gestaffelt.copy()
Expand All @@ -104,12 +107,14 @@
raw=spec_int_float,
left_tail_key=first_birthyear_to_consider,
right_tail_key=last_birthyear_to_consider,
xnp=xnp,
)


@param_function(start_date="2005-01-01")
def maximaler_altersentlastungsbetrag_gestaffelt(
raw_maximaler_altersentlastungsbetrag_gestaffelt: dict[str | int, int | float],
xnp: ModuleType,
) -> ConsecutiveInt1dLookupTableParamValue:
"""Convert the raw parameters for the age-based tax deduction allowance to a dict."""
spec = raw_maximaler_altersentlastungsbetrag_gestaffelt.copy()
Expand All @@ -120,13 +125,15 @@
raw=spec_int_float,
left_tail_key=first_birthyear_to_consider,
right_tail_key=last_birthyear_to_consider,
xnp=xnp,
)


def get_consecutive_int_1d_lookup_table_with_filled_up_tails(
raw: dict[int, float],
left_tail_key: int,
right_tail_key: int,
xnp: ModuleType,
) -> ConsecutiveInt1dLookupTableParamValue:
"""Create a consecutive integer lookup table with filled tails.

Expand All @@ -148,5 +155,6 @@
range(max_key_in_spec + 1, right_tail_key + 1), raw[max_key_in_spec]
)
return get_consecutive_int_1d_lookup_table_param_value(
{**consecutive_dict_start, **raw, **consecutive_dict_end}
raw={**consecutive_dict_start, **raw, **consecutive_dict_end},
xnp=xnp,
)
7 changes: 6 additions & 1 deletion src/_gettsim/einkommensteuer/abzüge/behinderung.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@
from ttsim.tt_dag_elements import piecewise_polynomial, policy_function

if TYPE_CHECKING:
from types import ModuleType

Check warning on line 10 in src/_gettsim/einkommensteuer/abzüge/behinderung.py

View check run for this annotation

Codecov / codecov/patch

src/_gettsim/einkommensteuer/abzüge/behinderung.py#L10

Added line #L10 was not covered by tests

from ttsim.tt_dag_elements import PiecewisePolynomialParam


@policy_function()
def pauschbetrag_behinderung_y(
behinderungsgrad: int, parameter_behindertenpauschbetrag: PiecewisePolynomialParam
behinderungsgrad: int,
parameter_behindertenpauschbetrag: PiecewisePolynomialParam,
xnp: ModuleType,
) -> float:
"""Assign tax deduction allowance for handicaped to different handicap degrees."""
return piecewise_polynomial(
x=behinderungsgrad,
parameters=parameter_behindertenpauschbetrag,
xnp=xnp,
)
4 changes: 4 additions & 0 deletions src/_gettsim/einkommensteuer/abzüge/vorsorge.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from ttsim.tt_dag_elements.column_objects_param_function import param_function

if TYPE_CHECKING:
from types import ModuleType

Check warning on line 9 in src/_gettsim/einkommensteuer/abzüge/vorsorge.py

View check run for this annotation

Codecov / codecov/patch

src/_gettsim/einkommensteuer/abzüge/vorsorge.py#L9

Added line #L9 was not covered by tests

from ttsim.tt_dag_elements.param_objects import PiecewisePolynomialParamValue


Expand Down Expand Up @@ -201,6 +203,7 @@
def rate_abzugsfähige_altersvorsorgeaufwendungen(
evaluationsjahr: int,
parameter_einführungsfaktor_altersvorsorgeaufwendungen: PiecewisePolynomialParamValue,
xnp: ModuleType,
) -> dict[str, Any]:
"""Calculate introductory factor for pension expense deductions which depends on the
current year as follows:
Expand All @@ -215,6 +218,7 @@
return piecewise_polynomial(
x=evaluationsjahr,
parameters=parameter_einführungsfaktor_altersvorsorgeaufwendungen,
xnp=xnp,
)


Expand Down
Loading
Loading