Ejemplo n.º 1
0
 def create_holbarun(i):
     progs_list = db.add_tablerecord(
         ldb.get_empty_TableRecord("exp_progs_lists")._replace(
             name=f"holbarun_{i}"))
     exps_list = db.add_tablerecord(
         ldb.get_empty_TableRecord("exp_exps_lists")._replace(
             name=f"holbarun_{i}"))
     holbarun = db.add_tablerecord(
         ldb.TR_holba_runs(id=None,
                           name=f"time {i}",
                           exp_progs_lists_id=progs_list.id,
                           exp_exps_lists_id=exps_list.id))
     return holbarun
Ejemplo n.º 2
0
def initial_readonly_db_tests(db):
    # readonly mode doesn't allow creation of rows
    ensure_failing(
        db.add_tablerecord,
        ldb.TR_db_meta(id=None,
                       kind="arbitraryfreshvalue",
                       name='anotherfresh123',
                       value='111'))
    # but it allows standard query functions
    _db_meta_ver_1 = db.get_tablerecord_matches(
        ldb.get_empty_TableRecord("db_meta")._replace(id=0))
    assert (_db_meta_ver_1 == [
        ldb.TR_db_meta(id=0, kind='logsdb', name='version', value='1')
    ])

    print("=" * 40)
    print(db.to_string(True))

    # query something with tablename
    _db_meta_ver_2 = db.get_tablerecords_sql(
        "select * from db_meta where id = 0", "db_meta")
    assert (_db_meta_ver_2 == _db_meta_ver_1)
    # query something without tablename
    _db_meta_ver_3 = db.get_tablerecords_sql(
        "select kind from db_meta where id = 0")
    assert (_db_meta_ver_3 == (['kind'], [['logsdb']]))
Ejemplo n.º 3
0
def op_create(db, json_args):
	# input check
	if not type(json_args) is dict:
		raise Exception("wrong input, must be a dictionary")
	if any(map(lambda x: not x in ["table", "values", "id_only", "match_existing"], json_args.keys())):
		raise Exception("unknown parameter in input")
	# fetching of arguments
	table = json_args["table"]
	values = json_args["values"]
	id_only = False
	try:
		id_only = json_args["id_only"]
	except KeyError:
		pass
	match_existing = False
	try:
		match_existing = json_args["match_existing"]
	except KeyError:
		pass
	if not type(match_existing) is bool:
		raise Exception("wrong input, 'match_existing' must be a bool")
	if not type(values) is dict:
		raise Exception("wrong input, 'values' must be a dictionary")
	# processing of arguments
	tr = ldb.get_empty_TableRecord(table)
	data = tr._replace(**values)
	# create an entry, basic definition: only essential data
	return db.add_tablerecord(data, id_only=id_only, match_existing=match_existing)._asdict()
Ejemplo n.º 4
0
    def __init__(self, db, prog):
        self.db = db

        if type(prog) == int:
            progs = db.get_tablerecord_matches(
                ldb.get_empty_TableRecord("exp_progs")._replace(id=prog))
            assert (len(progs) == 1)
            self.prog = progs[0]
        else:
            self.prog = prog
Ejemplo n.º 5
0
    def __init__(self, db, exprun):
        self.db = db

        if type(exprun) == int:
            expruns = db.get_tablerecord_matches(
                ldb.get_empty_TableRecord("exp_runs")._replace(id=exprun))
            assert (len(expruns) == 1)
            self.exprun = expruns[0]
        else:
            self.exprun = exprun
Ejemplo n.º 6
0
    def __init__(self, db, holbarun):
        self.db = db

        if type(holbarun) == int:
            holbaruns = db.get_tablerecord_matches(
                ldb.get_empty_TableRecord("holba_runs")._replace(id=holbarun))
            assert (len(holbaruns) == 1)
            self.holbarun = holbaruns[0]
        else:
            self.holbarun = holbarun
Ejemplo n.º 7
0
 def add_prog(i, holbarun):
     prog = db.add_tablerecord(
         ldb.get_empty_TableRecord("exp_progs")._replace(
             arch="arch5000", code=f"crazy code {i}"))
     db.add_tablerecord(
         ldb.TR_exp_progs_lists_entries(
             exp_progs_lists_id=holbarun.exp_progs_lists_id,
             exp_progs_id=prog.id,
             list_index=i))
     return prog
Ejemplo n.º 8
0
 def get_entry_ids(self):
     if self.entry_ids == None:
         tr = ldb.get_empty_TableRecord(
             f"exp_{self.listtype}s_lists_entries")
         tr_ = tr._replace(
             **{f"exp_{self.listtype}s_lists_id": self.get_logslist_id()})
         entries = self.db.get_tablerecord_matches(tr_)
         self.entry_ids = list(
             map(
                 lambda x:
                 (x.list_index, getattr(x, f"exp_{self.listtype}s_id")),
                 entries))
     return self.entry_ids
Ejemplo n.º 9
0
    def __init__(self, db, exp):
        self.db = db

        if type(exp) == int:
            exps = db.get_tablerecord_matches(
                ldb.get_empty_TableRecord("exp_exps")._replace(id=exp))
            assert (len(exps) == 1)
            self.exp = exps[0]
        else:
            self.exp = exp

        self.inputs = None
        self.prog = None
        self.metadata = None
Ejemplo n.º 10
0
    def __init__(self, db, listtype, logslist):
        self.db = db
        self.listtype = listtype

        assert (listtype == "prog" or listtype == "exp")
        if type(logslist) == int:
            logslists = db.get_tablerecord_matches(
                ldb.get_empty_TableRecord(f"exp_{listtype}s_lists")._replace(
                    id=logslist))
            assert (len(logslists) == 1)
            self.logslist = logslists[0]
        else:
            self.logslist = logslist

        self.entry_ids = None
        self.entries = None
Ejemplo n.º 11
0
def op_append(db, json_args):
	# input check
	if not type(json_args) is dict:
		raise Exception("wrong input, must be a dictionary")
	if any(map(lambda x: not x in ["table", "values"], json_args.keys())):
		raise Exception("unknown parameter in input")
	# fetching of arguments
	table = json_args["table"]
	values = json_args["values"]
	if not type(values) is dict:
		raise Exception("wrong input, 'values' must be a dictionary")
	# processing of arguments
	tr = ldb.get_empty_TableRecord(table)
	data = tr._replace(**values)
	# append string data to an existing entry
	db.append_tablerecord_meta(data)
	return True
Ejemplo n.º 12
0
    def write_new_run(self, exprun, run_spec, run_data):
        assert (len(run_spec.split(".")) == 2)
        assert (Experiment.is_complete_run(run_data))

        run_id = run_spec + "." + exprun.get_name()
        meta_name = _run_id_meta_prefix + run_id

        last_run_id = self.get_latest_run_id(run_spec)
        nomismatches = True
        if last_run_id == None:
            last_run_exists = False
        else:
            last_run_exists = True
            last_run_data = self.get_run_data(last_run_id)
            last_is_complete = Experiment.is_complete_run(last_run_data)
            nomismatches = nomismatches and last_is_complete

        if last_run_exists:
            for k in run_data.keys():
                if k in last_run_data.keys():
                    #print(f"{run_data[k]} == {last_run_data[k]}")
                    nomismatches = nomismatches and run_data[
                        k] == last_run_data[k]
                else:
                    nomismatches = False

        if (not nomismatches) or (not last_run_exists):
            tr_b = ldb.get_empty_TableRecord("exp_exps_meta")._replace(
                exp_exps_id=self.get_exp_id(), name=meta_name)
            for k in run_data.keys():
                v = json.dumps(run_data[k], separators=(
                    ',', ':')) if k == "result" else run_data[k]
                tr = tr_b._replace(kind=k, value=v)
                self.db.add_tablerecord(tr)

        return nomismatches
Ejemplo n.º 13
0

print("opening db...")
print()
db = ldb.LogsDB()
db.connect()

# collect progs
progs = logslist.LogsList._get_by_name(db, "prog", listname).get_entries()
print(f"found {len(progs)} progs")
print()

# create proglist for filtered progs
new_listname = f"FILTER.{listname}"
new_list = db.add_tablerecord(
    ldb.get_empty_TableRecord("exp_progs_lists")._replace(
        name=new_listname, description="filter_proglist_proto"))
print(f"created new list - '{new_listname}'")
print()

# iterate progs
n_progs = 0
for (lidx, prog) in progs:
    keep = filter_fun(prog.get_code())
    print_them = False
    if not keep:
        if print_them:
            print(f"prog_id = {prog.get_prog_id()}")
            print(f"list_id = {lidx}")
            print(prog.get_code())
            print()
        continue
Ejemplo n.º 14
0
 def _get_all(db):
     records = db.get_tablerecord_matches(
         ldb.get_empty_TableRecord("holba_runs"))
     return list(map(lambda x: HolbaRun(db, x), records))
Ejemplo n.º 15
0
def op_query(db, json_args):
	# input check
	if not type(json_args) is dict:
		raise Exception("wrong input, must be a dictionary")
	if any(map(lambda x: not x in ["type", "query"], json_args.keys())):
		raise Exception("unknown parameter in input")
	# fetching and processing of arguments
	q_type = json_args["type"]
	q = json_args["query"]

	## query in some way, try to be more structured and restricted here, not bare SQL strings

	# a) simple match
	if   q_type == "match_simple":
		# input check
		if not type(q) is dict:
			raise Exception("wrong input, must be a dictionary")
		if any(map(lambda x: not x in ["table", "values", "id_only"], q.keys())):
			raise Exception("unknown parameter in input ('query')")
		# fetching arguments
		table = q["table"]
		values = q["values"]
		id_only = False
		try:
			id_only = q["id_only"]
		except KeyError:
			pass
		if not type(values) is dict:
			raise Exception("wrong input, 'values' of 'query' must be a dictionary")
		# processing of arguments
		tr = ldb.get_empty_TableRecord(table)
		data = tr._replace(**values)
		# search for matches and return the results as a pair of field name list and individual lists with the same length
		if not id_only:
			fields = list(tr._fields)
		else:
			fields = list(ldb.TR_id_only._fields)
		matches = db.get_tablerecord_matches(data, id_only=id_only)
		rows = list(map(lambda m: list(map(lambda x: getattr(m, x), fields)), matches))
		res = {"fields": fields, "rows": rows}
		return res

	# b) join-based query
	elif q_type == "join_based":
		# input check
		if not type(q) is dict:
			raise Exception("wrong input, must be a dictionary")
		if any(map(lambda x: not x in ["table", "joins", "query_exp", "order_by", "id_only"], q.keys())):
			raise Exception("unknown parameter in input ('query')")
		# fetching arguments
		table = q["table"]
		joins = q["joins"]
		query_exp = q["query_exp"]
		order_by = []
		try:
			order_by = q["order_by"]
		except KeyError:
			pass
		id_only = False
		try:
			id_only = q["id_only"]
		except KeyError:
			pass

		if not type(values) is dict:
			raise Exception("wrong input, 'values' of 'query' must be a dictionary")
		# processing of arguments
		raise Exception("not implemented")
		# execute query and return results
		raise Exception("not implemented")

	# c) raw sql query
	elif q_type == "sql":
		# input check
		if not type(q) is dict:
			raise Exception("wrong input, must be a dictionary")
		if any(map(lambda x: not x in ["sql"], q.keys())):
			raise Exception("unknown parameter in input ('query')")
		# fetching arguments
		sql = q["sql"]
		# execute sql query and return results
		(fields, rows) = db.get_tablerecords_sql(sql)
		return {"fields": fields, "rows": rows}

	# d) unknown query type
	else:
		raise Exception("unknown query type: " + q_type)
Ejemplo n.º 16
0
 def _get_all(db, listtype):
     records = db.get_tablerecord_matches(
         ldb.get_empty_TableRecord(f"exp_{listtype}s_lists"))
     return list(map(lambda x: LogsList(db, listtype, x), records))
Ejemplo n.º 17
0
                                                          1][1]
    chunk_idxs.append((start_idx, start_idx + c_sz))
#print(chunk_idxs)

# prepare containers as chunks (all the efforts to keep the order)
containers = [progs[s_idx:e_idx] for (s_idx, e_idx) in chunk_idxs]
#print(containers[0])
container_szs = list(map(len, containers))
print(container_szs)
assert (container_szs == chunk_szs)

