Skip to content
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
4 changes: 2 additions & 2 deletions benchmarks/f3-save-int-1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def build_and_run_sim_drive():
veh.set_save_interval(1)
cyc = fsim.Cycle.from_resource("udds.csv")
sd = fsim.SimDrive(veh, cyc)
sd.walk()
sd.run()

if __name__ == "__main__":
build_and_run_sim_drive()
Expand All @@ -26,4 +26,4 @@ def build_and_run_sim_drive():
# 11 62.125 MiB 0.000 MiB 1 veh.save_interval = 1
# 12 62.312 MiB 0.188 MiB 1 cyc = fsim.Cycle.from_resource("udds.csv")
# 13 62.406 MiB 0.094 MiB 1 sd = fsim.SimDrive(veh, cyc)
# 14 62.953 MiB 0.547 MiB 1 sd.walk()
# 14 62.953 MiB 0.547 MiB 1 sd.run()
4 changes: 2 additions & 2 deletions benchmarks/f3-save-int-none.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def build_and_run_sim_drive():
veh.set_save_interval(None)
cyc = fsim.Cycle.from_resource("udds.csv")
sd = fsim.SimDrive(veh, cyc)
sd.walk()
sd.run()

if __name__ == "__main__":
build_and_run_sim_drive()
Expand All @@ -26,4 +26,4 @@ def build_and_run_sim_drive():
# 11 61.766 MiB 0.000 MiB 1 veh.save_interval = None
# 12 61.938 MiB 0.172 MiB 1 cyc = fsim.Cycle.from_resource("udds.csv")
# 13 62.031 MiB 0.094 MiB 1 sd = fsim.SimDrive(veh, cyc)
# 14 62.031 MiB 0.000 MiB 1 sd.walk()
# 14 62.031 MiB 0.000 MiB 1 sd.run()
6 changes: 3 additions & 3 deletions cal_and_val/f2-validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@
# %%
# Simulate FASTSim 3
for sd in f3_all_sds:
# sd_dict = sd.to_pydict(flatten=False)
# sd_dict = sd.to_dict(flatten=False)
# sd_dict["sim_params"]["trace_miss_opts"] = "Allow"
# sd = fastsim.SimDrive.from_pydict(sd_dict)
# sd = fastsim.SimDrive.from_dict(sd_dict)

try:
sd.walk()
sd.run()
except Exception as e:
print("FAILURE:", sd.veh.name, e)

Expand Down
4 changes: 2 additions & 2 deletions cal_and_val/tests/test_f2_to_f3.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ def test_f2_to_f3() -> None:
if f2file.suffix != ".yaml":
continue
f3veh = fsim.Vehicle.from_file(f2file)
f3veh_dict = f3veh.to_pydict()
f3veh_dict = f3veh.to_dict()
if f3veh_dict["doc"] is not None:
f3veh_dict["doc"] += "Generated by cal_and_val.tests.test_f2_to_f3.test_f2_to_f3"
else:
f3veh_dict["doc"] = "Generated by cal_and_val.tests.test_f2_to_f3.test_f2_to_f3"
fsim.Vehicle.from_pydict(f3veh_dict).to_file(target_dir / f2file.name)
fsim.Vehicle.from_dict(f3veh_dict).to_file(target_dir / f2file.name)
24 changes: 12 additions & 12 deletions cal_and_val/thermal/cal_bev.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
celsius_to_kelvin_offset = 273.15

veh = fsim.Vehicle.from_file(Path(__file__).parent / "f3-vehicles/2020 Chevrolet Bolt EV.yaml")
veh_dict = veh.to_pydict()
veh_dict = veh.to_dict()

sim_params_dict = fsim.SimParams.default().to_pydict()
sim_params_dict = fsim.SimParams.default().to_dict()
sim_params_dict["trace_miss_opts"] = "AllowChecked"
sim_params = fsim.SimParams.from_pydict(sim_params_dict, skip_init=False)
sim_params = fsim.SimParams.from_dict(sim_params_dict, skip_init=False)


# Obtain the data from
Expand Down Expand Up @@ -128,7 +128,7 @@ def df_to_cyc(df: pd.DataFrame) -> fsim.Cycle:
# TODO: pipe solar load from `Cycle` into cabin thermal model
# "pwr_solar_load_watts": df[],
}
return fsim.Cycle.from_pydict(cyc_dict, skip_init=False)
return fsim.Cycle.from_dict(cyc_dict, skip_init=False)


pt_type_var = "BatteryElectricVehicle"
Expand Down Expand Up @@ -173,7 +173,7 @@ def veh_init(cyc_file_stem: str, dfs: dict[str, pd.DataFrame]) -> fsim.Vehicle:
te_set + celsius_to_kelvin_offset if te_set is not None else None
)

return fsim.Vehicle.from_pydict(vd, skip_init=False)
return fsim.Vehicle.from_dict(vd, skip_init=False)


def resample_df(df: pd.DataFrame) -> pd.DataFrame:
Expand Down Expand Up @@ -213,7 +213,7 @@ def resample_df(df: pd.DataFrame) -> pd.DataFrame:
cyc: fsim.Cycle
# NOTE: maybe change `save_interval` to 5
veh = veh_init(cyc_file_stem, dfs_for_cal)
sds_for_cal[cyc_file_stem] = fsim.SimDrive(veh, cyc, sim_params).to_pydict()
sds_for_cal[cyc_file_stem] = fsim.SimDrive(veh, cyc, sim_params).to_dict()

cyc_files_for_val: list[Path] = list(set(cyc_files) - set(cyc_files_for_cal))
assert len(cyc_files_for_val) > 0
Expand Down Expand Up @@ -242,7 +242,7 @@ def resample_df(df: pd.DataFrame) -> pd.DataFrame:
cyc_file_stem: str
cyc: fsim.Cycle
veh = veh_init(cyc_file_stem, dfs_for_val)
sds_for_val[cyc_file_stem] = fsim.SimDrive(veh, cyc, sim_params).to_pydict()
sds_for_val[cyc_file_stem] = fsim.SimDrive(veh, cyc, sim_params).to_dict()


# Setup model objectives
Expand All @@ -252,19 +252,19 @@ def new_em_eff_max(sd_dict: dict, new_eff_max: float) -> dict:
"""
Set `new_eff_max` in `ElectricMachine`
"""
em = fsim.ElectricMachine.from_pydict(sd_dict["veh"]["pt_type"][pt_type_var]["em"])
em = fsim.ElectricMachine.from_dict(sd_dict["veh"]["pt_type"][pt_type_var]["em"])
em.__eff_fwd_max = new_eff_max
sd_dict["veh"]["pt_type"][pt_type_var]["em"] = em.to_pydict()
sd_dict["veh"]["pt_type"][pt_type_var]["em"] = em.to_dict()
return sd_dict


def new_em_eff_range(sd_dict, new_eff_range) -> dict:
"""
Set `new_eff_range` in `ElectricMachine`
"""
em = fsim.ElectricMachine.from_pydict(sd_dict["veh"]["pt_type"][pt_type_var]["em"])
em = fsim.ElectricMachine.from_dict(sd_dict["veh"]["pt_type"][pt_type_var]["em"])
em.__eff_fwd_range = new_eff_range
sd_dict["veh"]["pt_type"][pt_type_var]["em"] = em.to_pydict()
sd_dict["veh"]["pt_type"][pt_type_var]["em"] = em.to_dict()
return sd_dict


