Module 2

Numerical simulation tools

Python


Jacques Hertzberg, Vincent Le Bris,
Marc Odunlami, Germain Salvato Vallverdu
## Introduction

Schedule of the training course

Course materials

Operating mode

  • Priority is given to autonomy and group work.
  • Tutored instruction
## Schedule The training is scheduled over two days * Thursday, March 25th: 9:30am - 12:00pm / 2pm - 5pm, Einstein room * Friday, March 24: 9:30 am - 12:00 pm / 2:00 pm - 5:00 pm, Einstein room
## Organization * Part 1: learning of python language and syntax * Part 2: work on a personal project ![xkcd](img/xkcd.png)
## Goals * Programming awareness * Discovery of a programming language (python) * learn how to write programs for post or pre-processing of data ![python](img/python.png)
## Introduction to programming

The different layers of the software

  • How to use the operating system?
  • How to write new applications/programs?

Talk to a computer

Programming

  • There are many programming languages
  • The important thing is to know how to sequence the instructions
  • A computer is not intelligent, you have to guide it step by step.
## Programming languages ![langages](img/meilleurslangages.png) > Institute of Electrical and Electronics Engineers (IEEE)
## Two main families ![converter](img/compil.jpg) * **compiled languages** : high performance but not very portable * **interpreted languages** : Portable, simple but sometimes less efficient
## Compiled languages ### Examples: Fortran, C, C++ --- ### Compilation * Translate the language into a language understandable by the computer (binary, assembler ...) * The compilation consists of two steps: 1. The compilation, the translation into a binary object 2. Linking (links to libraries ...)
## Interpreted languages ### Examples: Python, bash, R --- ### operating phylosophy * Requires an interpreter, installed on each computer * The interpreter both translates and executes the instructions in the source code * The interpreter adapts the execution to the system, which facilitates code portability.

Python: a short introduction

Brief history

Python is an easy to learn, powerful programming language.

  • 1991: Conception of the language by: Guido van Rossum.
  • 1996: First version of Numerical python, future numpy.
  • 2001: Birth of the Python Software Fundation (PSF).
  • 2003: Development of matplotlib
  • 2008: Release of python2.6 and python3.0
  • 2020: End of support of python 2.7

Current highest python version: 3.9.2 (March 8, 2021)

The monty Python

## Caractéristiques du langage Python is an easy to learn, powerful programming language. * Interactive work, prompt mode, or script mode * Open source Language * Python is an efficient interpreted language (precompilation, butecode interpretation). * The syntax is simple and easy to read * It has efficient high-level data structures * a simple but effective approach to object-oriented programming * A huge library is available along with a large user community > The mission of the Python Software Foundation is to promote, protect, and advance the Python programming > language, and to support and facilitate the growth of a diverse and international community of Python programmers

women's community

PyLadies community

Django Girls: tutorials and meetup

Some apprehensions

Program ?

Conditions


if condition:
	go_forward()
elif new_condition:
	go_backward()
else:
	stay_in_place()
		

Loops


for element in a_list:
	jump()

while condition:
	wait()
		

Well done, you know how to program!

The tools

Jupyter notebooks

Features

  • web application
  • source code
  • explanatory text, equation
  • visualization, plots ...

Anaconda

  • Python distribution for data sciences
  • A set of python software : jupyter, spyder, package manager, vscode
  • Data science platform
  • An easier solution for windows ...
  • Installation in user folder, usb key, without admin rights
## on pyrene The python version of the linux distribution of pyrene is available by default (but is quite old and not recommended) ```sh # pyuser@pyrene <~/there/> python Python 2.7.5 (default, Apr 11 2018, 07:36:10) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>>``` --- Additional versions are available thanks to module: ```sh # pyuser@pyrene <~/there/> module avail anaconda --------------- /softs/contrib/modules --------------- anaconda/03.dev anaconda/2 anaconda/3 ``` `anaconda/3` is the recommended version.
## How to use python 3 Python 3 is the recommanded python version. You need to load the corresponding module. ```sh # pyuser@pyrene <~/there/> module load anaconda/3 # pyuser@pyrene <~/there/> python Python 3.7.6 | packaged by conda-forge | (default, Jan 7 2020, 22:33:48) [GCC 7.3.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>>``` * The main python modules are available in anaconda: numpy, scipy, pandas, matplotlib, scikitlearn * Prompt with an improved user experience: jupyter console, jupyter qtconsole, jupyter notebook

Merci de votre attention