Aims¶

  • Teach the techniques of computational physics and numerical methods
  • side benefit: develop familiarity with python

Syllabus¶

  • Numerical differentiation
  • Numerical integration
  • Numerical solution of ODEs
  • Monte Carlo techniques, random walks
  • Function minimization and optimization

Organisation¶

Contact¶

email: peter.richardson@durham.ac.uk

office: OC207

Office Hour: Friday 3-4.45 starting week 2, either in person in my office or via zoom.

Lectures¶

  • Fri 12-13. For week 1 the material will be presented in the lecture. After that we will use the lecture slot to go over the previous weeks assignment and as a Q&A session.
  • The material will be available as videos which can be watched while trying the programming.

Workshops¶

  • Mon, Tue, Thu, Fri 17-18
  • Attendance is not monitored
  • Cannot change the day
  • In D/ENGEX1 the annex to engineering, CANNOT be accessed from inside engineering. Enter either via the small door shown below or easier up the hill and turn left.

Computing environment¶

  • We will use Jupyter notebooks for all the works in this course
  • System introduced last year:
    • electronic submission, marking and feedback
    • easier interaction with python
    • better integration of plots and animations
    • accessible from anywhere
  • Please report problems!
  • Manual available at https://notes.dmaitre.phyip3.dur.ac.uk/notebooks/

Jupyter platform¶

  • log in to the server using your CIS username and password: https://compphys-2526.notebooks.danielmaitre.phyip3.dur.ac.uk/
  • go to the "Assignment" tab
  • select the assignment and "fetch" it
  • open the assignment section and select the notebook to use. It will open in a new tab.
  • work on the assignment
  • your work is automatically saved
  • you can also save your work with the "save icon" or the File menu

Programming environment¶

  • we use python 3
  • all packages you need should be installed on the server
    • if you think a package would be useful but is not installed let me know

Saving your work¶

  • your work is automatically saved every few minutes
  • save your work with the "save icon" or the File menu
  • your python session will be closed after 1-2 hours of inactivity
    • the text and output in the notebook will be saved
    • the state of the python interpreter will not be saved:
      • you need to reevaluate all cells to restore the state
      • use "Kernel" -> "Restart and run all"
      • it is useful to do this occasionally to make sure the notebook runs as written and does not rely on code executed previously and edited since
  • can save a copy of your notebooks using "File" -> "Download as" -> "Notebook"
  • backup every hours of saved files
    • only in emergencies: you have to ask me to restore the file
  • you can make copies of notebooks "File" -> "Make a copy" but for the assessment only the original file will be considered!

Working on the server¶

  • Feel free to create new notebooks to experiment and play
  • I can see everything you do on the server so:
    • follow the CIS usage policy
    • don't use the resources for other purposes than academic ones
    • don't try to trick the marking system

Assessments¶

  • 8 assessments
  • distributed through the notebook server
  • submitted through the notebook server
  • deadline: Mondays 14:00 (starting Week 3, i.e. 1st assignment due 20th October)
  • the last submission counts! Submit partial work to avoid having no submission in time at all.
  • if your first submission is after the deadline no marks will be awarded!

Assessment¶

  • Each assessment will be composed of one or more notebooks
  • Each notebook will have a description of the tasks to perform
  • It will be in the form of either:
    • a piece of code to provide
    • a task (for example producing a plot)
    • a free text question

Assessment: piece of code¶

  • if you are asked to provide a piece of code the location will be marked by a # YOUR CODE HERE marker
In [1]:
def double(x):
    # YOUR CODE HERE
    raise NotImplementedError()

Assessment: piece of code¶

  • replace the marker (and the raise statement) with a valid piece of code:
In [2]:
def double(x):
    return 2*x
    
  • code tasks will typically be followed by a test that helps you check that your code's functionality is correct
In [3]:
assert double(4) == 8

Assessment: piece of code¶

  • when you click on the "validate" button in the notebook or in the assignment list the notebook is run and checks that all these assert tests pass, you will get a warning if they don't.
  • these tests are part of the assessment: if they don't pass you won't get all marks!

Assessment: free text question¶

A free text question will be followed by a cell with the text

YOUR ANSWER HERE

You can double click on it and edit the text. You can use $\LaTeX$

Feedback¶

Feedback will be made available on the notebook server.

I will demonstrate it after your first assignment's feedback is ready.

Getting Help¶

  • course webpage: https://notes.dmaitre.phyip3.dur.ac.uk/compphys/
  • L1 resources: https://discoveryskills-python-2425.notebooks.danielmaitre.phyip3.dur.ac.uk/
  • demonstrators in workshop
  • Q& A in lecture slot

Useful packages¶

  • matplotlib: plotting
  • numpy: fast numerical calculations with arrays
  • scipy: collection of scientific functions
  • sympy: symbolic calculation

See new L1 python resource for more on these packages

Useful tips¶

  • tab completion
  • inline help (append ? to a command)
  • execution can be interrupted using the $\rm {\blacksquare}$ button

Generative AI¶

In addition to an understanding of the numerical algorithms we will discuss this courses aims to teach you to:

  • implement an algorithm to solve a problem;
  • test it to make sure it is giving the right answer;
  • understand the issues effecting the accuracy of your code.

To do this you need to understand how to write the code from scratch so that:

  • you can do it if you have nothing to start from;
  • if you are adapting an existing piece of code you can make sure its doing what you want;
  • if you get code from googling/genAI you can make sure it is doing what you want and giving the correct answer.

You will not develop the skills you'll need for the future (e.g. L3 computing, L4 projects, a job after graduating) by just using genAI.

You will not develop the skills you'll need for the future (e.g. L3 computing, L4 projects, a job after graduating) by just using genAI.

genAI can be a useful tool to help with programming if you know enough to understand whether the output is correct, check its doing what you want and adapt the answers to your specific problem.

For this course

  • Some uses of genAI are sensible and in the past we would have googled to get similar information. For example how to make a specific type of plot with pyplot or a specific operation with numpy;
  • You should not use genAI to write all the code for the numerical algorithms we are studying. While it may be possible for some of the algorithms we are studying for more specialised/complicated cases it won't be. You need to develop your skills so you can tackle harder problems;
  • You should include a statement saying how you have used genAI and reflect upon how you used it.

There is excellent information in the python handbook: https://discoveryskills-python-2425.notebooks.danielmaitre.phyip3.dur.ac.uk/