Skip to content

Commit 4f67dc7

Browse files
committed
endpoint partially working for now
1 parent efce967 commit 4f67dc7

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

bridger/logging_utils/cache_entry_database.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def get_top_n_by_sort_key(self, sort_key: "SortKey", n: int):
4949
print(f"Getting top {n} entries by {sort_key.key}")
5050
start_time = time.time()
5151
try:
52-
sorted_entries = self.sort_by_key(sort_key)
52+
sorted_entries = self.sort_by_key(sort_key())
5353
result = sorted_entries[:n]
5454
end_time = time.time()
5555
print(f"Retrieved top {n} entries in {end_time - start_time:.2f} seconds")

tools/web/sibyl.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,37 +76,40 @@ def _get_experiment_names() -> list[str]:
7676
]
7777

7878

79-
@app.route("/n_fewest_steps_since_led_to_something_new_go_explore", methods=["GET"])
80-
def n_fewest_steps_since_led_to_something_new_go_explore_plot_data():
79+
@app.route("/go_explore", methods=["GET"])
80+
def go_explore_plot_data():
8181
"""
8282
Provides plot data for the n states that have most recently seen a new cell.
8383
"""
8484
n = _get_int_or_default("n", 10)
85-
_CACHE_ENTRY_DATABASE = list(
85+
_OCCURRENCE_LOG_ENTRIES = list(
8686
read_object_log(os.path.join(_LOG_DIR, "go_explore", "state_cache-6.pkl"))
8787
)
88-
print(_CACHE_ENTRY_DATABASE)
88+
89+
caches = [cache.object._cache.values() for cache in _OCCURRENCE_LOG_ENTRIES]
90+
cache_entries = [cache_entry for cache in caches for cache_entry in cache]
91+
_CACHE_ENTRY_DATABASE = CacheEntryDatabase(cache_entries)
8992

9093
return {
9194
"states": [
92-
cache_entry.object.state
95+
cache_entry.state_representative
9396
for cache_entry in _CACHE_ENTRY_DATABASE.cache_entries
9497
],
95-
# "trajectory_length": _CACHE_ENTRY_DATABASE.get_top_n_by_sort_key(
96-
# TrajectorySortKey, n
97-
# ),
98-
# "steps_since_led_to_something_new": _CACHE_ENTRY_DATABASE.get_top_n_by_sort_key(
99-
# StepsSinceLedToSomethingNewSortKey, n
100-
# ),
101-
# "steps_since_led_to_something_new_reset_count": _CACHE_ENTRY_DATABASE.get_top_n_by_sort_key(
102-
# StepsSinceLedToSomethingNewResetCountSortKey, n
103-
# ),
104-
# "sample_count": _CACHE_ENTRY_DATABASE.get_top_n_by_sort_key(
105-
# SampleCountSortKey, n
106-
# ),
107-
# "visit_count": _CACHE_ENTRY_DATABASE.get_top_n_by_sort_key(
108-
# VisitCountSortKey, n
109-
# ),
98+
"trajectory_length": _CACHE_ENTRY_DATABASE.get_top_n_by_sort_key(
99+
TrajectorySortKey(), n
100+
),
101+
"steps_since_led_to_something_new": _CACHE_ENTRY_DATABASE.get_top_n_by_sort_key(
102+
StepsSinceLedToSomethingNewSortKey(), n
103+
),
104+
"steps_since_led_to_something_new_reset_count": _CACHE_ENTRY_DATABASE.get_top_n_by_sort_key(
105+
StepsSinceLedToSomethingNewResetCountSortKey(), n
106+
),
107+
"sample_count": _CACHE_ENTRY_DATABASE.get_top_n_by_sort_key(
108+
SampleCountSortKey(), n
109+
),
110+
"visit_count": _CACHE_ENTRY_DATABASE.get_top_n_by_sort_key(
111+
VisitCountSortKey(), n
112+
),
110113
}
111114

112115

0 commit comments

Comments
 (0)