Support run one step for debugging (#99)

This commit is contained in:
you-n-g
2024-07-23 19:00:59 +08:00
committed by GitHub
parent 44169507b2
commit 40d108687c
2 changed files with 17 additions and 4 deletions
+3 -3
View File
@@ -67,20 +67,20 @@ class ModelLoop(LoopBase, metaclass=LoopMeta):
self.trace.hist.append((prev_out["propose"],prev_out["running"] , feedback))
def main(path=None):
def main(path=None, step_n=None):
"""
You can continue running session by
.. code-block:: python
dotenv run -- python rdagent/app/qlib_rd_loop/model_w_sc.py $LOG_PATH/__session__/1/0_propose
dotenv run -- python rdagent/app/qlib_rd_loop/model_w_sc.py $LOG_PATH/__session__/1/0_propose --step_n 1 # `step_n` is a optional paramter
"""
if path is None:
model_loop = ModelLoop()
else:
model_loop = ModelLoop.load(path)
model_loop.run()
model_loop.run(step_n=step_n)
if __name__ == "__main__":
+14 -1
View File
@@ -51,9 +51,22 @@ class LoopBase:
self.loop_trace = defaultdict(list[LoopTrace]) # the key is the number of loop
self.session_folder = logger.log_trace_path / "__session__"
def run(self):
def run(self, step_n: int | None = None):
"""
Parameters
----------
step_n : int | None
How many steps to run;
`None` indicates to run forever until error or KeyboardInterrupt
"""
with tqdm(total=len(self.steps), desc="Workflow Progress", unit="step") as pbar:
while True:
if step_n is not None:
if step_n <= 0:
break
step_n -= 1
li, si = self.loop_idx, self.step_idx
start = datetime.datetime.now(datetime.timezone.utc)