Skip to content
Snippets Groups Projects
Commit 8065a9d6 authored by Martin Bauer's avatar Martin Bauer
Browse files

benchmark database

parent d76451a4
No related merge requests found
db.py 0 → 100644
import time
import socket
from collections import OrderedDict
import blitzdb
import pandas as pd
from pystencils.cpu.cpujit import getCompilerConfig
def removeConstantColumns(df):
remainingDf = df.loc[:, (df != df.ix[0]).any()]
constants = df.loc[:, (df == df.ix[0]).all()].ix[0]
return remainingDf, constants
class Database:
class SimulationResult(blitzdb.Document):
pass
def __init__(self, file):
self.backend = blitzdb.FileBackend(file)
self.backend.autocommit = True
def save(self, params, result, env={}):
env = env.copy()
env['timestamp'] = time.mktime(time.gmtime())
env['hostname'] = socket.gethostname()
env['cpuCompilerConfig'] = getCompilerConfig()
documentDict = {
'params': params,
'result': result,
'env': env,
}
document = Database.SimulationResult(documentDict, backend=self.backend)
document.save()
self.backend.commit()
def filter(self, **kwargs):
self.backend.filter(Database.SimulationResult, **kwargs)
def toPandas(self, query):
queryResult = self.backend.filter(self.SimulationResult, query)
records = []
index = set()
for e in queryResult:
record = OrderedDict(e.params.items())
record.update(e.result)
records.append(record)
index.update(e.params.keys())
df = pd.DataFrame.from_records(records)
#df.set_index([df[a] for a in list(index)], drop=True, inplace=True)
#for ind in index:
# del df[ind]
#df.set_index([getattr(df, n) for n in index], inplace=True)
#df.set_index(tuple(index), inplace=True)
#df.set_index([df[col] for col in index], inplace=True)
return df
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment