Vous avez reçu un message "Your GitLab account has been locked ..." ? Pas d'inquiétude : lisez cet article https://docs.gricad-pages.univ-grenoble-alpes.fr/help/unlock/

Commit 0ba606a5 authored by Franck Thollard's avatar Franck Thollard
Browse files

Merge branch 'master' of gricad-gitlab.univ-grenoble-alpes.fr:python-uga/training-hpc

parents ee47b450 ab5a9f67
......@@ -824,7 +824,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.7.2"
}
},
"nbformat": 4,
......
......@@ -40,6 +40,53 @@
"- IO bounded (wait for IO)"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Different parallel strategies"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"source": [
"### IO bounded: one process + `async`/`await`\n",
"\n",
"<p class=\"small\"><br></p>\n",
"\n",
"Cooperative concurrency\n",
"\n",
"<p class=\"small\"><br></p>\n",
"\n",
"Functions able to pause\n",
"\n",
"<p class=\"small\"><br></p>\n",
"\n",
"`asyncio`, [`trio`](https://trio.readthedocs.io)"
]
},
{
"cell_type": "raw",
"metadata": {
"slideshow": {
"slide_type": "-"
}
},
"source": [
"<div align=\"middle\">\n",
"<img src=\"./fig/logo_trio.png\" style=\"width: 15%\">\n",
"</div>"
]
},
{
"cell_type": "markdown",
"metadata": {
......
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Port Python 2 code to Python 3"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Once upon a time, it was very difficult to:\n",
"\n",
"- convert code written in Python 2\n",
"\n",
"- write code compatible for py2 and py3\n",
"\n",
"Dependencies + strong language incompatibilities (between Python 2.6 and 3.3).\n",
"\n",
"\n",
"Now, it much simpler!\n",
"\n",
"- main packages all work in Python 3\n",
"\n",
"- smaller language incompatibility (between Python 2.7 and >3.4) (for example `from __future__ import print_function, division`)\n",
"\n",
"- good tools to write compatible code ([six](https://pypi.org/project/six/) and [future](https://python-future.org))\n",
"\n",
"But... still some differences... For example for us in sciences:\n",
"\n",
"- division `int / int`\n",
"\n",
"- str are unicode in Python 3 but not in Python 2\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## Steps to port Python 2 code to Python 3\n",
"\n",
"- Solidify the Python 2 code (write tests!)\n",
"\n",
"- Use [pyupgrade](https://github.com/asottile/pyupgrade) to modernize the code to Python 2.7 ➡️ test!\n",
"\n",
"- Use the automatic tool `futurize -w mymodule.py` (provided by [future](https://python-future.org)) ➡️ test!\n",
"\n",
"Today, it can make sense to stop supporting Python 2.7 (and even Python 3.5). See https://python3statement.org/. \n",
"\n",
"Main advantage: One can use nice modern features, for example:\n",
"\n",
"- f-strings\n",
"\n",
"- `from pathlib import Path`\n",
"\n",
"It can be done automatically with pyupgrade:\n",
"\n",
"`find -name \"*.py\" | xargs pyupgrade --py36-plus`\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Developer tools\n",
"\n",
"## IDE (open-source)\n",
"\n",
"- Spyder\n",
"\n",
"- Visual Studio Code\n",
"\n",
"- ...\n",
"\n",
"\n",
"## Checker and formatter\n",
"\n",
"- [pylint](https://www.pylint.org/): check Python code\n",
"\n",
"- [black](https://github.com/python/black): The uncompromising Python code formatter\n",
"\n",
"- [mypy](http://mypy-lang.org/): Optional Static Typing for Python\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"# Port a Matlab code to Python\n",
"\n",
"⚠️ ⚠️ Difficult !! ⚠️ ⚠️\n",
"\n",
"### Converter (with runtime dependence)\n",
"\n",
"- [Smop](https://github.com/victorlei/smop), Small Matlab to Python compiler: convert Matlab code to Python code\n",
"\n",
"See https://stackoverflow.com/a/17535694\n",
"\n",
"### Other approach\n",
"\n",
"- fluidmat2py, provided by [fluiddyn](https://fluiddyn.readthedocs.io)\n",
"\n",
"```\n",
"usage: fluidmat2py [-h] [-c] path\n",
"\n",
"Utility to produce a strange code which is no longer Matlab and not yet Python.\n",
"\n",
"positional arguments:\n",
" path str indicating which file or directory has to be used.\n",
"\n",
"optional arguments:\n",
" -h, --help show this help message and exit\n",
" -c, --clean Only clean the Matlab code.\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
......@@ -30,8 +30,9 @@ module dtw_cort
end do
! Fill the dtw_matrix
do i = 2, len_s1
do j = 2, len_s2
do j = 2, len_s2
do i = 2, len_s1
dist = dabs(s1(i) - s2(j))
dtw_mat(i, j) = dist + dmin1(dtw_mat(i - 1, j), &
dtw_mat(i, j - 1), &
......
all:
python3 -m numpy.f2py -c "dtw_cort.f90" -m distances_fort
python3 -m numpy.f2py --opt="-O3 -march=native" -c "dtw_cort.f90" -m distances_fort
clean:
rm -f distances_fort.*.so *.mod
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment