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

light touch Market class refactoring #765

Merged
merged 23 commits into from
Aug 13, 2020
Merged

Conversation

sbenthall
Copy link
Contributor

CDC has asked me to familiarize myself with the Market code because of a certain project.

In this PR, I'll try to do some light maintenance based on previously established design principles.

Some considerations:

The current step in this PR, meant to be illustrative, is moving the storage of initial and state values for sow_vars into dictionaries. The trajectory of this work is to make similar adjustments for the reap_vars, etc. The Market class is a nice place to do these changes because the variables are already categorized in the class constructor. (I'd recommend similar changes to the Agent classes, but these are not yet written in as abstract a way.)

The current PR passes the test_ConsAggShockModel.py tests. I'd like to note that this is without changes to e.g. the SmallOpenEconomy that would be necessary to retain functionality. This indicates a gap in the current test suite. If this PR's direction gets approval, I would write tests for those other classes as part of this PR.

@project-bot project-bot bot added this to Needs Triage in Issues & PRs Jul 21, 2020
@sbenthall
Copy link
Contributor Author

Another reason to store Market state in this way is that this kind of representation is needed by the mill method anyway. Currently, this is done via awkward ad hoc construction. The trajectory of this PR is to have the Market natively store the reap and const variable values in dictionaries, making this ad hoc construction unnecessary.

https://github.com/econ-ark/HARK/blob/master/HARK/core.py#L1058-L1065

@@ -1678,12 +1680,12 @@ def update(self):
self.KtoLnow_init = self.kSS
Copy link
Contributor Author

Choose a reason for hiding this comment

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

did I miss one here? i think so

HARK/core.py Show resolved Hide resolved
HARK/core.py Outdated
setattr(self, this_var, this_product)

for sow_var in self.sow_state:
this_product = getattr(product, sow_var)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This simplifies if millRule returns a dict-like: self.sow_state.update(product)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

chose for millRule to return a tuple

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(closer to Dolo, supposed to be good for numba)

self.sow_init['Mnow'] = self.MSS
self.sow_init['Aprev'] = self.KSS
self.sow_init['Rnow'] = self.RSS
self.sow_init['Wnow'] = self.WSS
self.PermShkAggNow_init = 1.0
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Missed these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, not missing because these are not sow_vars in KS

'TranShkAggNow',
'KtoLnow',
'MrkvNow' # This one is new
],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When all the sow_vars are "Now", "Now" can be left out of the name...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But I don't dare.

@@ -2455,81 +2526,6 @@ def calcAFunc(self, Mnow, Aprev):
return AggShocksDynamicRule(AFunc_list)


class CobbDouglasAggVars(HARKobject):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

replaced these container classes with tuples same size/order as sow_vars

@@ -48,6 +48,9 @@ def test_macro(self):
self.assertAlmostEqual(self.economy.AFunc.slope,
1.116259456228145)

self.assertAlmostEqual(self.economy.history['MaggNow'][10],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These tests are added in #773, which should be merged first

@sbenthall sbenthall requested a review from mnwhite July 23, 2020 20:28
@sbenthall sbenthall changed the title [WIP] light touch Market class refactoring light touch Market class refactoring Jul 23, 2020
@sbenthall
Copy link
Contributor Author

This PR is now ready for review.

@llorracc
Copy link
Collaborator

Can use regular dicts instead of OrderedDict for Python 3.7+

@sbenthall
Copy link
Contributor Author

0.10.6 supports Python 3.6:
https://github.com/econ-ark/HARK/blob/master/setup.cfg#L42

I think in our meeting today we agreed 0.10.7 would drop Python 3.6 support

@sbenthall
Copy link
Contributor Author

OrderedDict replaced with dict in recent commit

@sbenthall sbenthall added the Ready-To-Merge Has been reviewed and when branch is updated and checks pass it should be merged label Jul 30, 2020
@sbenthall
Copy link
Contributor Author

I expect this to be merged AFTER the 0.10.7 release, since there seems to be a feature freeze there.

@MridulS MridulS removed the Ready-To-Merge Has been reviewed and when branch is updated and checks pass it should be merged label Aug 5, 2020
@llorracc llorracc added the Ready-To-Merge Has been reviewed and when branch is updated and checks pass it should be merged label Aug 13, 2020
@sbenthall sbenthall merged commit 1d15c4d into econ-ark:master Aug 13, 2020
Issues & PRs automation moved this from Needs Triage to Done Aug 13, 2020
sbenthall added a commit that referenced this pull request Aug 13, 2020
MridulS pushed a commit that referenced this pull request Aug 14, 2020
* update CHANGELOG with #765 change

* 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
Ready-To-Merge Has been reviewed and when branch is updated and checks pass it should be merged
Projects
Issues & PRs
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

4 participants