Skip to content

Adding notebook and codes for Krusell and Smith (1998)#39

Open
albep wants to merge 1 commit intoQuantEcon:masterfrom
albep:adding_ks_98
Open

Adding notebook and codes for Krusell and Smith (1998)#39
albep wants to merge 1 commit intoQuantEcon:masterfrom
albep:adding_ks_98

Conversation

@albep
Copy link
Contributor

@albep albep commented Jun 22, 2016

This PR adds the directory krusell_smith_98_deps in dependencies. Such directory contains 2 Julia files with the programs to solve the model and replicate some results from Krusell and Smith (1998). These programs are run in the notebook krusell_smith_98.ipynb - also added through this commit - with extensive descriptions.

@jstac
Copy link
Contributor

jstac commented Jun 22, 2016

@albep Great. This is very nice.

@mmcky How would you like to handle these dependencies?

@mmcky
Copy link
Contributor

mmcky commented Jun 22, 2016

Given this is a Julia project -- and the current notebook dependency tools support python only -- for now we should just add them in the dependencies folder and then ask Julia to include them from the github repo url directly. I will check with Spencer for the appropriate snippet. We will need to add a utility to QuantEcon.jl

@sglyon
Copy link
Member

sglyon commented Jun 22, 2016

I think this is a great time to write up some code for a proper solution in Julia. @mmcky can you summarize all the things the python dependency system currently does?

@mmcky
Copy link
Contributor

mmcky commented Jun 22, 2016

It is pretty basic -- it just uses requests to fetch a file and place it in the cwd.
It is written on the keep it simple philosophy for now. It is not automatic and requires a single line specifying the file name -- and that file needs to be in QuantEcon.notebooks/dependencies

import os
import requests

#-Remote Structure-#
REPO = "https://github.com/QuantEcon/QuantEcon.notebooks"
RAW = "raw"
BRANCH = "master"
DEPS = "dependencies"          #Hard Coded Dependencies Folder on QuantEcon.notebooks


def fetch_nb_dependencies(files, repo=REPO, raw=RAW, branch=BRANCH, deps=DEPS, overwrite=False, verbose=True):
    """
    Retrieve raw files from QuantEcon.notebooks or any other Github repo

    Parameters
    ----------
    file_list   list or dict
                A list of files to specify a collection of filenames
                A dict of dir : list(files) to specify a directory
    repo        str, optional(default=REPO)
    branch      str, optional(default=BRANCH)
    deps        str, optional(default=DEPS)
    overwrite   bool, optional(default=False)
    verbose     bool, optional(default=True)

    TODO
    ----
    1. Should we update this to allow people to specify their own folders on a different GitHub repo?

    """

    #-Generate Common Data Structure-#
    if type(files) == list:
        files = {"" : files}

    #-Obtain each requested file-#
    for directory in files.keys():
        if directory != "":
            if verbose: print("Parsing directory: %s")
        for fl in files[directory]:
            if directory != "":
                fl = directory+"/"+fl
            #-Check for Local Copy of File (Default Behaviour is to Skip)-#
            if not overwrite:
                if os.path.isfile(fl):
                    if verbose: print("A file named %s already exists in the specified directory ... skipping download."%fl)
                    continue
            else:
                if verbose: print("Overwriting file %s ..."%fl)
            if verbose: print("Fetching file: %s"%fl)
            #-Get file in OS agnostic way using requests-#
            url = "/".join([repo,raw,branch,deps,fl])
            r = requests.get(url)
            with open(fl, "wb") as fl:
                fl.write(r.content)

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

Successfully merging this pull request may close these issues.

4 participants