Skip to content

Revisions to Market parameter structure#1719

Merged
mnwhite merged 14 commits intomainfrom
MarketRefresh
Feb 26, 2026
Merged

Revisions to Market parameter structure#1719
mnwhite merged 14 commits intomainfrom
MarketRefresh

Conversation

@mnwhite
Copy link
Contributor

@mnwhite mnwhite commented Feb 10, 2026

This PR is meant to address issues #766 and #989 ; the main change is a regularization of get_economy_data. Rather than each AgentType subclass having their own method that says how to get information from the associated Market instance, there is now a unified AgentType.get_market_params method. AgentType subclasses that (usually) use an associate Market should specify a market_vars class attribute naming the parameters that should be pulled down from the Market. The user also doesn't need to write a trivial loop over AgentType instances in the Market; instead, they can just call Market.give_agent_params(), which also runs agent.construct() by default because the agents usually need information from the economy to finish building themselves.

The example notebook has been lightly edited to work with the changes, and most of the tests pass. However, two market-level solution results changed slightly. I am issuing the PR now so I can look carefully at what I changed and see if I made a mistake somewhere.

Incidentally, this PR also makes a tiny extension to the special get_it_from constructor. If the thing that it is told to get_it_from is just a single float, int, bool, complex, or string, then it is interpreted as literally just taking that value itself. In most cases, get_it_from is used to "unpack" attributes from an object or entries from a dictionary, but now it also means "it's this number by a different name".

Tomorrow morning I'll add some flexibility to allow "parameter-like" arguments to calc_dynamics, which is in a similar vein to these changes.

The `get_economy_data` method on various AgentType subclasses in ConsAggShockModel has been deprecated in favor of a single `AgentType.get_market_params` method. Parameters to be fetched should be named in the class attribute `market_params` on the `AgentType` subclass, and the `Market` instance should run its `give_agent_params` method. I might have that be automatically called as part of instantiation.

I also cleaned up the default dictionaries a little bit on this commit, and added an extremely small feature to the `get_it_from` special constructor.

The example notebook runs, but the test file has not been edited. Also need to revise the documentation to explain the new (easier) format.
Two tests fail with slight changes to solution results. Committing and will initiate a PR so I can look carefully at what's changed.
Didn't see before that this one was failing.
The result changes are because of random seed changes. Essentially, the agents' distributions are produced in a different sequence than before (because they don't do an initial build) so the seed that is set for each distribution is different.
@mnwhite
Copy link
Contributor Author

mnwhite commented Feb 10, 2026

The two changed test targets are because the seeds of distributions have changed. With the revisions here, the "order of operations" for building distributions has changed, so the agents' IncShkDstn ends up with a different seed(s) than before.

If an argument of `calc_dynamics` is not named in `track_vars`, then the code now looks for it as an attribute of the market. This improves compatibility with `calc_dynamics` being passed as a function but still using parameters from the market.
Notebooks now have correct descriptions of `give_agent_params()`.
@mnwhite mnwhite changed the title [WIP] Revisions to Market parameter structure Revisions to Market parameter structure Feb 10, 2026
@mnwhite mnwhite requested a review from alanlujan91 February 10, 2026 16:46
@mnwhite
Copy link
Contributor Author

mnwhite commented Feb 10, 2026

This is ready for review, but the CHANGELOG-only PR should be merged into main first, then pulled into this branch (and updated).

alanlujan91
alanlujan91 previously approved these changes Feb 10, 2026
@mnwhite
Copy link
Contributor Author

mnwhite commented Feb 10, 2026

CHANGELOG has been updated and this is now properly ready for review.

@mnwhite mnwhite requested a review from alanlujan91 February 10, 2026 23:46
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses issues #766 and #989 by regularizing how AgentType subclasses obtain parameters from their associated Market instances. The changes replace custom get_economy_data() methods with a unified get_market_params() approach that uses a market_vars class attribute to specify which parameters should be fetched from the Market.

Changes:

  • Introduced AgentType.get_market_params() method and market_vars class attribute to replace custom get_economy_data() methods across agent types
  • Added Market.give_agent_params() convenience method to distribute market-level parameters to all agents and run their construct() methods
  • Extended the get_it_from constructor to handle scalar values directly, not just objects and dictionaries
  • Modified Market.update_dynamics() to allow calc_dynamics to accept additional arguments beyond those in track_vars by looking for matching Market attributes
  • Refactored income shock distribution constructors into standalone functions in IncomeProcesses.py
  • Updated test assertion values that changed slightly due to different ordering of distribution construction

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
HARK/core.py Added get_market_params() method to AgentType and give_agent_params() method to Market; enhanced update_dynamics() to fetch non-tracked arguments from Market attributes
HARK/utilities.py Extended get_it_from constructor to return scalar values directly when the parent is a primitive type
HARK/ConsumptionSaving/ConsAggShockModel.py Major refactoring: removed get_economy_data() and add_AggShkDstn() methods; added market_vars attributes; moved income shock combination logic to standalone constructor functions; renamed MrkvNow_init to MrkvInit for consistency
HARK/ConsumptionSaving/ConsIndShockModel.py Updated docstring parameter names from aNrmInitMean/Std to kLogInitMean/Std and pLvlInitMean/Std to pLogInitMean/Std
HARK/Calibration/Income/IncomeProcesses.py Removed duplicate assertion; added combine_ind_and_agg_income_shocks() and combine_markov_ind_and_agg_income_shocks() utility functions
tests/ConsumptionSaving/test_ConsAggShockModel.py Updated tests to use give_agent_params() instead of manual loops calling get_economy_data(); updated expected test values that changed slightly due to constructor ordering changes
tests/ConsumptionSaving/test_SmallOpenEconomy.py Replaced manual parameter assignment and get_economy_data() loop with consolidated dictionary approach and give_agent_params() call
examples/Journeys/Journey-PhD.ipynb Updated to use new give_agent_params() method; incidentally changed Python version to 3.12.9
examples/Gentle-Intro/Market-Intro.ipynb Added documentation for max_loops parameter; clarified that calc_dynamics can accept additional Market attribute arguments; enhanced explanation of intractability in Krusell & Smith model; incidentally changed Python version to 3.12.9
examples/Gentle-Intro/Constructors-Intro.ipynb Added new section explaining the special case for AgentType subclasses in Market contexts that don't run construct() at instantiation
docs/CHANGELOG.md Documented breaking changes and new features

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

mnwhite and others added 3 commits February 26, 2026 09:45
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This cell isn't run by default so I missed it
@mnwhite mnwhite merged commit 791b3fa into main Feb 26, 2026
22 checks passed
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.

3 participants