-
-
Notifications
You must be signed in to change notification settings - Fork 199
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
adding PerfForesightConsumerTypeFast #774
Conversation
baseline PerfForesightConsumerType for comparison
add fast solver for PerfForesight model
reformat using "black" and add __eq__ method using parameter dictionary
add __eq__ to ConsumerSolution
also change code in ConsIndShock for correcting failed tests
add interpolation
For the changelog one, let's wait till we make a 0.10.7 release first, then you can add this to the changelog for 0.10.8. You would need to edit this file https://github.com/econ-ark/HARK/blob/master/Documentation/CHANGELOG.md For the documentation one, as you have added new functionality and files you also need to add this to the documentation folder so that the documentation site (https://hark.readthedocs.io/en/latest/) is able to scrap the new model class.
Sphinx will do rest of the work to scrap through the class docstrings and generate a documentation page for it. |
- remove __future__ as econ-ark is only python3 - fix __all__ - make helper functions private
generate documentation
remove `__eq__` tests
My preference for naming is to add extra things to the beginning or the end of the name of an existing object; so, PerfForesightConsumerTypeFast |
move `Fast` to end of name
remove `__eq__`, will be moved to own PR
remove `__eq__` modifications from this PR
fix requirements error
I've removed everything relating to |
revert formatting changes to resolve conflicts
Please ensure your pull request adheres to the following guidelines:
Would like suggestions on the boxes not checked.
This PR creates
ConsIndShockFastModel
which for now only containsPerfForesightFastConsumerType
, anumba
implementation ofPerfForesightConsumerType
.I have also added basic__eq__
for comparison of models and solutions as in #612.ConsIndShockFastModel
The goal of this PR is to create a mirror to
ConsIndShockModel.py
, but that implements faster solutions usingnumba
just-in-time compiling and optimization.PerfForesightSolution
The first step is to create a solution object called
PerfForesightSolution
that contains only python primitives andnumba
arrays. This object takes the place ofConsumerSolution
, which creates additional HARK objects and can lead to unnecessary time overhead in the solution iteration. Thedistance_criteria
for this solution is["cNrm", "mNrm"]
, which is identical to thedistance_criteria
forConsumerSolution
but more straight forward. ThisConsumerSolution
replacement is faster because instead of having to create HARK objects such ascFunc
,vFunc
, etc. asLinearInterpolator
s for every solution iteration, the solution method or algorithm only really needs the primitives that compose these objects. Below I will describe in more detail how this object is used in the solver.ConsPerfForesightFastSolver
The next step is to create a solver that replaces
ConsPerfForesightSolver
, aptly calledConsPerfForesightFastSolver
. The object uses anumba
-optimized helper function calledsolveConsPerfForesightNumba
. In this implementation, the outputs of this helper method are packaged into aPerfForesightSolution
object instead of aConsumerSolution
object. As I mentioned, this avoids the needless creation of other HARK objects in the iteration, leaving the creation of a proper HARK solution to the end of the iteration. An additional feature that has been removed from the solution iteration is the searching of steady-state normalized market resources withaddSSmNrm()
. As the iteration does not depend on this result as an intermediate input, this can be safely moved to the end of the solution method, or rather topostSolve()
.PerfForesightFastConsumerType
Finally, I create an agent that can use the above solution method called
PerfForesightFastConsumerType
. Since now the solution iteration usesPerfForesightSolution
, I first overridesolution_terminal_ = PerfForesightSolution()
. Then, on__init__
, I overridesolveOnePeriod
toConsPerfForesightFastSolver
. Since I am overriding the solution_terminal_, I might still need aConsumerSolution
terminal in the case of a non-infinite problem. So, I override the methodupdateSolutionTerminal()
to save an internalConsumerSolution
version of thesolution_terminal
. The final step is to implement apostSolve()
method to wrap everyPerfForesightSolution
parameter into a HARK object and to runaddSSmNrmNumba()
only on the final solution. As I had mentioned, there is no need to create these objects at every iteration step of the solution, and it is thus more efficient to leave them topostSolve()
. Now, ideally, the output ofsolve()
is the same between the standard HARK approach and the fast approach, a list ofConsumerSolution
objects withcFunc
,vFunc
, etc. as HARKLinearInterpolator
s.Checking for Equality