{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Introduction: The basics of Notebook\n", "\n", "You can write standard Python:\n", "\n", "\\begin{equation}\n", "\\int_0^\\infty f(x) dx\n", "\\end{equation}" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-1.0\n", "3.141592653589793\n" ] }, { "data": { "text/plain": [ "6.283185307179586" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from math import *\n", "print(cos(pi))\n", "print(pi)\n", "2*pi" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'comb', 'copysign', 'cos', 'cosh', 'degrees', 'dist', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'isqrt', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'perm', 'pi', 'pow', 'prod', 'radians', 'remainder', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc']\n", "3.321928094887362\n", "3.3219280948873626 3.321928094887362\n" ] } ], "source": [ "import math\n", "from scipy import *\n", "from numpy import *\n", "print(dir(math))\n", "print( log2(10) )\n", "print( math.log(10,2), math.log2(10) )\n", "#info(log2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Two modes\n", "\n", "**Command Mode** and **Edit Mode**\n", "\n", "\"Return\" and \"Esc\" to switch between **Command** and **Edit** modes\n", "\n", "**To Execute** : \"Shift Return\"\n", "\n", "**To return to Edit mode** : \"Return/double click\"\n", "\n", "**hide long cell output** double click" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [ { "data": { "text/plain": [ "b'\\n\\n\\n\\n\\n\\n\\nComputational Physics, Course 509 - Physics Applications of Computers\\n\\n\\n\\n\\n
\\n
\\n \\n \\n \\n \\n \\n \\n\\n \\n\\n \\n \\n \\n \\n
  Computational Physics 2023, Course 509 - Physics Applications of Computers
\\n
\\n \\n

\\n Overview
\\n

\\n

\\n Introductory lecture material
\\n

\\n

\\n Programming
\\n

\\n

\\n Basic numerical methods
\\n

\\n

\\n Methods and Algorithms
\\n Monte Carlo methods
\\n Quantum Monte Carlo methods
\\n\\t Continuous Time Quantum Monte Carlo
\\n Hartree-Fock method
\\n Density functional theory
\\n Molecular Dynamics
\\n
\\n

\\n

\\n
\\n\\n   \\n
\\n \\n Left: Simulation of a bacteria growth by DLA method, Right: Molecular dynamics simulation of a small system of atoms\\n Simulation codes is available to download in lecture material.\\n
\\n\\n

\\n This course introduces algorithmic concepts and familiarizes\\n students with the basic computational tools which are essential\\n for graduate students in computational physics, but are also very useful to most graduate students in STEM and related\\n areas, as well as to those students who plan to look for a job in the IT industry.\\n

\\n In this course, students work toward mastering computational\\n skills, and basic algorithms which appear in classical and quantum physics, but are not limited to those fields, for example\\n large scale minimization problems, high dimensional integration problems, and solving partial differential equations are constituting the bulk of the course,\\n but these same algorithms appear in all STEM fields and are also used by quants in major banks. While the examples are drawn mostly from quantum physics, \\n their applicability is far beyond this specific physics subfield.\\n

\\n As the programing language, we will use mostly Python and\\n its scientific library scipy & numpy.\\n To speed up parts of the code, we will also\\n use C++ (with pybind11) and fortran90 (f2py) for short examples, which will be used\\n through the Python interface.\\n

\\n This course has no prerequisites except for familiarity with \\n programming language. It is designed for the student who wishes to\\n broaden his/her knowledge of applications and develop\\n techniques.\\n\\n To complete the homework and perform the hands-on\\n training, it is desired that students use their laptops and bring their own laptops to\\n the class (when in person).\\n

\\n
\\n

Class Time: ARC 205 3:50pm-5:10pm Tuesday and Thursday

\\n \\n \\n \\n \\n \\n
Instructor:\\n Kristjan Haule
\\n Office: Serin E267
\\n email: haule@physics.rutgers.edu
\\n Phone: 445-3881
\\n Office hours: after lecture
\\n
\\n

\\n

 

\\n \\n \\n \\n \\n\\tCodes available at https://github.com/haulek/CompPhysics
\\n\\t
\\n\\tYoutube videos from 2021:\\n\\tLecture 1,\\n\\tLecture 2,\\n\\tLecture 3,\\n\\tLecture 4,\\n\\tLecture 5,\\n\\tLecture 6,\\n\\tLecture 7,\\n\\tLecture 8,\\n\\tLecture 9,\\n\\tLecture 10,\\n\\tLecture 11,\\n\\tLecture 12,\\n\\tLecture 13,\\n\\tLecture 14,\\n\\tLecture 15,\\n\\tLecture 16,\\n\\tLecture 17,\\n\\tLecture 18,\\n\\tLecture 19,\\n\\tLecture 20,\\n\\tLecture 21,\\n\\tLecture 22,\\n\\tLecture 23,\\n\\tLecture 24,\\n\\tLecture 25,\\n\\tLecture 26\\n\\t
\\n\\t

\\n Preliminary Course Outline and Tentative List of Topics include

\\n\\n A) Introduction \\n

\\n

    \\n
  1. Installation, comparison of\\n programing languages by computing Mandelbrot set, speed up the code with numba, f2py, pybind11, \\n parallelization with openMP
  2. \\n
  3. Numerical error accumulation, stable\\n recursion and Miller\\'s algorithm
  4. \\n
\\n

\\n

\\n Source code: https://github.com/haulek/CompPhysics \\n

\\n Text for recursive Homework in pdf\\n

\\n local copy of codes:\\n \\n

  • Plots of Mandelbrot set using fortran, C++, Perl and Python
  • \\n
  • Glues fortran and C++ to Python using f2py and pybind11
  • \\n
  • Computes Bessel functions with upward and downward recursion, shows the error.
  • \\n \\n
    \\n\\t\\n B) Learning high level programming with examples in Python(Numpy, SciPy, Pylab)\\n

    \\n

      \\n\\t
    1. 00_Introduction (to Jupyter)
    2. \\n\\t
    3. 01_Basic_Python
    4. \\n\\t
    5. 02_Numpy
    6. \\n\\t
    7. 03_Scipy
    8. \\n\\t
    9. 04_Scipy_example_Hydrogen_atom
    10. \\n\\t
    11. 05_Atom_in_LDA
    12. \\n\\tJupyter notebooks of these lectures can be downloaded at\\n\\thttps://github.com/haulek/CompPhysics/tree/main/Programing
      \\n
    \\n\\n This lectures are adopted from https://github.com/jrjohansson/scientific-python-lectures\\n\\t\\n

    \\n

    \\n Homeworks:
    \\n     Homework 3,\\n \\n     Numerov algorithm\\n
    \\n     Homework 4,\\n \\n      Script for XC potential: excor.py
    \\n     Total energies from NIST (Energies are given in Hartree\\'s)
    \\n

    \\n\\tMore literature on Learning Python:\\n\\t\\n
  • Software carpentry
  • \\n\\t
  • \\n How to Think Like a Computer Scientist: Learning with Python
  • \\n\\t
  • Python for beginners
  • \\n\\t
  • Python documentation
  • \\n\\t
  • Python regular expressions
  • \\n\\t
    \\n\\t
    \\n\\n C) Monte Carlo and Simulated Annealing\\n
      \\n\\t
    1. Random numbers, multidimensional Vegas integration\\n (source code in html)
    2. \\n
    3. Classical Monte Carlo, Simulated Annealing\\n (source code for Ising model,\\n Wang Landau,\\n Traveling Salesman)\\n
    4. \\n
    5. High-Dimensional integration by Metropolis
      \\n\\t Homework for high-D integration by Metropolis\\n
    \\n

    \\n Alternative implementation of Ising: online Ising model simulation\\n

    \\n \\n Source Codes:\\n
  • jupyter nb for Vegas algorithm
  • \\n
  • jupyter nb for Ising model
  • \\n
  • jupyter nb for Wang Landau
  • \\n
  • jupyter nb for The Traveling Salesman problem
  • \\n
  • jupyter nb for High-D integration by\\n Metropolis, mweight.py\\n C version of High-D integration\\n
  • \\n
  • Diffusion limited aggregation
  • \\n
  • Other MC codes
  • \\n
    \\n \\n
    \\n D) Machine Learning\\n
      \\n\\t
    1. Linear regression, pdf ( jupyter notebook, NucleousEnergy.dat)
    2. \\n\\t
    3. Logistic regression, pdf ( jupyter notebook)
    4. \\n\\t
    5. Deep Learning, pdf (jupyter notebook,NNfig.pdf,or_xor.pdf,NN_digits.pdf)
    6. \\n
    \\n
    \\n E) Parallel Programing\\n
      \\n
    1. Parallel programming with MPI\\t( source code)
    2. \\n
    \\n\\n F) Basic numerical methods:\\n\\t
      \\n\\t
    1. Numeric integration (source code) \\n
    2. \\n
    3. Interpolation, Splines and Fourier transformation (source code)
    4. \\n\\t
    5. Differential equations (source code)
    6. \\n\\t
    \\n\\t Literature:\\n\\t Numerical Recipes online\\n\\t

    \\n\\n\\t \\n G) More advanced topics in Computational Condensed Matter physics:\\n\\t
      \\n
    1. Hartree-Fock method
    2. \\n
    3. Density functional theory
    4. \\n
    5. Quantum Monte Carlo methods
    6. \\n
    7. Continuous Time Quantum Monte Carlo method
    8. \\n\\t
    9. Molecular dynamics simulation
    10. \\n\\t
    \\n\\t Literature:\\n\\t
      \\n\\t
    1. Computational Physics by J.M. Thijssen
    2. \\n\\t
    3. An introduction to Computer Simulation Methods by H. Gould, J Tobocnik and W. Christian
    4. \\n
    5. Electronic Structure, Basic Theory and Practical Methods by Richard M. Martin(Very good book for the Density functional part of the course)
    6. \\n
    7. An Introduction to Computational Physics by Tao Pang
    8. \\n
    9. Computational Physics by Rubin H. Landau and Manuel J. Paez(More elementary but good book)
    10. \\n\\t
    \\n\\n\\t
    \\n\\n

    \\n

    Students with Disabilities

    \\n \\n \\n \\n \\n

     

    \\n
    \\n
    \\n
    \\n\\n\\n\\n\\n'" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import requests\n", "resp = requests.get(\"http://www.physics.rutgers.edu/grad/509/\")\n", "resp.content" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Two (main) cell types\n", "\n", "In a different type of cell, you can:\n", "\n", "* write Markdown\n", "* embed LaTex equation in it\n", "\n", "So you can add comments to your code explaining that, to calculate your cycling speed, you must make use of the fact that\n", "\n", "$[x,p_x]=i \\hbar$." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Some basic operations and keystrokes:\n", "\n", "Toggling toolbars.\n", "\n", "* Return and Esc\n", "* A (new cell before) and B (new cell after)\n", "* X (cut cell), C (copy cell), V (paste cell)\n", "* DD (delete cell)\n", "\n", "The different types of Return:\n", "* Shift-Return\n", "* Ctrl-Return\n", "* Alt-Return\n", "\n", "Choosing cell type:\n", "* M (for Markdown)\n", "* Y (for code)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use ! to use shell comman right inside notebook" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "total 37432\n", "-rw-r--r--@ 1 haule staff 1756407 Dec 18 2020 Scientific-Computing-with-Python.pdf\n", "-rw-r--r--@ 1 haule staff 611082 Jan 20 2021 00_Introduction.html\n", "-rw-r--r--@ 1 haule staff 615891 Jan 20 2021 01_Basic_Python.html\n", "-rw-r--r--@ 1 haule staff 627779 Jan 20 2021 02_Numpy.html\n", "-rw-r--r--@ 1 haule staff 1303621 Mar 4 2021 03_Scipy.html\n", "-rw-r--r--@ 1 haule staff 1040661 Mar 4 2021 04_Scipy_example_Hydrogen_atom.html\n", "-rw-r--r-- 1 haule staff 47733 Jan 3 17:57 01_Basic_Python.ipynb\n", "-rw-r--r-- 1 haule staff 210051 Jan 3 17:57 02_Numpy.ipynb\n", "-rw-r--r-- 1 haule staff 826208 Jan 3 17:57 03_Scipy.ipynb\n", "-rw-r--r-- 1 haule staff 533268 Jan 3 17:57 04_Scipy_example_Hydrogen_atom.ipynb\n", "-rw-r--r-- 1 haule staff 4336264 Jan 3 17:57 ST_data.npy\n", "-rw-r--r-- 1 haule staff 3889864 Jan 3 17:57 StockholmT.dat\n", "-rw-r--r--@ 1 haule staff 430767 Jan 3 17:57 double_pendulum.mp4\n", "-rw-r--r-- 1 haule staff 752 Jan 3 17:57 mymodule.py\n", "-rw-r--r-- 1 haule staff 2038 Jan 3 17:57 pendulum.py\n", "-rw-r--r-- 1 haule staff 2864984 Jan 3 17:57 stockholm_td_adj.dat.txt\n", "-rw-r--r-- 1 haule staff 264 Jan 3 17:57 ttt.cc\n", "-rw-r--r-- 1 haule staff 24310 Jan 6 16:02 00_Introduction.ipynb\n", "/Users/haule/Teaching/488/Programing\n" ] } ], "source": [ "!ls -ltr\n", "!pwd" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Sharing your notebooks\n", "\n", "You can just send people the .ipynb files; they'll contain your input and (optionally) your output.\n", "\n", "Other ways to view and run:\n", "\n", "* **nbconvert** - e.g. convert to static HTML, LaTeX, PDF, Python script, etc\n", "* **Github & Bitbucket** - rendered, but static, e.g. for [qhue](https://github.com/quentinsf/qhue)\n", "* **nbviewer** - http://nbviewer.jupyter.org\n", "* **binder** or **Azure notebooks** - take a github repo with notebooks, and run them in a Docker session \\[mybinder.org\\]\n", "* **jupyterhub** - run locally to make jupyter environments available to users\n", "\n", "---" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Understanding the kernel setting\n", "\n", "The running Python environment is determined by the *kernel setting* of your notebook and not, for example, by the virtualenv you happen to be in.\n", "\n", "Here's where your shell environment will find python, pip etc:" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/Users/haule/opt/anaconda3/bin/python\r\n" ] } ], "source": [ "!which python" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "That's often the Python that's running the notebook server." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And here's the Python running *this notebook*, defined by the choice of kernel:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'/Users/haule/opt/anaconda3/bin/python'" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import sys\n", "sys.executable" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## And lastly...\n", "\n", "Close and Halt\n" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.8.18" } }, "nbformat": 4, "nbformat_minor": 4 }