SPB Git forge

spb/wp18_uqo

Public
6commits 1branches 0releases
5.4 MBsize
maindefault branch
yesterdaylast push
TeX 53.2% Python 46.6%
1.8 KB · 60 lines python
Raw Blame History
1"""Shared fixtures: a small, fast configuration of the Part B model solved once per session."""2from __future__ import annotations34import os5import sys67import numpy as np8import pytest910ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))11sys.path.insert(0, ROOT)12sys.path.insert(0, os.path.join(ROOT, "src"))1314from src import distributions as D  # noqa: E40215from src import equilibrium as E  # noqa: E40216from src import household_solver as HS  # noqa: E40217from src import model as M  # noqa: E4021819SMALL = {"simulation.n_dynasties": 12000, "simulation.burn_periods": 36, "grids.n_a": 40, "grids.n_x": 100,20         "income.sigma_transitory": 0.0}   # exact identities; the noisy-income identity has its own test212223@pytest.fixture(scope="session")24def P_small():25    cfg = M.load_config(overrides=SMALL)26    return M.build_params(cfg)272829@pytest.fixture(scope="session")30def lottery(P_small):31    K = P_small.K_estate32    return (np.array([0.0, 0.0, 0.05, 0.4, 1.0])[:K], np.full(K, 1.0 / K))333435@pytest.fixture(scope="session")36def prices(P_small):37    return M.stationary_prices(P_small, 1.0, 1.0)383940@pytest.fixture(scope="session")41def pols(P_small, prices, lottery):42    return HS.solve_lifecycle(P_small, prices, lottery)434445@pytest.fixture(scope="session")46def sim(P_small, pols, prices):47    recs, panel = D.simulate_stationary(P_small, pols, prices, n_record=6)48    return D.pool_records(recs), panel495051@pytest.fixture(scope="session")52def ge_small(P_small):53    """A small general equilibrium: supply scales from the calibration, then a GE solve from a54    perturbed price pair. Takes ~1 minute."""55    P = M.build_params(M.load_config(overrides=SMALL))56    log = E.RunLog("pytest_ge", echo=False)57    E.calibrate_supply(P, log)58    res = E.solve_stationary(P, p0=1.03, ptil0=0.98, log=log, name="pytest_ge", diagnostics=True)59    return P, res60