Skip to content

Commit 8db22f5

Browse files
committed
some files
1 parent 6a2406e commit 8db22f5

File tree

6 files changed

+89
-0
lines changed

6 files changed

+89
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*~
2+
*.pyc

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
# PythonMisc
22
Some standalone python scripts
3+
4+
* readSketchnet: tool to read data from the sketch-a-net dataset http://cybertron.cg.tu-berlin.de/eitz/projects/classifysketch/
5+
6+
* oncampus: Should graphs be sent from a warwick computer to the screen or a file.
7+
8+
* shapes: function for printing the "shape" of something like a tuple of lists of numpy arrays
9+
10+
* tinisMultiRun: script for parallelizing another script across the 4 GPUs you get on tinis
11+
12+
* tinisDummyProgram: a demo program for tinisMultiRun

oncampus.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#This module is intended to be run on a linux machine on the Warwick campus
2+
#it provides two boolean variables:
3+
# oncampus : whether you are sitting on campus (which implies you probably have a very fast connection to this machine)
4+
# draw : whetheer it would be a good idea to try to plot graphs to the screen. This will be false if you are offcampus or are using SSH without X forwarding
5+
import os, subprocess, string
6+
7+
if "SSH_CLIENT" in os.environ:
8+
oncampus = -1 < subprocess.check_output(["who", "-m"]).find(b"warwick")
9+
else:
10+
oncampus = True
11+
12+
draw = oncampus and "DISPLAY" in os.environ

shapes.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#vaguely useful for understanding the shape of an unknown large object which may be a load of nested lists and tuples.
2+
def shapes(a):
3+
if type(a)==list or type(a) == tuple:
4+
return [shapes(e) for e in a]
5+
if type(a) in (int,float):
6+
return 0
7+
return a.shape

tinisDummyProgram.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import sys, six, os, time
2+
3+
dev = "NOTSET"
4+
if "CUDA_VISIBLE_DEVICES" in os.environ:
5+
dev = os.environ["CUDA_VISIBLE_DEVICES"]
6+
7+
with open("f", "a") as f:
8+
six.print_(sys.argv[1:], dev, file=f)
9+
# six.print_(sys.argv[1:], dev)
10+
11+
#time.sleep(numpy.random.uniform()*4)

tinisMultiRun.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#Run another python script on sevaral background threads
2+
#using different GPUs
3+
4+
#This would be the outer script inside a tinis GPU job
5+
#where you want to run a certain script for several combinations
6+
#of that script's arguments. This script runs one instance for
7+
#each of the four GPUs
8+
9+
import subprocess, sys, six, threading,os, time, itertools
10+
11+
pythonCmd = "python2.7" #on tinis, specify this properly
12+
pythonScript = "tinisDummyProgram.py"
13+
14+
arg1s = [2,3,4,5,6]
15+
arg2s = range(3)
16+
17+
arglists = [arg1s, arg2s]
18+
19+
arglists = [map(str,i) for i in arglists]
20+
allargs = [list(i) for i in itertools.product(*arglists)]
21+
22+
nArg=0
23+
def getArgs():
24+
global nArg
25+
if nArg>=len(allargs):
26+
return False
27+
nArg=nArg+1
28+
return allargs[nArg-1]
29+
30+
31+
def doThread(threadNumber):
32+
env = os.environ.copy()
33+
env["CUDA_VISIBLE_DEVICES"] = str(threadNumber)
34+
while 1:
35+
args = getArgs()
36+
if args==False:
37+
return
38+
subprocess.call([pythonCmd, pythonScript] + args, env=env)
39+
40+
threads = []
41+
for i in range(4):
42+
threads.append(threading.Thread(target=doThread, args=[i]))
43+
for i in threads:
44+
i.start()
45+
for i in threads:
46+
i.join()
47+

0 commit comments

Comments
 (0)