Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Fix LTune utility functions #28

Merged
merged 1 commit into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions endure/ltune/util/ltune_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from endure.lcm.util import eval_lcm_impl
from endure.lsm.cost import EndureCost
from endure.lsm.types import LSMBounds, LSMDesign, System, Policy, STR_POLICY_DICT
from endure.lsm.types import LSMBounds, LSMDesign, System, Policy
from endure.ltune.data.generator import LTuneDataGenerator
from endure.ltune.loss import LearnedCostModelLoss
import endure.lsm.solver as Solver
Expand All @@ -17,9 +17,8 @@ def __init__(
self,
config: dict[str, Any],
model: torch.nn.Module,
design_type: str = "Level",
design_type: Policy,
) -> None:
self.policy = STR_POLICY_DICT.get(design_type, Policy.KHybrid)
self.bounds = LSMBounds()
self.gen = LTuneDataGenerator(self.bounds)
self.loss = LearnedCostModelLoss(
Expand Down Expand Up @@ -93,14 +92,14 @@ def get_solver_nominal_design(
w: float,
**kwargs,
) -> Tuple[LSMDesign, SciOpt.OptimizeResult]:
if self.design_type == "QLSM":
solver = Solver.QLSMSolver(self.config)
elif self.design_type == "KLSM":
solver = Solver.KLSMSolver(self.config)
elif self.design_type == "YZLSM":
solver = Solver.YZLSMSolver(self.config)
else: # design_type == "Classic"
solver = Solver.ClassicSolver(self.config)
if self.design_type == Policy.QFixed:
solver = Solver.QLSMSolver(self.bounds)
elif self.design_type == Policy.KHybrid:
solver = Solver.KLSMSolver(self.bounds)
elif self.design_type == Policy.YZHybrid:
solver = Solver.YZLSMSolver(self.bounds)
else: # design_type == Policy.Classic
solver = Solver.ClassicSolver(self.bounds)

design, sol = solver.get_nominal_design(
system,
Expand All @@ -114,11 +113,11 @@ def get_solver_nominal_design(
return design, sol

def convert_ltune_output(self, output: Tensor):
if self.design_type == "QLSM":
if self.design_type == Policy.QFixed:
design = self._qlsm_convert(output)
elif self.design_type == "KLSM":
elif self.design_type == Policy.KHybrid:
design = self._klsm_convert(output)
else:
else: # self.design_type == Policy.Classic
design = self._classic_convert(output)

return design
Expand Down
Loading