print()
for i in range(len(containers)):
    new_listname = f"SPLIT.{listname}.{i}"
    new_list = db.add_tablerecord(
        ldb.get_empty_TableRecord("exp_progs_lists")._replace(
            name=new_listname, description="split_list"))
    print(f"created new list - '{new_listname}'")

    container = containers[i]
    print(f"container {i} has length {len(container)}")

    for (lidx, prog) in container:
        db.add_tablerecord(
            ldb.TR_exp_progs_lists_entries(exp_progs_lists_id=new_list.id,
                                           exp_progs_id=prog.get_prog_id(),
                                           list_index=lidx))
        pass

    print()
Ejemplo n.º 18
0
    logging.info("using db file: " + db_export_file)
    # make sure export db is new
    if os.path.exists(db_export_file):
        raise Exception("export db must be new. exists already: " +
                        db_export_file)
    # return db (is intended to be used in a "with" statement)
    return db_export


# create db access object
alt_db_file = None if not is_testing else "data/testing.db"
with ldb.LogsDB(alt_db_file) as db:
    # find and collect list, experiments and their metadata
    # 1. list
    list_recs_ = db.get_tablerecord_matches(
        ldb.get_empty_TableRecord("exp_exps_lists"))
    list_recs = list(filter(lambda x: x.name == listname, list_recs_))
    assert (len(list_recs) < 2)
    if len(list_recs) != 1:
        raise Exception(f"could not find experiment list '{listname}'")
    list_rec = list_recs[0]
    print("found the list")

    # 2. list entries
    list_entr_recs = db.get_tablerecord_matches(
        ldb.get_empty_TableRecord("exp_exps_lists_entries")._replace(
            exp_exps_lists_id=list_rec.id))
    print(f"found {len(list_entr_recs)} list entries")

    # 3. exps
    expr_ref = ldb.QE_Bin(op=ldb.QE_Bop.EQ,
Ejemplo n.º 19
0
def initial_db_tests(db):
    # general tests
    TR_db_meta_empty = ldb.TR_db_meta._make([None] * 4)
    assert (TR_db_meta_empty == ldb.get_empty_TableRecord(ldb.TR_db_meta))
    assert (TR_db_meta_empty == ldb.get_empty_TableRecord("db_meta"))

    # make sure that the database is cleared
    try:
        for t in ldb.tables_all:
            n = db.get_tablerecord_matches(ldb.get_empty_TableRecord(t), True)
            if t == "db_meta":
                assert (n == 1)
            else:
                assert (n == 0)
    except:
        raise Exception("database must be cleared before testing")

    # add a bit of metadata
    _db_meta = db.get_tablerecord_matches(ldb.get_empty_TableRecord("db_meta"))
    _db_meta += [
        db.add_tablerecord(
            ldb.TR_db_meta(id=None, kind=None, name='hellO', value='me123'))
    ]
    _db_meta += [
        db.add_tablerecord(
            ldb.TR_db_meta(id=None, kind=None, name='hellO', value='me123'))
    ]
    _db_meta += [
        db.add_tablerecord(
            ldb.TR_db_meta(id=None, kind="hello8", name='123', value='me123'))
    ]
    _db_meta_1 = db.get_tablerecord_matches(
        ldb.get_empty_TableRecord("db_meta"))
    #print(_db_meta)
    #print(_db_meta_1)
    assert (_db_meta == _db_meta_1)
    # check countonly option
    assert (len(
        db.get_tablerecord_matches(ldb.get_empty_TableRecord("db_meta"))) ==
            db.get_tablerecord_matches(ldb.get_empty_TableRecord("db_meta"),
                                       True))
    # try to break uniqueness constraint
    ensure_failing(
        db.add_tablerecord,
        ldb.TR_db_meta(id=None, kind="hello8", name='123', value='111'))

    # add two expruns
    def create_exprun(i):
        exprun = db.add_tablerecord(
            ldb.TR_exp_runs(id=None, name=f"2021-01-14_20-38-05_069_{i}"))
        return exprun

    exprun_1 = create_exprun(1)
    exprun_2 = create_exprun(2)
    # not the same name twice
    ensure_failing(db.add_tablerecord, exprun_2._replace(id=None))

    # add two holbaruns
    def create_holbarun(i):
        progs_list = db.add_tablerecord(
            ldb.get_empty_TableRecord("exp_progs_lists")._replace(
                name=f"holbarun_{i}"))
        exps_list = db.add_tablerecord(
            ldb.get_empty_TableRecord("exp_exps_lists")._replace(
                name=f"holbarun_{i}"))
        holbarun = db.add_tablerecord(
            ldb.TR_holba_runs(id=None,
                              name=f"time {i}",
                              exp_progs_lists_id=progs_list.id,
                              exp_exps_lists_id=exps_list.id))
        return holbarun

    holbarun_1 = create_holbarun(1)
    holbarun_2 = create_holbarun(2)
    # try to break foreign key constraint
    ensure_failing(
        db.add_tablerecord,
        ldb.TR_holba_runs(
            id=None,
            name="some new string",
            exp_progs_lists_id=holbarun_1.exp_progs_lists_id + 10000,
            exp_exps_lists_id=holbarun_1.exp_exps_lists_id + 20000))

    # add two progs for each run
    def add_prog(i, holbarun):
        prog = db.add_tablerecord(
            ldb.get_empty_TableRecord("exp_progs")._replace(
                arch="arch5000", code=f"crazy code {i}"))
        db.add_tablerecord(
            ldb.TR_exp_progs_lists_entries(
                exp_progs_lists_id=holbarun.exp_progs_lists_id,
                exp_progs_id=prog.id,
                list_index=i))
        return prog

    prog_11 = add_prog(11, holbarun_1)
    prog_12 = add_prog(12, holbarun_1)
    prog_21 = add_prog(21, holbarun_2)
    prog_22 = add_prog(22, holbarun_2)
    # should not be able to add entry without index
    ensure_failing(
        db.add_tablerecord,
        ldb.TR_exp_progs_lists_entries(
            exp_progs_lists_id=holbarun_1.exp_progs_lists_id,
            exp_progs_id=prog_22.id,
            list_index=None))
    # add one program in the list of the other run, this should work
    db.add_tablerecord(
        ldb.TR_exp_progs_lists_entries(
            exp_progs_lists_id=holbarun_1.exp_progs_lists_id,
            exp_progs_id=prog_22.id,
            list_index=1))

    # add a few experiments, two per program
    def add_exp(i, prog, holbarun):
        exp = db.add_tablerecord(
            ldb.TR_exp_exps(
                id=None,
                exp_progs_id=prog.id,
                type="exps2",
                params="amazing_model",
                input_data=
                f'{{"input_1":{{}},"input_2":{{}},"input_train":{{}},"extra":"crazy inputs {i}"}}'
            ))
        db.add_tablerecord(
            ldb.TR_exp_exps_lists_entries(
                exp_exps_lists_id=holbarun.exp_exps_lists_id,
                exp_exps_id=exp.id,
                list_index=i))
        return exp

    exp_111 = add_exp(111, prog_11, holbarun_1)
    exp_112 = add_exp(112, prog_11, holbarun_1)
    exp_121 = add_exp(121, prog_12, holbarun_1)
    exp_122 = add_exp(122, prog_12, holbarun_1)
    exp_211 = add_exp(211, prog_21, holbarun_2)
    exp_212 = add_exp(212, prog_21, holbarun_2)
    exp_221 = add_exp(221, prog_22, holbarun_2)
    exp_222 = add_exp(222, prog_22, holbarun_2)

    # print state of database
    print("=" * 40)
    print(db.to_string(True))

    exp1 = ldb.QE_Bin(op=ldb.QE_Bop.LIKE,
                      arg1=ldb.QE_Ref(index=0, field="code"),
                      arg2=ldb.QE_Const(value="crazy%"))
    res1 = db.get_tablerecords("exp_progs", [],
                               exp1,
                               order_by=[(0, "id", False)],
                               count_only=False)
    res1_cnt = db.get_tablerecords("exp_progs", [],
                                   exp1,
                                   order_by=[(0, "id", False)],
                                   count_only=True,
                                   id_only=False)
    res1_cnt2 = db.get_tablerecords("exp_progs", [],
                                    exp1,
                                    order_by=[(0, "id", False)],
                                    count_only=True,
                                    id_only=True)
    res1_alt = db.get_tablerecords("exp_progs", [],
                                   exp1,
                                   order_by=[(0, "id", False)],
                                   count_only=False,
                                   id_only=True)
    res1_expect = [prog_22, prog_21, prog_12, prog_11]
    res1_expect_id = list(
        map(lambda x: ldb.TR_id_only._make([x.id]), res1_expect))
    assert (res1 == res1_expect)
    assert (res1_cnt == len(res1_expect))
    assert (res1_cnt2 == res1_cnt)
    assert (res1_alt == res1_expect_id)

    exp2 = ldb.QE_Bin(op=ldb.QE_Bop.EQ,
                      arg1=ldb.QE_Ref(index=0, field="code"),
                      arg2=ldb.QE_Const(value="crazy code 11"))
    res2 = db.get_tablerecords("exp_progs", [],
                               exp2,
                               order_by=[(0, "id", False)],
                               count_only=False)
    res2_expect = [prog_11]
    assert (res2 == res2_expect)

    exp3 = ldb.QE_Bin(
        op=ldb.QE_Bop.IN,
        arg1=ldb.QE_Ref(index=0, field="code"),
        arg2=ldb.QE_Const(value=["crazy code 11", "crazy code 21"]))
    res3 = db.get_tablerecords("exp_progs", [],
                               exp3,
                               order_by=[(0, "id", True), (0, "code", True)],
                               count_only=False)
    res3_alt = db.get_tablerecords("exp_progs", [],
                                   exp3,
                                   order_by=[],
                                   count_only=False)
    res3_expect = [prog_11, prog_21]
    assert (res3 == res3_expect)
    assert (res3_alt == res3_expect)

    # add tests for interesting joins and queries with AND, OR and NOT
    exp10 = ldb.QE_Bin(op=ldb.QE_Bop.EQ,
                       arg1=ldb.QE_Ref(index=2, field="name"),
                       arg2=ldb.QE_Const(value="holbarun_1"))
    res10 = db.get_tablerecords("exp_progs", [("exp_progs_lists_entries", 0),
                                              ("exp_progs_lists", 1)], exp10)
    res10_expect = [prog_11, prog_12, prog_22]
    assert (res10 == res10_expect)

    exp11 = ldb.QE_Bin(op=ldb.QE_Bop.EQ,
                       arg1=ldb.QE_Ref(index=2, field="name"),
                       arg2=ldb.QE_Const(value="holbarun_2"))
    res11 = db.get_tablerecords("exp_progs", [("exp_progs_lists_entries", 0),
                                              ("exp_progs_lists", 1)], exp11)
    res11_expect = [prog_21, prog_22]
    assert (res11 == res11_expect)

    exp12 = ldb.QE_Bin(op=ldb.QE_Bop.OR, arg1=exp10, arg2=exp11)
    res12 = db.get_tablerecords("exp_progs", [("exp_progs_lists_entries", 0),
                                              ("exp_progs_lists", 1)], exp12)
    res12_expect = [prog_11, prog_12, prog_22, prog_21]
    assert (res12 == res12_expect)

    exp13 = ldb.QE_Not(arg=exp10)
    res13 = db.get_tablerecords("exp_progs", [("exp_progs_lists_entries", 0),
                                              ("exp_progs_lists", 1)], exp13)
    res13_expect = res11_expect
    assert (res13 == res13_expect)

    exp14_p1 = exp10
    exp14_p2 = ldb.QE_Bin(ldb.QE_Bop.EQ, ldb.QE_Ref(4, "name"),
                          ldb.QE_Const("holbarun_2"))
    exp14 = ldb.QE_Bin(ldb.QE_Bop.AND, exp14_p1, exp14_p2)
    res14 = db.get_tablerecords("exp_progs", [("exp_progs_lists_entries", 0),
                                              ("exp_progs_lists", 1),
                                              ("exp_progs_lists_entries", 0),
                                              ("exp_progs_lists", 3)], exp14)
    res14_expect = [prog_22]
    assert (res14 == res14_expect)

    meta0_1 = ldb.TR_holba_runs_meta(holba_runs_id=holbarun_1.id,
                                     kind="test1",
                                     name="property1",
                                     value="some initial value\n")
    meta0_2 = ldb.TR_holba_runs_meta(holba_runs_id=holbarun_1.id,
                                     kind="test1",
                                     name="property1",
                                     value="some new value\n")
    # try to append to non-existing metadata (should not work)
    ensure_failing(db.append_tablerecord_meta, meta0_2)
    # then add and append successfully
    meta1_1 = db.add_tablerecord(meta0_1)
    meta1_2 = db.append_tablerecord_meta(meta0_2)
    meta1_2 = db.append_tablerecord_meta(meta0_1)
    meta1_expect = ldb.TR_holba_runs_meta(
        holba_runs_id=holbarun_1.id,
        kind="test1",
        name="property1",
        value="some initial value\nsome new value\nsome initial value\n")
    assert (meta1_2 == meta1_expect)

    # add some metadata to a program and an experiment
    meta2 = ldb.TR_exp_progs_meta(exp_progs_id=prog_12.id,
                                  kind="test2",
                                  name="property2",
                                  value="prog_12 special data\n")
    meta2_1 = db.add_tablerecord(meta2)
    assert (meta2 == meta2_1)
    meta3 = ldb.TR_exp_exps_meta(exp_exps_id=exp_122.id,
                                 kind="test3",
                                 name="property3",
                                 value="exp_122 special data\n")
    meta3_1 = db.add_tablerecord(meta3)
    assert (meta3 == meta3_1)

    # add a fake experiment run to play with
    meta_exp_run_name = "run.a4bc8ffc998095be7293fdea7a90f07faa257b40.rpi3." + exprun_1.name
    meta_exp_run_out = ldb.TR_exp_exps_meta(
        exp_exps_id=exp_122.id,
        kind="output_uart",
        name=meta_exp_run_name,
        value="Init complete.\nRESULT: EQUAL\nExperiment complete.\n")
    meta_exp_run_res = ldb.TR_exp_exps_meta(exp_exps_id=exp_122.id,
                                            kind="result",
                                            name=meta_exp_run_name,
                                            value="true")
    db.add_tablerecord(meta_exp_run_out)
    db.add_tablerecord(meta_exp_run_res)

    # print state of database
    print("=" * 40)
    print(db.to_string(True))
Ejemplo n.º 20
0
 def _get_all(db):
     records = db.get_tablerecord_matches(
         ldb.get_empty_TableRecord(f"exp_exps"))
     return list(map(lambda x: Experiment(db, x), records))
Ejemplo n.º 21
0
 def get_metadata(self):
     if self.metadata == None:
         self.metadata = self.db.get_tablerecord_matches(
             ldb.get_empty_TableRecord("exp_exps_meta")._replace(
                 exp_exps_id=self.get_exp_id()))
     return self.metadata
Ejemplo n.º 22
0
input100 = copy.deepcopy(input1)
input100["match_existing"] = True
input100_ret = run_db_interface_py("create", input100)
assert (input100_ret == input1_expect)

# the same should fail if we alter the description, but due to name uniqueness again
print(("-" * 20) + "> input101")
input101 = copy.deepcopy(input100)
input101["values"]["description"] = "some fancy description"
input101_ret = run_db_interface_py(
    "create", input101, "UNIQUE constraint failed: exp_progs_lists.name")
assert (input101_ret == ret_failure)

# test read-only mode
# ======================================================================================================================
tr_readonlytest = ldb.get_empty_TableRecord("exp_progs")._replace(
    arch="newarch", code="newcode")

with ldb.LogsDB(db_file, read_only=True) as db:
    ensure_failing(db.add_tablerecord, tr_readonlytest)

with ldb.LogsDB(db_file) as db:
    tr_readonlytest_res = db.add_tablerecord(tr_readonlytest)

with ldb.LogsDB(db_file, read_only=True) as db:
    tr_q = ldb.get_empty_TableRecord("exp_progs")._replace(
        id=tr_readonlytest_res.id)
    tr_readonlytest_res2 = db.get_tablerecord_matches(tr_q)[0]
    assert (tr_readonlytest_res2 == tr_readonlytest_res)
    ensure_failing(db.add_tablerecord,
                   tr_readonlytest._replace(arch="latestarch"))