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

Use Parameters class in solver #1389

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Mv77
Copy link
Contributor

@Mv77 Mv77 commented Feb 23, 2024

I think that one of the main advantages of the Parameters class that @alanlujan91 has created is that, with its __get_item__ method, we can do away with a lot of ugly and repetitive code in HARK that determines what arguments to give to a solver in a given period given what is time-varying and what is not.

In an ongoing project, I have created an agent class that stores its parameters in a Parameters object. That parameter is then used by the solver to feed time-specific parameters to the solve_one_period method.

Although I am not yet sharing the agent prototype, I wanted to share and get comments on the solver. Currently what I am doing is forking the solve_one_cycle method. If the agent has a Parameters object, it takes advantage of it. If not, it uses the old and unchanged method.

  • Tests for new functionality/models or Tests to reproduce the bug-fix in code.
  • Updated documentation of features that add new functionality.
  • Update CHANGELOG.md with major/minor changes.

@mnwhite
Copy link
Contributor

mnwhite commented Feb 23, 2024 via email

Copy link

codecov bot commented Feb 23, 2024

Codecov Report

Attention: Patch coverage is 57.50000% with 17 lines in your changes are missing coverage. Please review.

Project coverage is 71.45%. Comparing base (bbb07a5) to head (c11703b).

Files Patch % Lines
HARK/core.py 57.50% 17 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1389      +/-   ##
==========================================
- Coverage   71.53%   71.45%   -0.08%     
==========================================
  Files          83       83              
  Lines       13938    13955      +17     
==========================================
+ Hits         9971     9972       +1     
- Misses       3967     3983      +16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Mv77
Copy link
Contributor Author

Mv77 commented Feb 23, 2024

That's fair, I exaggerated. This is an instance where the Parameters tool that will eliminate a lot of ugly simulation code can also make solution code slightly more beautiful :)

            # Update time-varying single period inputs
            for name in agent.time_vary:
                if name in these_args:
                    solve_dict[name] = agent.__dict__[name][k]
            solve_dict["solution_next"] = solution_next

            # Make a temporary dictionary for this period
            temp_dict = {name: solve_dict[name] for name in these_args}

turns into

            # Make a temporary dictionary for this period
            temp_pars = agent.params[k]
            temp_dict = {
                name: solution_next if name == "solution_next" else temp_pars[name]
                for name in these_args
            }

@mnwhite
Copy link
Contributor

mnwhite commented Feb 26, 2024 via email

@mnwhite mnwhite mentioned this pull request May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants