Difference between revisions of "CompSciSpring2017"

From Predictive Chemistry
Jump to: navigation, search
(Notes)
m (Homework)
 
(26 intermediate revisions by the same user not shown)
Line 7: Line 7:
 
** No Class Jan. 16 or Mar. 13-17
 
** No Class Jan. 16 or Mar. 13-17
 
* Meeting Times: Mon. and Wed., 12:30-13:45 in SCA 222
 
* 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)
 
** Lab Session & Office Hours: Fri. 12:30-13:45 in IDR 214 (or SCA 222 by announcement)
   
Line 55: Line 56:
 
| A
 
| A
 
| 230
 
| 230
| 300
+
| 280
 
|-
 
|-
 
| B
 
| B
Line 85: Line 86:
 
== Projects ==
 
== Projects ==
   
TBA - see previous years (e.g. [[CompSciSpring2016]]) for a general idea.
 
  +
* Midterm Project Description [[Media:Midterm2017.pdf]]
  +
** [[Agile|Agile Development Tips & Tricks]]
  +
* Final Project Description [[Media:Final2017.pdf]]
   
 
== Textbooks and Resources ==
 
== Textbooks and Resources ==
Line 119: Line 122:
 
=== Notes ===
 
=== Notes ===
   
 
  +
* [[Media:Intro.pdf|Introduction Notes]]
 
* [[Media:Week2-2017.pdf|Week 2-3 Notes]]
  +
* Week 4: read through function syntax in [[Media:Week2.pdf|2016 Week 2]] and for-loops in [[Media:Week3.pdf|2016 Week 3-4]]
 
* In-Class Examples
 
* In-Class Examples
 
** [[Turing Exercise]]
 
** [[Turing Exercise]]
** [[Media:Week2-2017.pdf]]
 
  +
** [https://predictivestatmech.org/code/example.dcd Example DCD File]
  +
* [[Media:Week-5.2017.pdf|Week 5 Notes]]
  +
* [[Media:PlottingMaps.pdf|Week 6 Notes]]
  +
** [[Code:PyTesting]]
  +
* [[Media:NumpyArrays.pdf|Week 7 Notes]]
  +
** [http://www.labri.fr/perso/nrougier/from-python-to-numpy/ all about numpy]
  +
* Misc. Notes for Week 8
  +
** [[Physics:Pairs|Rundown of Pair Interactions]]
  +
** Parameterized surfaces [[Media:param1.jpg|1]] and [[Media:param2.jpg|2]]
  +
* Notes for Compilation Lab
  +
** [https://learnpythonthehardway.org/book/appendixa.html Command Line Crash Course] Cheat sheet for bash commands.
  +
** USF's compute cluster documentation at [https://wiki.rc.usf.edu/index.php/Main_Page RC Wiki].
  +
*** See especially the "Connecting to SC" and "Modules" sections
  +
** [[Code:Compiling|Cheat-codes]] for compilation lab.
  +
* [[Media:jobs.pdf|Research Computing Batch Queue]]
  +
* [[Media:Plug-in.pdf|Plugging Into Libraries]]
  +
* [[Media:Matrix.pdf|Matrix Algorithms]]
   
 
=== Homework ===
 
=== Homework ===
   
* Homework will be assigned through [https://repl.it/classroom/invite/BtxEVLe Repl.IT]
+
* Homework will be assigned through Repl.IT
 
** Homework 1 is due Friday, Jan. 20
 
** Homework 1 is due Friday, Jan. 20
 
** Homework 2 is due Friday, Jan 27
 
** 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
  +
<source lang="python">
  +
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)
  +
  +
</source>
  +
  +
3d plotting example:
  +
<source lang="python">
  +
# 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)
  +
</source>

Latest revision as of 09:26, 8 January 2018

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)

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

  1. 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)
  2. 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)
  3. Data Structures
    • Linked Lists
    • Trees (file system hierarchies)
    • Graphs
    • Arrays (dense & sparse) example: vectors & rotations / transpositions, densities and difference operators
  4. Presentation & visualization
    • Flat CSV files (and excel)
    • Working with binary data
    • Python matplotlib (2D images)
    • Binning histograms & weighted averages
  5. 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

Textbooks and Resources

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:

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

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 <source lang="python"> 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)
  1. 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)

</source>

3d plotting example: <source lang="python">

  1. 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) </source>