TBMT42 Labs: General info and optional getting started exercise¶
The exercises in this course will primarily be done in Python, but Lab 3 will use MATLAB. Both the Python and MATLAB parts will require that you have a valid C++ compiler installed if you want to work locally on your computer. You can choose to either run the lab locally or via the cloud services Google Colab, that offers a online Python environment, and Matlab Online, that offers a online MATLAB environment.
The Python parts will use a package that we have developed: SUND. SUND comes bundled with a fallback c-compiler if none exist on the system.
Installing python and MATLAB on your own computer (recommended)¶
We have put together a collection of the software needed and the steps to install both Python and MATLAB here:
The instructions vary a bit for different operating systems. A condensed version, with our preferred approach is given below.
Quick setup instructions for Python
We recommend that you use uv.
Install uv (which handles Python and packages):
winget install --id=astral-sh.uv -e
Install uv (which handles Python and packages):
curl -LsSf https://astral.sh/uv/install.sh | sh
Install uv (which handles Python and packages):
curl -LsSf https://astral.sh/uv/install.sh | sh
Then install Python 3.14:
uv python install 3.14
Setup project:
- Create project folder:
mkdir ~/projects/tbmt42_labs - Navigate:
cd ~/projects/tbmt42_labs - Initialize:
uv init - Test installation:
uv run --with sund python -c "import sund; sund.test_distribution()"
If the test_distribution() finds that everything is working as intended - then everything is installed correctly.
Troubleshooting (Windows)
Some Windows installations may prevent Python from starting due to security settings such as Smart App Control or Microsoft Defender.
If Python does not start, or Windows reports that the application is blocked:
-
Verify that Python was installed correctly and can be started from a command prompt:
python --version -
If Windows blocks Python, look for a More information or Run anyway option in the warning dialogue.
- If the issue persists, check Windows Security settings (Smart App Control / Reputation-based protection) or contact the course staff for assistance.
Quick setup instructions for Matlab
- Download the installer for your operating system from the MathWorks homepage. Use your Liu account to login to MathWorks.
- Install MATLAB from the downloader you downloaded earlier.
- Choose to log in as the installation method, and log in with your MathWorks account.
- You do not need to install all packages, but you need to include
Global optimization toolboxandStatistics and Machine Learning Toolboxfor this course.
-
Install a C-compiler
- In MATLAB, on the "Home" tab, click Add-Ons.
- In the pop-up window, search for the term "mingw" then click
MATLAB Support for MinGW-w64 C/C++ Compiler. - Choose the install option and follow the steps for installation.
To get a C-compiler, you need to install Xcode. Xcode is available in the Mac app store. After installation, start Xcode and agree to the license agreement.
It might also be possible to install gcc, e.g. by opening a terminal and typing
gccwhich should prompt a request for installing Command line developer tools.You probably already have a compiler available, otherwise install e.g.
gccthrough your package manager. -
Download and add
IQM toolswhich is a modelling toolbox, see instructions. This tool is also included in the files you download for lab 3 and the setup do no need to be repeated if you do this in advance.
Finally, we recommend installing an editor/IDE that you like writing code in. We like Visual Studio Code (VS Code) if you have no other preference.
Using cloud services to run MATLAB and python¶
Python via cloud¶
For the python parts, you can choose to run the labs via the cloud service Google Colab, that offers a online Python environment. For lab 1, 2 and 4b, you can find a cloud notebook in the beginning of the lab instructions. You can also choose to download the lab files locally and then upload them to google colab.
Matlab via cloud¶
For the matlab parts, you can choose to run the labs via the cloud service Matlab Online. Use your LiU account to log in. First, download the lab 3 files locally and then upload the lab 3 files in Matlab Drive. You can then access the files in Matlab Online.
When everything is installed¶
If you feel like you need to freshen up your coding knowledge, before or during the lab exercise, we recommend that you check out Google's Python class.
If you are having troubles with how to use SUND, we recommend that you check our introductory SUND exercise.