Lecture II - First Steps in Julia

Applied Optimization with Julia

Author
Affiliation

Dr. Tobias Vlćek

University of Hamburg - Fall 2024

Quick Recap on the Technical Setup

Download and Install Julia

To prepare for the upcoming lectures, we start by installing the Julia Programming Language and an Integrated Development Environment (IDE) to work with Julia.

Installaing Julia

. . .

Tip

If you are ever asked to add something to your “PATH”, do so!

VS Code

  • Next, we are going to install VS Code
  • Alternatively, you can install VS Codium
  • It is essentially VS Code but without any tracking by MS

Installing VS Code

Verify the Installation

  • Start the IDE and take a look around
  • Search for the field “Extensions” on the left sidebar
  • Click it and search for “Julia”
  • Download and install “Julia (Julia Language Support)”

Create a new file

  • Create a new file with a “.jl” ending
  • Save it somewhere on your computer
  • e.g., in a folder that you will use in the course
print("Hello World!")
Hello World!
  • Run the file by clicking “run” in the upper right corner
  • OR by pressing “Control+Enter” or “STRG+Enter”

Everything working?

  • If the terminal opens with a Hello World! → perfect!
  • If not, it is likely that the IDE cannot find the path to Julia
  • Try to determine the path and save it to VS Code
  • After saving it, try to run the file again
Tip

Don’t worry if it is not running right away. We will fix this together!

Learning Julia

Julia as a Programming Language

  • Following three lectures are dedicated to learning the basics
  • Start with the very basics and gradually move on
  • Focus in the first two lectures on the programming language
  • Third lecture dedicated to Mathematical Optimization

Working with VS Code

Notebooks in VS Code

  • The easiest way is by using VS Code
  • Install the Jupyter Extension
  • Now, you can open .ipynb files
  • Here you can run the code in the cells

Downloading the Notebooks

  • You will find the tutorial notebooks next to the tutorial pages
  • On each page, you will find a button Jupyter on the right
  • Click it to download the notebook and save it
  • I’d recommend storing the notebooks in a separate directory for this course

Learning by doing

  • The best way to learn a programming language is by doing
  • We will therefore solve problems the coming weeks
  • The goal is to get you familiar with the language
  • You can discuss the problems with your fellow students
  • You can hand in your solutions to receive bonus points!

Working with IJulia

IJulia

  • IJulia is an interface between Julia and Jupyter Notebooks
  • Popular tool for data analysis and visualization
  • You can use IJulia to run Julia code in the notebooks

. . .

Tip

You can also copy and paste code from the notebooks into your IDE!

Installing IJulia

  • Open the VS Code IDE and start a terminal
  • Start Julia by typing julia in the terminal
  • Install IJulia by typing ] to open the package manager
  • Install IJulia by typing add IJulia
  • Press Enter

Running IJulia

using IJulia; notebook()
  • Start IJulia by typing the above code in the Julia prompt
  • This will open a new browser window
  • You can now run code in the notebooks

. . .

Tip

You can also run the notebooks in VS Code, if you prefer!

Submission of Assignments

Submission of Assignments

  • You can work in groups of up to three people
  • Submit the assignment via OpenOlat
  • You will submit your assignment by uploading a notebook
  • The assignment is due the day before the next tutorial

. . .

Tip

Don’t forget to save your notebook before uploading it to OpenOlat!

Grading of Assignments

  • Each assignment is worth 0.5 points
  • You can get a maximum of 6.0 points from the assignments
  • The points will be added to your exam points
  • You need to pass the exam first, to receive any bonus points!

. . .

Note

The assignments are not mandatory, but highly recommended!

Five Tutorials for this Week

Topics of the Tutorials

  • Variables: Learn how to assign values to variables
  • Vectors: Learn how to create and manipulate vectors
  • Comparisons: Learn how to compare values
  • Loops: Learn how to use loops to repeat code
  • Scope: Learn about the scope of variables

Get started with the tutorials

  • Download the first notebook and open it
  • Start with the first problem and solve it step by step
  • You can find the tutorials here on the website
  • You can ask questions anytime!

. . .

And that’s it for this lecture!

The remaining time we will already start working on the first problems.

Literature

Literature

For more interesting literature to learn more about Julia, take a look at the literature list of this course.