probcomp / bdbcontrib

BayesDB contributions, including plotting, helper methods, and examples
http://probcomp.csail.mit.edu/bayesdb
Apache License 2.0
9 stars 6 forks source link

Feature request / search: Rename bdb file after analysis #130

Open leocasarsa opened 8 years ago

leocasarsa commented 8 years ago

The autosave system of bdb files makes it hard to track in which state the bdb file currently is.

Granted, one could do this by initializing a population and calling pop.analysis_status(), for instance, but this is not quick to do if someone works on multiple bdb files. Being able to copy and rename the bdb file after making the population - or maybe after each crucial inference step to avoid losing previous costly inference steps- would come in handy.

riastradh-probcomp commented 8 years ago
echo .backup foo-42.bdb | sqlite3 ./foo.bdb

https://github.com/probcomp/bayeslite/issues/316

riastradh-probcomp commented 8 years ago

Also, if you want to do something hypothetically, without permanently modifying the database, you can do it inside a transaction:

bdb.execute('BEGIN')
# Mess around -- interactively, if you like.
bdb.execute('...')
# File will not be modified until:
bdb.execute('COMMIT')

Or a savepoint, which is nicer for the Python API and nests, unlike transactions:

with bdb.savepoint():
    bdb.execute('...')
    # not saved yet 
print 'ok'
# saved once you see 'ok'

If you don't like your hypothetical changes, you can roll back out of a transaction, or raise an exception to abort a savepoint:

bdb.execute('BEGIN')
...
bdb.execute('ROLLBACK')

try:
    with bdb.savepoint():
        ...
        if not ok:
            raise NotOKException
except NotOKException:
    pass
leocasarsa commented 8 years ago

Nice! We should either make this more visible or make it standard to be inside a transaction.

riastradh-probcomp commented 8 years ago

http://probcomp.csail.mit.edu/bayesdb/doc/bql.html#transactions http://probcomp.csail.mit.edu/bayesdb/doc/api.html#bayeslite.BayesDB.savepoint

The docstring for BayesDB.savepoint() is a little terse. I will expand with a short example.