Code Monkey home page Code Monkey logo

lecture-source-jl's Introduction

"Quantitative Economics with Julia":

About this Repository

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

See LICENSE.md for licensing and copyright information.

Usage

Prerequisities

  • The latest quantecon/jupinx Docker image (see the Containerization section), or:
  1. Start within your home directory, using WSL if on Windows. If you're running from the shell, make sure you run as administrator.

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

cd
sudo apt update
sudo apt install make gcc unzip
sudo apt-get update
sudo apt-get install libxt6 libxrender1 libgl1-mesa-glx libqt5widgets5 
  1. Install Conda
wget https://repo.anaconda.com/archive/Anaconda3-2019.07-Linux-x86_64.sh
bash Anaconda3-2019.07-Linux-x86_64.sh

Choose yes to: "Do you wish the installer to initialize Anaconda3 by running conda init?"

  1. Install Julia
wget -qO- https://julialang-s3.julialang.org/bin/linux/x64/1.2/julia-1.2.0-linux-x86_64.tar.gz | tar -xzv
  1. Assuming you installed anaconda in your home directory then,
  • Within your home directory, 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.2.0/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
pip install jupinx
pip install sphinxcontrib.bibtex
conda install dask distributed
  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

It's recommended that you install and 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

(Optional, for Advanced Users)

To accelerate your builds with PackageCompiler

cd lecture-source-jl/util

Then

julia packagecompile.jl

Finally, go to the source/rst to continue

cd ../source/rst

This will have side-effects for your Julia system (i.e., it will "bake in" a version of Plots.jl) You can re-run the script again whenever the upstream quantecon-notebooks-julia TOML changes, and reinstall Julia with step 3. to get back to the old sysimg.

Finally, go to the source/rst to continue

cd ../source/rst
  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

You may see a lot of warnings during this step if you chose to use PackageCompiler acceleration above. They can be safely ignored.

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

Editing with WSL and VS Code

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.
  • Consider adding a RST Extension
  • Consider adding the Live Server extension for viewing the html from _build/website/jupyter_html files

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.

Containerized Build

Alternately, you can use the quantecon/jupinx docker image, which has all these dependencies baked in.

The advantage of a containerized setup is that you can use a siloed, "pre-baked" setup environment to build the lectures.

  1. Install Docker.

  2. Run docker pull quantecon/jupinx.

  3. In a terminal, cd to this repository, and run docker run --name quantecon-docker -it -d -v "$(pwd)":/home/jovyan/work quantecon/jupinx from inside the directory (Linux/macOS). It should spit out a container ID string then exit. Try ${PWD} on Windows, but your mileage may vary.

    โš ๏ธ In order to guarantee reproducibility, you should either be mounting a fresh clone of this repository, or sanitize things by running git clean -xdff (remove uncommitted/untracked files) and git reset --hard (reset to the last git state.) Otherwise, local variance in the mounted files may impact your results.

  4. In the same terminal (i.e., not inside the container), run docker exec quantecon-docker bash -c "cd work && make jupyter". Change it to jupyter-tests if you want it to output/execute the test blocks.

  5. Grab a coffee. The Julia side executes in serial, so it takes about an hour (modulo your processor speed.)

  6. After it's done, in a terminal run docker stop quantecon-docker and docker rm quantecon-docker. This will garbage-collect the container, and free the name quantecon-docker for your next run. If you're having trouble, run docker rm -f quantecon-docker to force removal.

lecture-source-jl's People

Contributors

jlperla avatar arnavs avatar nosferican avatar xiaojunguan avatar mmcky avatar pooyaravari avatar natashawatkins avatar aakashgfude avatar ajozefiak avatar anjujoon avatar yolsever avatar drdrij avatar amphibianoid avatar fratrik avatar quanteconuser avatar cc7768 avatar jstac avatar leopoldomig avatar pedropessoa avatar qirui-ubc avatar sgyetvay avatar anubhavpcjha avatar gava31 avatar sejinahn2 avatar yywingliang avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.