Course Software

Julia

Although this course is language agnostic, we will use Julia to demonstrate various algorithms. It is a high-level language for scientific computing that provides exceptional run-time performance, approaching that of statically-compiled languages like C. The software is free and open source and is under active development.

If you are already familiar with MATLAB, R, or Python, see this list of notable differences.

There are many ways to get going with Julia. Here are some options:

  1. Install Julia on your own machine. You can download and install the command line version or a version that is bundled with the Juno IDE.

  2. Run Julia on Stanford FarmShare or FarmShare2. All you need to do is ssh into corn.stanford.edu or rice.stanford.edu to access the shared computing enviornment. The default version of Julia available on the machines is 0.5. To use the latest Julia 0.6, first load the julia module:

    $ module load julia
    $ julia --version
    julia version 0.6.0
    
  3. Run Julia in the cloud on JuliaBox. You will want to make sure to back up your code to a Google Drive folder or a Git repository to reduce the risk of losing your work. Also, be sure not to exceed 500MB, otherwise your older files will be lost.

Note: Please be sure you are using Julia version 0.6.x!

Local Installation

To install the course software on your local machine, complete the steps outlined here.

Note: Throughout this section, lines beginning with julia> should be run in the Julia REPL.

Note: If anything goes wrong, see Troubleshooting below.

  1. Install Julia 0.6: Instructions

  2. To install Jupyter, Start Julia and run

    julia> Pkg.add("IJulia")
    
  3. Install the course code

  4. Download and unzip the aa228-notebook directory: aa228-notebook-archive.zip (or use git to clone the sisl/aa228-notebook repository)

    1. In Julia, run the install script to install all dependencies, replacing $PATH_TO_AA228_NOTEBOOK with the path to the aa228-notebook directory. julia> include("$PATH_TO_AA228_NOTEBOOK/install.jl")
    2. Run jupyter in the aa228-notebook directory julia> using IJulia julia> notebook(dir="$PATH_TO_AA228_NOTEBOOK")

Troubleshooting

Potential fixes for things that could go wrong.

Problems installing jupyter

First, check to see if IJulia was able to install it. julia> Pkg.add("IJulia") will download the IJulia Julia package, and, if you do not already have jupyter, this will automatically install it via miniconda via the Conda.jl package.

To test the installation, in Julia, run

  julia> using IJulia
  julia> notebook()

This should open a jupyter notebook browser in the current directory. If this doesn’t work, jupyter may not be installed correctly.

  • If you are using Windows and you get the message failed to create process, it is likely that you have spaces in the file path (if you are in this situation please contact Zach at zsunberg@stanford.edu so I can verify that these instructions are correct).

    • Check to see if there are any spaces in the path returned by julia> Pkg.dir(). If there are, one workaround is to install Miniconda in a path that does not have spaces:
      1. Install miniconda with python 3.5 from here [http://conda.pydata.org/miniconda.html](). Make sure to select install for all users. This should install miniconda in a directory like C:\Miniconda3.
      2. Install the required jupyter python package. In the windows command prompt, run the following command: conda install jupyter
      3. Close all command prompts and restart julia so that the environment is updated with the new miniconda installation, and rebuild IJulia: julia> Pkg.build("IJulia")
      4. Start the notebook with the following command in a command prompt: jupyter notebook and try creating a new Julia 0.6 notebook.

    Note: If you use this workaround, you may need to manually install dependencies for other packages (such as matplotlib for PyPlot.jl) using conda instead of from within julia, and you may have to notify julia of your Anaconda installation with julia> ENV["PYTHON"]="C:\\Miniconda3\\python.exe; Pkg.build("PyCall").

HDF5 build error when installing BayesNets.jl from install.jl

HDF5 is a data storage library (the same that is used in Matlab’s .mat files). Julia should automatically download and install the library, but you may need to do it manually. More instructions are at the HDF5.jl repo - Ubuntu: sudo apt-get install hdf5-tools

Bayesian network graph visualizations do not display correctly in notebooks

  • If text is displayed without an image:
    • TikzGraphs.jl or one of its dependencies may not be installed correctly. Try reinstalling it.
  • If only edges are displayed or node labels do not display correctly:
    • Use the google-chrome browser. Firefox and other browsers may not display the svgs correctly.

PGFPlots/SVG conversion errors when running notebooks

If you get an error similar to

Error saving as SVG
could not spawn `pdf2svg tikzpicture.pdf tikzpicture.svg`: no such file or directory (ENOENT)

You need to have pdf2svg installed on your machine. If on OSX, run:

brew install pdf2svg

Please install homebrew here if you do not have it yet. If you do not have xcode tools installed, refer to this. If on Ubuntu, run:

sudo apt-get install pdf2svg

If on Windows, download this: https://github.com/jalios/pdf2svg-windows/archive/master.zip. Extract the zip file where you want to keep it. Then add the directory inside called “dist-64bits” to your path. Instructions on how to do this can be found here.

And make sure that you add pdf2svg to your path, regardless of your platform, so that you can run “pdf2svg” from the terminal.

If you get an error similar to:

Error saving as SVG
could not spawn `lualatex --enable-write18 --output-directory=. tikzpicture`: no such file or directory (ENOENT)

To get plotting to work, I recommend installing texlive (either through your package manager on linux [texlive-extra-utils on ubuntu I believe] or from https://www.tug.org/texlive/quickinstall.html) or from https://www.tug.org/texlive/acquire-netinstall.html.