Difference between revisions of "CompSciWeek7"

From Predictive Chemistry
Jump to: navigation, search
(Class 1: The Git Revision Control System)
m (Binary Tree Code)
 
(4 intermediate revisions by the same user not shown)
Line 21: Line 21:
   
 
Starting up:
 
Starting up:
<code lang="bash">
+
<source lang="bash">
 
cd /path/to/source/dir
 
cd /path/to/source/dir
 
git init # create the .git directory for storing git objects
 
git init # create the .git directory for storing git objects
Line 27: Line 27:
 
git rm -r --cached the_unversioned_dir # remove the_unversioned_dir from the staged files
 
git rm -r --cached the_unversioned_dir # remove the_unversioned_dir from the staged files
 
git commit -am "First commit" # perform the commit, saving the files into git
 
git commit -am "First commit" # perform the commit, saving the files into git
</code>
+
</source>
   
 
Alternate start-up:
 
Alternate start-up:
<code lang="bash">
+
<source lang="bash">
 
cd /path/to/source/dir
 
cd /path/to/source/dir
 
git clone https://github.com/git/git # create your own copy of a git tree
 
git clone https://github.com/git/git # create your own copy of a git tree
</code>
+
</source>
   
 
Reading status:
 
Reading status:
<code lang="bash">
+
<source lang="bash">
 
git status # check current directory against HEAD
 
git status # check current directory against HEAD
 
git branch # print a list of branches
 
git branch # print a list of branches
 
git diff <branchname> # see how branchname is different
 
git diff <branchname> # see how branchname is different
</code>
+
</source>
   
 
Making changes:
 
Making changes:
<code lang="bash">
+
<source lang="bash">
 
git commit -am "A descriptive commit message." # save the current working state
 
git commit -am "A descriptive commit message." # save the current working state
 
git checkout <branch> # switch to another (existing) branch
 
git checkout <branch> # switch to another (existing) branch
 
git checkout -b <new_branch_name> # make a new branch
 
git checkout -b <new_branch_name> # make a new branch
</code>
+
</source>
   
 
Repository to repository commands. If you used clone to start your project, these should "just work".
 
Repository to repository commands. If you used clone to start your project, these should "just work".
 
If you didn't you have to use git remote. Follow the [http://gitref.org/remotes/ Gitref Docs] to do that.
 
If you didn't you have to use git remote. Follow the [http://gitref.org/remotes/ Gitref Docs] to do that.
<code lang="bash>
+
<source lang="bash">
 
git pull # merge remote changes with current work.
 
git pull # merge remote changes with current work.
 
git push # push current changes to the remote server (this won't work unless you have permission to write there)
 
git push # push current changes to the remote server (this won't work unless you have permission to write there)
</code>
+
</source>
   
 
= Class 2: Parallel Programming =
 
= Class 2: Parallel Programming =
Line 61: Line 61:
 
* Eigenvalue computation - the "google" algo.
 
* Eigenvalue computation - the "google" algo.
 
* Web Services
 
* Web Services
  +
  +
= Binary Tree Code =
  +
<source lang="python">
  +
class TreeNode:
  +
def __init__(self, left=None, right=None):
  +
self.left = left
  +
self.right = right
  +
  +
def decode(G, addr):
  +
if G == None or len(addr) < 1: # base cases
  +
return G
  +
if addr[0] == '0': # inductive cases
  +
return decode(G.left, addr[1:])
  +
return decode(G.right, addr[1:])
  +
  +
def decode_name(G, addr):
  +
res = decode(G, addr)
  +
return res.name
  +
  +
# 'names' should be sorted on the first call, to make the tree balanced
  +
def create_tree(names):
  +
if len(names) == 0: # base cases
  +
return None
  +
if len(names) == 1:
  +
T = TreeNode()
  +
T.name = names[0]
  +
return T
  +
half = len(names)/2
  +
return TreeNode(create_tree(names[:half]), create_tree(names[half:])) # inductive case
  +
  +
# generate all codes as a list of (name, code) values
  +
# It returns the correct input format for dict(), to create a dictionary mapping names to codes.
  +
def get_codes(G):
  +
if G != None:
  +
if G.left == None and G.right == None: # base cases
  +
yield (G.name, "")
  +
else:
  +
for k,v in get_codes(G.left): # build up name structures
  +
yield (k, '0'+v)
  +
for k,v in get_codes(G.right):
  +
yield (k, '1'+v)
  +
</source>

Latest revision as of 11:18, 13 October 2014

Reading (shared with Week 6)

  • Beginning Python - skim. chapters 8-14 (use as reference material)
    • see especially urlopen on p. 300, forks and threads on p. 304
  • Beginning Python - Chapter 15 (Web services)

Class 1: The Git Revision Control System

  • Repository structure
    • git clone, init
    • examining git objects
    • code branches, git branch, status, checkout
  • Version histories and diff-s
    • git diff, patch
  • Working with remote repo-s
    • git commit, pull, push

References (optional):

Example git workflow:

Starting up: <source lang="bash"> cd /path/to/source/dir git init # create the .git directory for storing git objects git add . # add all files in the current folder git rm -r --cached the_unversioned_dir # remove the_unversioned_dir from the staged files git commit -am "First commit" # perform the commit, saving the files into git </source>

Alternate start-up: <source lang="bash"> cd /path/to/source/dir git clone https://github.com/git/git # create your own copy of a git tree </source>

Reading status: <source lang="bash"> git status # check current directory against HEAD git branch # print a list of branches git diff <branchname> # see how branchname is different </source>

Making changes: <source lang="bash"> git commit -am "A descriptive commit message." # save the current working state git checkout <branch> # switch to another (existing) branch git checkout -b <new_branch_name> # make a new branch </source>

Repository to repository commands. If you used clone to start your project, these should "just work". If you didn't you have to use git remote. Follow the Gitref Docs to do that. <source lang="bash"> git pull # merge remote changes with current work. git push # push current changes to the remote server (this won't work unless you have permission to write there) </source>

Class 2: Parallel Programming

  • Parallel complexity - sum / min / max
  • Parallel caching
  • Eigenvalue computation - the "google" algo.
  • Web Services

Binary Tree Code

<source lang="python"> class TreeNode:

   def __init__(self, left=None, right=None):
       self.left = left
       self.right = right

def decode(G, addr):

   if G == None or len(addr) < 1: # base cases
       return G
   if addr[0] == '0': # inductive cases
       return decode(G.left, addr[1:])
   return decode(G.right, addr[1:])

def decode_name(G, addr):

   res = decode(G, addr)
   return res.name
  1. 'names' should be sorted on the first call, to make the tree balanced

def create_tree(names):

   if len(names) == 0: # base cases
       return None
   if len(names) == 1:
       T = TreeNode()
       T.name = names[0]
       return T
   half = len(names)/2
   return TreeNode(create_tree(names[:half]), create_tree(names[half:])) # inductive case
  1. generate all codes as a list of (name, code) values
  2. It returns the correct input format for dict(), to create a dictionary mapping names to codes.

def get_codes(G):

   if G != None:
     if G.left == None and G.right == None: # base cases
       yield (G.name, "")
     else:
       for k,v in get_codes(G.left): # build up name structures
         yield (k, '0'+v)
       for k,v in get_codes(G.right):
         yield (k, '1'+v)

</source>