mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-07-28 07:57:44 +00:00
e0a24fb46f
* ignore result csv file * fix app scripts * rename taskgenerator to developer and generate to develop * fix a config bug in coder * fix a small bug in factor coder evaluators * remove a single logger in factor coder evaluators * fix a small bug in model coder main.py * rename Implementation to Workspace * move the prepare the inject_code into FBWorkspace to align all the behavior * fix a small bug in model feedback * remove debug lines for multi processing and simplify evaluators multi proc * add a copy function to workspace to freeze the workspace && add config prefix to speed up debugging * make hypothesisgen a abc class * use Qlib***Experiment * fix a small bug * rename Imp to Ws * rename sub_implementations to sub_workspace_list * fix a bug in feedback not presented as content in prompts * move proposal pys to proposal folder * reformat the folder * align factor and model qlib workspace and use template to handle the workspace * add a filter to evoagent to filter out false evo * align multi_proc_n into RDAGENT seeting * handle when runner gets empty experiment * fix logger merge remaining problems * fix black and isort automatically
57 lines
1.6 KiB
Python
57 lines
1.6 KiB
Python
import json
|
|
import pickle
|
|
from datetime import datetime, timezone
|
|
from pathlib import Path
|
|
from typing import Literal
|
|
|
|
from .base import Storage
|
|
|
|
|
|
class FileStorage(Storage):
|
|
"""
|
|
The info are logginged to the file systems
|
|
|
|
TODO: describe the storage format
|
|
"""
|
|
|
|
def __init__(self, path: str = "./log/") -> None:
|
|
self.path = Path(path)
|
|
self.path.mkdir(parents=True, exist_ok=True)
|
|
|
|
def log(
|
|
self,
|
|
obj: object,
|
|
name: str = "",
|
|
save_type: Literal["json", "text", "pkl"] = "text",
|
|
timestamp: datetime | None = None,
|
|
) -> Path:
|
|
# TODO: We can remove the timestamp after we implement PipeLog
|
|
if timestamp is None:
|
|
timestamp = datetime.now(timezone.utc)
|
|
else:
|
|
timestamp = timestamp.astimezone(timezone.utc)
|
|
|
|
cur_p = self.path / name.replace(".", "/")
|
|
cur_p.mkdir(parents=True, exist_ok=True)
|
|
|
|
path = cur_p / f"{timestamp.strftime('%Y-%m-%d_%H-%M-%S-%f')}.log"
|
|
|
|
if save_type == "json":
|
|
path = path.with_suffix(".json")
|
|
with path.open("w") as f:
|
|
try:
|
|
json.dump(obj, f)
|
|
except TypeError:
|
|
json.dump(json.loads(str(obj)), f)
|
|
return path
|
|
elif save_type == "pkl":
|
|
path = path.with_suffix(".pkl")
|
|
with path.open("wb") as f:
|
|
pickle.dump(obj, f)
|
|
return path
|
|
elif save_type == "text":
|
|
obj = str(obj)
|
|
with path.open("w") as f:
|
|
f.write(obj)
|
|
return path
|