From c3b46af4d9aba4cf380f0c85f30606fa6442bbc1 Mon Sep 17 00:00:00 2001 From: Chad Baker Date: Thu, 30 Jan 2025 17:06:15 -0700 Subject: [PATCH] fc range works --- cal_and_val/thermal/cal_hev.py | 7 ++----- python/fastsim/pymoo_api.py | 16 +++++++++++----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/cal_and_val/thermal/cal_hev.py b/cal_and_val/thermal/cal_hev.py index 24604fa6..f9ef001b 100644 --- a/cal_and_val/thermal/cal_hev.py +++ b/cal_and_val/thermal/cal_hev.py @@ -301,15 +301,12 @@ def get_exp_pwr_hvac(df): get_mod_pwr_hvac, get_exp_pwr_hvac ), - # TODO: add objectives for: - # - battery temperature -- BEV only, if available - # - HVAC power for cabin, if available ), param_fns=( new_em_eff_max, new_em_eff_range, new_fc_eff_max, - # new_fc_eff_range, + new_fc_eff_range, # TODO: make sure this has functions for modifying # - cabin thermal # - thermal mass @@ -337,7 +334,7 @@ def get_exp_pwr_hvac(df): (0.80, 0.99), (0.1, 0.6), (0.32, 0.45), - # (0.0, 0.45), + (0.2, 0.45), ), verbose=False, ) diff --git a/python/fastsim/pymoo_api.py b/python/fastsim/pymoo_api.py index c6e93602..3e093dfa 100644 --- a/python/fastsim/pymoo_api.py +++ b/python/fastsim/pymoo_api.py @@ -138,17 +138,23 @@ def update_params(self, xs: List[Any]): t0 = time.perf_counter() + # Instantiate SimDrive objects + sim_drives = {} + # Update all model parameters for key, pydict in self.models.items(): - for (param_fn, new_val) in zip(self.param_fns, xs): - pydict = param_fn(pydict, new_val) + try: + for (param_fn, new_val) in zip(self.param_fns, xs): + pydict = param_fn(pydict, new_val) + except Exception as err: + sim_drives[key] = err # this assignement may be redundant, but `pydict` is probably **not** mutably modified. # If this is correct, then this assignment is necessary self.models[key] = pydict - # Instantiate SimDrive objects - sim_drives = {} for key, pydict in self.models.items(): + if key in list(sim_drives.keys()): + continue try: sim_drives[key] = fsim.SimDrive.from_pydict(pydict, skip_init=False) except Exception as err: @@ -188,7 +194,7 @@ def get_errors( if not isinstance(sd, fsim.SimDrive): solved_mods[key] = sd - objectives[key] = [1e12] * len(self.obj_fns) * len(self.dfs) + objectives[key] = [1e12] * len(self.obj_fns) continue try: