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

ConsumptionSavingModel will not load from outside sources #58

Closed
ganong123 opened this issue Jun 20, 2016 · 7 comments
Closed

ConsumptionSavingModel will not load from outside sources #58

ganong123 opened this issue Jun 20, 2016 · 7 comments

Comments

@ganong123
Copy link

Here are two places where it fails.

  File "/Users/ganong/repo/HARK/cstwMPC/cstwMPC.py", line 19, in <module>
    import ConsumptionSavingModel as Model

ImportError: No module named ConsumptionSavingModel
  File "/Users/ganong/repo/HARK/TractableBufferStock/TBSexamples.py", line 13, in <module>
    from ConsumptionSavingModel import ConsumerType, solveConsumptionSavingMarkov

ImportError: No module named ConsumptionSavingModel

However, when I run ConsumptionSavingModel.py directly, it runs with no trouble at all.

@ganong123
Copy link
Author

Let me know if there's anything else I can do to help with reproducibility. Here's some platform information.

Version      : 2.7.11
Version tuple: ('2', '7', '11')
Compiler     : GCC 4.2.1 (Apple Inc. build 5577)
Build        : ('default', 'Dec  6 2015 18:57:58')

@mnwhite
Copy link
Contributor

mnwhite commented Jun 20, 2016

For reproducibility, let's try this:

  1. Download and unpack a fresh copy of the repo; right now, the comments-and-cleanup branch has the most up-to-date code.
  2. Open .../HARK/cstwMPC/cstwMPC.py in Spyder
  3. Click the green arrow "run" button in the toolbar.

That should run a really small estimation ("beta-point infinite horizon") and tell you that beta=0.9893 or so. You can also try doing this for .../HARK/ConsumptionSavingModel/TractableBufferStockModel.py ... That will take ~1 second and solve the same simple model two different ways.

If the method you used to run the modules and get that error is substantially different than the procedure I described, please tell me what you were doing. If there are other ways to run files that should work but don't work, we want to know.

@ghost
Copy link

ghost commented Jun 20, 2016

ganong123,
The problem could be your python path. I guess that you ran cstwMPC.py in the cstwMPC folder.
In this case, ConsumptionSavingModel could not be called because the compiler did not know where ConsumptionSavingModel is, unless you inserted the path.
Inserting the path is easy. You can see the command line sys.path.insert(0,'../') in cstwMPC.py
Check your Hark-cloned directory. In my case, I write:
sys.path.insert(0,'/Users/yeabinmoon/Documents/HARK-master/ConsumptionSavingModel')

@mnwhite
Copy link
Contributor

mnwhite commented Jun 20, 2016

John:

Without making that change, do you get the same error? The lines

sys.path.insert(0,'../')
sys.path.insert(0,'../ConsumptionSavingModel')

are meant to work on every machine, no matter where you put HARK, because it's a relative filepath. The intention is that it adds the directory directly above the current one (which should be the root directory of HARK), and the ConsumptionSavingModel directory off of that one.

@ghost
Copy link

ghost commented Jun 20, 2016

My understanding on python is not quite good to be honest. But,
Using just command
import sys
sys.path.insert(0,'../')
sys.path.insert(0,'../ConsumptionSavingModel')
did not import ConsumptionSavingModel.py. In fact, I had the same problem before. So I added the direct path, and it worked. I am using Jupyter by the way.

@mnwhite
Copy link
Contributor

mnwhite commented Jun 20, 2016

I have a guess of the problem. Do:

import os
os.getcwd()

That should tell you the current working directory. Before you run a file, the current working directory should be the one that the module is in. You can change the CWD with os.chdir. If you use Spyder and click the green arrow "run" button, it does a version of this by using the runfile command with the wdir keyword.

We strongly recommend using Spyder, an iPython IDE that comes with Anaconda. Just type spyder at a command prompt after installing Anaconda.

@ganong123
Copy link
Author

(1) I was (and continue to be) working in Spyder
(2) cstwMPC.py already had the snippet

import sys 
sys.path.insert(0,'../')
sys.path.insert(0,'../ConsumptionSavingModel')

But this was not sufficient to load the relevant functions.

In any case, switching to comments-and-cleanup branch in my fork resolved the issue. Thanks everyone for your help and I'll continue to report out issues as I find them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants