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

Fix HARK GUI issue #444

Merged
merged 4 commits into from
Dec 10, 2019
Merged

Fix HARK GUI issue #444

merged 4 commits into from
Dec 10, 2019

Conversation

MridulS
Copy link
Member

@MridulS MridulS commented Dec 5, 2019

#199

User will no longer get the import Matplotlib error as I have moved it to inside the function instead of a global level import.

For example this will work without any issue

In [21]: import HARK 

In [22]: from HARK.ConsumptionSaving.ConsIndShockModel import PerfForesightConsumerType

In [23]: PF_params = {
    ...:     'CRRA' : 2.5,           # Relative risk aversion
    ...:     'DiscFac' : 0.96,       # Discount factor
    ...:     'Rfree' : 1.03,         # Risk free interest factor
    ...:     'LivPrb' : [0.98],      # Survival probability
    ...:     'PermGroFac' : [1.01],  # Income growth factor
    ...:     'T_cycle' : 1,
    ...:     'cycles' : 0,
    ...:     'AgentCount' : 10000
    ...: }

In [24]: PFexample = PerfForesightConsumerType(**PF_params) 

In [25]: PFexample.solve()

In [26]: PFexample.solution[0].cFunc
Out[26]: <HARK.interpolation.LinearInterp at 0x7f102555aa50>

In [27]: PFexample.solution[0].hNrm
Out[27]: 50.49994992551661

In [28]: PFexample.unpackcFunc()

In [29]: PFexample.timeFwd()

In [30]: mMin = PFexample.solution[0].mNrmMin

This fix will give an error if the user tries to plot something on the server without having Matplotlib with the proper backend installed.

the plotting wouldn't

In [31]: plotFuncs(PFexample.cFunc[0],mMin,mMin+10)
    ..........
    ..........
ImportError: No module named _tkinter, please install the python-tk package

The plotting one can be fixed by changing the backend to 'agg' (this has to be done before anything Matplotlib related is imported)

In [1]: import matplotlib

In [2]: matplotlib.use('agg')

In [..]: plotFuncs(PFexample.cFunc[0],mMin,mMin+10)

plotFuncs wouldn't throw any error now and it wouldn't do anything as it is implemented to just do plt.show() (which doesn't work for a server without any display) . Should we add the capability to save the figure too with plotting functions by passing an argument like plotFuncs(save_fig=True, show_fig=False)?

@project-bot project-bot bot added this to Needs Triage in Issues & PRs Dec 5, 2019
@MridulS
Copy link
Member Author

MridulS commented Dec 10, 2019

This is good to go, will update other instances of Matplotlib in ConsumptionSaving refactor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Issues & PRs
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants