Skip to content

Latest commit

 

History

History
167 lines (115 loc) · 9.13 KB

student_instructions.md

File metadata and controls

167 lines (115 loc) · 9.13 KB

Hands-On Optics Calculations - Setup Instructions


During the course we will use Python3 in a Jupyter and, mostly, the numpy, matplotlib and cpymad packages. We will explain in the following sections how to install all necessary software on your laptop. A basic knowledge of Python is assumed. If you are not familiar with Python, you can find a few resources to fill the gap in the following sections.

Do not worry about the theory for the moment (it will be discussed in details during the school) but focus on the Python syntax and data types (tuples, lists,...).

After a short introduction, where we provided some useful links to get familiar with Python, we will focus on the software setup. Finally, in appendix you will find links and cheatsheets for the most common Python packages that will be used during the course.

Important: we kindly ask you to go throw this document before coming to CAS, such as to prepare yourself (and your laptop) for the course.


A very short introduction to Python

You can find several nice courses, videos and resources on the internet. Here you have a couple of suggestions you can find on YouTube:

Python for Beginners - Learn Python in 1 Hour      Learn Python - Full Course for Beginners

Test Python on a web page

If you are not familiar with Python and you have not it installed on your laptop, you can start playing with simple python snippets on the web (e.g., CoLab, a google account is needed).

You can test the following commands:

import numpy as np

# Matrix definition
Omega=np.array([[0, 1],[-1,0]])
M=np.array([[1, 0],[1,1]])

# Sum and multiplication of matrices
Omega - M.T @ Omega @ M
# M.T means the "traspose of M".

# Function definition
def Q(f=1):
    return np.array([[1, 0],[-1/f,1]])

# Eigenvalues and eigenvectors
np.linalg.eig(M)

You can compare and check your output with the ones here.


Software Setup

In this section we will explain how to install Python and Jupyter on your laptop. JupyterLab is a user-friendly environment to work with Python. You can find an overview on JupyterLab here.

If you already have your favorite Python distribution installed on your laptop, including JupyterLab, you might want to skip the installation and jump to launch Jupyter Lab and test that everything works.

Installation

We suggest to install the Anaconda distribution from https://www.anaconda.com/distribution/

We suggest to install one of the latest distribution (for example version Python 3.9).

The installation process clearly depends on your operating system. We suggest you to follow the official documentation for Windows, Linux, or Mac as appropriate. After having installed Anaconda, and verified your installation - as suggested in the installation documentation - we invite you to start launching Jupyter Lab and then test that everything works:

Launch Jupyter

Once the installation of Anaconda is finalised or within your existing Python distribution, you should be able to start Jupyter from a terminal:

  1. Open a (Anaconda) terminal on your operating system:

    • Windows: From the Start menu, search for and open “Anaconda Prompt”:
    • macOS: Open Launchpad, then click the terminal icon.
    • Linux: Open a terminal window.
  2. Launch Jupyter from your terminal:

    jupyter notebook

    or, in case you want a jupyter lab server

    jupyter lab
  3. Follow the instructions given in the terminal. You should end-up on your default browser with a page similar to the following:

    On the left hand side of the widows you should see all files under the folder in your operating system where you executed the jupyter lab command. This will be your working directory.

  4. Start playing with Python! Please, make sure to go throw all the examples/test.ipynb to familiarize with the typical Python concepts that will be used during the course, but also to verify your installation. If you happen to experience any problem, please check to have installed the whole anaconda distribution. Alternatively, you can try to go back to your terminal, and install each single (or missing) package independently, e.g.:

pip install numpy matplotlib seaborn scipy ipywidgets jupyter jupyterlab sympy cpymad PyNAFF
  1. If you are not familiar with Python, you can start playing with simple python snippets. For example, have a look to the following examples/PythonBasic.ipynb (courtesy of Simon Albright).

  2. Just before the start of the course, we will ask you to download the latest version of the hands-on lattice exercises (even better, the whole repository) in your working directory.

  3. Optional: instead of running Jupyter lab within a browser, you can try to install and the jupyterlab-desktop application.


Appendix: Python Packages

You can leverage python's capability by exploring a galaxy of packages. Below you can find the most useful for our course (focus mostly on numpy and matplotlib) and some very popular ones.

The numpy package

To get familiar with the numpy package have a look at the following summary poster. You can google many other resources, but the one presented of the poster covers the set of instructions you should familiar with.

The matplotlib package

To get familiar with the matplotlib package have a look at the following summary poster.

The linalg module

To get familiar with the Linear Algebra (linalg) module have a look at the following summary poster.

The pandas package (optional)

To get familiar with the pandas package have a look at the following summary poster.

The seaborn package (optional)

To get familiar with the seaborn package have a look at the following summary poster.

The sympy package (optional)

To get familiar with the sympy package have a look at the following summary poster.