uv.sql package

Submodules

uv.sql.reporter module

Reporter implementation that relies on SQLAlchemy.

Uses this as inspiration: https://source.cloud.google.com/research-3141/tf2-jax-notebooks/+/master:experiment_manager.py

class uv.sql.reporter.Experiment(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

Stores general metadata, about the experiment, and provides a key that links together all of the metrics.

You would create one of these when you create a reporter.

id
params
class uv.sql.reporter.Metric(**kwargs)[source]

Bases: sqlalchemy.ext.declarative.api.Base

An individual metric that we’ll report to the table.

experiment_id
id
run_id
step
tag
value
class uv.sql.reporter.SQLReader(e: Union[sqlalchemy.engine.base.Engine, sqlalchemy.orm.session.sessionmaker], experiment: uv.sql.reporter.Experiment, run_id: int, step_key: Optional[str] = None)[source]

Bases: uv.reader.base.AbstractReader, uv.reader.base.IterableReader

AbstractReader implementation backed by a sqlite store.

keys() → Iterable[Any][source]

Returns a list of all keys in the DB for this particular experiment and run.

read(k: str) → List[Any][source]

Returns a list of all metrics ever logged for the supplied t.MetricKey, or an empty list if the backing store has no record.

read_all(ks: List[str]) → Dict[str, List[Any]][source]

Accepts a list of t.MetricKey instances and returns a mapping of t.MetricKey to a list of all metrics ever logged using that MetricKey.

The interface requires that the set of keys in the returned dictionary equal the input set; any missing key in the store has to map to a default empty list.

class uv.sql.reporter.SQLReporter(e: Union[sqlalchemy.engine.base.Engine, sqlalchemy.orm.session.sessionmaker], experiment: uv.sql.reporter.Experiment, run_id: int)[source]

Bases: uv.reporter.base.AbstractReporter

SQLite-backed reporter. This currently only does the things that you’d expect a reporter to be able to do; we don’t yet support actual experiment creation, but that’s coming.

reader()uv.reader.base.AbstractReader[source]

Returns an implementation of AbstractReader that can access the data in this store.

Returns None by default; extending classes are encouraged, but not required, to override.

report_all(step: int, m: Dict[str, Any])None[source]

Accepts a step (an ordered int referencing some timestep) and a dictionary of metric key => metric value, and persists the metric into some underlying store.

Extending classes are expected to perform some side effect that’s either visually useful, as in a live-plot, or recoverable via some matching extension of AbstractReader.

uv.sql.reporter.create_tables(engine: sqlalchemy.engine.base.Engine)[source]

This triggers table creation for the classes defined at the top. Run this to get your local DB ready before you write any metrics.

uv.sql.reporter.new_experiment(e: Union[sqlalchemy.engine.base.Engine, sqlalchemy.orm.session.sessionmaker], config: Dict[str, Any])uv.sql.reporter.Experiment[source]

Generates a new experiment.

uv.sql.util module

Utility functions used by the SQL reporter and reader.

uv.sql.util.rep_string(instance)[source]

Returns a pretty string representation for sqlalchemy classes.

uv.sql.util.session_maker(e: Union[sqlalchemy.engine.base.Engine, sqlalchemy.orm.session.sessionmaker]) → sqlalchemy.orm.session.sessionmaker[source]

Returns a session maker from the specified Engine, or acts as identity if e is already a sessionmaker.

uv.sql.util.sqlite_engine(location: str, verbose=False) → sqlalchemy.engine.base.Engine[source]

Currently this just creates a local sqlalchemy engine in a local file.

uv.sql.util.sqlite_file_exists(arg: Union[sqlalchemy.engine.base.Engine, sqlalchemy.engine.url.URL])bool[source]

Taken from sqlalchemy-utils. We can import that library once we move to potentially many databases, since it seems useful to NOT re-implement the world once we release this thing, and folks can make their own DBs.

https://sqlalchemy-utils.readthedocs.io/en/latest/_modules/sqlalchemy_utils/functions/database.html#database_exists

Module contents