Skip to content

Commit

Permalink
Remove SQLite logging and loading.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 550190579
Change-Id: I5d4c3d05f19702b9f68d1087b88b30201e8cde36
  • Loading branch information
yotam authored and Copybara-Service committed Jul 22, 2023
1 parent 9870364 commit 77b4652
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 477 deletions.
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,14 @@ sweep.TAGS['scale']

### Loading an environment with logging included

We include two implementations of automatic logging, available via:

* [`bsuite.load_and_record_to_csv`]. This outputs one CSV file per
`bsuite_id`, so is suitable for running a set of bsuite experiments split
over multiple machines. The implementation is in [`logging/csv_logging.py`]
* [`bsuite.load_and_record_to_sqlite`]. This outputs a single file, and is
best suited when running a set of bsuite experiments via multiple processes
on a single workstation. The implementation is in
[`logging/sqlite_logging.py`].
We include one implementation of automatic logging, available via:

[`bsuite.load_and_record_to_csv`]. This outputs one CSV file per `bsuite_id`,
so is suitable for running a set of bsuite experiments split over multiple
machines. The implementation is in [`logging/csv_logging.py`]

Note, older versions of bsuite included an SQLite logger. If you would like to
use this, please contact us and we can update and reinstate it.

We also include a terminal logger in [`logging/terminal_logging.py`], exposed
via `bsuite.load_and_record_to_terminal`.
Expand Down
52 changes: 2 additions & 50 deletions bsuite/bsuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
from bsuite.experiments.umbrella_length import umbrella_length

from bsuite.logging import csv_logging
from bsuite.logging import sqlite_logging
from bsuite.logging import terminal_logging

import dm_env
Expand Down Expand Up @@ -113,61 +112,14 @@ def load_and_record(bsuite_id: str,
save_path: str,
logging_mode: str = 'csv',
overwrite: bool = False) -> dm_env.Environment:
"""Returns a bsuite environment wrapped with either CSV or SQLite logging."""
"""Returns a bsuite environment wrapped with CSV or terminal logging."""
if logging_mode == 'csv':
return load_and_record_to_csv(bsuite_id, save_path, overwrite)
elif logging_mode == 'sqlite':
if not save_path.endswith('.db'):
save_path += '.db'
if overwrite:
print('WARNING: overwrite option is ignored for SQLite logging.')
return load_and_record_to_sqlite(bsuite_id, save_path)
elif logging_mode == 'terminal':
return load_and_record_to_terminal(bsuite_id)
else:
raise ValueError((f'Unrecognised logging_mode "{logging_mode}". '
'Must be "csv", "sqlite", or "terminal".'))


def load_and_record_to_sqlite(bsuite_id: str,
db_path: str) -> dm_env.Environment:
"""Returns a bsuite environment that saves results to an SQLite database.
The returned environment will automatically save the results required for
the analysis notebook when stepping through the environment.
To load the results, specify the file path in the provided notebook, or to
manually inspect the results use:
```python
from bsuite.logging import sqlite_load
results_df, sweep_vars = sqlite_load.load_bsuite('/path/to/database.db')
```
Args:
bsuite_id: The bsuite id identifying the environment to return. For example,
"catch/0" or "deep_sea/3".
db_path: Path to the database file for this set of results. The file will be
created if it does not already exist. When generating results using
multiple different processes, specify the *same* db_path for every
bsuite_id.
Returns:
A bsuite environment determined by the bsuite_id.
"""
raw_env = load_from_id(bsuite_id)
experiment_name, setting_index = unpack_bsuite_id(bsuite_id)
termcolor.cprint(
f'Logging results to SQLite database in {db_path}.',
color='yellow',
attrs=['bold'])
return sqlite_logging.wrap_environment(
env=raw_env,
db_path=db_path,
experiment_name=experiment_name,
setting_index=setting_index,
)
'Must be "csv" or "terminal".'))


def load_and_record_to_csv(bsuite_id: str,
Expand Down
66 changes: 0 additions & 66 deletions bsuite/logging/sqlite_load.py

This file was deleted.

75 changes: 0 additions & 75 deletions bsuite/logging/sqlite_load_test.py

This file was deleted.

155 changes: 0 additions & 155 deletions bsuite/logging/sqlite_logging.py

This file was deleted.

0 comments on commit 77b4652

Please sign in to comment.