Skip to content

Commit

Permalink
Disable numba in pytest sessions (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
segsell authored Mar 13, 2024
1 parent dc1e45e commit 5a9337a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 44 deletions.
3 changes: 2 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ coverage:
target: 90%
ignore:
- setup.py
- src/upper_envelope/shared.py
- tests/*
- tests/**/*
- .tox/**/*
- .tox/**/*
6 changes: 3 additions & 3 deletions src/upper_envelope/upper_envelope_jax.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Extension of the Fast Upper-Envelope Scan.
"""Jax implementation of the extended Fast Upper-Envelope Scan (FUES).
The original algorithm is based on Loretti I. Dobrescu and Akshay Shanker (2022) 'Fast
Upper-Envelope Scan for Solving Dynamic Optimization Problems',
The original FUES algorithm is based on Loretti I. Dobrescu and Akshay Shanker (2022)
'Fast Upper-Envelope Scan for Solving Dynamic Optimization Problems',
https://dx.doi.org/10.2139/ssrn.4181302
"""
Expand Down
6 changes: 3 additions & 3 deletions src/upper_envelope/upper_envelope_numba.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Extension of the Fast Upper-Envelope Scan.
"""Numba implementation of the Fast Upper-Envelope Scan (FUES).
The original algorithm is based on Loretti I. Dobrescu and Akshay Shanker (2022) 'Fast
Upper-Envelope Scan for Solving Dynamic Optimization Problems',
The original FUES algorithm is based on Loretti I. Dobrescu and Akshay Shanker (2022)
'Fast Upper-Envelope Scan for Solving Dynamic Optimization Problems',
https://dx.doi.org/10.2139/ssrn.4181302
"""
Expand Down
45 changes: 8 additions & 37 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import glob
import os
import sys
from pathlib import Path

import jax
import pandas as pd
import pytest
import yaml


# Obtain the test directory of the package
TEST_DIR = Path(__file__).parent
Expand All @@ -17,7 +12,6 @@

WEALTH_GRID_POINTS = 100


# Add the utils directory to the path so that we can import helper functions.
sys.path.append(os.path.join(os.path.dirname(__file__), "utils"))

Expand All @@ -26,34 +20,11 @@ def pytest_sessionstart(session): # noqa: ARG001
jax.config.update("jax_enable_x64", val=True)


@pytest.hookimpl(tryfirst=True)
def pytest_sessionfinish(session, exitstatus): # noqa: ARG001
# Get the current working directory
cwd = os.getcwd()

# Search for .npy files that match the naming pattern
pattern = os.path.join(cwd, "[endog_grid_, policy_, value_]*.npy")
npy_files = glob.glob(pattern)

# Delete the matching .npy files
for file in npy_files:
os.remove(file)


@pytest.fixture(scope="session")
def load_example_model():
def load_options_and_params(model):
"""Return parameters and options of an example model."""
params = pd.read_csv(
REPLICATION_TEST_RESOURCES_DIR / f"{model}" / "params.csv",
index_col=["category", "name"],
)
params = (
params.reset_index()[["name", "value"]].set_index("name")["value"].to_dict()
)
options = yaml.safe_load(
(REPLICATION_TEST_RESOURCES_DIR / f"{model}" / "options.yaml").read_text()
)
return params, options

return load_options_and_params
def pytest_configure(config): # noqa: ARG001
"""Called after command line options have been parsed."""
os.environ["NUMBA_DISABLE_JIT"] = "1"


def pytest_unconfigure(config): # noqa: ARG001
"""Called before test process is exited."""
os.environ.pop("NUMBA_DISABLE_JIT", None)

0 comments on commit 5a9337a

Please sign in to comment.