Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Source files for "Lectures in Quantitative Economics" -- Julia version

License

Notifications You must be signed in to change notification settings

QuantEcon/lecture-source-jl

Repository files navigation

"Quantitative Economics with Julia":

About this Repository

This is the source repository for Quantitative Economics with Julia. These instructions required for authoring/editing the textbook and notebooks, and are not necessary for typical usage.

See LICENSE.md for licensing and copyright information.

Release

For information on releasing a new lecture version, see the docs.

Usage

WSL and VSCode if on Windows

  • To get "Ubuntu on Windows" and other linux kernels see instructions.
    • For the installation, run it in Powershell as an administrator
    • Hint on copy-paste: One way to paste into a a windows (of any sort) is the <ctrl-c> text somewhere else and then, while selected in the terminal at the cursor, to <right click> the mouse (which pastes).
  • Install VSCode and remote WSL support on windows
  • Consider installing the shiny new Windows Terminal See VS Code Remote Editing and VS Code Remote WSL

In a windows terminal run

 git config --global credential.helper wincred

In a WSL terminal,

git config --global user.email "[email protected]"
git config --global user.name "Your Name"
git config --global credential.helper "/mnt/c/Program\ Files/Git/mingw64/libexec/git-core/git-credential-wincred.exe"

(see more details in Sharing Credentials )

To open the WSL in VS Code

  • Click on the "><" icon on the bottom left hand corner, and open the remote folder in your WSL image (e.g. ~/lecture-source-jl)
  • Choose "TERMINAL" to open a WSL terminal, and run any of the above jupinx or make commands.

Prerequisities

  1. Start within your home directory

  2. Go to your home directory and make sure key dependencies are installed

cd ~
sudo sudo apt update
apt-get upgrade
sudo apt install make gcc unzip
sudo apt-get update
sudo apt-get install libxt6 libxrender1 libgl1-mesa-glx libqt5widgets5 
  1. Install Conda

    • In the Ubuntu terminal, first install python/etc. tools
    wget https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh
    bash Anaconda3-2020.02-Linux-x86_64.sh
    • Create a directory .conda by running mkdir ~/.conda if the warning "Unable to register the environment" shows up
  2. The installation will take time. You should:

    • accept default paths
    • accept licensing terms
    • IMPORTANT Manually choose yes to have it do the conda init
    • Delete the installation file
      sudo pip install --upgrade --force-reinstall pyzmq
      rm Anaconda3-2020.02-Linux-x86_64.sh
  3. Install Julia

wget -qO- https://julialang-s3.julialang.org/bin/linux/x64/1.4/julia-1.4.1-linux-x86_64.tar.gz | tar -xzv
  1. Assuming you installed anaconda in your home directory then,
  • Within your home directory modify the .bashrc
    • Use VSCode Remote on Windows or
    • edit .bashrc. This opens Vim. Go to the bottom of the file, and type i to enter insert mode.
  • Add something like the following:
export PATH=~/anaconda3/bin:~/julia-1.4.1/bin:$PATH

Hit <Esc> to exit insert mode, and then type :x to save and exit.

Then, from your terminal, run source .bashrc to load the changes in the current WSL terminal.

  1. Install Jupinx and deps
conda upgrade conda
conda install dask distributed
pip install jupinx sphinxcontrib.bibtex jupinx guzzle_sphinx_theme
  1. Clone the repo to your preferred location (note that WSL+vscode+ssh cloning has bugs, so use https)
git clone https://github.com/QuantEcon/lecture-source-jl

Precompile the packages used by the lectures before building. To do this:

  1. (Optional) Delete your ~/.julia folder to start fresh.

  2. In a Julia REPL (i.e. julia in terminal if your .bashrc was edited above), run

] add InstantiateFromURL IJulia; precompile
  1. Start a new REPL

(If you didn't run the package compilation step, then cd lecture-source-jl/source/rst) In the REPL, run

] activate .; instantiate; precompile

This will take a long time to run. You can safely ignore build errors for Electron

Building

There are a few different targets, notably:

  • make website, which will generate Jupyter, execute notebooks, and then turn that into HTML

  • make coverage, which will do steps (1) and (2) above (with otherwise hidden unit tests), and then generate a report about which notebooks fail.

  • make preview, which will do steps (1), (2), and (3) above and then fire up a local HTTP server.

  • jupinx -w --files source/rst/getting_started_julia/julia_by_example.rst, or any other .rst for a single file

In vscode, the Live Server allows you to watch an output HTML file. Install the extension (in WSL if required) and after generating the HTML, right click on it and say "Open with Live Server"

Options and Special Cases

Specifying parallel execution (i.e., make coverage parallel=8) will use 8 cores instead of 1. This leads to a notable speedup in build times. (There are some zmq errors that sporadically pop up at very high core counts, i.e. above 8.)

You can build only a few notebooks by jupinx -w --files source/rst/<file>.rst.