# CompSciSpring2017

### From Predictive Chemistry

**Introduction to Scientific Computing**

Course Info

- Course Numbers CHM 4932-004/6938-010, CRN: 21864/21865
- Credit Hours: 3
- Meeting Dates: January 9 - April 26, 2017
- No Class Jan. 16 or Mar. 13-17

- Meeting Times: Mon. and Wed., 12:30-13:45 in SCA 222
- Final Wednesday, May 3, 10:00am – 12:00pm
- Lab Session & Office Hours: Fri. 12:30-13:45 in IDR 214 (or SCA 222 by announcement)

## Contents |

## Overview

Mathematical models in the natural sciences take many shapes and forms. The moment they become more complicated than tracking a few variables over time, we have to put away our Excel spreadsheets and make use of a solid foundation in computational science. The course establishes this foundation by introducing data structures and algorithms used in everyday scientific computing using examples in the python scripting language. By the end of the Semester, students will be able to navigate the Linux command-line to go from a mathematical model to a numerical solution. Best practices for working with computer code and visualizing data will also be covered.

## Topics

- Languages
- bash (shell)
- python (scripting)
- stack & register-based machine languages: overview of C and Fortran syntax & compiling with gcc, ‘thread safety’
- Shared libraries & language inter-operability (FFI)

- Algorithms
- Horner’s algorithm for polynomials
- Newton’s root finding algo.
- Overview of general optimization algo-s (example: linear & nonlin. least-squares)
- Numerical integration (scripted, plus gnu ODE)
- Communication (how HTTP get/put works)

- Data Structures
- Linked Lists
- Trees (file system hierarchies)
- Graphs
- Arrays (dense & sparse) example: vectors & rotations / transpositions, densities and difference operators

- Presentation & visualization
- Flat CSV files (and excel)
- Working with binary data
- Python matplotlib (2D images)
- Binning histograms & weighted averages

- Best Practices
- High-level code design (modularity, interface specifications, unit testing, etc.)
- Code audit: open-source libraries, ex. Gnu Scientific Library, qsort in libc, Boost
- Source code versioning (example: git or mercurial)
- gdb & execution profiling
- documentation
- Makefiles

## Grading

**Grading Scale (out of 400 points possible)**

Grade | Undergraduate | Graduate |
---|---|---|

A | 230 | 280 |

B | 180 | 230 |

C | 150 | 180 |

D | 120 | 150 |

- Points Possible:
- 10 homework assignments (20 points per homework)
- 2 projects / competitions (100 points per project)

- Homework Rules
- For work done in groups, credit is divided equally among participants - so the max homework grade for a group of 2 is 10 points each.
- For each homework, 1 re-do at full credit can be sent at any time after the due date, but must present a unique solution to previous work from yourself or others.
- All work must cite co-group members (if any) and the source of any code snippets used online.

### Grading Rationale

Homework points will only be awarded for correct, working code and correct algorithmic analysis, while the homework problems will become progressively tougher. Undergraduates should be able to pass the course with an A if they have correctly answered most of the homework, and made a strong attempt at one of the projects. Graduate students should both perform well on the homework and successfully complete one or two projects. Essentially, this means you should do your own homework when possible and may do a project in a small group. The re-grading and group options for homework allow making up for missed assignments, and encourage returning to core concepts at a later point in the class. Students who have completed significant portions of the homework have thus demonstrated programming proficiency, and are qualified for at least B/C grades.

## Projects

- Midterm Project Description Media:Midterm2017.pdf
- Final Project Description Media:Final2017.pdf

## Textbooks and Resources

- Beginning Python, Hetland, 2005 (eBook avail. from USF Library)
- Python Algorithms, Hetland, 2010 (eBook avail. from USF Library)
- The Architecture of Open Source Applications
- Python Documentation
- Google Introductory Python Notes
- Tao of Programming

Other (possibly useful) materials:

