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:
- 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 or VS Code.
- All you need to do is ssh into
rice.stanford.eduto access the shared computing environment. The default version of Julia available on the machines is 0.5. To use the latest Julia 1.5.1, first load the Julia module and check the version. You can then save it to be the default:
$ module load julia $ julia --version julia version 1.5.1 $ module save
Using Julia Packages
Julia’s base installation already comes with several handy packages for containers, linear algebra, random number generation, and the like. The
Base features are directly usable in the REPL while for the Standard Library, you need to import individual stdlib packages in the REPL with
julia> using LinearAlgebra and so on. Check the left-hand pane of the docs for the list of features under Base and under Standard Library. For any further packages, you will have to add them separately. You can use the Package manager (which is part of stdlib) by doing
julia> using Pkg; Pkg.add("XYZ") or by pressing
] in the REPL to go to package manager mode directly and doing
] add XYZ, where
XYZ is the name of some registered package. It is unlikely you will need to install unregistered packages, but if so, check here for more instructions or ask us in office hours.
Jupyter notebooks are useful for visualizations and code in a single working document. To install Juypter (using the
IJulia package) follow the steps here:
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 Robert at firstname.lastname@example.org 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:
- Install miniconda with python 3.6 from here. Make sure to select install for all users. This should install miniconda in a directory like
- Install the required jupyter python package. In the windows command prompt, run the following command:
conda install jupyter
- Close all command prompts and restart julia so that the environment is updated with the new miniconda installation, and rebuild IJulia:
- Start the notebook with the following command in a command prompt:
jupyter notebookand try creating a new Julia notebook.
Note: If you use this workaround, you may need to manually install dependencies for other packages (such as
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
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 notebook
- 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 in a notebook
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
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)
then you do not have tex plotting capabilities. To get plotting to work, we recommend installing texlive (either through your package manager on linux [texlive-extra-utils on ubuntu] or from https://www.tug.org/texlive/quickinstall.html) or from https://www.tug.org/texlive/acquire-netinstall.html.