===== Python Development ===== In order to work on the assignments you will need several tools: ==== Git ==== **All assignments are available through the [[https://gitlab.fel.cvut.cz/B201_B4B33RPZ/rpz-python-assignment-templates|assignment template repository]]. ** You can download a git version for your operating system at [[https://git-scm.com/]]. If you are new to git, check one of the [[https://git-scm.com/doc|tutorials]], [[https://git-scm.com/book/en/v2|Pro Git book]] or [[https://try.github.io/]]. **Make sure to get the current template version before starting to work on an assignment!** Keep in mind that the assignments and the assignment templates will be updated during the semester. Always use **git pull** to have the current template version before starting to work on the assignment! Make sure **not to push the repository with your solutions to any public remote (=plagiarism!!!)**, you can use [[https://gitlab.fel.cvut.cz/|FEE GitLab]] for private remote repo. ==== Python ==== The programing language of the course is Python. You can either use an environment manager such as **Conda** to automatically download Python alongside all required packages (works on Linux, Windows and MacOS), or you can install the packages manually using Python's native package manager **pip**. ---- == Conda == - Install Anaconda to your PC. You can download it from [[https://www.anaconda.com/download/]] - Create a new Conda environment called **rpz** (all packages are installed just inside the Conda environment, not to interfere with other packages/Python version that might exist on your PC) conda create --name rpz python=3.10 - Activate the environment conda activate rpz - Install the following packages into the environment conda install numpy=1.24 matplotlib=3.7 jupyter ipywidgets scipy pyyaml=6.0 conda install pytorch==1.12.1 torchvision==0.13.1 cpuonly -c pytorch - Test everything is installed properly python -c "import numpy as np; print(np.ones(4))" //Expected output// [1. 1. 1. 1.] ---- == PIP == - Install Python to your PC. The version used by the upload system - BRUTE is 3.10, we strongly recommend to use the same version. You can download Python from [[https://www.python.org/downloads/]] - (Recommended) It is a good practice to to setup a virtual environment such as [[https://virtualenv.pypa.io/en/latest/|virtualenv]] to keep the installed Python packages separate. This is especially useful when you work on several Python projects at the same time during the semester and each one has different package versions. - Install the following packages using **pip** pip install numpy==1.24 matplotlib==3.7 jupyter ipywidgets scipy pyyaml==6.0 pip install torch==1.12.1+cpu torchvision==0.13.1+cpu --extra-index-url https://download.pytorch.org/whl/cpu - Test everything is installed properly python -c "import numpy as np; print(np.ones(4))" //Expected output// [1. 1. 1. 1.] ==== IDE ==== We develop and test the lab code in various editors and the code should be working with any of them. All code is tested to work in [[https://code.visualstudio.com/|VSCode]], but should work with others as well. Feel free to use your favorite one if you know how to setup it for the course. If you are new to Python development, we recommend [[https://code.visualstudio.com/|VSCode]] or [[https://www.jetbrains.com/pycharm/|PyCharm]] (CTU has free student licenses). In case you need help with other IDE, we also have experience also with [[https://www.gnu.org/software/emacs/|Emacs]], or [[https://neovim.io/|neovim]]. Feel free to contact us at the forum if you need some help. ==== Jupyter notebooks ==== All assignments are contained in Jupyter notebooks. Although you may opt for not using it and still be able to finish the course, they are a convenient way to have the explanation, tests and basic lab structure at one place. To be able to open them in VSCode, you will need to install [[https://marketplace.visualstudio.com/items?itemName=ms-python.python|Python extension]] and [[https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter-renderers|Jupyter Notebook Renderers extension]]. /* ===== Python Development ===== * Use the [[https://cw.felk.cvut.cz/forum/forum-1792.html|forum]] to discuss any Python issues. * If you want to use an IDE, there is a professional PyCharm licence available at [[https://download.cvut.cz|https://download.cvut.cz]] (but feel free to use [[https://www.xkcd.com/378/|butterflies]] instead). * If you have experience with MATLAB programming, you can start by [[https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html|Numpy for MATLAB users]]. ===== Jupyter Notebooks ===== * We have prepared a lot of code and animations to make it easier for you to complete the tasks and understand the material. The codes are prepared in JupyterNotebook ''.ipynb'' files, which are part of all assignments. * There is no need to use notebooks to pass the semester. However, we recommend their use, as they contain codes for generating graphs and loading data. The ''.ipynb'' files contents can be non-interactively viewed in the template repo gitlab if you don't want to install * For running notebooks, we recommend using [[https://jupyter.org/|JupyterNotebook or JupyterLab]], or you can use it in your favourite IDE if it supports ''*.ipynb'' files (such as PyCharm). The basic installation is done by running ''$ pip install notebook'' and then ''$ jupyter notebook'' (or ''$ pip install jupyterlab'' and ''$ jupyter-lab''). * [[https://ipywidgets.readthedocs.io/en/stable/user_install.html|IPyWidgets]] needs to be installed for the animations to work correctly. However, the animations are only intended for a better understanding of algorithms or individual functions and do not need to be run to pass the semester. Install simply with ''$ pip install ipywidgets''. ===== Common Issues and Solutions ===== * Not working with correct shapes of input/output data: Shapes of all input/output data are defined in the docstring of individual methods. Please strictly stick to the prescribed shapes. * If you want to use i.e. np array <1xn> as (n,), you can use np.squeeze() at the beginning of the method. * For returning data in certain shape, you can use np.expand_dims() or np.at_leastXd() (where X is the number of dimmensions). * The template does not specify something correctly or differs from the assignment text * You are probably using an old version of the template. As noted in the git repository readme: **Keep in mind that the assignments and the assignment templates will be updated during the semester. Always pull the current template version before starting to work on the assignment!** ===== Assignment Templates ===== * All assignment templates are stored in a [[https://gitlab.fel.cvut.cz/B201_B4B33RPZ/rpz-python-assignment-templates|git repository]] * If you don't know how to use git: [[https://git-scm.com/book/en/v2|Pro Git book]], [[https://try.github.io/]], duckduck, google, ... * Follow the instruction in the repository README * Make sure to get the current template version before starting to work on an assignment * Make sure **not to push the repository with your solutions to any public remote (=plagiarism!!!)**, you can use [[https://gitlab.fel.cvut.cz/|FEE GitLab]] for private remote repo. * Each assignment template contains a Jupyter notebook (.ipynb) that you can use to testrun the assignment functions you implement. **This notebook will not be checked by the BRUTE.** ===== Package Versions ===== * The evaluation server has the following packages installed: * python (3.10.6) * numpy (1.21.5) * matplotlib (3.5.2) * scipy (1.7.3) * pillow (9.2.0) * pandas (1.3.5) * torch (1.12.1+cpu) * torchvision (0.13.1+cpu) * If there is something important missing, please contact us on [[https://cw.felk.cvut.cz/forum/forum-1792.html|forum]]. We will do our best to install it on the evaluation server. /* ===== Setup recommended by Radim ===== This setup is recommended by Radim Shpetleek(tm)(r) {{:courses:be5b33rpz:labs:rs.jpg?50|}}. \\ Works both on Windows and Linux. The macOS is not for serious work anymore.\\ - Install [[https://docs.conda.io/en/latest/miniconda.html|Miniconda]], Python version 3.X.\\ - Run **conda** CLI.\\ - Create conda environment and install basic apps with conda create --name rpz python=3 numpy matplotlib scipy pillow pandas - Do one of the following: **Work in the interactive python interpreter** after activating the environment with conda activate rpz **OR** \\ \\ **Work in an IDE of your choice** (IntelliJ PyCharm, of course) and set the interpreter of your project to the **python** executable/binary in your environment's path. Run your scripts using PyCharm's //configurations//.[[https://docs.anaconda.com/anaconda/user-guide/tasks/integration/python-path/|How to find the path to your environment's interpreter?]]\\ */