Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numpyrize backward induction. #145

Merged
merged 112 commits into from Apr 2, 2019
Merged

Numpyrize backward induction. #145

merged 112 commits into from Apr 2, 2019

Conversation

tobiasraabe
Copy link
Member

@tobiasraabe tobiasraabe commented Mar 8, 2019

Problem

One major bottleneck of the Python implementation is in pyth_backward_induction which accounts for the majority of time used. Even for a small state space (10 periods, 2 types) extracting a state and finding the emax of its children states in the subsequent period takes 11% and 86% of the time. This obstacle can only be alleviated if the procedure can be translated to Numpy and Numba.

Solution

The final solution is very fast. Getting the emax from subsequent periods is no obstacle anymore and will not be a bottleneck anytime soon. The new bottleneck which accounts for over 92% of the time is construct_emax_risk. You can find the profiling results for 10 evaluations in the appendix.

  • Rewrite the state space to contain only Numpy arrays.
  • Include pyth_create_systematic_rewards in state space and add an update function for the rewards used in pyth_criterion.
  • Numpyrize complete pyth_backward_induction
  • Adjust pyth_simulate, pyth_contributions and other related functions to the new state space.
  • Fix test suite and reimplement skipped tests
  • Check 50 regression tests
  • Test explicit parallelization in get_emaxs_sub, but it doubles runtime.
  • Rework construct_emax_risk as independent gufunc.
  • Added another restriction to pyth_create_state_space so that no states are allowed were an agent chose always occupation A or B or education and lagged choice is home. (Thanks @mo2561057)
  • testing_pull_request.py works.

Appendix

tobiasraabe and others added 30 commits February 6, 2019 21:04
… construct_emax_risk and get_exogenous_variables. Removed unused functions.
@tobiasraabe
Copy link
Member Author

Hi @janosg, I am not able to reproduce the error in test_f2py::test_6 on my machine. Check out the second failed run on travis as the first log is not very informative. Can you give me a hint?

@janosg
Copy link
Member

janosg commented Mar 13, 2019

@tobiasraabe, On my machine test_f2py::test_6 also passes.

@tobiasraabe
Copy link
Member Author

tobiasraabe commented Mar 13, 2019

Did you also not deactivate mpi or omp? Now, if I deactivate one of them during compilation, I get a segementation fault.

@janosg
Copy link
Member

janosg commented Mar 13, 2019

If I deactivate any of the two or both I also get a segfault with no further information that would help you.

@tobiasraabe
Copy link
Member Author

Thanks for helping me! The seg fault was not caused by Fortran, but by an indexerror in a jitted function which also returns a segmentation fault. I thought Numba is more verbose than this.

@janosg
Copy link
Member

janosg commented Mar 14, 2019 via email

Copy link

@peisenha peisenha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the great work! I create some issues to address later when we have settled down in our development a bit after these tumultous times :)

respy/conftest.py Outdated Show resolved Hide resolved
environment.yml Outdated Show resolved Hide resolved
development/testing/testing_pull_request.py Outdated Show resolved Hide resolved
@tobiasraabe tobiasraabe changed the base branch from extract-covariates to new-python March 31, 2019 14:20
@tobiasraabe
Copy link
Member Author

I cancelled the build as it took too much time. But, tests were successful on my machine, the Python suite was fine on Appveyor and Fortran on Travis.

@tobiasraabe tobiasraabe merged commit 9f2d1cb into new-python Apr 2, 2019
@tobiasraabe tobiasraabe deleted the numpyrize branch April 3, 2019 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants