This repository contains source code and material (e.g. notes) about problems faced during the course Algorithms for optimization, inference and learning, attended during the second semester of academic year 2022-2023 for the master's degree in Physics of Complex Systems at University of Torino.
The regular teacher of this course is Professor Braunstein. The course and its official web site are hosted at Politecnico di Torino.
This repository exists just as an effective way to save the code while the exercises are being done, it is not meant for presenting them in a complete and nice way. Just information sufficient for the resolution of the problems are included.
Files related to a particular problem are contained in a directory with name Problem_n
where n is the number corresponding to the problem at the time of creation of the directory. This numbering comes from the problem list on professor's LaTeX notes, so it could go out of sync with the real numbering on the notes at any time. To provide consistency, the following list associates numbers to problems permanently and it is updated each time a new problem is inserted in the repository:
- 003 Sierpinski’s triangle
- 028 Linear max-convolutions
- 035 Making a difference
During lesson code is written in Julia, but in this repository both Python and Julia are present (since I am new to Julia language).
I use Python version 3.10.4 and Julia LTS release version 1.6.7.
VS Code is my visual text editor equipped with Jupyter notebook extension.
I can use Google Colab to use Julia notebooks stored in this repository. The trick is the language-specific metadata of the notebooks loaded in Google Colab, hence it is fundamental to use specific template notebooks and not notebooks created directly on Google Colab. In this repository the bare minimum data for a notebook to be identified as Julia notebook are stored in file bare_julia.ipynb
.
-
To load an existing notebook the procedure is:
- log into Google Colab;
- choose to open notebook from GitHub;
- select the notebook to open from branch
main
; - once the notebook is loaded, run the first block of code and wait until completion (it takes about 1 minute);
- select Julia kernel (it is called runtime on Google Colab).
Steps 2 and 3 can be avoided by clicking on the badge "Open in Colab" present in the notebook.
It is extremely important to not switch to other kernels after step 5, otherwise the notebook metadata get overwritten and the notebook ceases to be a Julia notebook. If this happens, save it anyway, because it can be restored at a later time (cfr. notebook recovery paragraph).
-
To save back to GitHub the changes applied to a notebook on Google Colab, choose to save a copy to GitHub, then specify the destination path in the repository and a commit message, which will be added to the Git history of the file. Changes are pushed by the same GitHub account whose access is granted to Google Colab, but they are not signed.
-
To create a new notebook in Google Colab the procedure is similar to load an existing notebook, except for point 3 which is altered as follows: the selected notebook must be
template_julia.ipynb
(or it can be opened by clicking on the badge "Open in Colab" present in the notebook, remember to update the filename in the badge URL for the new notebook), then soon after it is loaded it must be saved back to the repository with a different name.
Notebook recovery
If for any chance a notebook ceases to be identified as a Julia notebook (e.g. because on Google Colab the kernel has been changes to Python), its condition can be restored by changing the notebook metadata. Simply compare the raw source of the file (Jupyter notebooks are JSON files) with template_julia.ipynb
and restore the values which happen to be different in key kernelspec
.
If for some reason Google Colab can not be used to work on J
5DD4
ulia notebooks, website Binder can load this repository and access its content on a cloud VM. File Project.toml
is mandatory for this task because it instructs Binder on the environment to set up. If a different Julia version is chosen, it must be updated also in this file at the key julia
of section [comp]
.
After the environment is loaded in Binder, successive changes in the repository are not reflected there. To circumvent the problem, Git can be used inside the Binder environment to pull the latest changes, since the repository is public. Shell script pull_branch.sh
is a reminder of this detail.
Saving changes back to Git is more convoluted since it is necessary to download them locally first (to avoid privacy and security issues in a direct connection through Git).
Click on the following badge to load the main
branch of this repository on Binder:
To set up the cloud environment I took inspiration from the following references: