Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/Documentation.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: '1.10'
version: '1.11'
- uses: julia-actions/cache@v2
- name: Install dependencies
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
[![](https://img.shields.io/badge/docs-stable-blue.svg)](https://juliateachingctu.github.io/Julia-for-Optimization-and-Learning/stable/)
[![](https://img.shields.io/badge/docs-dev-blue.svg)](https://juliateachingctu.github.io/Julia-for-Optimization-and-Learning/dev/)

This repository is supplementary material to the course **Julia for Optimization and Learning**, which is taught at the Czech Technical University in Prague. More information can be found on the [official course website](https://juliateachingctu.github.io/Julia-for-Optimization-and-Learning/stable/) or in the [course syllabus](http://bilakniha.cvut.cz/en/predmet6985806.html)
This repository is supplementary material to the course **Julia for Optimization and Learning**, which is taught at the Czech Technical University in Prague. More information can be found on the [official course website](https://juliateachingctu.github.io/Julia-for-Optimization-and-Learning/stable/) or in the [course syllabus](http://bilakniha.cvut.cz/en/predmet6985806.html).
2 changes: 1 addition & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ Query = "1.0"
RDatasets = "0.7"
SpecialFunctions = "2.4"
StatsPlots = "0.15"
julia = "1.10"
julia = "1.11"
12 changes: 12 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Build docs

Build locally with
```
julia --project=. make.jl
```
from the `/docs` folder or from the base directory with
```
julia --project=docs docs/make.jl
```

Don't forget to instantiate the `docs` environment. Julia v1.11 changed some of the error message functionality, therefore it is necessary to use Julia v1.11 to build this version of documentation.
7 changes: 4 additions & 3 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ mv(download("$(site)icons/favicon.ico"), assetsdir("favicon.ico"); force)

# outline
installation = [
"Installation" => "./installation/installation.md",
"Quickstart guide" => "./installation/tutorial.md",
"Install" => "./installation/installation.md",
"Project setup" => "./installation/tutorial.md",
"Running Julia" => "./installation/running.md",
]

lecture_01 = [
Expand Down Expand Up @@ -123,7 +124,7 @@ makedocs(;
pages=[
"Home" => "index.md",
"Why Julia?" => "why.md",
"Installation" => installation,
"Setup guide" => installation,
"1: Basics I" => lecture_01,
"2: Basics II" => lecture_02,
"3: Packages" => lecture_03,
Expand Down
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ gr()
```

Welcome to our course *Julia for Optimization and Learning*. This course consists of two parts:
- *Basics of Julia*: [Julia](https://julialang.org/) is a fast programming language for scientific computing. Designed and developed at MIT, it quickly keeps gaining popularity and scored rank 25 among programming languages in the [PYPL rating](https://pypl.github.io/PYPL.html) (as of September 2024).
- *Basics of Julia*: [Julia](https://julialang.org/) is a fast programming language for scientific computing. Designed and developed at MIT, it quickly keeps gaining popularity and scored rank 22 among programming languages in the [PYPL rating](https://pypl.github.io/PYPL.html) (as of September 2025).
- *Applications*: The second part of the course will be dedicated to applications. The main emphasis will given to machine learning, but we will also go through statistics and differential equations.

This course is taught at the [Czech Technical University](https://www.cvut.cz/en/) in Prague. It is part of the [prg.ai minor](https://prg.ai/minor/), a study programme combining top courses from four faculties of two Prague universities.
Expand Down
45 changes: 35 additions & 10 deletions docs/src/installation/installation.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Installation
## Julia

There are multiple ways how to install Julia and it's version manager Juliaup. We recommend to follow the [official documentation](https://julialang.org/downloads/):
There are multiple ways how to install Julia. We recommend using the official version manager [Juliaup](https://julialang.org/install/):

- **Windows** users can install Julia and also Juliaup directly from [Windows Store](https://apps.microsoft.com/detail/9njnww8pvkmn?hl=cs-cz&gl=CZ) or equivalently use the following command

Expand All @@ -19,18 +19,42 @@ Once finished, the `julia` and `juliaup` commands should be available via comman
!!! info "Other installation options:"
For more options how to install Julia and Juliaup, see the [Juliaup Github repository](https://github.com/JuliaLang/juliaup).

For the upcoming course, we recommend to install Julia version 1.10 and set is as a default Julia. It can be done in the following way
For the upcoming course, we recommend to install Julia version 1.11 and set is as a default Julia. It can be done in the following way

```shell
> juliaup add 1.10
> juliaup add 1.11

> juliaup default 1.10
Configured the default Julia version to be '1.10'.
> juliaup default 1.11
Configured the default Julia version to be '1.11'.
```

### Git
### Optional: Setting-up Julia Multi-Threading

[Git](https://git-scm.com/) is a distributed version control system for tracking changes in any set of text files. It is designed for coordinating work among cooperating programmers during software development. Git installer can be download from the official [download page](https://git-scm.com/downloads). Download the proper installer, run it and follow the instructions. Before using Git, we need to make the necessary settings. It can be done easily using command line interface the two following commands
Julia runs on a single thread by default. We will not tackle multi-threading in this course, but many Julia packages are parallelized by default. Thus, starting Julia with multiple threads **can greatly improve performance**.

Julia can be started with multiple threads by calling `julia -t N` or `julia --threads N`, where `N` is the required number of threads. Alternatively, one can use the value `auto` instead of `N` to let julia automatically determine the optimal number of threads (usually equal to the number of physical CPU cores).

In order to avoid having to specify the number of threads every time we start Julia, we can export the environment variable `JULIA_NUM_THREADS` instead. To make the setting persistent, we need to add the export to the *shell configuration file*. The exact way to do this depends on the shell you use. Several common shell variants are shown below:

- **Linux + bash**: Add `export JULIA_NUM_THREADS=auto` to `~/.bashrc`.

- **Linux + zsh**: Add `export JULIA_NUM_THREADS=auto` to `~/.zshrc`.

- **MacOS + bash**: Add `export JULIA_NUM_THREADS=auto` to `~/.bash_profile`.

- **MacOS + zsh**: Add `export JULIA_NUM_THREADS=auto` to `~/.zshrc`.

- **Windows + cmd**: Evaluate `setx JULIA_NUM_THREADS auto` in cmd.

(Or use a specific number of threads instead of `auto`.)

To verify your setup, evaluate `julia -e "@show Threads.nthreads()"`. If you've done everything correctly, you should see a number of threads greater than 1.

See the [official documentation](https://docs.julialang.org/en/v1/manual/multi-threading/) for more information.

## Git

[Git](https://git-scm.com/) is a distributed version control system for tracking changes in any set of text files. It is designed for coordinating work among cooperating programmers during software development. Git installer can be downloaded from the official [download page](https://git-scm.com/downloads). Download the proper installer, run it and follow the instructions. Before using Git, we need to make the necessary settings. It can be done easily using command line interface the two following commands

```shell
> git config --global user.name "<your_username>"
Expand All @@ -43,9 +67,10 @@ The commands above set the user name and email for Git. Because Git is designed
!!! info "GitHub Account:"
The Julia package system is based on Git, and the Julia project is hosted on [GitHub](https://github.com/). GitHub is a service that provides internet hosting for software development and version control using Git. We use GitHub to host all the materials and final projects in this course. Therefore, every student needs to create a GitHub account to be able to finish the course. It can be done in a few steps on the official [GitHub page](https://github.com/).

### Visual Studio Code
## Visual Studio Code

It is possible to write Julia codes in any text editor, and run them directly from the terminal. However, it is usually better to use an IDE that provides additional features such as syntax highlighting, or code suggestions. We recommend using [Visual Studio Code](https://code.visualstudio.com/), a free source-code editor made by Microsoft. It supports many programming languages (Julia, Python, LaTex, ...) via extensions. The editor is available at the official [download page](https://code.visualstudio.com/download). Download the proper installer, run it and follow the instructions.

To use the VS Code as an IDE for Julia, we have to install the [Julia extension](https://marketplace.visualstudio.com/items?itemName=julialang.language-julia). It can be done directly from the VS Code. Open the `Extension MarketPlace` by pressing the button in the `Activity bar` (the left bar). Type `julia` in the search bar and select the Julia extension. Then press the `Install` button to install the extension. For more information see the [official documentation](https://www.julia-vscode.org/docs/stable/#)
To use the VS Code as an IDE for Julia, we have to install the [Julia extension](https://marketplace.visualstudio.com/items?itemName=julialang.language-julia). It can be done directly from the VS Code. Open the `Extension MarketPlace` by pressing the button in the `Activity bar` (the left bar). Type `julia` in the search bar and select the Julia extension. Then press the `Install` button to install the extension. For more information see the [official documentation](https://www.julia-vscode.org/docs/stable/#).

![](julia-extension-install.png)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/installation/repl_help1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/installation/repl_help_usage1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/installation/repl_pkg1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/installation/repl_pkg_usage1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/installation/repl_shell1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/installation/repl_shell_usage1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 64 additions & 0 deletions docs/src/installation/running.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
## Julia in Visual Studio Code

In the labs, we will be using Visual Studio Code to work on Julia projects and run Julia. An IDE like VS Code allows us to use certain keyboard shortcuts and other utilities (such as syntax highlighting) to more effectively work with Julia code.

We recommend to install at least the Julia Extension, which comes with a lot of functionality to run, format, and work with Julia scripts.

![](vscode1.png)

### Julia commands

Julia Extension enables us to use important Julia-specific commands. Running `cmd + shift + P` opens VS code command pallete. When searching for `>Julia`, you can see the available commands.

The most important ones are
- `Julia: Start REPL`
- `Julia: Send Current Line or Selection to REPL`
- `Julia: Execute Code in REPL`
- `Julia: Execute Code in REPL and Move`
- `Julia: Execute Code Cell in REPL and Move`
- `Julia: Execute Code Cell in REPL and Move`.

Some of these are already mapped to keyboard shortcuts. We recommend to test what those commands do and to map the ones you are comfortable with to your custom keyboard shortcuts.

We will spend a lot of time in the Julia REPL, therefore we recommend to get used to the commands that either send or execute lines of code in the Julia REPL.

## Julia REPL

Julia is a language that is very easy to work with in terminal (inside Julia REPL). The REPL comes with additional functionality that makes developing Julia code easy.

In previous versions, there did not exist any debugging tools. Nowadays, debugging exists in Julia, but we will not be using these tools and run the code directly in Julia REPL. We believe this approach to be easier, faster, and better manageable.

Note: When Julia is started with the `Julia: Start REPL` command, it starts the Julia REPL in the project directory and activates the environment that is set in the bottom status bar in `Julia env:`.

### REPL utilities

Using basic commands (keys), we can easily switch from standard Julia REPL into other modes
- help
- Julia package manager
- shell

To get into help, simply type `?` in the Julia REPL.

![](repl_help1.png)


In help, you can use any function or type to search for its documentation. For example, we can see documentation of the function `sum` from standard library:

![](repl_help_usage1.png)


To get into Julia package manager, type `]` in the Julia REPL.

![](repl_pkg1.png)

Inside the package manager, we can easily install, update, or remove packages. We can also check the installed packages with the `st` or `status` commands.

![](repl_pkg_usage1.png)

Lastly, to get into standard shell terminal, type `;` in the Julia REPL.

![](repl_shell1.png)

The shell environment works like a standard default terminal and allows for easy terminal commands.

![](repl_shell_usage1.png)
Binary file added docs/src/installation/vscode1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/src/lecture_01/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ Accessing matrix elements can be also done in the same way as for vectors.
julia> M[1] # the first element, equivalent to m[begin]
1

julia> M[2] # the the second element element
julia> M[2] # the second element
5

julia> M[end-1] # the second to last element
Expand Down
8 changes: 4 additions & 4 deletions docs/src/lecture_02/conditions.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Conditional evalutions
# Conditional evaluations

This lecture handles control flow. The first part focuses on `if` conditions and the second one of loops.

Expand All @@ -22,7 +22,7 @@ end
compare (generic function with 1 method)
```

If the expression `x < y` is true, the functions prints *"x is less than y"*, otherwise, the expression `x > y` is evaluated, and if it is true, the functions prints *"x is greater than y"*. If neither expression is true, the function prints the remaining option *"x is equal to y"*.
If the expression `x < y` is true, the function prints *"x is less than y"*, otherwise, the expression `x > y` is evaluated, and if it is true, the function prints *"x is greater than y"*. If neither expression is true, the function prints the remaining option *"x is equal to y"*.

```jldoctest conditions
julia> compare(1, 2.3)
Expand Down Expand Up @@ -150,7 +150,7 @@ julia> compare(2.3, 2.3)

Make sure that the input argument is a non-negative integer. For negative input arguments and for arguments that can not be represented as an integer, the function should throw an error.

**Hint:** use recursion, the `isinteger` function and the `error` function. The or operator is written by `|`.
**Hint:** use recursion, the `isinteger` function and the `error` function. The or operator is written as `|`.

!!! details "Solution:"
We split the solution into three cases:
Expand Down Expand Up @@ -215,7 +215,7 @@ Since we wrapped the whole expression into the `println` function, the ternary o

## Short-circuit evaluation

Julia provides the so-called short-circuit evaluation which is similar to the conditional evaluation. The behaviour exists in most imperative programming languages having the `&&` and `||` boolean operators. In a series of boolean expressions connected by these operators, only the minimal number of expressions is evaluated to determine the final boolean value of the entire chain:
Julia provides the so-called short-circuit evaluation which is similar to the conditional evaluation. The behaviour exists in most imperative programming languages, which have the `&&` and `||` boolean operators. In a series of boolean expressions connected by these operators, only the minimal number of expressions is evaluated to determine the final boolean value of the entire chain:
- In the expression `a && b`, the subexpression `b` is only evaluated if `a` evaluates true.
- In the expression `a || b`, the subexpression `b` is only evaluated if `a` evaluates to false.

Expand Down
10 changes: 5 additions & 5 deletions docs/src/lecture_02/exercises.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
So far, we used only the standard library shipped with Julia. However, the standard library provides only basic functionality. If we want to get additional functions, we have to use extra packages. There is a [Plots](https://github.com/JuliaPlots/Plots.jl) package for creating plots. Packages can be installed via Pkg REPL. To enter the Pkg REPL from the Julia REPL, press `]` and install the package by

```julia
(@v1.10) pkg> add Plots
(@v1.11) pkg> add Plots
```

We need to use the `using` keyword to load the package. For example, we can use the Plots package to visualize the `sin` and `cos` functions.
Expand All @@ -12,8 +12,8 @@ We need to use the `using` keyword to load the package. For example, we can use
using Plots
x = 0:0.01π:2π

plot(x, sin.(x); label = "sinus", linewidth = 2)
plot!(x, cos.(x); label = "cosinus", linewidth = 2)
plot(x, sin.(x); label = "sine", linewidth = 2)
plot!(x, cos.(x); label = "cosine", linewidth = 2)

savefig("sin.svg") # hide
```
Expand Down Expand Up @@ -140,7 +140,7 @@ There will be a whole [section](@ref Plots.jl) dedicated to the Plots package. H
end
```

We use the ternary operator to decide which value is returned. Now we need to define all input parameters as in the previous exercise.
We use the ternary operator `? :` to decide which value is returned. Now we need to define all input parameters as in the previous exercise.

```julia
c = - 0.4 + 0.61im
Expand Down Expand Up @@ -213,7 +213,7 @@ Firstly, we create the vector of all values `c` by combining the `range` functio
cs = 0.7885 .* exp.(range(π/2, 3π/2; length = 500) .* im)
```

Note that we use the `length` keyword to specify the length of `cs`. To create an animation, it suffices to use the `for` loop in combination with the `@animate` macro.
Note that we use the `length` keyword to specify the length of `cs`. To create an animation, it is sufficient to use the `for` loop in combination with the `@animate` macro.

```julia
anim = @animate for c in cs
Expand Down
Loading