refactor: update dice handling and optimization flow to return structured results
This commit is contained in:
@@ -4,7 +4,7 @@ from diceplayer.dice.dice_input import (
|
||||
NVTEqConfig,
|
||||
NVTTerConfig,
|
||||
)
|
||||
from diceplayer.dice.dice_wrapper import DiceWrapper
|
||||
from diceplayer.dice.dice_wrapper import DiceWrapper, DiceEnvironment
|
||||
from diceplayer.logger import logger
|
||||
from diceplayer.state.state_model import StateModel
|
||||
|
||||
@@ -17,7 +17,7 @@ class DiceHandler:
|
||||
def __init__(self, step_directory: Path):
|
||||
self.dice_directory = step_directory / "dice"
|
||||
|
||||
def run(self, state: StateModel, cycle: int) -> StateModel:
|
||||
def run(self, state: StateModel, cycle: int) -> list[DiceEnvironment]:
|
||||
if self.dice_directory.exists():
|
||||
logger.info(
|
||||
f"Found dice directory: {self.dice_directory}, this directory will be purged for a clean state"
|
||||
@@ -25,13 +25,9 @@ class DiceHandler:
|
||||
shutil.rmtree(self.dice_directory)
|
||||
self.dice_directory.mkdir(parents=True)
|
||||
|
||||
simulation_results = self.run_simulations(state, cycle)
|
||||
return self.run_simulations(state, cycle)
|
||||
|
||||
result = self.aggregate_results(simulation_results)
|
||||
|
||||
return self.commit_simulation_state(state, result)
|
||||
|
||||
def run_simulations(self, state: StateModel, cycle: int) -> list[dict]:
|
||||
def run_simulations(self, state: StateModel, cycle: int) -> list[DiceEnvironment]:
|
||||
results = []
|
||||
|
||||
threads = []
|
||||
@@ -48,15 +44,12 @@ class DiceHandler:
|
||||
f"Expected {state.config.dice.nprocs} simulation results, but got {len(results)}"
|
||||
)
|
||||
|
||||
return results
|
||||
|
||||
def aggregate_results(self, simulation_results: list[dict]) -> dict: ...
|
||||
|
||||
def commit_simulation_state(self, state: StateModel, result: dict) -> StateModel:
|
||||
return state
|
||||
return [
|
||||
i for i in [r for r in results]
|
||||
]
|
||||
|
||||
def _simulation_process(
|
||||
self, state: StateModel, cycle: int, proc: int, results: list[dict]
|
||||
self, state: StateModel, cycle: int, proc: int, results: list[list[DiceEnvironment]]
|
||||
) -> None:
|
||||
proc_directory = self.dice_directory / f"{proc:02d}"
|
||||
if proc_directory.exists():
|
||||
|
||||
Reference in New Issue
Block a user