callat-qcd / lattedb

Lattice QCD database interface using EspressoDB as the content manager.
https://ithems.lbl.gov/lattedb
BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

Consistency checks (for Baryon2pt) #25

Closed ckoerber closed 4 years ago

ckoerber commented 4 years ago

General thought

It would be nice if every time we (massively) populate a table, we ensure that we implement a method which checks internal consistency.

For example, all propagators used are based on the same gauge config.

I would propose that each table / class has a method called

def check_consistency(self)

which raises specific errors if the instance is not consistent. If we have that, we can make the base class call this method before inserting in the database.

ToDo

As a first use case, it would be nice if we could write this method for the Baryon2pt class.

ckoerber commented 4 years ago

With commit bed3fac833b6ee870ee161abc4cd38f782cce205 of EspressoDB (which will be in version 1.0.0), the check_consistency method will be a class method. E.g., it has to be called like

@classmethod
def check_consistency(cls, data: Dict[str, Any]):
    assert data["column1"] >= some_number

We should aim for this behavior.

Footnote

You can also raise more verbose errors like

if data["column1"] < some_number:
    raise ValueError("column 1 value is too small...")

The new EspressoDB checking behavior will inform the user which class raises which error with which values. So there is no need to append data to the error.

ckoerber commented 4 years ago

Done with commit f58c5621f90162f364a9ad4a57601d358e381383 and previous.