Expand Down Expand Up @@ -477,7 +477,7 @@ def perturb_params(pos_perturb_dec: float = 0.05, neg_perturb_dec: float = 0.1):
# - `pos_perturb_doc`: perturbation percentage added to all params. Can be overridden invididually
# - `neg_perturb_doc`: perturbation percentage subtracted from all params. Can be overridden invididually
"""
em = fsim.ElectricMachine.from_pydict(veh_dict["pt_type"][pt_type_var]["em"], skip_init=False)
em = fsim.ElectricMachine.from_dict(veh_dict["pt_type"][pt_type_var]["em"], skip_init=False)
baseline_params_and_bounds = [
(em.eff_fwd_max, None),
(em.eff_fwd_range, None),
Expand Down
34 changes: 17 additions & 17 deletions cal_and_val/thermal/cal_hev.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
veh = fsim.Vehicle.from_file(
Path(__file__).parent / "f3-vehicles/2021_Hyundai_Sonata_Hybrid_Blue.yaml"
)
veh_dict = veh.to_pydict()
veh_dict = veh.to_dict()

sim_params_dict = fsim.SimParams.default().to_pydict()
sim_params_dict = fsim.SimParams.default().to_dict()
sim_params_dict["trace_miss_opts"] = "AllowChecked"
sim_params = fsim.SimParams.from_pydict(sim_params_dict, skip_init=False)
sim_params = fsim.SimParams.from_dict(sim_params_dict, skip_init=False)

# Obtain the data from
# https://www.anl.gov/taps/d3-2021-hyundai-sonata-hybrid
Expand Down Expand Up @@ -130,7 +130,7 @@ def df_to_cyc(df: pd.DataFrame) -> fsim.Cycle:
# TODO: pipe solar load from `Cycle` into cabin thermal model
# "pwr_solar_load_watts": df[],
}
return fsim.Cycle.from_pydict(cyc_dict, skip_init=False)
return fsim.Cycle.from_dict(cyc_dict, skip_init=False)


pt_type_var = "HybridElectricVehicle"
Expand Down Expand Up @@ -177,7 +177,7 @@ def veh_init(cyc_file_stem: str, dfs: Dict[str, pd.DataFrame]) -> fsim.Vehicle:
te_set + celsius_to_kelvin_offset if te_set is not None else None
)

return fsim.Vehicle.from_pydict(vd, skip_init=False)
return fsim.Vehicle.from_dict(vd, skip_init=False)


def resample_df(df: pd.DataFrame) -> pd.DataFrame:
Expand Down Expand Up @@ -220,7 +220,7 @@ def resample_df(df: pd.DataFrame) -> pd.DataFrame:
cyc: fsim.Cycle
# NOTE: maybe change `save_interval` to 5
veh = veh_init(cyc_file_stem, dfs_for_cal)
sds_for_cal[cyc_file_stem] = fsim.SimDrive(veh, cyc, sim_params).to_pydict()
sds_for_cal[cyc_file_stem] = fsim.SimDrive(veh, cyc, sim_params).to_dict()

cyc_files_for_val: List[Path] = list(set(cyc_files) - set(cyc_files_for_cal))
assert len(cyc_files_for_val) > 0
Expand All @@ -245,7 +245,7 @@ def resample_df(df: pd.DataFrame) -> pd.DataFrame:
cyc_file_stem: str
cyc: fsim.Cycle
veh = veh_init(cyc_file_stem, dfs_for_val)
sds_for_val[cyc_file_stem] = fsim.SimDrive(veh, cyc, sim_params).to_pydict()
sds_for_val[cyc_file_stem] = fsim.SimDrive(veh, cyc, sim_params).to_dict()


# Setup model parameters and objectives
Expand All @@ -254,41 +254,41 @@ def new_em_eff_max(sd_dict, new_eff_max) -> Dict:
"""
Set `new_eff_max` in `ElectricMachine`
"""
em = fsim.ElectricMachine.from_pydict(sd_dict["veh"]["pt_type"][pt_type_var]["em"])
em = fsim.ElectricMachine.from_dict(sd_dict["veh"]["pt_type"][pt_type_var]["em"])
em.__eff_fwd_max = new_eff_max
sd_dict["veh"]["pt_type"][pt_type_var]["em"] = em.to_pydict()
sd_dict["veh"]["pt_type"][pt_type_var]["em"] = em.to_dict()
return sd_dict


def new_em_eff_range(sd_dict, new_eff_range) -> Dict:
"""
Set `new_eff_range` in `ElectricMachine`
"""
em = fsim.ElectricMachine.from_pydict(sd_dict["veh"]["pt_type"][pt_type_var]["em"])
em = fsim.ElectricMachine.from_dict(sd_dict["veh"]["pt_type"][pt_type_var]["em"])
em.__eff_fwd_range = new_eff_range
sd_dict["veh"]["pt_type"][pt_type_var]["em"] = em.to_pydict()
sd_dict["veh"]["pt_type"][pt_type_var]["em"] = em.to_dict()
return sd_dict


def new_fc_eff_max(sd_dict, new_eff_max) -> Dict:
"""
Set `new_eff_max` in `FuelConverter`
"""
fc = fsim.FuelConverter.from_pydict(sd_dict["veh"]["pt_type"][pt_type_var]["fc"])
fc = fsim.FuelConverter.from_dict(sd_dict["veh"]["pt_type"][pt_type_var]["fc"])
fc.__eff_max = new_eff_max
sd_dict["veh"]["pt_type"][pt_type_var]["fc"] = fc.to_pydict()
sd_dict["veh"]["pt_type"][pt_type_var]["fc"] = fc.to_dict()
return sd_dict


def new_fc_eff_range(sd_dict, new_eff_range) -> Dict:
"""
Set `new_eff_range` in `FuelConverter`
"""
fc = fsim.FuelConverter.from_pydict(sd_dict["veh"]["pt_type"][pt_type_var]["fc"])
fc = fsim.FuelConverter.from_dict(sd_dict["veh"]["pt_type"][pt_type_var]["fc"])
fc_eff_max = fc.eff_max
# TODO: this is a quick and dirty apprach, change to using constraints in PyMOO
fc.__eff_range = min(new_eff_range, fc_eff_max * 0.95)
sd_dict["veh"]["pt_type"][pt_type_var]["fc"] = fc.to_pydict()
sd_dict["veh"]["pt_type"][pt_type_var]["fc"] = fc.to_dict()
return sd_dict


Expand Down Expand Up @@ -654,8 +654,8 @@ def perturb_params(pos_perturb_dec: float = 0.05, neg_perturb_dec: float = 0.1):
# - `pos_perturb_doc`: perturbation percentage added to all params. Can be overridden invididually
# - `neg_perturb_doc`: perturbation percentage subtracted from all params. Can be overridden invididually
"""
em = fsim.ElectricMachine.from_pydict(veh_dict["pt_type"][pt_type_var]["em"], skip_init=False)
fc = fsim.FuelConverter.from_pydict(veh_dict["pt_type"][pt_type_var]["fc"], skip_init=False)
em = fsim.ElectricMachine.from_dict(veh_dict["pt_type"][pt_type_var]["em"], skip_init=False)
fc = fsim.FuelConverter.from_dict(veh_dict["pt_type"][pt_type_var]["fc"], skip_init=False)
baseline_params_and_bounds = [
(em.eff_fwd_max, None),
(em.eff_fwd_range, None),
Expand Down
22 changes: 11 additions & 11 deletions cal_and_val/thermal/val_bev.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,18 +298,18 @@ def get_soc_exp_mod_cal_no_thrml() -> tuple[list[float], list[float]]:
sd_cal_no_thrml["veh"]["hvac"] = "None"
sd_cal_no_thrml["veh"]["cabin"] = "None"
sd_cal_no_thrml["veh"]["pt_type"][pt_type_var]["res"]["thrml"] = "None"
res = fsim.ReversibleEnergyStorage.from_pydict(
res = fsim.ReversibleEnergyStorage.from_dict(
sd_cal_no_thrml["veh"]["pt_type"][pt_type_var]["res"], skip_init=False
)
res.set_default_pwr_interp()
sd_cal_no_thrml["veh"]["pt_type"][pt_type_var]["res"] = res.to_pydict()
sd_cal_no_thrml["veh"]["pt_type"][pt_type_var]["res"] = res.to_dict()

sd_cal_no_thrml = fsim.SimDrive.from_pydict(sd_cal_no_thrml, skip_init=False)
sd_cal_no_thrml = fsim.SimDrive.from_dict(sd_cal_no_thrml, skip_init=False)
try:
sd_cal_no_thrml.walk_once()
sd_cal_no_thrml.run_once()
except Exception:
pass
sd_cal_no_thrml = sd_cal_no_thrml.to_pydict()
sd_cal_no_thrml = sd_cal_no_thrml.to_dict()

df_cal = df_cal[: len(sd_cal_no_thrml["veh"]["history"]["time_seconds"])]

Expand Down Expand Up @@ -339,18 +339,18 @@ def get_soc_exp_mod_val_no_thrml() -> tuple[list[float], list[float]]:
sd_val_no_thrml["veh"]["hvac"] = "None"
sd_val_no_thrml["veh"]["cabin"] = "None"
sd_val_no_thrml["veh"]["pt_type"][pt_type_var]["res"]["thrml"] = "None"
res = fsim.ReversibleEnergyStorage.from_pydict(
res = fsim.ReversibleEnergyStorage.from_dict(
sd_val_no_thrml["veh"]["pt_type"][pt_type_var]["res"], skip_init=False
)
res.set_default_pwr_interp()
sd_val_no_thrml["veh"]["pt_type"][pt_type_var]["res"] = res.to_pydict()
sd_val_no_thrml["veh"]["pt_type"][pt_type_var]["res"] = res.to_dict()

sd_val_no_thrml = fsim.SimDrive.from_pydict(sd_val_no_thrml, skip_init=False)
sd_val_no_thrml = fsim.SimDrive.from_dict(sd_val_no_thrml, skip_init=False)
try:
sd_val_no_thrml.walk_once()
sd_val_no_thrml.run_once()
except Exception:
pass
sd_val_no_thrml = sd_val_no_thrml.to_pydict()
sd_val_no_thrml = sd_val_no_thrml.to_dict()

df_val = df_val[: len(sd_val_no_thrml["veh"]["history"]["time_seconds"])]

Expand Down Expand Up @@ -388,7 +388,7 @@ def get_soc_exp_mod_val_no_thrml() -> tuple[list[float], list[float]]:
veh_dict_new = deepcopy(sd_cal["veh"])
veh_dict_new["hvac"]["LumpedCabinAndRES"]["te_set_cab_kelvin"] = 22 + celsius_to_kelvin_offset
veh_dict_new["hvac"]["LumpedCabinAndRES"]["te_set_res_kelvin"] = 22 + celsius_to_kelvin_offset
veh_new = fsim.Vehicle.from_pydict(veh_dict_new)
veh_new = fsim.Vehicle.from_dict(veh_dict_new)
veh_new.clear()
if OVERWRITE_VEH:
veh_new.to_file("./f3-vehicles/2020 Chevrolet Bolt EV thrml.yaml")
20 changes: 10 additions & 10 deletions cal_and_val/thermal/val_hev.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,20 +242,20 @@ def draw_error_zones(ax):
sd_cal_no_thrml['veh']['cabin'] = 'None'
sd_cal_no_thrml['veh']['pt_type']['HybridElectricVehicle']['fc']['thrml'] = 'None'
sd_cal_no_thrml['veh']['pt_type']['HybridElectricVehicle']['res']['thrml'] = 'None'
res = fsim.ReversibleEnergyStorage.from_pydict(
res = fsim.ReversibleEnergyStorage.from_dict(
sd_cal_no_thrml['veh']['pt_type']['HybridElectricVehicle']['res'], skip_init=False)
res.set_default_pwr_interp()
sd_cal_no_thrml['veh']['pt_type']['HybridElectricVehicle']['res'] = res.to_pydict()
sd_cal_no_thrml['veh']['pt_type']['HybridElectricVehicle']['res'] = res.to_dict()
sd_cal_no_thrml['veh']['pt_type']['HybridElectricVehicle']['pt_cntrl']['RGWDB']['temp_fc_allowed_off_kelvin'] = None
sd_cal_no_thrml['veh']['pt_type']['HybridElectricVehicle']['pt_cntrl']['RGWDB']['temp_fc_forced_on_kelvin'] = None

sd_cal_no_thrml = fsim.SimDrive.from_pydict(
sd_cal_no_thrml = fsim.SimDrive.from_dict(
sd_cal_no_thrml, skip_init=False)
try:
sd_cal_no_thrml.walk_once()
sd_cal_no_thrml.run_once()
except Exception:
pass
sd_cal_no_thrml = sd_cal_no_thrml.to_pydict()
sd_cal_no_thrml = sd_cal_no_thrml.to_dict()

df_cal = df_cal[:len(sd_cal_no_thrml['veh']['history']['time_seconds'])]

Expand Down Expand Up @@ -284,19 +284,19 @@ def draw_error_zones(ax):
sd_val_no_thrml['veh']['cabin'] = 'None'
sd_val_no_thrml['veh']['pt_type']['HybridElectricVehicle']['fc']['thrml'] = 'None'
sd_val_no_thrml['veh']['pt_type']['HybridElectricVehicle']['res']['thrml'] = 'None'
res = fsim.ReversibleEnergyStorage.from_pydict(
res = fsim.ReversibleEnergyStorage.from_dict(
sd_val_no_thrml['veh']['pt_type']['HybridElectricVehicle']['res'], skip_init=False)
res.set_default_pwr_interp()
sd_val_no_thrml['veh']['pt_type']['HybridElectricVehicle']['res'] = res.to_pydict()
sd_val_no_thrml['veh']['pt_type']['HybridElectricVehicle']['res'] = res.to_dict()
sd_val_no_thrml['veh']['pt_type']['HybridElectricVehicle']['pt_cntrl']['RGWDB']['temp_fc_allowed_off_kelvin'] = None
sd_val_no_thrml['veh']['pt_type']['HybridElectricVehicle']['pt_cntrl']['RGWDB']['temp_fc_forced_on_kelvin'] = None
sd_val_no_thrml = fsim.SimDrive.from_pydict(
sd_val_no_thrml = fsim.SimDrive.from_dict(
sd_val_no_thrml, skip_init=False)
try:
sd_val_no_thrml.walk_once()
sd_val_no_thrml.run_once()
except Exception:
pass
sd_val_no_thrml = sd_val_no_thrml.to_pydict()
sd_val_no_thrml = sd_val_no_thrml.to_dict()

df_val = df_val[:len(sd_val_no_thrml['veh']['history']['time_seconds'])]

Expand Down
3 changes: 2 additions & 1 deletion docs/content/developers/vehicle-databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
## Structure

FASTSim vehicle databases,
such as the public database available at https://github.com/NatLabRockies/fastsim-vehicles,
such as the public database available at https://github.com/NatLabRockies/fastsim-vehicles
(browsable at https://natlabrockies.github.io/fastsim-vehicles/),
enforce a strict organizational structure.

### Database Organizational Schema (v1)
Expand Down
Loading
Loading