Pluto & Julia
In the solution of practical exercises, tests, and exams, we will use the computer extensively in this course.
Specifically, we will use an IDE (Integrated Development Environment) called Pluto.jl. This IDE is a package developed for the Julia computing language. This tool is easy to install, easy to learn, beautiful, and extremely powerful, as you will find out. No previous relevant knowledge of computation is required. You only have to bring your computer to classes and know the basic things associated with using a computer: turning on the computer, creating a folder, naming and saving a file. That is all!
In the period in which we live, keeping on solving exercises using pencil&paper and with the help of a small calculator and Excel is like being still in the medieval age in the evolution of humankind. We have to adapt quickly to the age of “Big Data”, “Artificial Intelligence”, and “Machine Learning”, even in teaching tools and course syllabi.
Pluto’s use will be a funny, handy tool for learning, teaching, and conducting the evaluation process. We assure students that Pluto will be the less demanding part of this course but one of its most valuable items.
__________________________________________________________
A quick installation of Julia and Pluto in Windows
Note. When we see below \(~\)add \(~\)Pluto \(~\)—> \(~\) enter , it means that we should type “add Pluto” followed by clicking on “enter”
- Go here: \(~~\) https://julialang.org/downloads/.
- Download the executable: \(~~\) 64-bit (installer)
- Run the executable file: double-click on it
- Allow the installation to be done in the default directory
- Click on: \(~~\) Add Julia to Path
- Click on: \(~~\) Finish
- Julia installation is completed. Next we will install Pluto
- Start Julia by double-clicking on its icon (three little circles)
- With Julia running, click on the keyboard’s key: \(~~\) ]
- Then type: \(~~\)add \(~\)Pluto \(~~\)—> \(~~\) enter
- When the Pluto installation is completed, click on the keyboard’s key: \(~~\) backspace
- Julia and Pluto are ready to use.
- To start Pluto:
- If Julia is not running already, start Julia
- Type in the Julia window: \(~~\) import\(~\) Pluto \(~\) —> \(~\) enter \(~~~~~~~~~~~~~~\)(notice the space between “import” and “Pluto”)
- Then type:\(~~\) Pluto.run() \(~\) —> \(~\) enter \(~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\)(notice the dot between “Pluto” and “run()”)
- To open a Pluto notebook see point (7) below.
_________________________________________________________ _________________________________________________________
Julia detailed installation: Windows, macOS, Linux
If someone does not have a Windows machine (or something goes wrong with the Windows installation above), below one will find all small details about installing and running Julia and Pluto.
1. Install Julia
Go to the following address: \(~~\) https://julialang.org/downloads/
Download the installer that suits your computer’s Operating System
_________________________________________________________
2. Set Julia Properties (only in Windows)
This step is only required for the Windows operating system. The macOS and Linux installations do not require this step.
The Julia window is black by default, as seen on the first right-hand side figure (we can change its color if it is necessary).
To allow the “Copy+Paste” thing into the Julia window, firstly click on the icon of Julia (those three little circles on the top left-hand corner of the first figure on the right).
Then, a menu with various entries will pop up (see the second figure): click on Properties
A new window will appear (see the third figure). Here, to enable the Copy+Paste functionality, we have to click on the empty little box to activate
- Use Ctrl + Shift +C/V as Copy/Past
Then, finally, choose
- OK
That is it. Your Julia window is ready to accept the “Copy+Paste” functionality. However, remember that to copy something, one should click simultaneously on:
- ctrl \(~~\) and \(~~\) C
and to paste it into the Julia window, click simultaneously on:
- ctrl \(~~\) and \(~~\) shift \(~~\) and \(~~\) C
________________________________________________________________________
3. Start using Julia
Double click on the icon of Julia: 3 little circles
A black window will pop up (see first figure on the right): this is Julia’s window, also called the REPL (we can make it the size we want: larger, taller)
Type: 3*4 , then click on enter. If the output is 12, Julia is running.
Julia executes under two modes:
- Julia mode: \(~~\) julia>\(~~\) . This is the default mode, it appears whenever you open Julia. It is in this mode that computation takes place.
- Package mode: \(~~\) (@v1.8) pkg> \(~~\). This mode is designed to manage packages (to install, upgrade, or remove them) and manage projects.
To switch from one mode to the other:
- Julia mode: start Julia
- From Julia mode to Package mode: pressing the keyboard’s key: \(~~\) ] \(~~\)
- From Package mode to Julia mode: on the keyboard click on \(~~\) backspace
________________________________________________________________________
4. Managing packages
We will work with around 25 packages in our course (currently, there are around 7500 packages available).
For doing different jobs, people use different packages.
The following commands are used to manage the packages’ system. Be sure you are in the Package mode:\(~\) (@v1.8) pkg> \(~\).
add PackageName \(~\) —> \(~\) enter\(~~\) : adds a package called PackageName.jl to the Julia environment (obviously, PackageName.jl is an illustration).
remove PackageName \(~\) —> \(~\) enter \(~~\) : removes a package called PackageName.jl from the Julia environment (or use the short name \(~\) rm\(~\)).
update \(~\) —> \(~\) enter \(~~\) : updates the packages installed in the Julia environment to the latest versions (we can use also the short name \(~\) up\(~\)).
status \(~\) —> \(~\) enter \(~\) : shows all packages installed in the Julia environment (we can use also the short name \(~\) st\(~\)).
______________________________________________________________________
5. Installing Packages
In our case, we need to install only one package: Pluto
When used in a notebook, this package will automatically install the other packages called by the notebook.
Go to the Package mode \(~~\) (@v1.8) pkg> \(~\) and type:
- add Pluto \(~\) —> \(~\) enter \(~\)
That is all we have to do.
Take into account that the package names are case sensitive (“A” and “a” are different letters), and no spaces are allowed inside a package name.
The packages we will work with (but you do not need to bother about them, do not install them) are the following:
LinearAlgebra, DataFrames, PlotlyJS, PlotlyBase, HypertextLiteral, Pluto, PlutoUI, CSV, HTTP, TimeSeries, RollingFunctions, Dates, PeriodicalDates, SparseArrays, StatsBase, ColorSchemes, NLsolve, JuMP, Clp, GLPK, Ipopt,d Symbolics, Plots, Statistics, Random
________________________________________________________________________
6. Start using Pluto
In Julia mode \(~\) julia> \(~\), type:
- import \(~\) Pluto \(~\) —> \(~\) enter
Notice the blank space between \(~~\) import \(~~\) and \(~~\) Pluto
Then type:
- Pluto.run() \(~\) —> \(~\) enter
That’s it: Pluto has opened a window in your default browser (Mozilla, Chrome, Edge, or others).
It is in a browser that we will work with Pluto, using Julia as the engine at the back.
________________________________________________________________________
7. Opening a Pluto notebook
Go to the folder where your notebook is saved and copy the folder’s path.
To obtain this path, press the mouse’s right button on top of that folder, click on Properties, and copy the path seen in the Location entry.
This path will look something like this:
Windows: \(~~\) F:\Teaching\MacroI\Notebooks\Week01
Linux: \(~~\) /home/viola/Desktop/Teaching/MacroI/Notebooks/Week01
macOS: \(~~\) /Users/viola/Desktop/Teaching/MacroI/Notebooks/Week01
Paste that path to the small box seen on the figure below:
Inside the small window, at the end of the copied path (see arrow number 1 in the following figure):
add a back-slash \(~~\) \ \(~~\) (if you use Windows)
add a forward-slash \(~~\) / \(~~\) (if you use Linux)
add a forward-slash \(~~\) / \(~~\) (if you use macOS)
Once the slash is added, a small window displays the files in that folder.
Click only once on top of the file name you want to run. In this example, the file is “My_First_PlutoNotebook.jl”. See arrow number 2. Notice that Pluto can only open Julia files, which have an extension \(~~\) .jl
Then, click on “Open”, see arrow number 3.
Pluto will start our notebook. It takes a while to open the first notebook.
The notebook is now ready to use.
________________________________________________________________________
8. Running a cell and saving a Pluto notebook
When we apply changes to a notebook, by creating a new cell or introducing changes to an existing cell, there are two ways to run these changes:
To run one individual cell, we have two alternatives:
Click simultaneously on: \(~~\) shift \(~~\) and \(~~\) enter
Click on the small circle as in the figure on the right.
To run all cells and saving the entire notebook:
- Click simultaneously on: \(~~\) ctrl \(~~\) and \(~~\) s
________________________________________________________________________
9. Exporting a Pluto notebook
A Pluto notebook can be exported in three other formats:
as a “Julia” file
as an “HTML” file
as a “pdf” file
To do that, go to the beginning of your notebook. There is a small icon with the export box at the top right-hand side of the monitor (see image below);
click on that icon.
It will open the boxes below.
The three alternative ways of saving your notebook are visible in the following figure:
- .jl \(~~~~\) .html \(~~~~\) .pdf