def __init__(self, r, debug=False): self.B = shelve.open('B.txt') # B contains the parents of the pebble. self.all_graphs = shelve.open( 'all_graphs.txt', writeback=True ) # all_graphs contains the parents of every single ptc graph up to size r. self.pebble_value = shelve.open( 'pebble_value.txt' ) # pebble_value stores the value of the hash associated with the pebble. self.num_pebbles = 0 # num_pebbles is the number of pebbles currently on the graph. self.max_pebbles = 0 # max_pebbles it the maximum number of pebbles that have been on the graph since the last reset. self.graph_num = r ptc.PTC(r, self.all_graphs) for i in range(self.size()): self.B[str(i)] = self.all_graphs[str(self.graph_num)][i] for i in range(self.size()): self.pebble_value[str(i)] = None self.debug = debug
def create_butterfly_graphs( n): # creates all butterfly PTC graphs up to and including n. print "***************" print "Running create_butterfly_graphs(" + str( n) + "), starting at " + str(datetime.datetime.now()) + "." start_generate = time.time() all_graphs = open('all_graphs.txt', 'r+') ptc.PTC(n, all_graphs) end_generate = time.time() print "Vertices in created graph: " + str(ptc.ptcsize(n)) print "Total seconds elapsed: " + str(end_generate - start_generate) print "Vertices generated per second: " + str( ptc.ptcsize(n) / (end_generate - start_generate)) print "create_butterfly_graphs(" + str(n) + ") completed at " + str( datetime.datetime.now()) + "." print "***************" all_graphs.close()
def __init__(self, r, pre_generated_graph=False, debug=False): # set pre_generated_graph to be True if the file all_graphs already contains all the neccessary parents on your computer. self.hash_length = utils.hash_length() self.all_graphs = open('all_graphs.txt', 'r+') self.pebble_value = open('pebble_value.txt', 'r+') self.num_pebbles = 0 # num_pebbles is the number of pebbles currently on the graph. self.max_pebbles = 0 # max_pebbles it the maximum number of pebbles that have been on the graph since the last reset. self.graph_num = r self.size = ptc.ptcsize(self.graph_num) if not pre_generated_graph: self.all_graphs.seek(0) ptc.PTC(r, self.all_graphs) self.all_graphs_increment = len(str(self.size)) # The number of bytes each parent in all_graphs takes self.all_graphs_start = ptc.all_graphs_start(self.graph_num) # The position where the rth graph is stored in all_graphs. self.all_graphs.seek(self.all_graphs_start + 2 * 2**self.graph_num * self.all_graphs_increment) self.pebble_value.seek(0) for i in range(self.size): self.pebble_value.write("z"*self.hash_length) self.pebble_value.seek(0) self.debug = debug
import ptc import time import logging p = ptc.PTC() logging.info("PTC Version=%s", p.version()) logging.info("Status=%s", p.getstatus()) logging.info("Lid status=%s", p.getlidstatus())
import ptc import sys import string import logging if len(sys.argv) != 5 or (sys.argv[2] != "BLOCK" and sys.argv[2] != "PROBE" and sys.argv[2] != "CALC"): print "Usage: %s PGM (BLOCK|PROBE|CALC) (TRACKING,xx|CONSTANT,xx|OFF) volume" % sys.argv[ 0] exit(1) p = ptc.PTC(5) p.setdebug() if sys.argv[3] == "OFF": hl = "OFF" else: ss = string.split(sys.argv[3], ',') if len(ss) != 2 or (ss[0] != "TRACKING" and ss[0] != "CONSTANT"): logging.error("Bad lid setting: %s" % sys.argv[3]) exit(1) res = p.execute('HOTLID "%s",%s,25' % (ss[0], ss[1])) hl = "ON" res = p.execute('VESSEL "Plate"') res = p.execute("VOLUME %s" % sys.argv[4]) res = p.execute('RUN "%s",%s,%s' % (sys.argv[1], sys.argv[2], hl)) status = p.getstatus() if (status.bsr & status.RUNNING) == 0: logging.error("Failed to start program %s: status=%s" % (sys.argv[1], str(status)))
# Setup TRP programs on PTC import ptc import sys p = ptc.PTC() # 10s timeout p.setdebug() p.execute('FOLDER "TRP"') p.program('TRP', sys.argv[1], [s.replace('@', ' ') for s in sys.argv[2:]]) pgms = p.programs("TRP") print "pgms=", pgms
# Get status of the various parts of the thermocycler and store in Gemini using named pipes interface import ptc import sys if len(sys.argv) < 2: print "Usage: ptcclean.py FOLDER [ FOLDER ... ]" exit(2) p = ptc.PTC(10) # 10s timeout folders = sys.argv[1:] for folder in folders: print "Scanning folder %s..." % folder pgms = p.programs(folder) print "pgms=", pgms for pgm in pgms: print "Erasing %s/%s: " % (folder, pgm), sys.stdout.flush() res = p.erase(pgm) print res if res != "PGM DELETED": print "Error deleting %s/%s: %s" % (folder, pgm, res) res = p.execute('DELFOLDER "%s"' % folder) print "Deleting folder %s: %s" % (folder, res) exit(0)