From c52f6452286a053857287aa243e1f07bd3516448 Mon Sep 17 00:00:00 2001 From: Annica Gehlen <39128048+amageh@users.noreply.github.com> Date: Thu, 26 Aug 2021 13:57:09 +0200 Subject: [PATCH] Release 2.1.1 (#419) --- .conda/meta.yaml | 6 +-- respy/tests/test_regression.py | 11 +++-- respy/tests/test_solve.py | 88 ++++++++++++++++++---------------- 3 files changed, 56 insertions(+), 49 deletions(-) diff --git a/.conda/meta.yaml b/.conda/meta.yaml index caec27594..9a7d6f962 100644 --- a/.conda/meta.yaml +++ b/.conda/meta.yaml @@ -15,9 +15,9 @@ build: requirements: host: - - python >=3.6 + - python >=3.7 run: - - python >=3.6 + - python >=3.7 - click - estimagic >=0.1.2 - hypothesis @@ -25,7 +25,7 @@ requirements: - fastparquet - mkl - numba >=0.42 - - numpy + - numpy>=1.21.0 - pandas >=0.24 - pytest - python-snappy diff --git a/respy/tests/test_regression.py b/respy/tests/test_regression.py index 26f6533ad..e442446c3 100644 --- a/respy/tests/test_regression.py +++ b/respy/tests/test_regression.py @@ -4,6 +4,7 @@ import numpy as np import pytest +from respy.config import CHAOSPY_INSTALLED from respy.config import TEST_RESOURCES_DIR from respy.config import TOL_REGRESSION_TESTS from respy.likelihood import get_log_like_func @@ -37,8 +38,10 @@ def regression_vault(): def test_single_regression(regression_vault, index): """Run a single regression test.""" params, options, exp_val = regression_vault[index] - crit_val = compute_log_likelihood(params, options) - assert np.isclose( - crit_val, exp_val, rtol=TOL_REGRESSION_TESTS, atol=TOL_REGRESSION_TESTS - ) + if CHAOSPY_INSTALLED or options["monte_carlo_sequence"] == "random": + crit_val = compute_log_likelihood(params, options) + + assert np.isclose( + crit_val, exp_val, rtol=TOL_REGRESSION_TESTS, atol=TOL_REGRESSION_TESTS + ) diff --git a/respy/tests/test_solve.py b/respy/tests/test_solve.py index 0f5c77ad8..eca5a062d 100644 --- a/respy/tests/test_solve.py +++ b/respy/tests/test_solve.py @@ -1,6 +1,7 @@ import numpy as np import pytest +from respy.config import CHAOSPY_INSTALLED from respy.config import EXAMPLE_MODELS from respy.config import INDEXER_INVALID_INDEX from respy.config import KEANE_WOLPIN_1994_MODELS @@ -274,58 +275,61 @@ def test_dense_choice_cores(): where this is not the case! """ - point_constr = {"n_periods": 6, "observables": [3], "n_lagged_choices": 1} + if CHAOSPY_INSTALLED: + point_constr = {"n_periods": 6, "observables": [3], "n_lagged_choices": 1} - params, options = generate_random_model(point_constr=point_constr) - options["monte_carlo_sequence"] = "sobol" - - # Add some inadmissible states - optim_paras, _ = process_params_and_options(params, options) - - # Solve the base model - solve = get_solve_func(params, options) - state_space = solve(params) + params, options = generate_random_model(point_constr=point_constr) + options["monte_carlo_sequence"] = "sobol" - # Retrieve index - edu_start = np.random.choice(list(optim_paras["choices"]["edu"]["start"].keys())) - state = (3, 0, 3, edu_start, 1) - core_ix = state_space.indexer[state] + # Add some inadmissible states + optim_paras, _ = process_params_and_options(params, options) - # Choose dense covar - pos = np.random.choice(range(len(state_space.dense))) + # Solve the base model + solve = get_solve_func(params, options) + state_space = solve(params) - # Get indices - dense_combination = list(state_space.dense.keys())[pos] - dense_index = state_space.dense_covariates_to_dense_index[dense_combination] - ix = ( - state_space.core_key_and_dense_index_to_dense_key[core_ix[0], dense_index], - core_ix[1], - ) + # Retrieve index + edu_start = np.random.choice( + list(optim_paras["choices"]["edu"]["start"].keys()) + ) + state = (3, 0, 3, edu_start, 1) + core_ix = state_space.indexer[state] + + # Choose dense covar + pos = np.random.choice(range(len(state_space.dense))) + + # Get indices + dense_combination = list(state_space.dense.keys())[pos] + dense_index = state_space.dense_covariates_to_dense_index[dense_combination] + ix = ( + state_space.core_key_and_dense_index_to_dense_key[core_ix[0], dense_index], + core_ix[1], + ) - unrestricted_cont = state_space.get_continuation_values(3)[ix[0]][ix[1]] + unrestricted_cont = state_space.get_continuation_values(3)[ix[0]][ix[1]] - # Impose some restriction - options["negative_choice_set"] = {"a": ["period == 4 & exp_b ==4"]} + # Impose some restriction + options["negative_choice_set"] = {"a": ["period == 4 & exp_b ==4"]} - # Solve the restricted model - solve = get_solve_func(params, options) - state_space = solve(params) - core_ix = state_space.indexer[state] + # Solve the restricted model + solve = get_solve_func(params, options) + state_space = solve(params) + core_ix = state_space.indexer[state] - # Get indices - dense_combination = list(state_space.dense.keys())[pos] - dense_index = state_space.dense_covariates_to_dense_index[dense_combination] - ix = ( - state_space.core_key_and_dense_index_to_dense_key[core_ix[0], dense_index], - core_ix[1], - ) + # Get indices + dense_combination = list(state_space.dense.keys())[pos] + dense_index = state_space.dense_covariates_to_dense_index[dense_combination] + ix = ( + state_space.core_key_and_dense_index_to_dense_key[core_ix[0], dense_index], + core_ix[1], + ) - # Check some features of the state_space - restricted_cont = state_space.get_continuation_values(3)[ix[0]][ix[1]] + # Check some features of the state_space + restricted_cont = state_space.get_continuation_values(3)[ix[0]][ix[1]] - for i in [0, 2, 3]: - assert restricted_cont[i] == unrestricted_cont[i] - assert restricted_cont[1] != unrestricted_cont[1] + for i in [0, 2, 3]: + assert restricted_cont[i] == unrestricted_cont[i] + assert restricted_cont[1] != unrestricted_cont[1] @pytest.mark.end_to_end