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

Distribute parameter dictionaries to nearby class definitions #527

Merged
merged 34 commits into from
Mar 17, 2020

Conversation

sbenthall
Copy link
Contributor

A PR for the next proposed stage of #446

Currently, all default model parameters are defined in ConsumerParameters.py.
Thus, in order to know the default parameters for a model type, one has to look in a separate file.
This is very nonstandard for default parameter values in Python.

Moreover, while the old means of having models "inherit" parameters made this structure necessary or at least convenient, now that models inherit the default parameters of their superclasses at initialization, it makes more sense to have parameters be defined near to where they are used.

This PR is for ongoing work to see what this different way of laying out the default parameters would look like.

@project-bot project-bot bot added this to Needs Triage in Issues & PRs Feb 16, 2020
@sbenthall sbenthall changed the title [WIP] Distribute parameter dictionaries to nearby class definitions Distribute parameter dictionaries to nearby class definitions Feb 21, 2020
@sbenthall
Copy link
Contributor Author

OK, this PR is now ready for review.

I expect @mnwhite will want to take a look.

The general idea is that it has moved the default ConsumptionSaving model parameters from ConsumerParams (which doesn't exist any more, in this PR) to objects that are defined much closer to the AgentTypes where the parameters are primarily used.

These objects are exposed through their respective module interfaces, so they are still used elsewhere.

The main benefits to this are:

  • Because the parameter objects are defined closer to where they are used, it's easier to see what the input variables to an AgentType are without having to flip between files.
  • I've made it stylistically more succinct: this commit removes 60 lines of code from the repository. There's one fewer module (no more ConsumerParams)
  • Now, not every new type has to touch the additional ConsumerParams file; a new model can be wholy contained in its own module.

While admittedly a rather small and mainly cosmetic change, it's working towards a more systematic way of documenting, inheriting, and accessing parameters. With a bit more work, the new parameters for each sub-AgentType can be properly documented, and the parameters list can be stored in a way that can be easily exported for viewing. Most software tooling (like Sphinx) will assume default arguments are near their classes. We won't have to fight the documentation engine to list these parameters.

@llorracc
Copy link
Collaborator

llorracc commented Feb 21, 2020 via email

@sbenthall
Copy link
Contributor Author

I think I see the issue you are raising.

I believe the non-backwards compatible changes will be cases where a DemARK or REMARK imports one of the parameter objects (e.g. init_idiosyncratic_shocks) from ConsumerParameters.

I would not advise having code dynamically choose the import path to ensure backwards compatibility. That gets very messy.

Rather, I think the way to handle this is through skilled release management. Something like this:

  • Very soon (already?) there will be a new release of HARK.
  • Any REMARK that is finalized should have it HARK dependency pegged to the new release in master
  • If a REMARK is still "under construction" but it's important to have a functioning copy available for demonstration, then the REMARK can have a release/tag in which the HARK dependency is pegged to the new version.
  • Because DemARKs are used in teaching and need to be functioning all the time, DemARK master should peg it HARK dependency to the most recent version.

These changes would secure the downstream dependencies from breaking due to changes in HARK.

Next: pull in these changes to parameter handling to HARK master. And any other changes that are slated for the next release. Before too long, issue a new release of HARK.

Finally: in the downstream projects, work on PRs that update the HARK dependency and fix any problems that result from that change.

@sbenthall
Copy link
Contributor Author

sbenthall commented Mar 12, 2020

Some changes needed to get this to work:

  • the Market class now does an assignParameters in its initalizer
  • CobbDouglasEconomy passes its keywords to Market

@sbenthall
Copy link
Contributor Author

The failing test_ConsIndShockSolverBasic is due to a change in the LivPrb for that solver from 0.99 to 0.98

I must have missed something when moving the parameter dictionaries...

@sbenthall
Copy link
Contributor Author

Ah, it was a bug in how I was initializing the agent type from the dictionary in the test.
Tests are working locally now.

I request a review and merge. @MridulS ? @mnwhite ?

@mnwhite
Copy link
Contributor

mnwhite commented Mar 17, 2020

This looks good to me. I like the new format. I'm happy to merge if no one objects.

@mnwhite mnwhite merged commit 6631c0d into econ-ark:master Mar 17, 2020
Issues & PRs automation moved this from Needs Triage to Done Mar 17, 2020
@MridulS
Copy link
Member

MridulS commented Mar 17, 2020

@sbenthall this will probably break demarks and remarks too. Have you looked into that?

@MridulS
Copy link
Member

MridulS commented Mar 17, 2020

@sbenthall examples too.

@llorracc
Copy link
Collaborator

llorracc commented Mar 17, 2020

  • Now, not every new type has to touch the additional ConsumerParams file; a new model can be wholy contained in its own module.

@sbenthall, in the Portfolio model, we never had init_portfolio in ConsumerParams.py, it was defined in the portfolio model itself. Is that the preferred way of doing things going forward, or should @mnwhite put init_portfolio in ConsumerParameters.py?

@mnwhite
Copy link
Contributor

mnwhite commented Mar 17, 2020 via email

@MridulS
Copy link
Member

MridulS commented Mar 17, 2020

@sbenthall this is a major change, can you add it to v0.10.5
https://github.com/econ-ark/HARK/blob/master/CHANGELOG.md#major-changes

let's add any major/minor change to the codebase to this just before a merge, as it will make our release process quick.

@sbenthall
Copy link
Contributor Author

Made #580 to address the examples/ in HARK
The way to prevent DemARKs and REMARKs from breaking is to pin their dependency on 0.10.4.

@MridulS
Copy link
Member

MridulS commented Mar 18, 2020

The way to prevent DemARKs and REMARKs from breaking is to pin their dependency on 0.10.4.

I get it for REMARKs but DemARKs are supposed to work with the master branch of HARK. We don't want users to do pip install econ-ark and not have DemARKs working for them.

@llorracc
Copy link
Collaborator

I agree with @MridulS: We want DemARKs (and examples) to always work with the latest version of HARK. If we make a change that breaks a DemARK, but really want to make that change, then I think we will want to remove that DemARK to a "release-10.4-broke-me" branch until fixed. I guess that ideally we would want to version-control the DemARK itself. We could do that by having an initialization cell in every DemARK that just tested whether the version of HARK being used was greater than the version of DemARK, and if so halting with a message that the person should pull down the updated DemARK version.

@sbenthall
Copy link
Contributor Author

I've made an issue to discuss this further here econ-ark/DemARK#108

MridulS pushed a commit that referenced this pull request Mar 22, 2020
* Add parameter movement to major changes for 0.10.5, see #527

* Update CHANGELOG.md

Co-authored-by: Mridul Seth <seth.mridul+github@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Issues & PRs
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants