mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-08-06 19:47:44 +00:00
Implement model (and some factor) coder with evolving (#52)
* store code into FBImplementation * fix path related bugs * fix a bug * fix factor related small bugs * re-submit all model related code * new code to model coder * finish the model evolving code --------- Co-authored-by: xuyang1 <xuyang1@microsoft.com>
This commit is contained in:
+15
-21
@@ -1,6 +1,6 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from pathlib import Path
|
||||
from typing import Generic, Optional, Sequence, TypeVar
|
||||
from typing import Any, Dict, Generic, Optional, Sequence, TypeVar
|
||||
|
||||
"""
|
||||
This file contains the all the class about organizing the task in RD-Agent.
|
||||
@@ -22,25 +22,9 @@ class Implementation(ABC, Generic[ASpecificTask]):
|
||||
self.target_task = target_task
|
||||
|
||||
@abstractmethod
|
||||
def execute(self, data=None, config: dict = {}) -> object:
|
||||
"""
|
||||
The execution of the implementation can be dynamic.
|
||||
|
||||
So we may pass in the data and config dynamically.
|
||||
"""
|
||||
def execute(self, *args, **kwargs) -> object:
|
||||
raise NotImplementedError("execute method is not implemented.")
|
||||
|
||||
@abstractmethod
|
||||
def execute_desc(self):
|
||||
"""
|
||||
return the description how we will execute the code in the folder.
|
||||
"""
|
||||
raise NotImplementedError(f"This type of input is not supported")
|
||||
|
||||
# TODO:
|
||||
# After execution, it should return some results.
|
||||
# Some evaluators will input the results and output
|
||||
|
||||
|
||||
ASpecificImp = TypeVar("ASpecificImp", bound=Implementation)
|
||||
|
||||
@@ -78,8 +62,17 @@ class FBImplementation(Implementation):
|
||||
# Why not directly reuse FileBasedFactorImplementation.
|
||||
# Because it has too much concrete dependencies.
|
||||
# e.g. dataframe, factors
|
||||
def __init__(self, *args, code_dict: Dict[str, str] = None, **kwargs) -> None:
|
||||
super().__init__(*args, **kwargs)
|
||||
self.code_dict = code_dict # The code to be injected into the folder, store them in the variable
|
||||
self.workspace_path: Optional[Path] = None
|
||||
|
||||
path: Optional[Path]
|
||||
@property
|
||||
def code(self) -> str:
|
||||
code_string = ""
|
||||
for file_name, code in self.code_dict.items():
|
||||
code_string += f"File: {file_name}\n{code}\n"
|
||||
return code_string
|
||||
|
||||
@abstractmethod
|
||||
def prepare(self, *args, **kwargs):
|
||||
@@ -100,8 +93,9 @@ class FBImplementation(Implementation):
|
||||
"model.py": "<model code>"
|
||||
}
|
||||
"""
|
||||
self.code_dict = files
|
||||
for k, v in files.items():
|
||||
with open(self.path / k, "w") as f:
|
||||
with open(self.workspace_path / k, "w") as f:
|
||||
f.write(v)
|
||||
|
||||
def get_files(self) -> list[Path]:
|
||||
@@ -111,7 +105,7 @@ class FBImplementation(Implementation):
|
||||
To be general, we only return a list of filenames.
|
||||
How to summarize the environment is the responsibility of the TaskGenerator.
|
||||
"""
|
||||
return list(self.path.iterdir())
|
||||
return list(self.workspace_path.iterdir())
|
||||
|
||||
|
||||
class Experiment(ABC, Generic[ASpecificTask, ASpecificImp]):
|
||||
|
||||
Reference in New Issue
Block a user