|
| 1 | +require "lsqlite3" |
| 2 | +require 'sys' |
| 3 | + |
| 4 | +local results = {} |
| 5 | + |
| 6 | +filename = os.getenv("JR_RESULTSFILE") or "results.sqlite" |
| 7 | +con = sqlite3.open(filename) |
| 8 | +filecontents = "" |
| 9 | + |
| 10 | +function append_file_to_filecontents_string(f) |
| 11 | + local ff = io.open(f,"r") |
| 12 | + local content = ff:read("*all") |
| 13 | + ff:close() |
| 14 | + filecontents = filecontents .. f .."\n"..content |
| 15 | +end |
| 16 | + |
| 17 | +function check(x) |
| 18 | + if x~=sqlite3.OK then |
| 19 | + error(con:errmsg()) |
| 20 | + end |
| 21 | +end |
| 22 | + |
| 23 | +--if sql is a statement which doesn't return results, |
| 24 | +--resultless(sql, param1, param2) executes it with the given parameters |
| 25 | +function resultless(st, ...) |
| 26 | + local s = con:prepare(st) |
| 27 | + assert(s) |
| 28 | + s:bind_values(...) |
| 29 | + local res = s:step() |
| 30 | + if res~=sqlite3.DONE then |
| 31 | + error(con:errmsg()) |
| 32 | + end |
| 33 | + s:finalize() |
| 34 | +end |
| 35 | + |
| 36 | +function results.startRun(repnname, repnlength, continuation, batchTr, batchTe, layertype, layers, width, architecture, solver, callerFilePath) |
| 37 | + if "table" == type(callerFilePath) then |
| 38 | + for i,name in ipairs(callerFilePath) do |
| 39 | + append_file_to_filecontents_string(name) |
| 40 | + end |
| 41 | + else |
| 42 | + append_file_to_filecontents_string(callerFilePath) |
| 43 | + end |
| 44 | + local setup=[[create table if not exists RUNS(COUNT INTEGER PRIMARY KEY, TIME TEXT DEFAULT CURRENT_TIMESTAMP NOT NULL, REPN TEXT, REPNLENGTH INT, CONTINUATION TEXT, BATCHTR INT, BATCHTE INT, LAYERTYPE TEXT, LAYERS INT, WIDTH INT, ARCHITECTURE TEXT, SOLVER TEXT, CODE TEXT) ; |
| 45 | + create table if not exists STEPS(STEP INTEGER PRIMARY KEY, RUN int, OBJECTIVE real, TRAINACC real, TESTOBJECTIVE real, TESTACC REAL ); |
| 46 | + create table if not exists TIMES(RUN INT, TIME real) |
| 47 | + ]] |
| 48 | + check(con:exec(setup)) |
| 49 | + local infoquery = "insert into RUNS (REPN, REPNLENGTH, CONTINUATION, BATCHTR, BATCHTE, LAYERTYPE, LAYERS, WIDTH, ARCHITECTURE, SOLVER, CODE) VALUES (?,?,?,?,?,?,?,?,?,?,?)" |
| 50 | + local info = {repnname, repnlength, continuation, batchTr, batchTe, layertype, layers, width, architecture, solver, filecontents} |
| 51 | + resultless(infoquery,unpack(info)) |
| 52 | + nrun = con:last_insert_rowid() |
| 53 | + sys.tic() |
| 54 | + nsteps = 0 |
| 55 | + filecontents = nil |
| 56 | +end |
| 57 | + |
| 58 | +function results.step(obj,train,objte,test) |
| 59 | + nsteps = 1+nsteps |
| 60 | + resultless("insert into steps values (NULL, ?, ?, ?, ?, ?)", nrun,obj,train,objte, test) |
| 61 | + if nsteps == 10 then |
| 62 | + resultless("insert into TIMES VALUES (?,?)", nrun, sys.toc()) |
| 63 | + end |
| 64 | +end |
| 65 | + |
| 66 | +return results |
0 commit comments