- The Jargon File
- Chapters 7&8 of Modelling and Simulation, Birta and Arbez, Springer 2007 (eBook avail. from USF Library).
- Chapters 4-6 of Models and Algorithms for Intelligent Data Analysis, Runkler, Springer 2012 (eBook avail. from USF Library).
- Guide to Scientific Computing in C++, Francis and Whiteley, Springer, 2012. (eBook avail. from USF Library)
- Extra info. On the basics:
- Chapters 3 and 7 of Mathematics in Computing, Regan, Springer 2013. (eBook avail. from USF Library)
- Instant feedback graphical programming with Khan Academy

- Local PyBulls Meetings

Code:

- Python Libraries Useful for Geospatial Problems
- Python Libraries Useful for Computational Chemistry (very small list at present)

Interactive Interpreters:

- CodeWars Recommended for building experience with practice problems.
- CodeCombat A very visual way to interact with your python code.
- Exercism A command-line client with a similar learn-through-challenge philosophy.
- repl.it A read-eval-print loop for several computer languages.
- CppReference Documentation with an online evaluator for C++ code.

### Notes

- Introduction Notes
- Week 2-3 Notes
- Week 4: read through function syntax in 2016 Week 2 and for-loops in 2016 Week 3-4
- In-Class Examples
- Week 5 Notes
- Week 6 Notes
- Week 7 Notes
- Misc. Notes for Week 8
- Rundown of Pair Interactions
- Parameterized surfaces 1 and 2

- Notes for Compilation Lab
- Command Line Crash Course Cheat sheet for bash commands.
- USF's compute cluster documentation at RC Wiki.
- See especially the "Connecting to SC" and "Modules" sections

- Cheat-codes for compilation lab.

- Research Computing Batch Queue
- Plugging Into Libraries
- Matrix Algorithms

### Homework

- Homework will be assigned through Repl.IT
- Homework 1 is due Friday, Jan. 20
- Homework 2 is due Friday, Jan 27
- Homework 3 is due Friday, Feb 10
- Homework 4 is due Friday, Feb 17
- Homework 5 is due Wednesday, Mar. 8

- Project presentations will be on Wed., Mar 29
- Homework 6 is due Friday, Mar. 31
- Homework 7 is due Friday, Apr. 7
- Homework 8 is due Friday, Apr. 14
- Homework 9 is due Friday, Apr. 21
- Homework 10 is due Friday, Apr. 28

- Final Project presentations will be during exam time.

Hints for HW 4

def translate(nuc): # 1. remove all non-ATGC characters from nuc # str -> str (nuc.translate) # str -> [char], [char] -> str # 2. capitalize all characters : str -> str # 3. translate 3-char blocks # str -> [char] # hint: range(0, len(s), 3) prot = [] for i in range(2): prot += gencode[nuc[i:i+3]] # 4. join characters return "".join(prot) # TODO: fix empty return and string-values! def get_params(sparams): print(sparams) # 1. split sparams on newlines # str -> [str] lines = sparams.split('\n') print(lines) # 2. create an empty dictionary d = {} # 3. for each line, split on ' ' # add key = val to d for line in lines: tok = line.split() print(tok) continue d[tok[0]] = tok[2] return d def newton(x, v, m, k, dt): dxdt = v dvdt = # acceleration (use F = m a), F = (use Hook's law) return (x+dt*dxdt, v+dt*dvdt)

3d plotting example:

# modified 3d plot from http://matplotlib.org/examples/mplot3d/rotate_axes3d_demo.html from numpy import * import pylab as plt from mpl_toolkits.mplot3d import axes3d def plot_a_list(x): fig = plt.figure() ax = fig.add_subplot(111, projection='3d') x = array(x) X = x[:,0] Y = x[:,1] #[x[0,1], x[1,1], x[2,1], ... Z = x[:,2] # [x[0,2], x[1,2], ... ax.scatter(X, Y, Z) # rotate the axes and update for angle in range(0, 360): ax.view_init(30, angle) plt.draw() plt.pause(.001) x = [ [5,5,0], [6,7,-1], [7, 9, -2], [8, 11, -3], [9, 13, -4]] x.append([10,15,-5]) plot_a_list(x)