-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from soukaryag/master
Interactive feature addition, big fixes, code abstraction and seperation
- Loading branch information
Showing
8 changed files
with
255 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
__pycache__/ | ||
venv/ | ||
/.vscode | ||
results.p |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: sh setup.sh && streamlit run app.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Args(): | ||
def __init__(self, model, recipe, model_batch_size=32, query_budget=200, model_cache_size=2**18, constraint_cache_size=2**18): | ||
self.model = model | ||
self.recipe = recipe | ||
self.model_batch_size = model_batch_size | ||
self.model_cache_size = model_cache_size | ||
self.query_budget = query_budget | ||
self.constraint_cache_size = constraint_cache_size | ||
|
||
def __getattr__(self, item): | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import pickle | ||
|
||
from config import PRECOMPUTED_RESULTS_DICT_NAME, HISTORY | ||
|
||
class Cache(): | ||
def __init__(self, log=False): | ||
self.log = log | ||
self.cache = self.load_precomputed_results() | ||
|
||
def load_precomputed_results(self): | ||
try: | ||
precomputed_results = pickle.load(open(PRECOMPUTED_RESULTS_DICT_NAME, "rb")) | ||
except FileNotFoundError: | ||
precomputed_results = {} | ||
if self.log: print(f'Found {len(precomputed_results)} keys in pre-computed results.') | ||
return precomputed_results | ||
|
||
def add(self, key, data): | ||
self.cache = self.load_precomputed_results() | ||
self.cache[key] = data | ||
|
||
# update history | ||
if isinstance(data, list): | ||
self.cache[HISTORY] = data + self.cache.get(HISTORY, []) | ||
else: | ||
self.cache[HISTORY] = [data] + self.cache.get(HISTORY, []) | ||
|
||
pickle.dump(self.cache, open(PRECOMPUTED_RESULTS_DICT_NAME, 'wb')) | ||
if self.log: print(f'Successfully added {key} to the cache') | ||
|
||
def to_top(self, key): | ||
self.cache = self.load_precomputed_results() | ||
data, history = self.cache.get(key, None), self.cache.get(HISTORY, None) | ||
if not data or not history: | ||
return [] | ||
|
||
if isinstance(data, list): | ||
for d in data: | ||
history.pop(history.index(d)) | ||
history.insert(0, d) | ||
else: | ||
history.pop(history.index(data)) | ||
history.insert(0, data) | ||
|
||
def exists(self, key): | ||
self.cache = self.load_precomputed_results() | ||
return key in self.cache | ||
|
||
def purge(self, key=None): | ||
self.cache = self.load_precomputed_results() | ||
if not key: | ||
self.cache.clear() | ||
elif key in self.cache: | ||
del self.cache[key] | ||
if self.log: print(f'Cache successfully purged') | ||
pickle.dump(self.cache, open(PRECOMPUTED_RESULTS_DICT_NAME, 'wb')) | ||
|
||
def get(self, key): | ||
self.cache = self.load_precomputed_results() | ||
return self.cache.get(key, []) |
Oops, something went wrong.