diff --git a/benchmarks/f3-save-int-1.py b/benchmarks/f3-save-int-1.py
index c868637d9..72ba53dae 100755
--- a/benchmarks/f3-save-int-1.py
+++ b/benchmarks/f3-save-int-1.py
@@ -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()
@@ -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()
diff --git a/benchmarks/f3-save-int-none.py b/benchmarks/f3-save-int-none.py
index 774e98026..3f84244b0 100755
--- a/benchmarks/f3-save-int-none.py
+++ b/benchmarks/f3-save-int-none.py
@@ -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()
@@ -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()
diff --git a/cal_and_val/f2-validation.py b/cal_and_val/f2-validation.py
index 72d6c8060..b68c05c75 100644
--- a/cal_and_val/f2-validation.py
+++ b/cal_and_val/f2-validation.py
@@ -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)
diff --git a/cal_and_val/tests/test_f2_to_f3.py b/cal_and_val/tests/test_f2_to_f3.py
index 9b5efa0de..fa276504d 100644
--- a/cal_and_val/tests/test_f2_to_f3.py
+++ b/cal_and_val/tests/test_f2_to_f3.py
@@ -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)
diff --git a/cal_and_val/thermal/cal_bev.py b/cal_and_val/thermal/cal_bev.py
index 9a5d766b3..b393ff69c 100644
--- a/cal_and_val/thermal/cal_bev.py
+++ b/cal_and_val/thermal/cal_bev.py
@@ -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
@@ -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"
@@ -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:
@@ -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
@@ -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
@@ -252,9 +252,9 @@ 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
@@ -262,9 +262,9 @@ 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
@@ -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),
diff --git a/cal_and_val/thermal/cal_hev.py b/cal_and_val/thermal/cal_hev.py
index 1bdd520fb..711ea2cd8 100644
--- a/cal_and_val/thermal/cal_hev.py
+++ b/cal_and_val/thermal/cal_hev.py
@@ -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
@@ -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"
@@ -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:
@@ -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
@@ -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
@@ -254,9 +254,9 @@ 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
@@ -264,9 +264,9 @@ 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
@@ -274,9 +274,9 @@ 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
@@ -284,11 +284,11 @@ 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
@@ -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),
diff --git a/cal_and_val/thermal/val_bev.py b/cal_and_val/thermal/val_bev.py
index c943edd4b..ab063c053 100644
--- a/cal_and_val/thermal/val_bev.py
+++ b/cal_and_val/thermal/val_bev.py
@@ -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"])]
@@ -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"])]
@@ -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")
diff --git a/cal_and_val/thermal/val_hev.py b/cal_and_val/thermal/val_hev.py
index b0116673e..f1654cf5c 100644
--- a/cal_and_val/thermal/val_hev.py
+++ b/cal_and_val/thermal/val_hev.py
@@ -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'])]
@@ -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'])]
diff --git a/docs/content/developers/vehicle-databases.md b/docs/content/developers/vehicle-databases.md
index cd49c8b94..8d4f50978 100644
--- a/docs/content/developers/vehicle-databases.md
+++ b/docs/content/developers/vehicle-databases.md
@@ -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)
diff --git a/docs/content/getting-started.ipynb b/docs/content/getting-started.ipynb
index b32b0e177..c734e67ab 100644
--- a/docs/content/getting-started.ipynb
+++ b/docs/content/getting-started.ipynb
@@ -47,75 +47,15 @@
"cell_type": "markdown",
"id": "cell-2",
"metadata": {},
- "source": [
- "## Loading a Vehicle\n",
- "\n",
- "`Vehicle.from_resource` loads one of the vehicle models bundled with FASTSim.\n",
- "The full list of bundled vehicles can be printed:"
- ]
+ "source": "## Loading a Vehicle\n\n`Vehicle.from_db` loads a vehicle from the [FASTSim Vehicle Database](https://natlabrockies.github.io/fastsim-vehicles/), a public collection of vehicle models maintained by NLR. Browse the database website to search by make, model, year, and powertrain, then copy a vehicle's path to load it in Python. For other ways to load a vehicle, including local files and vehicles bundled with FASTSim, see [](user-guide/vehicle-models/loading-vehicles.ipynb).\n\nThis example uses the conventional 2012 Ford Fusion. After loading, a few\nkey parameters can be read from the vehicle dictionary:"
},
{
"cell_type": "code",
- "execution_count": 2,
- "id": "cell-3",
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "[PosixPath('2012_Ford_Fusion.yaml'),\n",
- " PosixPath('2016 Nissan Leaf 30 kWh thrml.yaml'),\n",
- " PosixPath('2016_TOYOTA_Prius_Two.yaml'),\n",
- " PosixPath('2020 Chevrolet Bolt EV thrml.yaml'),\n",
- " PosixPath('2021_Hyundai_Sonata_Hybrid_Blue_thrml.yaml'),\n",
- " PosixPath('2022 Tesla Model 3 RWD thrml.yaml'),\n",
- " PosixPath('2022_Renault_Zoe_ZE50_R135.yaml'),\n",
- " PosixPath('2026_Chrysler_Pacifica_Select.yaml'),\n",
- " PosixPath('2026_Chrysler_Pacifica_Select_thrml.yaml')]"
- ]
- },
- "execution_count": 2,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "fastsim.Vehicle.list_resources()"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "cell-4",
- "metadata": {},
- "source": [
- "This example uses the conventional 2012 Ford Fusion. After loading, a few\n",
- "key parameters can be read from the vehicle dictionary:"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 3,
+ "execution_count": null,
"id": "cell-5",
"metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Vehicle loaded: 2012 Ford Fusion\n",
- "Vehicle mass: 1644.3 kg\n",
- "Drag coefficient: 0.393\n"
- ]
- }
- ],
- "source": [
- "veh = fastsim.Vehicle.from_resource(\"2012_Ford_Fusion.yaml\")\n",
- "\n",
- "veh_dict = veh.to_pydict()\n",
- "print(f\"Vehicle loaded: {veh_dict['name']}\")\n",
- "print(f\"Vehicle mass: {veh_dict['mass_kilograms']:.1f} kg\")\n",
- "print(f\"Drag coefficient: {veh_dict['chassis']['drag_coef']}\")"
- ]
+ "outputs": [],
+ "source": "veh = fastsim.Vehicle.from_db(path=\"v1/fastsim-3/conv/ford/fusion/2012/base/r1\")\n\nveh_dict = veh.to_dict()\nprint(f\"Vehicle loaded: {veh_dict['name']}\")\nprint(f\"Vehicle mass: {veh_dict['mass_kilograms']:.1f} kg\")\nprint(f\"Drag coefficient: {veh_dict['chassis']['drag_coef']}\")"
},
{
"cell_type": "markdown",
@@ -1018,7 +958,7 @@
"source": [
"## Running the Simulation\n",
"\n",
- "`SimDrive` combines a vehicle and a cycle, and `walk()` runs the simulation\n",
+ "`SimDrive` combines a vehicle and a cycle, and `run()` runs the simulation\n",
"from start to finish."
]
},
@@ -1030,7 +970,7 @@
"outputs": [],
"source": [
"sd = fastsim.SimDrive(veh, cyc)\n",
- "sd.walk()"
+ "sd.run()"
]
},
{
@@ -1040,7 +980,7 @@
"source": [
"## Inspecting Results\n",
"\n",
- "The `SimDrive` object contains the inputs, and after the `walk()` method is\n",
+ "The `SimDrive` object contains the inputs, and after the `run()` method is\n",
"called, which runs the simulation, it also contains the resulting time-series\n",
"data from the simulated vehicle over the provided drive cycle. You can\n",
"explore these data to understand exactly how the vehicle is performing.\n",
@@ -2849,7 +2789,7 @@
"\n",
"def mpg_from_sim(sd) -> float:\n",
" \"\"\"Compute miles per gallon gasoline equivalent from a solved SimDrive.\"\"\"\n",
- " sd_dict = sd.to_pydict(flatten=True)\n",
+ " sd_dict = sd.to_dict(flatten=True)\n",
" fuel_kwh = sd_dict[\"veh.pt_type.Conv.fc.state.energy_fuel_joules\"] / 3.6e6\n",
" miles = sd_dict[\"veh.state.dist_meters\"] / METERS_PER_MILE\n",
" return miles / (fuel_kwh / KWH_PER_GGE)\n",
@@ -2906,13 +2846,13 @@
}
],
"source": [
- "veh_dict_heavy = veh.to_pydict()\n",
+ "veh_dict_heavy = veh.to_dict()\n",
"veh_dict_heavy[\"mass_kilograms\"] += 800.0\n",
- "veh_heavy = fastsim.Vehicle.from_pydict(veh_dict_heavy)\n",
+ "veh_heavy = fastsim.Vehicle.from_dict(veh_dict_heavy)\n",
"veh_heavy.set_save_interval(1)\n",
"\n",
"sd_heavy = fastsim.SimDrive(veh_heavy, cyc)\n",
- "sd_heavy.walk()\n",
+ "sd_heavy.run()\n",
"\n",
"mpg_heavy = mpg_from_sim(sd_heavy)\n",
"print(f\"Original mass: {veh_dict['mass_kilograms']:.0f} kg -> {mpg:.1f} mpg\")\n",
@@ -3849,4 +3789,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
-}
+}
\ No newline at end of file
diff --git a/docs/content/intro.md b/docs/content/intro.md
index 94b46130b..13754b67e 100644
--- a/docs/content/intro.md
+++ b/docs/content/intro.md
@@ -35,7 +35,7 @@ any on-road vehicle over realistic scenarios.
For information on FASTSim's history and modeling philosophy, see the
[Background](background/what-is-fastsim.md) section.
-For a collection of prebuilt vehicle models, see the [FASTSim Vehicle Database](https://github.com/NatLabRockies/fastsim-vehicles).
+For a searchable collection of prebuilt vehicle models, see the [FASTSim Vehicle Database](https://natlabrockies.github.io/fastsim-vehicles/).
## Getting Started
@@ -49,7 +49,7 @@ For a collection of prebuilt vehicle models, see the [FASTSim Vehicle Database](
## Learn More
- GitHub Repository: https://github.com/NatLabRockies/fastsim
-- FASTSim Vehicle Database: https://github.com/NatLabRockies/fastsim-vehicles
+- FASTSim Vehicle Database: https://natlabrockies.github.io/fastsim-vehicles/
- Documentation: https://natlabrockies.github.io/fastsim
- Release Notes: https://github.com/NatLabRockies/fastsim/releases
- NLR FASTSim Homepage: https://www.nlr.gov/transportation/fastsim
diff --git a/docs/content/migration-guide.ipynb b/docs/content/migration-guide.ipynb
index 0d3027f0e..908e4a0a0 100644
--- a/docs/content/migration-guide.ipynb
+++ b/docs/content/migration-guide.ipynb
@@ -23,52 +23,13 @@
"cell_type": "markdown",
"id": "cell-2",
"metadata": {},
- "source": [
- "## What Changed?\n",
- "\n",
- "The biggest change is how vehicle data is stored:\n",
- "\n",
- "- **FASTSim 2** used a flat structure - every parameter (`fc_max_kw`, `ess_max_kwh`, `mc_max_kw`, …) was a top-level attribute on the `Vehicle` object, and every powertrain field existed on every vehicle regardless of whether it applied (e.g. conventional vehicles still had a battery field).\n",
- "- **FASTSim 3** uses a **nested hierarchical structure** where each vehicle only contains the fields relevant to its powertrain (`Conv`, `HEV`, `PHEV`, or `BEV`). Combining incompatible fields (e.g. a conventional vehicle with a battery) is now impossible. This allows for safer, clearer data handling.\n",
- "\n",
- "Other important differences:\n",
- "\n",
- "- **SI units are baked into field names** (`_watts`, `_joules`, `_kilograms`, `_meters`, `_seconds`). This means some variable units have been updated (no more kW or mph units), and all variables now have clear and uniformly labeled units.\n",
- "- **Simulation results are accessed via `to_dataframe()` and `to_pydict()`** rather than as direct array attributes on the `SimDrive` object.\n",
- "- **Method to modify vehicle attributes has changed.** Modifying a field now requires first changing to a pydict, modifying, then changing back.\n",
- "- **Configurable save intervals** (`set_save_interval`) - disabling per-step recording gives roughly a 10× speedup and decreased memory usage.\n",
- "- **Thermal modeling** (cabin, HVAC, battery, engine) is now supported."
- ]
+ "source": "## What Changed?\n\nThe biggest change is how vehicle data is stored:\n\n- **FASTSim 2** used a flat structure - every parameter (`fc_max_kw`, `ess_max_kwh`, `mc_max_kw`, …) was a top-level attribute on the `Vehicle` object, and every powertrain field existed on every vehicle regardless of whether it applied (e.g. conventional vehicles still had a battery field).\n- **FASTSim 3** uses a **nested hierarchical structure** where each vehicle only contains the fields relevant to its powertrain (`Conv`, `HEV`, `PHEV`, or `BEV`). Combining incompatible fields (e.g. a conventional vehicle with a battery) is now impossible. This allows for safer, clearer data handling.\n\nOther important differences:\n\n- **SI units are baked into field names** (`_watts`, `_joules`, `_kilograms`, `_meters`, `_seconds`). This means some variable units have been updated (no more kW or mph units), and all variables now have clear and uniformly labeled units.\n- **Simulation results are accessed via `to_dataframe()` and `to_dict()`** rather than as direct array attributes on the `SimDrive` object.\n- **Method to modify vehicle attributes has changed.** Modifying a field now requires first changing to a dict, modifying, then changing back.\n- **Configurable save intervals** (`set_save_interval`) - disabling per-step recording gives roughly a 10× speedup and decreased memory usage.\n- **Thermal modeling** (cabin, HVAC, battery, engine) is now supported."
},
{
"cell_type": "markdown",
"id": "cell-3",
"metadata": {},
- "source": [
- "## Quick Reference\n",
- "\n",
- "The table below covers common FASTSim actions.\n",
- "\n",
- "| Task | FASTSim 2 | FASTSim 3 |\n",
- "| --- | --- | --- |\n",
- "| Import | `import fastsim as fsim` | `import fastsim as fsim` |\n",
- "| Load vehicle from resource | `fsim.Vehicle.from_resource(\"2012_Ford_Fusion.yaml\")` | `fsim.Vehicle.from_resource(\"2012_Ford_Fusion.yaml\")` |\n",
- "| Load vehicle from database | `fsim.vehicle.Vehicle.from_vehdb` | `fsim.Vehicle.from_db` (see [](user-guide/vehicle-models/loading-vehicles.ipynb) for more information) |\n",
- "| Vehicle from file | `fsim.vehicle.Vehicle.from_file(\"veh.yaml\")` | `fsim.Vehicle.from_file(\"veh.yaml\")` |\n",
- "| Load a FASTSim 2 file into FASTSim 3 | N/A | `fsim.Vehicle.from_file(\"veh_f2.yaml\")` |\n",
- "| List vehicles in resources | `fsim.Vehicle.list_resources()` | `fsim.Vehicle.list_resources()` |\n",
- "| Load cycle from resource | `fsim.cycle.Cycle.from_file(\"udds\")` | `fsim.Cycle.from_resource(\"udds.csv\")`|\n",
- "| Load cycle from file | `fsim.cycle.Cycle.from_file(\"cycle.csv\")` | `fsim.Cycle.from_file(\"cycle.csv\")` |\n",
- "| Access Powertrain type | `veh.veh_pt_type` (string) | `veh.veh_type()` → `\"Conv\"` / `\"HEV\"` / `\"PHEV\"` / `\"BEV\"` |\n",
- "| Read a vehicle variable value | `veh.fc_max_kw` | `veh.to_pydict(flatten=True)[\"pt_type.Conv.fc.pwr_out_max_watts\"]` |\n",
- "| Modify a parameter | `veh.fc_max_kw = 100` | `d = veh.to_pydict(flatten=False)`
`d[\"pt_type\"][\"Conv\"][\"fc\"][\"pwr_out_max_watts\"] = 100`
`veh = fsim.Vehicle.from_pydict(d)` |\n",
- "| Create simulation | `fsim.simdrive.SimDrive(cyc, veh)` | `fsim.SimDrive(veh, cyc)` (**argument order reversed**) |\n",
- "| Run simulation | `sd.sim_drive()` | `sd.walk()` |\n",
- "| Access time-series result | `sd.fc_kw_in_ach` (array attribute) | `sd.to_dataframe()[\"veh.pt_type.Conv.fc.history.pwr_fuel_watts\"]` |\n",
- "| Access scalar cumulative result | `sd.fs_kwh_out_ach[-1]` | `sd.to_pydict(flatten=True)[\"veh.pt_type.Conv.fc.state.energy_fuel_joules\"]` |\n",
- "| Configure save interval | (save interval always 1) | `veh.set_save_interval(1)` / `veh.set_save_interval(None)` |\n",
- "| Save vehicle | `veh.to_file(\"veh.yaml\")` | `veh.to_file(\"veh.yaml\")` |"
- ]
+ "source": "## Quick Reference\n\nThe table below covers common FASTSim actions.\n\n| Task | FASTSim 2 | FASTSim 3 |\n| --- | --- | --- |\n| Import | `import fastsim as fsim` | `import fastsim as fsim` |\n| Load vehicle from resource | `fsim.Vehicle.from_resource(\"2012_Ford_Fusion.yaml\")` | `fsim.Vehicle.from_resource(\"2012_Ford_Fusion.yaml\")` |\n| Load vehicle from database | `fsim.vehicle.Vehicle.from_vehdb` | `fsim.Vehicle.from_db` (see [](user-guide/vehicle-models/loading-vehicles.ipynb) for more information) |\n| Vehicle from file | `fsim.vehicle.Vehicle.from_file(\"veh.yaml\")` | `fsim.Vehicle.from_file(\"veh.yaml\")` |\n| Load a FASTSim 2 file into FASTSim 3 | N/A | `fsim.Vehicle.from_file(\"veh_f2.yaml\")` |\n| List vehicles in resources | `fsim.Vehicle.list_resources()` | `fsim.Vehicle.list_resources()` |\n| Load cycle from resource | `fsim.cycle.Cycle.from_file(\"udds\")` | `fsim.Cycle.from_resource(\"udds.csv\")`|\n| Load cycle from file | `fsim.cycle.Cycle.from_file(\"cycle.csv\")` | `fsim.Cycle.from_file(\"cycle.csv\")` |\n| Access Powertrain type | `veh.veh_pt_type` (string) | `veh.veh_type()` → `\"Conv\"` / `\"HEV\"` / `\"PHEV\"` / `\"BEV\"` |\n| Read a vehicle variable value | `veh.fc_max_kw` | `veh.to_dict(flatten=True)[\"pt_type.Conv.fc.pwr_out_max_watts\"]` |\n| Modify a parameter | `veh.fc_max_kw = 100` | `d = veh.to_dict(flatten=False)`
`d[\"pt_type\"][\"Conv\"][\"fc\"][\"pwr_out_max_watts\"] = 100`
`veh = fsim.Vehicle.from_dict(d)` |\n| Create simulation | `fsim.simdrive.SimDrive(cyc, veh)` | `fsim.SimDrive(veh, cyc)` (**argument order reversed**) |\n| Run simulation | `sd.sim_drive()` | `sd.run()` |\n| Access time-series result | `sd.fc_kw_in_ach` (array attribute) | `sd.to_dataframe()[\"veh.pt_type.Conv.fc.history.pwr_fuel_watts\"]` |\n| Access scalar cumulative result | `sd.fs_kwh_out_ach[-1]` | `sd.to_dict(flatten=True)[\"veh.pt_type.Conv.fc.state.energy_fuel_joules\"]` |\n| Configure save interval | (save interval always 1) | `veh.set_save_interval(1)` / `veh.set_save_interval(None)` |\n| Save vehicle | `veh.to_file(\"veh.yaml\")` | `veh.to_file(\"veh.yaml\")` |"
},
{
"cell_type": "markdown",
@@ -182,21 +143,7 @@
"cell_type": "markdown",
"id": "cell-11",
"metadata": {},
- "source": [
- "## Reading Vehicle Parameters\n",
- "\n",
- "In FASTSim 2 you accessed parameters as flat attributes on the `Vehicle` object:\n",
- "\n",
- "```python\n",
- "# FASTSim 2\n",
- "veh.fc_max_kw # 130.5\n",
- "veh.ess_max_kwh # not applicable - 0.0 for conventional\n",
- "veh.drag_coef # 0.393\n",
- "veh.veh_kg # 1644\n",
- "```\n",
- "\n",
- "In FASTSim 3 the recommended approach is to call `to_pydict(flatten=True)`, which returns a flat `dict` whose keys use dot-separated paths matching the nested vehicle structure. See the [Field-Mapping Reference](#field-mapping-reference-guide) section of this guide for a list of FASTSim 2 vehicle variables and their corresponding FASTSim 3 variable paths/names, since in many cases both paths to variables and names have been updated."
- ]
+ "source": "## Reading Vehicle Parameters\n\nIn FASTSim 2 you accessed parameters as flat attributes on the `Vehicle` object:\n\n```python\n# FASTSim 2\nveh.fc_max_kw # 130.5\nveh.ess_max_kwh # not applicable - 0.0 for conventional\nveh.drag_coef # 0.393\nveh.veh_kg # 1644\n```\n\nIn FASTSim 3 the recommended approach is to call `to_dict(flatten=True)`, which returns a flat `dict` whose keys use dot-separated paths matching the nested vehicle structure. See the [Field-Mapping Reference](#field-mapping-reference-guide) section of this guide for a list of FASTSim 2 vehicle variables and their corresponding FASTSim 3 variable paths/names, since in many cases both paths to variables and names have been updated."
},
{
"cell_type": "code",
@@ -204,18 +151,7 @@
"id": "cell-12",
"metadata": {},
"outputs": [],
- "source": [
- "d = veh.to_pydict(flatten=True)\n",
- "\n",
- "print(\"name :\", d[\"name\"])\n",
- "print(\"year :\", d[\"year\"])\n",
- "print(\"mass_kilograms :\", d[\"mass_kilograms\"], \"kg\")\n",
- "print(\"drag_coef :\", d[\"chassis.drag_coef\"])\n",
- "print(\"frontal area :\", d[\"chassis.frontal_area_square_meters\"], \"m^2\")\n",
- "print(\"FC peak power :\", d[\"pt_type.Conv.fc.pwr_out_max_watts\"] / 1e3, \"kW\")\n",
- "print(\"FS energy capac. :\", d[\"pt_type.Conv.fs.energy_capacity_joules\"] / 3.6e6, \"kWh\")\n",
- "print(\"aux base load :\", d[\"pwr_aux_base_watts\"], \"W\")"
- ]
+ "source": "d = veh.to_dict(flatten=True)\n\nprint(\"name :\", d[\"name\"])\nprint(\"year :\", d[\"year\"])\nprint(\"mass_kilograms :\", d[\"mass_kilograms\"], \"kg\")\nprint(\"drag_coef :\", d[\"chassis.drag_coef\"])\nprint(\"frontal area :\", d[\"chassis.frontal_area_square_meters\"], \"m^2\")\nprint(\"FC peak power :\", d[\"pt_type.Conv.fc.pwr_out_max_watts\"] / 1e3, \"kW\")\nprint(\"FS energy capac. :\", d[\"pt_type.Conv.fs.energy_capacity_joules\"] / 3.6e6, \"kWh\")\nprint(\"aux base load :\", d[\"pwr_aux_base_watts\"], \"W\")"
},
{
"cell_type": "markdown",
@@ -262,23 +198,7 @@
"cell_type": "markdown",
"id": "cell-16",
"metadata": {},
- "source": [
- "## Modifying Vehicle Parameters\n",
- "\n",
- "**In FASTSim 2**, you could assign values to variables directly:\n",
- "\n",
- "```python\n",
- "# FASTSim 2\n",
- "veh.fc_max_kw = 150\n",
- "veh.drag_coef = 0.30\n",
- "```\n",
- "\n",
- "**In FASTSim 3**, `Vehicle` objects are immutable from Python. To modify a field, convert to a nested Python dictionary, modify, and then convert back:\n",
- "\n",
- "1. `d = veh.to_pydict(flatten=False)` - convert to nested dict\n",
- "2. Edit `d`\n",
- "3. `veh = fsim.Vehicle.from_pydict(d)` - convert back to a FASTSim 3 Vehicle"
- ]
+ "source": "## Modifying Vehicle Parameters\n\n**In FASTSim 2**, you could assign values to variables directly:\n\n```python\n# FASTSim 2\nveh.fc_max_kw = 150\nveh.drag_coef = 0.30\n```\n\n**In FASTSim 3**, `Vehicle` objects are immutable from Python. To modify a field, convert to a nested Python dictionary, modify, and then convert back:\n\n1. `d = veh.to_dict(flatten=False)` - convert to nested dict\n2. Edit `d`\n3. `veh = fsim.Vehicle.from_dict(d)` - convert back to a FASTSim 3 Vehicle"
},
{
"cell_type": "code",
@@ -286,19 +206,7 @@
"id": "cell-17",
"metadata": {},
"outputs": [],
- "source": [
- "# Example modifying fuel converter peak power (+15%) and drag coefficient\n",
- "\n",
- "# convert vehicle to nested dictionary\n",
- "d = veh.to_pydict(flatten=False)\n",
- "\n",
- "# Modify the nested dictionary\n",
- "d[\"pt_type\"][\"Conv\"][\"fc\"][\"pwr_out_max_watts\"] *= 1.15\n",
- "d[\"chassis\"][\"drag_coef\"] = 0.30\n",
- "\n",
- "# Convert back to a Vehicle object\n",
- "veh_modified = fsim.Vehicle.from_pydict(d)"
- ]
+ "source": "# Example modifying fuel converter peak power (+15%) and drag coefficient\n\n# convert vehicle to nested dictionary\nd = veh.to_dict(flatten=False)\n\n# Modify the nested dictionary\nd[\"pt_type\"][\"Conv\"][\"fc\"][\"pwr_out_max_watts\"] *= 1.15\nd[\"chassis\"][\"drag_coef\"] = 0.30\n\n# Convert back to a Vehicle object\nveh_modified = fsim.Vehicle.from_dict(d)"
},
{
"cell_type": "markdown",
@@ -346,16 +254,7 @@
"cell_type": "markdown",
"id": "cell-20",
"metadata": {},
- "source": [
- "## Running a Simulation\n",
- "\n",
- "Four things changed:\n",
- "\n",
- "1. **Class name:** `fsim.SimDrive` (was `fsim.simdrive.SimDrive`)\n",
- "2. **Argument order:** `SimDrive(veh, cyc)` (was `SimDrive(cyc, veh)` -- order of inputs switched)\n",
- "3. **Run method:** `sd.walk()` (was `sd.sim_drive()`)\n",
- "4. **Save intervals:** configurable using `set_save_interval` (not configurable in FASTSim 2)"
- ]
+ "source": "## Running a Simulation\n\nFour things changed:\n\n1. **Class name:** `fsim.SimDrive` (was `fsim.simdrive.SimDrive`)\n2. **Argument order:** `SimDrive(veh, cyc)` (was `SimDrive(cyc, veh)` -- order of inputs switched)\n3. **Run method:** `sd.run()` (was `sd.sim_drive()`)\n4. **Save intervals:** configurable using `set_save_interval` (not configurable in FASTSim 2)"
},
{
"cell_type": "code",
@@ -363,27 +262,13 @@
"id": "cell-21",
"metadata": {},
"outputs": [],
- "source": [
- "# Create simdrive object and run a simulation\n",
- "sd = fsim.SimDrive(veh, cyc)\n",
- "sd.walk()"
- ]
+ "source": "# Create simdrive object and run a simulation\nsd = fsim.SimDrive(veh, cyc)\nsd.run()"
},
{
"cell_type": "markdown",
"id": "cell-26",
"metadata": {},
- "source": [
- "FASTSim 3 lets you configure how much time-series data is recorded via `set_save_interval` (see below). Saving less time-series data (or setting to None) allows for faster simulation when detailed time-series results aren't needed.\n",
- "\n",
- "FASTSim 2 always recorded every time step. FASTSim 3 lets you trade time-series detail for speed:\n",
- "\n",
- "- `veh.set_save_interval(1)` - record every step (default; needed for time-series plots).\n",
- "- `veh.set_save_interval(n)` - record every *n*-th step.\n",
- "- `veh.set_save_interval(None)` - disable per-step recording entirely. About 10× faster than FASTSim 2. Cumulative totals from `sd.to_pydict(flatten=True)` are still available.\n",
- "\n",
- "Use `None` for parameter sweeps, large batch runs, and other applications where you only need aggregate results."
- ]
+ "source": "FASTSim 3 lets you configure how much time-series data is recorded via `set_save_interval` (see below). Saving less time-series data (or setting to None) allows for faster simulation when detailed time-series results aren't needed.\n\nFASTSim 2 always recorded every time step. FASTSim 3 lets you trade time-series detail for speed:\n\n- `veh.set_save_interval(1)` - record every step (default; needed for time-series plots).\n- `veh.set_save_interval(n)` - record every *n*-th step.\n- `veh.set_save_interval(None)` - disable per-step recording entirely. About 10× faster than FASTSim 2. Cumulative totals from `sd.to_dict(flatten=True)` are still available.\n\nUse `None` for parameter sweeps, large batch runs, and other applications where you only need aggregate results."
},
{
"cell_type": "code",
@@ -391,42 +276,13 @@
"id": "cell-27",
"metadata": {},
"outputs": [],
- "source": [
- "# Fast run: no per-step recording, cumulative totals only\n",
- "veh_fast = fsim.Vehicle.from_resource(\"2012_Ford_Fusion.yaml\")\n",
- "veh_fast.set_save_interval(None)\n",
- "\n",
- "sd_fast = fsim.SimDrive(veh_fast, cyc)\n",
- "sd_fast.walk()\n",
- "\n",
- "# to_pydict still works - history arrays will be empty but state totals are populated\n",
- "sd_dict = sd_fast.to_pydict(flatten=True)\n",
- "print(\"Fuel energy:\", sd_dict[\"veh.pt_type.Conv.fc.state.energy_fuel_joules\"] / 3.6e6, \"kWh\")"
- ]
+ "source": "# Fast run: no per-step recording, cumulative totals only\nveh_fast = fsim.Vehicle.from_resource(\"2012_Ford_Fusion.yaml\")\nveh_fast.set_save_interval(None)\n\nsd_fast = fsim.SimDrive(veh_fast, cyc)\nsd_fast.run()\n\n# to_dict still works - history arrays will be empty but state totals are populated\nsd_dict = sd_fast.to_dict(flatten=True)\nprint(\"Fuel energy:\", sd_dict[\"veh.pt_type.Conv.fc.state.energy_fuel_joules\"] / 3.6e6, \"kWh\")"
},
{
"cell_type": "markdown",
"id": "cell-22",
"metadata": {},
- "source": [
- "## Reading Simulation Results\n",
- "\n",
- "FASTSim 2 exposed results as array attributes on the `SimDrive` object:\n",
- "\n",
- "```python\n",
- "# FASTSim 2\n",
- "sd.mph_ach # numpy array of achieved speeds (mph)\n",
- "sd.fc_kw_in_ach # numpy array of fuel power in (kW)\n",
- "sd.fc_kw_out_ach # numpy array of fuel power out (kW)\n",
- "sd.fs_kwh_out_ach[-1] # total fuel energy consumed (kWh)\n",
- "sd.soc # state of charge (for HEV/PHEV/BEV)\n",
- "```\n",
- "\n",
- "FASTSim 3 exposes results through two methods on `SimDrive`:\n",
- "\n",
- "- **`sd.to_dataframe()`** - returns a Polars DataFrame (pass `pandas=True` for pandas). Recommended for accessing time series data. Column names are dot-separated paths mirroring the vehicle hierarchy.\n",
- "- **`sd.to_pydict(flatten=True)`** - returns a flat `dict`. Used to access cumulative end-of-simulation totals which live under `*.state.*`. Available even when `set_save_interval(None)` is used."
- ]
+ "source": "## Reading Simulation Results\n\nFASTSim 2 exposed results as array attributes on the `SimDrive` object:\n\n```python\n# FASTSim 2\nsd.mph_ach # numpy array of achieved speeds (mph)\nsd.fc_kw_in_ach # numpy array of fuel power in (kW)\nsd.fc_kw_out_ach # numpy array of fuel power out (kW)\nsd.fs_kwh_out_ach[-1] # total fuel energy consumed (kWh)\nsd.soc # state of charge (for HEV/PHEV/BEV)\n```\n\nFASTSim 3 exposes results through two methods on `SimDrive`:\n\n- **`sd.to_dataframe()`** - returns a Polars DataFrame (pass `pandas=True` for pandas). Recommended for accessing time series data. Column names are dot-separated paths mirroring the vehicle hierarchy.\n- **`sd.to_dict(flatten=True)`** - returns a flat `dict`. Used to access cumulative end-of-simulation totals which live under `*.state.*`. Available even when `set_save_interval(None)` is used."
},
{
"cell_type": "code",
@@ -468,51 +324,19 @@
"id": "cell-24",
"metadata": {},
"outputs": [],
- "source": [
- "# Scalar cumulative totals via to_pydict(flatten=True).\n",
- "# These are the FASTSim 3 equivalents of cumulative scalars accessed as the\n",
- "# last element of an array in FASTSim 2 (e.g. sd.fs_kwh_out_ach[-1]).\n",
- "sd_dict = sd.to_pydict(flatten=True)\n",
- "\n",
- "fuel_energy_kwh = sd_dict[\"veh.pt_type.Conv.fc.state.energy_fuel_joules\"] / 3.6e6\n",
- "distance_km = sd_dict[\"veh.state.dist_meters\"] / 1e3\n",
- "cyc_met = sd_dict[\"veh.state.cyc_met_overall\"]\n",
- "\n",
- "print(f\"Fuel energy consumed : {fuel_energy_kwh:.2f} kWh\")\n",
- "print(f\"Distance driven : {distance_km:.2f} km\")\n",
- "print(f\"Fuel economy : {distance_km / fuel_energy_kwh:.2f} km/kWh\")\n",
- "print(f\"Cycle met throughout : {cyc_met}\")"
- ]
+ "source": "# Scalar cumulative totals via to_dict(flatten=True).\n# These are the FASTSim 3 equivalents of cumulative scalars accessed as the\n# last element of an array in FASTSim 2 (e.g. sd.fs_kwh_out_ach[-1]).\nsd_dict = sd.to_dict(flatten=True)\n\nfuel_energy_kwh = sd_dict[\"veh.pt_type.Conv.fc.state.energy_fuel_joules\"] / 3.6e6\ndistance_km = sd_dict[\"veh.state.dist_meters\"] / 1e3\ncyc_met = sd_dict[\"veh.state.cyc_met_overall\"]\n\nprint(f\"Fuel energy consumed : {fuel_energy_kwh:.2f} kWh\")\nprint(f\"Distance driven : {distance_km:.2f} km\")\nprint(f\"Fuel economy : {distance_km / fuel_energy_kwh:.2f} km/kWh\")\nprint(f\"Cycle met throughout : {cyc_met}\")"
},
{
"cell_type": "markdown",
"id": "cell-25",
"metadata": {},
- "source": [
- "### Updating Result Paths\n",
- "\n",
- "Common FASTSim 2 result attributes and their FASTSim 3 equivalents:\n",
- "\n",
- "| FASTSim 2 | FASTSim 3 |\n",
- "| --- | --- |\n",
- "| `sd.cyc.mps` (target speed) | `sd.to_dataframe(pandas=True)[\"cyc.speed_meters_per_second\"]` |\n",
- "| `sd.mph_ach` | `sd.to_dataframe(pandas=True)[\"veh.history.speed_ach_meters_per_second\"]` |\n",
- "| `sd.dist_mi[-1]` | `sd.to_pydict(flatten=True)[\"veh.state.dist_meters\"]` (in meters) |\n",
- "| `sd.fc_kw_out_ach` | `sd.to_dataframe(pandas=True)[\"veh.pt_type..fc.history.pwr_prop_watts\"]` |\n",
- "| `sd.fc_kw_in_ach` | `sd.to_dataframe(pandas=True)[\"veh.pt_type..fc.history.pwr_fuel_watts\"]` |\n",
- "| `sd.fs_kwh_out_ach[-1]` | `sd.to_pydict(flatten=True)[\"veh.pt_type..fc.state.energy_fuel_joules\"]` |\n",
- "| `sd.soc` | `sd.to_dataframe(pandas=True)[\"veh.pt_type..res.history.soc\"]` |\n",
- "| `sd.ess_kw_out_ach` | `sd.to_dataframe(pandas=True)[\"veh.pt_type..res.history.pwr_out_electrical_watts\"]` |\n",
- "| `sd.mc_kw_out_ach` | `sd.to_dataframe(pandas=True)[\"veh.pt_type..em.history.pwr_prop_watts\"]` |\n",
- "\n",
- "Replace `` with the actual powertrain variant returned by `veh.veh_type()`.\n"
- ]
+ "source": "### Updating Result Paths\n\nCommon FASTSim 2 result attributes and their FASTSim 3 equivalents:\n\n| FASTSim 2 | FASTSim 3 |\n| --- | --- |\n| `sd.cyc.mps` (target speed) | `sd.to_dataframe(pandas=True)[\"cyc.speed_meters_per_second\"]` |\n| `sd.mph_ach` | `sd.to_dataframe(pandas=True)[\"veh.history.speed_ach_meters_per_second\"]` |\n| `sd.dist_mi[-1]` | `sd.to_dict(flatten=True)[\"veh.state.dist_meters\"]` (in meters) |\n| `sd.fc_kw_out_ach` | `sd.to_dataframe(pandas=True)[\"veh.pt_type..fc.history.pwr_prop_watts\"]` |\n| `sd.fc_kw_in_ach` | `sd.to_dataframe(pandas=True)[\"veh.pt_type..fc.history.pwr_fuel_watts\"]` |\n| `sd.fs_kwh_out_ach[-1]` | `sd.to_dict(flatten=True)[\"veh.pt_type..fc.state.energy_fuel_joules\"]` |\n| `sd.soc` | `sd.to_dataframe(pandas=True)[\"veh.pt_type..res.history.soc\"]` |\n| `sd.ess_kw_out_ach` | `sd.to_dataframe(pandas=True)[\"veh.pt_type..res.history.pwr_out_electrical_watts\"]` |\n| `sd.mc_kw_out_ach` | `sd.to_dataframe(pandas=True)[\"veh.pt_type..em.history.pwr_prop_watts\"]` |\n\nReplace `` with the actual powertrain variant returned by `veh.veh_type()`.\n"
},
{
"cell_type": "markdown",
"id": "cell-30",
"metadata": {},
- "source": "(field-mapping-reference-guide)=\n## Field-Mapping Reference Guide\n\nThe tables below map every FASTSim 2 `Vehicle` field to its FASTSim 3 equivalent. FASTSim 3 paths are the keys returned by `veh.to_pydict(flatten=True)`. Paths with `` change based on the powertrain type: `Conv`, `HEV`, `PHEV`, or `BEV`."
+ "source": "(field-mapping-reference-guide)=\n## Field-Mapping Reference Guide\n\nThe tables below map every FASTSim 2 `Vehicle` field to its FASTSim 3 equivalent. FASTSim 3 paths are the keys returned by `veh.to_dict(flatten=True)`. Paths with `` change based on the powertrain type: `Conv`, `HEV`, `PHEV`, or `BEV`."
},
{
"cell_type": "markdown",
diff --git a/docs/content/old/advanced_coasting.ipynb b/docs/content/old/advanced_coasting.ipynb
index e8c850cd9..63844c121 100644
--- a/docs/content/old/advanced_coasting.ipynb
+++ b/docs/content/old/advanced_coasting.ipynb
@@ -87,7 +87,7 @@
"outputs": [],
"source": [
"man = fsim.Maneuver.create_from(cyc, veh.copy())\n",
- "d = man.to_pydict()\n",
+ "d = man.to_dict()\n",
"d[\"coast_allow\"] = True\n",
"d[\"coast_brake_start_speed_meters_per_second\"] = 8.9408 # 20 mph\n",
"d[\"coast_brake_accel_meters_per_second_squared\"] = -2.5\n",
@@ -95,7 +95,7 @@
"d[\"coast_allow_passing\"] = True\n",
"d[\"coast_max_speed_meters_per_second\"] = 33.5280 # 75 mph\n",
"d[\"coast_time_horizon_for_adjustment_seconds\"] = 120.0\n",
- "man = fsim.Maneuver.from_pydict(d)\n",
+ "man = fsim.Maneuver.from_dict(d)\n",
"\n",
"cyc = man.apply_maneuvers()\n",
"cyc = cyc.trim_ending_idle(idle_to_keep_s=end_idle_duration_s)"
@@ -109,7 +109,7 @@
"outputs": [],
"source": [
"sd = fsim.SimDrive(veh, cyc)\n",
- "sd.walk()"
+ "sd.run()"
]
},
{
@@ -151,7 +151,7 @@
],
"source": [
"if SHOW_PLOTS:\n",
- " c0 = cyc0.to_pydict()\n",
+ " c0 = cyc0.to_dict()\n",
" df = sd.to_dataframe(backend='polars')\n",
" plot_speed_by_time(df, c0, title=\"Advanced Coasting\",\n",
" save_figs=SAVE_FIGS, show_plots=SHOW_PLOTS)\n",
diff --git a/docs/content/old/basic_coasting.ipynb b/docs/content/old/basic_coasting.ipynb
index a1a8ab30b..81b04d7f3 100644
--- a/docs/content/old/basic_coasting.ipynb
+++ b/docs/content/old/basic_coasting.ipynb
@@ -90,10 +90,10 @@
"outputs": [],
"source": [
"man = fsim.Maneuver.create_from(cyc, veh.copy())\n",
- "d = man.to_pydict()\n",
+ "d = man.to_dict()\n",
"d[\"coast_allow\"] = True\n",
"d[\"coast_start_speed_meters_per_second\"] = coast_speed_mps\n",
- "man = fsim.Maneuver.from_pydict(d)\n",
+ "man = fsim.Maneuver.from_dict(d)\n",
"\n",
"cyc = man.apply_maneuvers()\n",
"cyc = cyc.trim_ending_idle(idle_to_keep_s=end_idle_duration_s)"
@@ -107,7 +107,7 @@
"outputs": [],
"source": [
"sd = fsim.SimDrive(veh, cyc)\n",
- "sd.walk()"
+ "sd.run()"
]
},
{
@@ -149,7 +149,7 @@
],
"source": [
"if SHOW_PLOTS:\n",
- " c0 = cyc0.to_pydict()\n",
+ " c0 = cyc0.to_dict()\n",
" df = sd.to_dataframe(backend='polars')\n",
" plot_speed_by_time(df, c0, title=f\"Coasting from {coast_speed_mps} m/s\",\n",
" save_figs=SAVE_FIGS, show_plots=SHOW_PLOTS)\n",
diff --git a/docs/content/old/bev.ipynb b/docs/content/old/bev.ipynb
index 526663b9a..2e999490f 100644
--- a/docs/content/old/bev.ipynb
+++ b/docs/content/old/bev.ipynb
@@ -77,10 +77,10 @@
"source": [
"# instantiate `SimDrive` simulation object\n",
"sd = fsim.SimDrive(veh, cyc)\n",
- "sd.walk()\n",
+ "sd.run()\n",
"\n",
"df = sd.to_dataframe(backend='polars')\n",
- "sd_dict = sd.to_pydict(flatten=True)"
+ "sd_dict = sd.to_dict(flatten=True)"
]
},
{
diff --git a/docs/content/old/bev_thrml_cs_ca.ipynb b/docs/content/old/bev_thrml_cs_ca.ipynb
index 7fed2442a..16523839e 100644
--- a/docs/content/old/bev_thrml_cs_ca.ipynb
+++ b/docs/content/old/bev_thrml_cs_ca.ipynb
@@ -70,12 +70,12 @@
"# load 2020 Chevrolet Bolt BEV with thermal model\n",
"veh = fsim.Vehicle.from_resource(\"2020 Chevrolet Bolt EV thrml.yaml\")\n",
"\n",
- "veh_dict = veh.to_pydict()\n",
+ "veh_dict = veh.to_dict()\n",
"veh_dict[\"cabin\"][\"LumpedCabin\"][\"state\"][\"temperature_kelvin\"] = temp_amb_and_init\n",
"veh_dict[\"pt_type\"][\"BEV\"][\"res\"][\"thrml\"][\"RESLumpedThermal\"][\"state\"][\"temperature_kelvin\"] = (\n",
" temp_amb_and_init\n",
")\n",
- "veh = fsim.Vehicle.from_pydict(veh_dict)\n",
+ "veh = fsim.Vehicle.from_dict(veh_dict)\n",
"\n",
"veh.set_save_interval(1)"
]
@@ -88,9 +88,9 @@
"outputs": [],
"source": [
"# load cycle and set ambient temperature\n",
- "cyc_dict = fsim.Cycle.from_resource(\"udds.csv\").to_pydict()\n",
+ "cyc_dict = fsim.Cycle.from_resource(\"udds.csv\").to_dict()\n",
"cyc_dict[\"temp_amb_air_kelvin\"] = [temp_amb_and_init] * len(cyc_dict[\"time_seconds\"])\n",
- "cyc = fsim.Cycle.from_pydict(cyc_dict)"
+ "cyc = fsim.Cycle.from_dict(cyc_dict)"
]
},
{
@@ -101,10 +101,10 @@
"outputs": [],
"source": [
"sd = fsim.SimDrive(veh, cyc)\n",
- "sd.walk()\n",
+ "sd.run()\n",
"\n",
"df = sd.to_dataframe(backend='polars')\n",
- "sd_dict = sd.to_pydict(flatten=True)"
+ "sd_dict = sd.to_dict(flatten=True)"
]
},
{
diff --git a/docs/content/old/bev_thrml_ws_ca.ipynb b/docs/content/old/bev_thrml_ws_ca.ipynb
index 673d490e4..068233f92 100644
--- a/docs/content/old/bev_thrml_ws_ca.ipynb
+++ b/docs/content/old/bev_thrml_ws_ca.ipynb
@@ -71,12 +71,12 @@
"# load 2020 Chevrolet Bolt BEV with thermal model\n",
"veh = fsim.Vehicle.from_resource(\"2020 Chevrolet Bolt EV thrml.yaml\")\n",
"\n",
- "veh_dict = veh.to_pydict()\n",
+ "veh_dict = veh.to_dict()\n",
"veh_dict[\"cabin\"][\"LumpedCabin\"][\"state\"][\"temperature_kelvin\"] = temp_init_bat_and_cab\n",
"veh_dict[\"pt_type\"][\"BEV\"][\"res\"][\"thrml\"][\"RESLumpedThermal\"][\"state\"][\"temperature_kelvin\"] = (\n",
" temp_init_bat_and_cab\n",
")\n",
- "veh = fsim.Vehicle.from_pydict(veh_dict)\n",
+ "veh = fsim.Vehicle.from_dict(veh_dict)\n",
"\n",
"veh.set_save_interval(1)"
]
@@ -89,9 +89,9 @@
"outputs": [],
"source": [
"# load cycle and set ambient temperature\n",
- "cyc_dict = fsim.Cycle.from_resource(\"udds.csv\").to_pydict()\n",
+ "cyc_dict = fsim.Cycle.from_resource(\"udds.csv\").to_dict()\n",
"cyc_dict[\"temp_amb_air_kelvin\"] = [temp_amb] * len(cyc_dict[\"time_seconds\"])\n",
- "cyc = fsim.Cycle.from_pydict(cyc_dict)"
+ "cyc = fsim.Cycle.from_dict(cyc_dict)"
]
},
{
@@ -102,10 +102,10 @@
"outputs": [],
"source": [
"sd = fsim.SimDrive(veh, cyc)\n",
- "sd.walk()\n",
+ "sd.run()\n",
"\n",
"df = sd.to_dataframe(backend='polars')\n",
- "sd_dict = sd.to_pydict(flatten=True)"
+ "sd_dict = sd.to_dict(flatten=True)"
]
},
{
diff --git a/docs/content/old/bev_thrml_ws_wa.ipynb b/docs/content/old/bev_thrml_ws_wa.ipynb
index ad2f1ff9d..298c6ab20 100644
--- a/docs/content/old/bev_thrml_ws_wa.ipynb
+++ b/docs/content/old/bev_thrml_ws_wa.ipynb
@@ -71,12 +71,12 @@
"# load 2020 Chevrolet Bolt BEV with thermal model\n",
"veh = fsim.Vehicle.from_resource(\"2020 Chevrolet Bolt EV thrml.yaml\")\n",
"\n",
- "veh_dict = veh.to_pydict()\n",
+ "veh_dict = veh.to_dict()\n",
"veh_dict[\"cabin\"][\"LumpedCabin\"][\"state\"][\"temperature_kelvin\"] = temp_init\n",
"veh_dict[\"pt_type\"][\"BEV\"][\"res\"][\"thrml\"][\"RESLumpedThermal\"][\"state\"][\"temperature_kelvin\"] = (\n",
" temp_init\n",
")\n",
- "veh = fsim.Vehicle.from_pydict(veh_dict)\n",
+ "veh = fsim.Vehicle.from_dict(veh_dict)\n",
"\n",
"veh.set_save_interval(1)"
]
@@ -89,9 +89,9 @@
"outputs": [],
"source": [
"# load cycle and set ambient temperature\n",
- "cyc_dict = fsim.Cycle.from_resource(\"udds.csv\").to_pydict()\n",
+ "cyc_dict = fsim.Cycle.from_resource(\"udds.csv\").to_dict()\n",
"cyc_dict[\"temp_amb_air_kelvin\"] = [temp_amb] * len(cyc_dict[\"time_seconds\"])\n",
- "cyc = fsim.Cycle.from_pydict(cyc_dict)"
+ "cyc = fsim.Cycle.from_dict(cyc_dict)"
]
},
{
@@ -102,10 +102,10 @@
"outputs": [],
"source": [
"sd = fsim.SimDrive(veh, cyc)\n",
- "sd.walk()\n",
+ "sd.run()\n",
"\n",
"df = sd.to_dataframe(backend='polars')\n",
- "sd_dict = sd.to_pydict(flatten=True)"
+ "sd_dict = sd.to_dict(flatten=True)"
]
},
{
diff --git a/docs/content/old/coast_with_grade.ipynb b/docs/content/old/coast_with_grade.ipynb
index e00525c09..09376c1e7 100644
--- a/docs/content/old/coast_with_grade.ipynb
+++ b/docs/content/old/coast_with_grade.ipynb
@@ -71,7 +71,7 @@
" 0.02, 0.02, 0.02, 0.02, 0.02, -0.02, -0.02, -0.02, -0.02,\n",
" ],\n",
"}\n",
- "cyc0 = fsim.Cycle.from_pydict(cyc_d)\n",
+ "cyc0 = fsim.Cycle.from_dict(cyc_d)\n",
"cyc = cyc0.resample(time_step_s=1.0)"
]
},
@@ -97,7 +97,7 @@
"veh.set_save_interval(1)\n",
"\n",
"man = fsim.Maneuver.create_from(cyc, veh.copy())\n",
- "d = man.to_pydict()\n",
+ "d = man.to_dict()\n",
"d[\"coast_allow\"] = True\n",
"d[\"coast_brake_start_speed_meters_per_second\"] = 8.9408 # 20 mph\n",
"d[\"coast_brake_accel_meters_per_second_squared\"] = -2.5\n",
@@ -105,7 +105,7 @@
"d[\"coast_allow_passing\"] = True\n",
"d[\"coast_max_speed_meters_per_second\"] = 33.5280 # 75 mph\n",
"d[\"coast_time_horizon_for_adjustment_seconds\"] = 120.0\n",
- "man = fsim.Maneuver.from_pydict(d)\n",
+ "man = fsim.Maneuver.from_dict(d)\n",
"\n",
"cyc = man.apply_maneuvers()"
]
@@ -118,7 +118,7 @@
"outputs": [],
"source": [
"sd = fsim.SimDrive(veh, cyc)\n",
- "sd.walk()"
+ "sd.run()"
]
},
{
@@ -160,7 +160,7 @@
],
"source": [
"if SHOW_PLOTS:\n",
- " c0 = cyc0.to_pydict()\n",
+ " c0 = cyc0.to_dict()\n",
" df = sd.to_dataframe(backend='polars')\n",
" plot_speed_by_time(df, c0, title=\"Coast with Grade\", with_elevation=True,\n",
" save_figs=SAVE_FIGS, show_plots=SHOW_PLOTS)\n",
diff --git a/docs/content/old/conv.ipynb b/docs/content/old/conv.ipynb
index c77a1ce1a..256851ae3 100644
--- a/docs/content/old/conv.ipynb
+++ b/docs/content/old/conv.ipynb
@@ -77,10 +77,10 @@
"source": [
"# instantiate `SimDrive` simulation object\n",
"sd = fsim.SimDrive(veh, cyc)\n",
- "sd.walk()\n",
+ "sd.run()\n",
"\n",
"df = sd.to_dataframe(backend='polars')\n",
- "sd_dict = sd.to_pydict(flatten=True)"
+ "sd_dict = sd.to_dict(flatten=True)"
]
},
{
diff --git a/docs/content/old/cruise_and_coast.ipynb b/docs/content/old/cruise_and_coast.ipynb
index 862573bf1..542bef84d 100644
--- a/docs/content/old/cruise_and_coast.ipynb
+++ b/docs/content/old/cruise_and_coast.ipynb
@@ -85,7 +85,7 @@
"outputs": [],
"source": [
"man = fsim.Maneuver.create_from(cyc, veh.copy())\n",
- "d = man.to_pydict()\n",
+ "d = man.to_dict()\n",
"\n",
"# Coasting parameters\n",
"d[\"coast_allow\"] = True\n",
@@ -105,7 +105,7 @@
"d[\"idm_acceleration_meters_per_second_squared\"] = 1.0\n",
"d[\"idm_deceleration_meters_per_second_squared\"] = 2.5\n",
"\n",
- "man = fsim.Maneuver.from_pydict(d)\n",
+ "man = fsim.Maneuver.from_dict(d)\n",
"cyc = man.apply_maneuvers()\n",
"cyc_for_coast = cyc.copy()\n",
"cyc = cyc.trim_ending_idle(idle_to_keep_s=end_idle_duration_s)"
@@ -119,7 +119,7 @@
"outputs": [],
"source": [
"sd = fsim.SimDrive(veh, cyc)\n",
- "sd.walk()"
+ "sd.run()"
]
},
{
@@ -162,10 +162,10 @@
],
"source": [
"if SHOW_PLOTS:\n",
- " c0 = cyc0.to_pydict()\n",
+ " c0 = cyc0.to_dict()\n",
" df = sd.to_dataframe(backend='polars')\n",
" is_coast = np.array(man.is_coasting()) * 5.0\n",
- " cd = cyc_for_coast.to_pydict()\n",
+ " cd = cyc_for_coast.to_dict()\n",
" dist = cd[\"dist_meters\"]\n",
" is_coast_d = [\n",
" np.interp(d, dist, is_coast)\n",
diff --git a/docs/content/old/dfco.ipynb b/docs/content/old/dfco.ipynb
index c66300519..59afffd45 100644
--- a/docs/content/old/dfco.ipynb
+++ b/docs/content/old/dfco.ipynb
@@ -80,7 +80,7 @@
"\n",
"# instantiate `SimDrive` simulation object and run\n",
"sd = fsim.SimDrive(veh, cyc)\n",
- "sd.walk()\n",
+ "sd.run()\n",
"df = sd.to_dataframe(backend='polars')"
]
},
@@ -103,7 +103,7 @@
"veh_dfco.set_save_interval(1)\n",
"\n",
"sd_dfco = fsim.SimDrive(veh_dfco, cyc)\n",
- "sd_dfco.walk()\n",
+ "sd_dfco.run()\n",
"df_dfco = sd_dfco.to_dataframe(backend='polars')"
]
},
@@ -135,7 +135,7 @@
}
],
"source": [
- "cyc_dict = cyc.to_pydict()\n",
+ "cyc_dict = cyc.to_dict()\n",
"distance_m = cyc_dict[\"dist_meters\"][-1]\n",
"distance_mi = distance_m / METERS_PER_MILE\n",
"\n",
diff --git a/docs/content/old/eco_cruise.ipynb b/docs/content/old/eco_cruise.ipynb
index 3b9356236..f21b14f3b 100644
--- a/docs/content/old/eco_cruise.ipynb
+++ b/docs/content/old/eco_cruise.ipynb
@@ -90,7 +90,7 @@
"outputs": [],
"source": [
"man = fsim.Maneuver.create_from(cyc, veh.copy())\n",
- "d = man.to_pydict()\n",
+ "d = man.to_dict()\n",
"d[\"idm_allow\"] = True\n",
"d[\"idm_desired_speed_meters_per_second\"] = vavg\n",
"d[\"idm_headway_seconds\"] = 1.0\n",
@@ -98,7 +98,7 @@
"d[\"idm_delta\"] = 4.0\n",
"d[\"idm_acceleration_meters_per_second_squared\"] = 1.0\n",
"d[\"idm_deceleration_meters_per_second_squared\"] = 2.5\n",
- "man = fsim.Maneuver.from_pydict(d)\n",
+ "man = fsim.Maneuver.from_dict(d)\n",
"\n",
"cyc = man.apply_maneuvers()\n",
"cyc = cyc.trim_ending_idle(idle_to_keep_s=end_idle_duration_s)"
@@ -112,7 +112,7 @@
"outputs": [],
"source": [
"sd = fsim.SimDrive(veh, cyc)\n",
- "sd.walk()"
+ "sd.run()"
]
},
{
@@ -154,7 +154,7 @@
],
"source": [
"if SHOW_PLOTS:\n",
- " c0 = cyc0.to_pydict()\n",
+ " c0 = cyc0.to_dict()\n",
" df = sd.to_dataframe(backend='polars')\n",
" plot_speed_by_time(df, c0, title=\"Eco-Cruise (IDM)\",\n",
" save_figs=SAVE_FIGS, show_plots=SHOW_PLOTS)\n",
diff --git a/docs/content/old/hev.ipynb b/docs/content/old/hev.ipynb
index 3033aaadf..a66a12b04 100644
--- a/docs/content/old/hev.ipynb
+++ b/docs/content/old/hev.ipynb
@@ -77,10 +77,10 @@
"source": [
"# instantiate `SimDrive` simulation object\n",
"sd = fsim.SimDrive(veh, cyc)\n",
- "sd.walk()\n",
+ "sd.run()\n",
"\n",
"df = sd.to_dataframe(backend='polars')\n",
- "sd_dict = sd.to_pydict(flatten=True)"
+ "sd_dict = sd.to_dict(flatten=True)"
]
},
{
diff --git a/docs/content/old/hev_thrml_cs_ca.ipynb b/docs/content/old/hev_thrml_cs_ca.ipynb
index a410262cf..c733b7ab9 100644
--- a/docs/content/old/hev_thrml_cs_ca.ipynb
+++ b/docs/content/old/hev_thrml_cs_ca.ipynb
@@ -84,7 +84,7 @@
"# load 2021 Hyundai Sonata HEV with thermal model\n",
"veh_dict = fsim.Vehicle.from_resource(\n",
" \"2021_Hyundai_Sonata_Hybrid_Blue_thrml.yaml\",\n",
- ").to_pydict()\n",
+ ").to_dict()\n",
"veh_dict[\"cabin\"][\"LumpedCabin\"][\"state\"][\"temperature_kelvin\"] = temp_amb_and_init\n",
"veh_dict[\"pt_type\"][\"HEV\"][\"res\"][\"thrml\"][\"RESLumpedThermal\"][\"state\"][\"temperature_kelvin\"] = (\n",
" temp_amb_and_init\n",
@@ -92,7 +92,7 @@
"veh_dict[\"pt_type\"][\"HEV\"][\"fc\"][\"thrml\"][\"FuelConverterThermal\"][\"state\"][\"temperature_kelvin\"] = (\n",
" temp_amb_and_init\n",
")\n",
- "veh = fsim.Vehicle.from_pydict(veh_dict)\n",
+ "veh = fsim.Vehicle.from_dict(veh_dict)\n",
"\n",
"veh.set_save_interval(1)"
]
@@ -105,9 +105,9 @@
"outputs": [],
"source": [
"# load cycle and set ambient temperature\n",
- "cyc_dict = fsim.Cycle.from_resource(\"udds.csv\").to_pydict()\n",
+ "cyc_dict = fsim.Cycle.from_resource(\"udds.csv\").to_dict()\n",
"cyc_dict[\"temp_amb_air_kelvin\"] = [temp_amb_and_init] * len(cyc_dict[\"time_seconds\"])\n",
- "cyc = fsim.Cycle.from_pydict(cyc_dict)"
+ "cyc = fsim.Cycle.from_dict(cyc_dict)"
]
},
{
@@ -118,10 +118,10 @@
"outputs": [],
"source": [
"sd = fsim.SimDrive(veh, cyc)\n",
- "sd.walk()\n",
+ "sd.run()\n",
"\n",
"df = sd.to_dataframe(backend='polars')\n",
- "sd_dict = sd.to_pydict(flatten=True)"
+ "sd_dict = sd.to_dict(flatten=True)"
]
},
{
diff --git a/docs/content/old/hev_thrml_ws_ca.ipynb b/docs/content/old/hev_thrml_ws_ca.ipynb
index c50134ac8..3a352038e 100644
--- a/docs/content/old/hev_thrml_ws_ca.ipynb
+++ b/docs/content/old/hev_thrml_ws_ca.ipynb
@@ -87,7 +87,7 @@
"# load 2021 Hyundai Sonata HEV with thermal model\n",
"veh_dict = fsim.Vehicle.from_resource(\n",
" \"2021_Hyundai_Sonata_Hybrid_Blue_thrml.yaml\",\n",
- ").to_pydict()\n",
+ ").to_dict()\n",
"veh_dict[\"cabin\"][\"LumpedCabin\"][\"state\"][\"temperature_kelvin\"] = temp_init_bat_and_cab\n",
"veh_dict[\"pt_type\"][\"HEV\"][\"res\"][\"thrml\"][\"RESLumpedThermal\"][\"state\"][\"temperature_kelvin\"] = (\n",
" temp_init_bat_and_cab\n",
@@ -95,7 +95,7 @@
"veh_dict[\"pt_type\"][\"HEV\"][\"fc\"][\"thrml\"][\"FuelConverterThermal\"][\"state\"][\"temperature_kelvin\"] = (\n",
" temp_init_eng\n",
")\n",
- "veh = fsim.Vehicle.from_pydict(veh_dict)\n",
+ "veh = fsim.Vehicle.from_dict(veh_dict)\n",
"\n",
"veh.set_save_interval(1)"
]
@@ -108,9 +108,9 @@
"outputs": [],
"source": [
"# load cycle and set ambient temperature\n",
- "cyc_dict = fsim.Cycle.from_resource(\"udds.csv\").to_pydict()\n",
+ "cyc_dict = fsim.Cycle.from_resource(\"udds.csv\").to_dict()\n",
"cyc_dict[\"temp_amb_air_kelvin\"] = [temp_amb] * len(cyc_dict[\"time_seconds\"])\n",
- "cyc = fsim.Cycle.from_pydict(cyc_dict)"
+ "cyc = fsim.Cycle.from_dict(cyc_dict)"
]
},
{
@@ -121,10 +121,10 @@
"outputs": [],
"source": [
"sd = fsim.SimDrive(veh, cyc)\n",
- "sd.walk()\n",
+ "sd.run()\n",
"\n",
"df = sd.to_dataframe(backend='polars')\n",
- "sd_dict = sd.to_pydict(flatten=True)"
+ "sd_dict = sd.to_dict(flatten=True)"
]
},
{
diff --git a/docs/content/old/hev_thrml_ws_wa.ipynb b/docs/content/old/hev_thrml_ws_wa.ipynb
index b0e9748b1..0822d681e 100644
--- a/docs/content/old/hev_thrml_ws_wa.ipynb
+++ b/docs/content/old/hev_thrml_ws_wa.ipynb
@@ -85,7 +85,7 @@
"# load 2021 Hyundai Sonata HEV with thermal model\n",
"veh_dict = fsim.Vehicle.from_resource(\n",
" \"2021_Hyundai_Sonata_Hybrid_Blue_thrml.yaml\",\n",
- ").to_pydict()\n",
+ ").to_dict()\n",
"veh_dict[\"cabin\"][\"LumpedCabin\"][\"state\"][\"temperature_kelvin\"] = temp_init\n",
"veh_dict[\"pt_type\"][\"HEV\"][\"res\"][\"thrml\"][\"RESLumpedThermal\"][\"state\"][\"temperature_kelvin\"] = (\n",
" temp_init\n",
@@ -93,7 +93,7 @@
"veh_dict[\"pt_type\"][\"HEV\"][\"fc\"][\"thrml\"][\"FuelConverterThermal\"][\"state\"][\"temperature_kelvin\"] = (\n",
" temp_init\n",
")\n",
- "veh = fsim.Vehicle.from_pydict(veh_dict)\n",
+ "veh = fsim.Vehicle.from_dict(veh_dict)\n",
"\n",
"veh.set_save_interval(1)"
]
@@ -106,9 +106,9 @@
"outputs": [],
"source": [
"# load cycle and set ambient temperature\n",
- "cyc_dict = fsim.Cycle.from_resource(\"udds.csv\").to_pydict()\n",
+ "cyc_dict = fsim.Cycle.from_resource(\"udds.csv\").to_dict()\n",
"cyc_dict[\"temp_amb_air_kelvin\"] = [temp_amb] * len(cyc_dict[\"time_seconds\"])\n",
- "cyc = fsim.Cycle.from_pydict(cyc_dict)"
+ "cyc = fsim.Cycle.from_dict(cyc_dict)"
]
},
{
@@ -119,10 +119,10 @@
"outputs": [],
"source": [
"sd = fsim.SimDrive(veh, cyc)\n",
- "sd.walk()\n",
+ "sd.run()\n",
"\n",
"df = sd.to_dataframe(backend='polars')\n",
- "sd_dict = sd.to_pydict(flatten=True)"
+ "sd_dict = sd.to_dict(flatten=True)"
]
},
{
diff --git a/docs/content/old/maneuver_intro.ipynb b/docs/content/old/maneuver_intro.ipynb
index 71176bc8b..49eda4b38 100644
--- a/docs/content/old/maneuver_intro.ipynb
+++ b/docs/content/old/maneuver_intro.ipynb
@@ -72,9 +72,9 @@
"source": [
"## Inspecting and Modifying Parameters\n",
"\n",
- "`to_pydict()` serializes the Maneuver to a Python dictionary.\n",
+ "`to_dict()` serializes the Maneuver to a Python dictionary.\n",
"Parameters can be modified in the dictionary and then loaded back\n",
- "with `Maneuver.from_pydict()`.\n",
+ "with `Maneuver.from_dict()`.\n",
"\n",
"The Maneuver struct has two groups of configurable parameters:\n",
"\n",
@@ -119,7 +119,7 @@
}
],
"source": [
- "d = man.to_pydict()\n",
+ "d = man.to_dict()\n",
"\n",
"print(\"Coasting parameters:\")\n",
"for k in sorted(d):\n",
@@ -152,7 +152,7 @@
"source": [
"d[\"coast_allow\"] = True\n",
"d[\"coast_start_speed_meters_per_second\"] = 15.0\n",
- "man = fsim.Maneuver.from_pydict(d)\n",
+ "man = fsim.Maneuver.from_dict(d)\n",
"\n",
"cyc_modified = man.apply_maneuvers()"
]
@@ -186,8 +186,8 @@
],
"source": [
"if SHOW_PLOTS:\n",
- " c0 = cyc0.to_pydict()\n",
- " cm = cyc_modified.to_pydict()\n",
+ " c0 = cyc0.to_dict()\n",
+ " cm = cyc_modified.to_dict()\n",
"\n",
" fig, ax = plt.subplots(figsize=(10, 4))\n",
" ax.plot(c0[\"time_seconds\"], c0[\"speed_meters_per_second\"], label=\"Original\")\n",
@@ -216,7 +216,7 @@
"outputs": [],
"source": [
"sd = fsim.SimDrive(veh, cyc_modified)\n",
- "sd.walk()"
+ "sd.run()"
]
},
{
diff --git a/docs/content/old/microtrips.ipynb b/docs/content/old/microtrips.ipynb
index 943c67def..d21d1a814 100644
--- a/docs/content/old/microtrips.ipynb
+++ b/docs/content/old/microtrips.ipynb
@@ -96,7 +96,7 @@
" fig, ax = plt.subplots()\n",
" num = min(max_microtrips, len(microtrips))\n",
" for idx, mt in enumerate(microtrips):\n",
- " mtd = mt.to_pydict()\n",
+ " mtd = mt.to_dict()\n",
" color = BASE_COLORS[idx % len(BASE_COLORS)]\n",
" line = BASE_LINE_STYLES[idx % len(BASE_LINE_STYLES)]\n",
" ax.plot(\n",
diff --git a/docs/content/old/start_stop.ipynb b/docs/content/old/start_stop.ipynb
index 0f3dd724a..65252c9de 100644
--- a/docs/content/old/start_stop.ipynb
+++ b/docs/content/old/start_stop.ipynb
@@ -82,7 +82,7 @@
"\n",
"# instantiate `SimDrive` simulation object and run\n",
"sd = fsim.SimDrive(veh, cyc)\n",
- "sd.walk()\n",
+ "sd.run()\n",
"df = sd.to_dataframe()"
]
},
@@ -99,7 +99,7 @@
"veh_ss.set_save_interval(1)\n",
"\n",
"sd_ss = fsim.SimDrive(veh_ss, cyc)\n",
- "sd_ss.walk()\n",
+ "sd_ss.run()\n",
"df_ss = sd_ss.to_dataframe()"
]
},
@@ -131,7 +131,7 @@
}
],
"source": [
- "cyc_dict = cyc.to_pydict()\n",
+ "cyc_dict = cyc.to_dict()\n",
"distance_m = cyc_dict[\"dist_meters\"][-1]\n",
"distance_mi = distance_m / METERS_PER_MILE\n",
"\n",
@@ -191,7 +191,7 @@
" assert res_capacity_joules > 0.0\n",
" assert res_eff > 0.0 and res_eff <= 1.0, \"res_eff must be in range (0.0, 1.0]\"\n",
" assert em_eff > 0.0 and em_eff <= 1.0, \"em_eff must be in range (0.0, 1.0]\"\n",
- " veh_dict = veh.to_pydict()\n",
+ " veh_dict = veh.to_dict()\n",
" res = {\n",
" \"thrml\": \"None\",\n",
" \"mass_kilograms\": None,\n",
@@ -391,7 +391,7 @@
" \"sim_params\": sim_params,\n",
" },\n",
" }\n",
- " veh_uhev = fsim.Vehicle.from_pydict(veh_dict)\n",
+ " veh_uhev = fsim.Vehicle.from_dict(veh_dict)\n",
" return veh_uhev"
]
},
@@ -404,7 +404,7 @@
"source": [
"veh_uhev = conv_to_micro_hybrid(veh)\n",
"sd_uhev = fsim.SimDrive(veh_uhev, cyc)\n",
- "sd_uhev.walk()\n",
+ "sd_uhev.run()\n",
"df_uhev = sd_uhev.to_dataframe()"
]
},
diff --git a/docs/content/old/trace_miss.ipynb b/docs/content/old/trace_miss.ipynb
index 1547c5760..8d669c74e 100644
--- a/docs/content/old/trace_miss.ipynb
+++ b/docs/content/old/trace_miss.ipynb
@@ -60,7 +60,7 @@
" \"time_seconds\": [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0],\n",
" \"speed_meters_per_second\": [0.0, 0.0, 8.0, 8.0, 8.0, 8.0, 8.0, 0.0, 0.0],\n",
"}\n",
- "cyc = fsim.Cycle.from_pydict(cyc_d)\n",
+ "cyc = fsim.Cycle.from_dict(cyc_d)\n",
"cyc0 = cyc.copy()"
]
},
@@ -101,12 +101,12 @@
"metadata": {},
"outputs": [],
"source": [
- "params = fsim.SimParams.default().to_pydict()\n",
+ "params = fsim.SimParams.default().to_dict()\n",
"params[\"trace_miss_opts\"] = \"Correct\"\n",
"params[\"trace_miss_correct_max_steps\"] = 6\n",
"\n",
- "sd = fsim.SimDrive(veh, cyc, fsim.SimParams.from_pydict(params))\n",
- "sd.walk()"
+ "sd = fsim.SimDrive(veh, cyc, fsim.SimParams.from_dict(params))\n",
+ "sd.run()"
]
},
{
@@ -138,7 +138,7 @@
],
"source": [
"if SHOW_PLOTS:\n",
- " c0 = cyc0.to_pydict()\n",
+ " c0 = cyc0.to_dict()\n",
" df = sd.to_dataframe(backend='polars')\n",
"\n",
" fig, ax = plt.subplots(figsize=(10, 4))\n",
diff --git a/docs/content/user-guide/drive-cycles/drive-cycle.ipynb b/docs/content/user-guide/drive-cycles/drive-cycle.ipynb
index 36e900caf..9dd7f73ab 100644
--- a/docs/content/user-guide/drive-cycles/drive-cycle.ipynb
+++ b/docs/content/user-guide/drive-cycles/drive-cycle.ipynb
@@ -1061,7 +1061,7 @@
],
"source": [
"# Convert a Cycle to a Python dictionary\n",
- "cyc_dict = cyc.to_pydict()\n",
+ "cyc_dict = cyc.to_dict()\n",
"print(cyc_dict.keys())\n",
"print(cyc_dict)"
]
@@ -1147,7 +1147,7 @@
"outputs": [],
"source": [
"# Convert the cycle dictionary back into a FASTSim Cycle\n",
- "cyc = fastsim.Cycle.from_pydict(cyc_dict)"
+ "cyc = fastsim.Cycle.from_dict(cyc_dict)"
]
}
],
diff --git a/docs/content/user-guide/running-simulations/advanced/cavs.ipynb b/docs/content/user-guide/running-simulations/advanced/cavs.ipynb
index 78c894aed..7ad2758d1 100644
--- a/docs/content/user-guide/running-simulations/advanced/cavs.ipynb
+++ b/docs/content/user-guide/running-simulations/advanced/cavs.ipynb
@@ -118,7 +118,7 @@
" man = None\n",
" else:\n",
" man = fastsim.Maneuver.create_from(cyc_seed, veh.copy())\n",
- " d = man.to_pydict()\n",
+ " d = man.to_dict()\n",
"\n",
" if enable_coast:\n",
" d[\"coast_allow\"] = True\n",
@@ -138,14 +138,14 @@
" d[\"idm_acceleration_meters_per_second_squared\"] = 1.0\n",
" d[\"idm_deceleration_meters_per_second_squared\"] = 2.5\n",
"\n",
- " man = fastsim.Maneuver.from_pydict(d)\n",
+ " man = fastsim.Maneuver.from_dict(d)\n",
" cyc_run = man.apply_maneuvers().trim_ending_idle(idle_to_keep_s=ending_idle_s)\n",
"\n",
" sd = fastsim.SimDrive(veh, cyc_run)\n",
- " sd.walk()\n",
+ " sd.run()\n",
" df = sd.to_dataframe()\n",
"\n",
- " cyc_dict = cyc_run.to_pydict()\n",
+ " cyc_dict = cyc_run.to_dict()\n",
" dist_m = cyc_dict[\"dist_meters\"][-1]\n",
" dist_mi = dist_m / METERS_PER_MILE\n",
" fuel_mj = df[\"veh.pt_type.Conv.fc.history.energy_fuel_joules\"].iloc[-1] / 1e6\n",
@@ -1834,7 +1834,7 @@
" t_combined = np.array(df_combined[\"cyc.time_seconds\"], dtype=float)\n",
" d_combined = np.array(df_combined[\"cyc.dist_meters\"], dtype=float)\n",
"\n",
- " cyc_combined = combined[\"cycle\"].to_pydict()\n",
+ " cyc_combined = combined[\"cycle\"].to_dict()\n",
" d_maneuver = np.array(cyc_combined[\"dist_meters\"], dtype=float)\n",
"\n",
" n = min(len(d_maneuver), len(coast_raw))\n",
diff --git a/docs/content/user-guide/running-simulations/advanced/dfco.ipynb b/docs/content/user-guide/running-simulations/advanced/dfco.ipynb
index 594fd63be..1dc9df2fa 100644
--- a/docs/content/user-guide/running-simulations/advanced/dfco.ipynb
+++ b/docs/content/user-guide/running-simulations/advanced/dfco.ipynb
@@ -70,7 +70,7 @@
" max_accel_for_dfco_m_per_s2=0.0,\n",
")\n",
"sd = fastsim.SimDrive(veh, cyc)\n",
- "sd.walk()\n",
+ "sd.run()\n",
"df = sd.to_dataframe()\n",
"\n",
"# DFCO case: enabled above 25 mph and during moderate deceleration\n",
@@ -81,7 +81,7 @@
" max_accel_for_dfco_m_per_s2=-0.2,\n",
")\n",
"sd_dfco = fastsim.SimDrive(veh_dfco, cyc)\n",
- "sd_dfco.walk()\n",
+ "sd_dfco.run()\n",
"df_dfco = sd_dfco.to_dataframe()"
]
},
@@ -112,7 +112,7 @@
}
],
"source": [
- "cyc_dict = cyc.to_pydict()\n",
+ "cyc_dict = cyc.to_dict()\n",
"distance_m = cyc_dict[\"dist_meters\"][-1]\n",
"distance_mi = distance_m / METERS_PER_MILE\n",
"\n",
diff --git a/docs/content/user-guide/running-simulations/advanced/start-stop.ipynb b/docs/content/user-guide/running-simulations/advanced/start-stop.ipynb
index cf4923d50..035b8fe3f 100644
--- a/docs/content/user-guide/running-simulations/advanced/start-stop.ipynb
+++ b/docs/content/user-guide/running-simulations/advanced/start-stop.ipynb
@@ -72,7 +72,7 @@
"cyc = fastsim.Cycle.from_resource(\"udds.csv\")\n",
"\n",
"sd = fastsim.SimDrive(veh, cyc)\n",
- "sd.walk()\n",
+ "sd.run()\n",
"df = sd.to_dataframe()\n",
"\n",
"veh_ss = fastsim.Vehicle.from_resource(\"2012_Ford_Fusion.yaml\")\n",
@@ -80,7 +80,7 @@
"veh_ss.set_save_interval(1)\n",
"\n",
"sd_ss = fastsim.SimDrive(veh_ss, cyc)\n",
- "sd_ss.walk()\n",
+ "sd_ss.run()\n",
"df_ss = sd_ss.to_dataframe()"
]
},
@@ -129,7 +129,7 @@
}
],
"source": [
- "cyc_dict = cyc.to_pydict()\n",
+ "cyc_dict = cyc.to_dict()\n",
"distance_m = cyc_dict[\"dist_meters\"][-1]\n",
"distance_mi = distance_m / METERS_PER_MILE\n",
"\n",
@@ -189,7 +189,7 @@
" assert 0.0 < res_eff <= 1.0\n",
" assert 0.0 < em_eff <= 1.0\n",
"\n",
- " veh_dict = veh.to_pydict()\n",
+ " veh_dict = veh.to_dict()\n",
"\n",
" res = {\n",
" \"thrml\": \"None\",\n",
@@ -369,7 +369,7 @@
" }\n",
" }\n",
"\n",
- " return fastsim.Vehicle.from_pydict(veh_dict)"
+ " return fastsim.Vehicle.from_dict(veh_dict)"
]
},
{
@@ -404,7 +404,7 @@
"veh_uhev.set_save_interval(1)\n",
"\n",
"sd_uhev = fastsim.SimDrive(veh_uhev, cyc)\n",
- "sd_uhev.walk()\n",
+ "sd_uhev.run()\n",
"df_uhev = sd_uhev.to_dataframe()\n",
"\n",
"fuel_uhev_mj = df_uhev[\"veh.pt_type.HEV.fc.history.energy_fuel_joules\"].iloc[-1] / 1e6\n",
diff --git a/docs/content/user-guide/running-simulations/advanced/thermal-simulations.ipynb b/docs/content/user-guide/running-simulations/advanced/thermal-simulations.ipynb
index 682d50d75..1a1bf16fc 100644
--- a/docs/content/user-guide/running-simulations/advanced/thermal-simulations.ipynb
+++ b/docs/content/user-guide/running-simulations/advanced/thermal-simulations.ipynb
@@ -155,7 +155,7 @@
"\n",
"def run_thermal_hev_case(name, temps_c):\n",
" # Start from the same thermal HEV template for each scenario.\n",
- " veh_dict = fastsim.Vehicle.from_resource(THERMAL_HEV_RESOURCE).to_pydict()\n",
+ " veh_dict = fastsim.Vehicle.from_resource(THERMAL_HEV_RESOURCE).to_dict()\n",
"\n",
" # Set initial component temperatures (cabin, battery/RES, fuel converter).\n",
" veh_dict[\"cabin\"][\"LumpedCabin\"][\"state\"][\"temperature_kelvin\"] = c_to_k(\n",
@@ -167,20 +167,20 @@
" veh_dict[\"pt_type\"][\"HEV\"][\"fc\"][\"thrml\"][\"FuelConverterThermal\"][\"state\"][\n",
" \"temperature_kelvin\"\n",
" ] = c_to_k(temps_c[\"temp_fc_c\"])\n",
- " veh = fastsim.Vehicle.from_pydict(veh_dict)\n",
+ " veh = fastsim.Vehicle.from_dict(veh_dict)\n",
" # Save full time-series history so thermal trajectories are available in outputs.\n",
" veh.set_save_interval(1)\n",
"\n",
" # Apply scenario ambient temperature to every cycle time step.\n",
- " cyc_dict = fastsim.Cycle.from_resource(\"udds.csv\").to_pydict()\n",
+ " cyc_dict = fastsim.Cycle.from_resource(\"udds.csv\").to_dict()\n",
" cyc_dict[\"temp_amb_air_kelvin\"] = [c_to_k(temps_c[\"temp_amb_c\"])] * len(\n",
" cyc_dict[\"time_seconds\"]\n",
" )\n",
- " cyc = fastsim.Cycle.from_pydict(cyc_dict)\n",
+ " cyc = fastsim.Cycle.from_dict(cyc_dict)\n",
"\n",
" # Run FASTSim and capture time histories for comparison.\n",
" sd = fastsim.SimDrive(veh, cyc)\n",
- " sd.walk()\n",
+ " sd.run()\n",
" df = sd.to_dataframe()\n",
"\n",
" # Compute cycle-level fuel economy from distance and cumulative fuel energy.\n",
diff --git a/docs/content/user-guide/running-simulations/editing-sim-params.ipynb b/docs/content/user-guide/running-simulations/editing-sim-params.ipynb
index 517e4d697..1f21f248b 100644
--- a/docs/content/user-guide/running-simulations/editing-sim-params.ipynb
+++ b/docs/content/user-guide/running-simulations/editing-sim-params.ipynb
@@ -86,7 +86,7 @@
"import fastsim\n",
"\n",
"# Create a SimParams object from default values\n",
- "params = fastsim.SimParams.default().to_pydict()\n",
+ "params = fastsim.SimParams.default().to_dict()\n",
"\n",
"print(\"Simulation params:\")\n",
"params"
@@ -118,9 +118,9 @@
"cyc = fastsim.Cycle.from_resource(\"udds.csv\")\n",
"\n",
"# Run simulation with modified parameters\n",
- "sim_params = fastsim.SimParams.from_pydict(params)\n",
+ "sim_params = fastsim.SimParams.from_dict(params)\n",
"sd = fastsim.SimDrive(veh, cyc, sim_params)\n",
- "sd.walk()\n",
+ "sd.run()\n",
"\n",
"print(f\"Modified trace_miss_opts: {params['trace_miss_opts']}\")\n",
"print(\"Simulation completed\")"
@@ -182,8 +182,8 @@
"# Load an HEV vehicle\n",
"veh_hev = fastsim.Vehicle.from_resource(\"2016_TOYOTA_Prius_Two.yaml\")\n",
"\n",
- "# Access HEV parameters via to_pydict()\n",
- "veh_dict = veh_hev.to_pydict()\n",
+ "# Access HEV parameters via to_dict()\n",
+ "veh_dict = veh_hev.to_dict()\n",
"hev_params = veh_dict[\"pt_type\"][\"HEV\"][\"sim_params\"]\n",
"\n",
"print(\"HEV simulation params:\")\n",
@@ -207,16 +207,16 @@
],
"source": [
"# Modify SOC balancing to allow more iterations\n",
- "veh_dict = veh_hev.to_pydict()\n",
+ "veh_dict = veh_hev.to_dict()\n",
"veh_dict[\"pt_type\"][\"HEV\"][\"sim_params\"][\"soc_balance_iter_err\"] = 10\n",
"\n",
"# Recreate the vehicle with modified parameters\n",
- "veh_hev_modified = fastsim.Vehicle.from_pydict(veh_dict)\n",
+ "veh_hev_modified = fastsim.Vehicle.from_dict(veh_dict)\n",
"\n",
"# Run a simulation with the modified HEV parameters\n",
"cyc = fastsim.Cycle.from_resource(\"udds.csv\")\n",
"sd = fastsim.SimDrive(veh_hev_modified, cyc)\n",
- "sd.walk()\n",
+ "sd.run()\n",
"\n",
"print(\n",
" f\"Modified soc_balance_iter_err: {veh_dict['pt_type']['HEV']['sim_params']['soc_balance_iter_err']}\"\n",
diff --git a/docs/content/user-guide/running-simulations/label-fe.ipynb b/docs/content/user-guide/running-simulations/label-fe.ipynb
index fe651c5ab..e6f96f32c 100644
--- a/docs/content/user-guide/running-simulations/label-fe.ipynb
+++ b/docs/content/user-guide/running-simulations/label-fe.ipynb
@@ -128,7 +128,7 @@
"simulated_highway_mpg = label_fe['adj_hwy_mpgge']\n",
"simulated_combined_mpg = label_fe['adj_comb_mpgge']\n",
"\n",
- "print(f\"Vehicle: {veh.to_pydict()['name']}\")\n",
+ "print(f\"Vehicle: {veh.to_dict()['name']}\")\n",
"print(f\"Simulated label fuel economy:\")\n",
"print(f\" City: {simulated_city_mpg:.1f} mpg\")\n",
"print(f\" Highway: {simulated_highway_mpg:.1f} mpg\")\n",
diff --git a/docs/content/user-guide/running-simulations/simdrive.ipynb b/docs/content/user-guide/running-simulations/simdrive.ipynb
index af295bd67..42337b01a 100644
--- a/docs/content/user-guide/running-simulations/simdrive.ipynb
+++ b/docs/content/user-guide/running-simulations/simdrive.ipynb
@@ -11,7 +11,7 @@
"`Vehicle` (what the vehicle is) and a `Cycle` (what the vehicle does) into a\n",
"single simulation scenario.\n",
"\n",
- "Calling `sd.walk()` steps the vehicle through the drive cycle one time step at\n",
+ "Calling `sd.run()` steps the vehicle through the drive cycle one time step at\n",
"a time, computing energy flows, achieved speed, and component states at each\n",
"step.\n"
]
@@ -73,18 +73,18 @@
"source": [
"## Running the Simulation\n",
"\n",
- "Call `sd.walk()` to execute the simulation. This steps through every time step\n",
+ "Call `sd.run()` to execute the simulation. This steps through every time step\n",
"in the cycle and computes the vehicle's energy flows, achieved speed, and\n",
"component states.\n",
"\n",
- "`walk()` applies powertrain-specific corrections automatically:\n",
+ "`run()` applies powertrain-specific corrections automatically:\n",
"\n",
"- **Conventional**: simulates once.\n",
"- **BEV / PHEV**: sets initial SOC to the maximum before simulating.\n",
"- **HEV**: iterates until the initial and final SOC are balanced (charge-sustaining operation).\n",
"\n",
"If you need to run exactly one iteration without any of those corrections (e.g.,\n",
- "you have already set an initial SOC yourself in the RES `state`), use `sd.walk_once()` instead.\n"
+ "you have already set an initial SOC yourself in the RES `state`), use `sd.run_once()` instead.\n"
]
},
{
@@ -103,7 +103,7 @@
],
"source": [
"sd = fastsim.SimDrive(veh, cyc)\n",
- "sd.walk()\n",
+ "sd.run()\n",
"print(\"Simulation complete.\")\n"
]
},
@@ -114,7 +114,7 @@
"source": [
"## Extracting Results\n",
"\n",
- "After `walk()`, the simulation results are stored inside the `SimDrive` object.\n",
+ "After `run()`, the simulation results are stored inside the `SimDrive` object.\n",
"There are two primary ways to access them.\n",
"\n",
"### `to_dataframe()`\n",
@@ -1067,9 +1067,9 @@
"id": "f32085cf",
"metadata": {},
"source": [
- "### `to_pydict()`\n",
+ "### `to_dict()`\n",
"\n",
- "`to_pydict(flatten=True)` returns a flat dictionary mapping dotted key paths to\n",
+ "`to_dict(flatten=True)` returns a flat dictionary mapping dotted key paths to\n",
"scalar values (cumulative totals and final states). This is useful for\n",
"extracting summary metrics such as total fuel consumed or total distance driven.\n"
]
@@ -1091,7 +1091,7 @@
}
],
"source": [
- "sd_dict = sd.to_pydict(flatten=True)\n",
+ "sd_dict = sd.to_dict(flatten=True)\n",
"\n",
"fuel_joules = sd_dict[\"veh.pt_type.Conv.fc.state.energy_fuel_joules\"]\n",
"dist_meters = sd_dict[\"veh.state.dist_meters\"]\n",
@@ -1149,9 +1149,9 @@
"veh_no_hist.set_save_interval(None) # disable per-step history\n",
"\n",
"sd_no_hist = fastsim.SimDrive(veh_no_hist, cyc)\n",
- "sd_no_hist.walk()\n",
+ "sd_no_hist.run()\n",
"\n",
- "sd_dict_no_hist = sd_no_hist.to_pydict(flatten=True)\n",
+ "sd_dict_no_hist = sd_no_hist.to_dict(flatten=True)\n",
"fuel_kwh_no_hist = sd_dict_no_hist[\"veh.pt_type.Conv.fc.state.energy_fuel_joules\"] / 3.6e6\n",
"miles_no_hist = sd_dict_no_hist[\"veh.state.dist_meters\"] / METERS_PER_MILE\n",
"mpg_no_hist = miles_no_hist / (fuel_kwh_no_hist / KWH_PER_GGE)\n",
@@ -1224,20 +1224,20 @@
"\n",
"# Simulate UDDS cycle\n",
"sd_udds = fastsim.SimDrive(veh, cyc_udds)\n",
- "sd_udds.walk()\n",
+ "sd_udds.run()\n",
"\n",
"# Simulate HWFET cycle\n",
"sd_hwfet = fastsim.SimDrive(veh, cyc_hwfet)\n",
- "sd_hwfet.walk()\n",
+ "sd_hwfet.run()\n",
"\n",
"# UDDS calculations\n",
- "sd_udds_dict = sd_udds.to_pydict(flatten=True)\n",
+ "sd_udds_dict = sd_udds.to_dict(flatten=True)\n",
"fuel_kwh_udds = sd_udds_dict[\"veh.pt_type.Conv.fc.state.energy_fuel_joules\"] / 3.6e6\n",
"miles_udds = sd_udds_dict[\"veh.state.dist_meters\"] / METERS_PER_MILE\n",
"mpg_udds = miles_udds / (fuel_kwh_udds / KWH_PER_GGE)\n",
"\n",
"# HWFET calculations\n",
- "sd_hwfet_dict = sd_hwfet.to_pydict(flatten=True)\n",
+ "sd_hwfet_dict = sd_hwfet.to_dict(flatten=True)\n",
"fuel_kwh_hwfet = sd_hwfet_dict[\"veh.pt_type.Conv.fc.state.energy_fuel_joules\"] / 3.6e6\n",
"miles_hwfet = sd_hwfet_dict[\"veh.state.dist_meters\"] / METERS_PER_MILE\n",
"mpg_hwfet = miles_hwfet / (fuel_kwh_hwfet / KWH_PER_GGE)\n",
diff --git a/docs/content/user-guide/running-simulations/trace-miss.ipynb b/docs/content/user-guide/running-simulations/trace-miss.ipynb
index 02e587026..c5356669b 100644
--- a/docs/content/user-guide/running-simulations/trace-miss.ipynb
+++ b/docs/content/user-guide/running-simulations/trace-miss.ipynb
@@ -47,7 +47,7 @@
" \"time_seconds\": [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0],\n",
" \"speed_meters_per_second\": [0.0, 8.0, 8.0, 8.0, 8.0, 8.0, 4.0, 0.0, 0.0],\n",
"}\n",
- "cyc = fastsim.Cycle.from_pydict(cyc_dict)\n",
+ "cyc = fastsim.Cycle.from_dict(cyc_dict)\n",
"\n",
"# Load vehicle\n",
"veh = fastsim.Vehicle.from_resource(\"2012_Ford_Fusion.yaml\")\n"
@@ -101,7 +101,7 @@
"# By default, SimParams uses \"Error\" for trace miss\n",
"sd_error = fastsim.SimDrive(veh, cyc)\n",
"try:\n",
- " sd_error.walk()\n",
+ " sd_error.run()\n",
"except Exception as e:\n",
" print(f\"Expected error: {type(e).__name__}\")\n",
" print(f\"Message (truncated): {str(e)[:100]}...\")\n"
@@ -131,12 +131,12 @@
],
"source": [
"# Use \"Allow\" to silently permit the vehicle to fall behind\n",
- "params = fastsim.SimParams.default().to_pydict()\n",
+ "params = fastsim.SimParams.default().to_dict()\n",
"params[\"trace_miss_opts\"] = \"Allow\"\n",
"\n",
"veh_allow = fastsim.Vehicle.from_resource(\"2012_Ford_Fusion.yaml\")\n",
- "sd_allow = fastsim.SimDrive(veh_allow, cyc, fastsim.SimParams.from_pydict(params))\n",
- "sd_allow.walk()\n",
+ "sd_allow = fastsim.SimDrive(veh_allow, cyc, fastsim.SimParams.from_dict(params))\n",
+ "sd_allow.run()\n",
"\n",
"df_allow = sd_allow.to_dataframe()\n",
"print(f\"Simulation completed without error. {len(df_allow)} time steps recorded.\")\n"
@@ -169,7 +169,7 @@
],
"source": [
"# Use \"AllowChecked\" with custom tolerances\n",
- "params = fastsim.SimParams.default().to_pydict()\n",
+ "params = fastsim.SimParams.default().to_dict()\n",
"params[\"trace_miss_opts\"] = \"AllowChecked\"\n",
"# Very relaxed tolerances for this extremely challenging cycle\n",
"params[\"trace_miss_tol\"] = {\n",
@@ -180,8 +180,8 @@
"}\n",
"\n",
"veh_checked = fastsim.Vehicle.from_resource(\"2012_Ford_Fusion.yaml\")\n",
- "sd_checked = fastsim.SimDrive(veh_checked, cyc, fastsim.SimParams.from_pydict(params))\n",
- "sd_checked.walk()\n",
+ "sd_checked = fastsim.SimDrive(veh_checked, cyc, fastsim.SimParams.from_dict(params))\n",
+ "sd_checked.run()\n",
"\n",
"df_checked = sd_checked.to_dataframe()\n",
"print(f\"Simulation with AllowChecked completed. {len(df_checked)} time steps recorded.\")\n"
@@ -215,13 +215,13 @@
],
"source": [
"# Use \"Correct\" to automatically adjust the driver to catch back up\n",
- "params = fastsim.SimParams.default().to_pydict()\n",
+ "params = fastsim.SimParams.default().to_dict()\n",
"params[\"trace_miss_opts\"] = \"Correct\"\n",
"params[\"trace_miss_correct_max_steps\"] = 6\n",
"\n",
"veh_correct = fastsim.Vehicle.from_resource(\"2012_Ford_Fusion.yaml\")\n",
- "sd_correct = fastsim.SimDrive(veh_correct, cyc, fastsim.SimParams.from_pydict(params))\n",
- "sd_correct.walk()\n",
+ "sd_correct = fastsim.SimDrive(veh_correct, cyc, fastsim.SimParams.from_dict(params))\n",
+ "sd_correct.run()\n",
"\n",
"df_correct = sd_correct.to_dataframe()\n",
"print(f\"Simulation with correction completed. {len(df_correct)} time steps recorded.\")\n"
@@ -1126,7 +1126,7 @@
"}\n",
"\n",
"# Get target distance from cycle (convert time/speed to distance)\n",
- "cyc_dict_py = cyc.to_pydict()\n",
+ "cyc_dict_py = cyc.to_dict()\n",
"cyc_time = np.array(cyc_dict_py[\"time_seconds\"])\n",
"cyc_speed = np.array(cyc_dict_py[\"speed_meters_per_second\"])\n",
"cyc_dist = np.cumsum(cyc_speed * np.diff(cyc_time, prepend=cyc_time[0]))\n",
@@ -2129,7 +2129,7 @@
}
],
"source": [
- "print(f\"Prescribed cycle distance: {cyc.to_pydict()['dist_meters'][-1]} m\")\n",
+ "print(f\"Prescribed cycle distance: {cyc.to_dict()['dist_meters'][-1]} m\")\n",
"print(f\"Achieved cycle distance:\")\n",
"print(f\" trace_miss_opts = 'Allow': {df_allow['veh.history.dist_meters'].iloc[-1]:.1f} m\")\n",
"print(f\" trace_miss_opts = 'AllowChecked': {df_checked['veh.history.dist_meters'].iloc[-1]:.1f} m\")\n",
diff --git a/docs/content/user-guide/vehicle-models/loading-vehicles.ipynb b/docs/content/user-guide/vehicle-models/loading-vehicles.ipynb
index 5ded6afd2..16adac4ee 100644
--- a/docs/content/user-guide/vehicle-models/loading-vehicles.ipynb
+++ b/docs/content/user-guide/vehicle-models/loading-vehicles.ipynb
@@ -96,40 +96,7 @@
"cell_type": "markdown",
"id": "7ce56cb0",
"metadata": {},
- "source": [
- "(3-database)=\n",
- "## Loading from the FASTSim vehicle database\n",
- "\n",
- "The public FASTSim vehicle database is hosted at https://github.com/NatLabRockies/fastsim-vehicles.\n",
- "\n",
- "### Database Structure\n",
- "\n",
- "Vehicles in the database are organized in a machine-searchable directory structure, detailed below:\n",
- "\n",
- "| Level | Description | Example |\n",
- "| --- | --- | --- |\n",
- "| Schema version | Describes the format of subsequent organizational levels. | `v1` |\n",
- "| FASTSim version | Major FASTSim version. | `fastsim-3` |\n",
- "| Powertrain | Powertrain type (e.g. `conv`/`hev`/`phev`/`bev`/`fcev`) | `conv` |\n",
- "| Make | Vehicle make/manufacturer name. | `ford` |\n",
- "| Model | Vehicle model name and any applicable trim information. | `fusion` |\n",
- "| Year | Model year or year range. | `2012` |\n",
- "| Variant | Description of active modeling feature set. | `base` |\n",
- "| Revision | Model revision number for updates and corrections. | `r1` |\n",
- "\n",
- "Example full filepath:\n",
- "\n",
- "`v1/fastsim-3/conv/ford/fusion/2012/base/r1.yaml`\n",
- "\n",
- "### Examples\n",
- "\n",
- "FASTSim provides `Vehicle.from_db` to load from the default database, with flexibility to point to similarly structured databases in the local filesystem or at different URLs (e.g. `https://raw.githubusercontent.com/...`).\n",
- "\n",
- "The below examples load the following vehicle from different database locations:\n",
- "```python\n",
- "vehicle_path = \"v1/fastsim-3/conv/ford/fusion/2012/base/r1\"\n",
- "```"
- ]
+ "source": "(3-database)=\n## Loading from the FASTSim vehicle database\n\nThe public FASTSim vehicle database is hosted at https://github.com/NatLabRockies/fastsim-vehicles. Browse and search it at the [FASTSim Vehicle Database website](https://natlabrockies.github.io/fastsim-vehicles/) to find a vehicle and its path.\n\n### Database Structure\n\nVehicles in the database are organized in a machine-searchable directory structure, detailed below:\n\n| Level | Description | Example |\n| --- | --- | --- |\n| Schema version | Describes the format of subsequent organizational levels. | `v1` |\n| FASTSim version | Major FASTSim version. | `fastsim-3` |\n| Powertrain | Powertrain type (e.g. `conv`/`hev`/`phev`/`bev`/`fcev`) | `conv` |\n| Make | Vehicle make/manufacturer name. | `ford` |\n| Model | Vehicle model name and any applicable trim information. | `fusion` |\n| Year | Model year or year range. | `2012` |\n| Variant | Description of active modeling feature set. | `base` |\n| Revision | Model revision number for updates and corrections. | `r1` |\n\nExample full filepath:\n\n`v1/fastsim-3/conv/ford/fusion/2012/base/r1.yaml`\n\n### Examples\n\nFASTSim provides `Vehicle.from_db` to load from the default database, with flexibility to point to similarly structured databases in the local filesystem or at different URLs (e.g. `https://raw.githubusercontent.com/...`).\n\nThe below examples load the following vehicle from different database locations:\n```python\nvehicle_path = \"v1/fastsim-3/conv/ford/fusion/2012/base/r1\"\n```"
},
{
"cell_type": "markdown",
@@ -221,4 +188,4 @@
},
"nbformat": 4,
"nbformat_minor": 5
-}
+}
\ No newline at end of file
diff --git a/docs/myst.yml b/docs/myst.yml
index 5519100ed..4c30d0a88 100644
--- a/docs/myst.yml
+++ b/docs/myst.yml
@@ -47,7 +47,7 @@ project:
title: Migration Guide
- url: https://github.com/NatLabRockies/fastsim
title: GitHub Repository
- - url: https://github.com/NatLabRockies/fastsim-vehicles
+ - url: https://natlabrockies.github.io/fastsim-vehicles/
title: FASTSim Vehicle Database
- url: https://docs.rs/fastsim-core/latest/fastsim_core/
title: Rust API Documentation
diff --git a/fastsim-core/src/compat/fastsim_2/mod.rs b/fastsim-core/src/compat/fastsim_2/mod.rs
index 1089842c3..1ca58e978 100644
--- a/fastsim-core/src/compat/fastsim_2/mod.rs
+++ b/fastsim-core/src/compat/fastsim_2/mod.rs
@@ -27,7 +27,7 @@ mod tests {
.unwrap();
let f3_veh = Vehicle::try_from(f2_veh).unwrap();
let mut f3_sd = SimDrive::new(f3_veh, cyc.clone(), None);
- assert!(f3_sd.walk().is_ok());
+ assert!(f3_sd.run().is_ok());
let mut f2_sd = f3_sd.to_fastsim2().unwrap();
assert!(f2_sd.sim_drive(None, None).is_ok());
});
diff --git a/fastsim-core/src/drive_cycle/maneuvers.rs b/fastsim-core/src/drive_cycle/maneuvers.rs
index 52ce57ca4..9888bed4c 100644
--- a/fastsim-core/src/drive_cycle/maneuvers.rs
+++ b/fastsim-core/src/drive_cycle/maneuvers.rs
@@ -284,11 +284,11 @@ impl Maneuver {
self.impose_coast = vec![false; cyc_len];
self.idm_target_speed_m_per_s = vec![0.0; cyc_len];
self.cyc0_cache = self.cyc0.build_cache();
- self.walk(cyc_len);
+ self.run(cyc_len);
}
/// Walk from step to step for the maneuver simulation.
- fn walk(&mut self, cyc_len: usize) {
+ fn run(&mut self, cyc_len: usize) {
while self.i < cyc_len {
self.step();
}
@@ -1400,7 +1400,7 @@ mod tests {
man.apply();
let udds_mod = man.cyc;
let mut sd = SimDrive::new(veh, udds_mod, None);
- sd.walk().unwrap();
+ sd.run().unwrap();
}
#[test]
@@ -1420,7 +1420,7 @@ mod tests {
man.apply();
let udds_mod = man.cyc;
let mut sd = SimDrive::new(veh, udds_mod, None);
- sd.walk().unwrap();
+ sd.run().unwrap();
}
#[test]
@@ -1453,6 +1453,6 @@ mod tests {
}
assert!(found_coast);
let mut sd = SimDrive::new(veh, udds_mod, None);
- sd.walk().unwrap();
+ sd.run().unwrap();
}
}
diff --git a/fastsim-core/src/simdrive/mod.rs b/fastsim-core/src/simdrive/mod.rs
index 93a563ba3..0cdcfc175 100644
--- a/fastsim-core/src/simdrive/mod.rs
+++ b/fastsim-core/src/simdrive/mod.rs
@@ -32,17 +32,31 @@ impl SimDrive {
}
/// Run vehicle simulation once
- #[pyo3(name = "walk_once")]
- fn walk_once_py(&mut self) -> anyhow::Result<()> {
- self.walk_once()
+ #[pyo3(name = "run_once")]
+ fn run_once_py(&mut self) -> anyhow::Result<()> {
+ self.run_once()
}
/// Run vehicle simulation, and, if applicable, apply powertrain-specific
- /// corrections (e.g. iterate `walk` until SOC balance is achieved -- i.e. initial
+ /// corrections (e.g. iterate `run` until SOC balance is achieved -- i.e. initial
/// and final SOC are nearly identical)
+ #[pyo3(name = "run")]
+ fn run_py(&mut self) -> anyhow::Result<()> {
+ self.run()
+ }
+
+ /// Deprecated alias for [Self::run_once]
+ #[pyo3(name = "walk_once")]
+ fn walk_once_py(&mut self, py: Python<'_>) -> anyhow::Result<()> {
+ Self::warn_deprecated_walk(py, "walk_once", "run_once");
+ self.run_once()
+ }
+
+ /// Deprecated alias for [Self::run]
#[pyo3(name = "walk")]
- fn walk_py(&mut self) -> anyhow::Result<()> {
- self.walk()
+ fn walk_py(&mut self, py: Python<'_>) -> anyhow::Result<()> {
+ Self::warn_deprecated_walk(py, "walk", "run");
+ self.run()
}
#[pyo3(name = "reset")]
@@ -95,6 +109,19 @@ impl SimDrive {
}
}
+ /// Emit a Python `DeprecationWarning` pointing users from `old_name` to `new_name`
+ #[cfg(feature = "pyo3")]
+ fn warn_deprecated_walk(py: Python<'_>, old_name: &str, new_name: &str) {
+ if let Ok(warnings) = py.import("warnings") {
+ let msg =
+ format!("SimDrive.{old_name} is deprecated; use SimDrive.{new_name} instead.",);
+ let kwargs = PyDict::new(py);
+ let _ = kwargs.set_item("stacklevel", 2);
+ let _ = kwargs.set_item("category", py.get_type::());
+ let _ = warnings.call_method("warn", (msg,), Some(&kwargs));
+ }
+ }
+
// # TODO:
// ## Features
// - [ ] regen limiting curve during speeds approaching zero per f2 -- less urgent
@@ -107,7 +134,7 @@ impl SimDrive {
/// Run vehicle simulation, and, if applicable, apply powertrain-specific
/// corrections:
/// - for HEV, set initial SOC to mean of min and max SOC, and then iterate
- /// `walk` until SOC balance is achieved -- i.e. initial and final SOC are
+ /// `run_once` until SOC balance is achieved -- i.e. initial and final SOC are
/// nearly identical
/// - for PHEV, set initial SOC to max SOC, and then simulate once
/// - for BEV, set initial SOC to max SOC, and then simulate once
@@ -116,8 +143,8 @@ impl SimDrive {
/// # Important Considerations
/// If you need to run a [ReversibleEnergyStorage]-equipped vehicle for
/// only one iteration without modifying the initial SOC, then run the
- /// [Self::walk_once] method directly
- pub fn walk(&mut self) -> anyhow::Result<()> {
+ /// [Self::run_once] method directly
+ pub fn run(&mut self) -> anyhow::Result<()> {
match self.veh.pt_type {
PowertrainType::HybridElectricVehicle(_) => {
// Net battery energy used per amount of fuel used
@@ -140,9 +167,9 @@ impl SimDrive {
.with_context(|| format_dbg!())?
.soc_bal_iters
.increment(1, || format_dbg!())?;
- self.walk_once().map_err(|err| {
+ self.run_once().map_err(|err| {
anyhow::anyhow!(format!(
- "HEV walk_once failed at line {}\ntime step: {}\n with originating error: [{}]",
+ "HEV run_once failed at line {}\ntime step: {}\n with originating error: [{}]",
format_dbg!(),
self.veh.state.i,
err
@@ -229,7 +256,7 @@ impl SimDrive {
.state
.soc
.update(res_mut.max_soc, || format_dbg!())?;
- self.walk_once()?
+ self.run_once()?
}
PowertrainType::BatteryElectricVehicle(_) => {
let res_mut = self.veh.res_mut().with_context(|| format_dbg!())?;
@@ -238,15 +265,20 @@ impl SimDrive {
.state
.soc
.update(res_mut.max_soc, || format_dbg!())?;
- self.walk_once()?
+ self.run_once()?
}
- PowertrainType::ConventionalVehicle(_) => self.walk_once()?,
+ PowertrainType::ConventionalVehicle(_) => self.run_once()?,
}
Ok(())
}
+ #[deprecated(since = "3.1.0", note = "Use SimDrive::run instead")]
+ pub fn walk(&mut self) -> anyhow::Result<()> {
+ self.run()
+ }
+
/// Run vehicle simulation once
- pub fn walk_once(&mut self) -> anyhow::Result<()> {
+ pub fn run_once(&mut self) -> anyhow::Result<()> {
let len = &self.cyc.len_checked().with_context(|| format_dbg!())?;
ensure!(len >= &2, format_dbg!(len < &2));
self.save_state(|| format_dbg!())?;
@@ -309,6 +341,11 @@ impl SimDrive {
Ok(())
}
+ #[deprecated(since = "3.1.0", note = "Use SimDrive::run_once instead")]
+ pub fn walk_once(&mut self) -> anyhow::Result<()> {
+ self.run_once()
+ }
+
/// Calculates the derivative dv/dd (change in speed by change in distance)
/// - speed_m_per_s: the speed at which to evaluate dv/dd (m/s)
/// - grade: the road grade as a decimal fraction
@@ -897,7 +934,7 @@ mod tests {
let _veh = Vehicle::from_resource("2012_Ford_Fusion.yaml", false).unwrap();
let _cyc = Cycle::from_resource("udds.csv", false).unwrap();
let mut sd = SimDrive::new(_veh, _cyc, Default::default());
- sd.walk().unwrap();
+ sd.run().unwrap();
assert!(
*sd.veh.state.i.get_fresh(String::new).unwrap() == sd.cyc.len_checked().unwrap() - 1
);
@@ -920,7 +957,7 @@ mod tests {
let _veh = Vehicle::from_resource("2016_TOYOTA_Prius_Two.yaml", false).unwrap();
let _cyc = Cycle::from_resource("udds.csv", false).unwrap();
let mut sd = SimDrive::new(_veh, _cyc, Default::default());
- sd.walk().unwrap();
+ sd.run().unwrap();
assert!(
*sd.veh.state.i.get_fresh(String::new).unwrap() == sd.cyc.len_checked().unwrap() - 1
);
@@ -1033,7 +1070,7 @@ mod tests {
let mut cyc = _cyc.clone();
cyc.temp_amb_air = vec![*te_amb; cyc.len_checked().unwrap()];
let mut sd = SimDrive::new(veh, cyc, Default::default());
- sd.walk()
+ sd.run()
.with_context(|| {
format!(
"ambient temperature: {}*C\ninit temperature: {}",
@@ -1168,7 +1205,7 @@ mod tests {
dbg!("Running `sd_prep`");
let mut sd_prep = SimDrive::new(veh, prep_cyc, None);
sd_prep
- .walk()
+ .run()
.with_context(|| {
format!(
"\nprep cycle:\nambient temperature: {}*C\ninit temperature: {}",
@@ -1196,7 +1233,7 @@ mod tests {
}),
);
sd_soak
- .walk()
+ .run()
.with_context(|| {
format!(
"\nsoak cycle:\nambient temperature: {}*C\ninit temperature: {}",
@@ -1217,7 +1254,7 @@ mod tests {
dbg!("Running `sd_test`");
let mut sd_test = SimDrive::new(sd_soak.veh.clone(), test_cyc, None);
sd_test
- .walk()
+ .run()
.with_context(|| {
format!(
"\ntest cycle:\nambient temperature: {}*C\ninit temperature: {}",
@@ -1317,7 +1354,7 @@ mod tests {
dbg!("Running `sd_prep`");
let mut sd_prep = SimDrive::new(veh, prep_cyc, None);
sd_prep
- .walk()
+ .run()
.with_context(|| {
format!(
"\nprep cycle:\nambient temperature: {}*C\ninit temperature: {}",
@@ -1345,7 +1382,7 @@ mod tests {
}),
);
sd_soak
- .walk()
+ .run()
.with_context(|| {
format!(
"\nsoak cycle:\nambient temperature: {}*C\ninit temperature: {}",
@@ -1366,7 +1403,7 @@ mod tests {
dbg!("Running `sd_test`");
let mut sd_test = SimDrive::new(sd_soak.veh.clone(), test_cyc, None);
sd_test
- .walk()
+ .run()
.with_context(|| {
format!(
"\ntest cycle:\nambient temperature: {}*C\ninit temperature: {}",
@@ -1395,7 +1432,7 @@ mod tests {
cyc: _cyc,
sim_params: Default::default(),
};
- sd.walk().unwrap();
+ sd.run().unwrap();
assert!(
*sd.veh.state.i.get_fresh(String::new).unwrap() == sd.cyc.len_checked().unwrap() - 1
);
@@ -1489,7 +1526,7 @@ mod tests {
} else {
panic!();
};
- sd.walk()
+ sd.run()
.with_context(|| {
format!(
"ambient temperature: {}*C\ninit temperature: {}",
@@ -1521,7 +1558,7 @@ mod tests {
.update(si::Time::ZERO, || format_dbg!())
.unwrap();
assert!(*sd.veh.state.i.get_fresh(|| format_dbg!()).unwrap() == 0);
- sd.walk()
+ sd.run()
.with_context(|| {
format!(
"ambient temperature: {}*C\ninit temperature: {}",
diff --git a/fastsim-core/src/simdrive/params.rs b/fastsim-core/src/simdrive/params.rs
index 80ee9af64..65f6f6d1c 100644
--- a/fastsim-core/src/simdrive/params.rs
+++ b/fastsim-core/src/simdrive/params.rs
@@ -226,7 +226,7 @@ mod tests {
};
let cyc = crate::drive_cycle::CYC_ACCEL.clone();
let mut sim = SimDrive::new(veh, cyc, Some(params));
- assert!(sim.walk().is_ok());
+ assert!(sim.run().is_ok());
}
#[test]
@@ -243,7 +243,7 @@ mod tests {
..Default::default()
};
let mut sim = SimDrive::new(veh.clone(), cyc.clone(), Some(params));
- assert!(sim.walk().is_err());
+ assert!(sim.run().is_err());
// meets modified tolerances
let params = SimParams {
trace_miss_opts: TraceMissOptions::AllowChecked,
@@ -256,7 +256,7 @@ mod tests {
..Default::default()
};
let mut sim = SimDrive::new(veh.clone(), cyc.clone(), Some(params));
- sim.walk().unwrap();
+ sim.run().unwrap();
// misses mixed tolerances
let params = SimParams {
trace_miss_opts: TraceMissOptions::AllowChecked,
@@ -269,7 +269,7 @@ mod tests {
..Default::default()
};
let mut sim = SimDrive::new(veh.clone(), cyc.clone(), Some(params));
- assert!(sim.walk().is_err());
+ assert!(sim.run().is_err());
// misses mixed tolerances
let params = SimParams {
trace_miss_opts: TraceMissOptions::AllowChecked,
@@ -282,7 +282,7 @@ mod tests {
..Default::default()
};
let mut sim = SimDrive::new(veh.clone(), cyc.clone(), Some(params));
- assert!(sim.walk().is_err());
+ assert!(sim.run().is_err());
// misses mixed tolerances
let params = SimParams {
trace_miss_opts: TraceMissOptions::AllowChecked,
@@ -295,7 +295,7 @@ mod tests {
..Default::default()
};
let mut sim = SimDrive::new(veh.clone(), cyc.clone(), Some(params));
- assert!(sim.walk().is_err());
+ assert!(sim.run().is_err());
}
// TODO: implement when TraceMissOptions::Warn is implemented
@@ -327,7 +327,7 @@ mod tests {
};
let cyc = crate::drive_cycle::CYC_ACCEL.clone();
let mut sim = SimDrive::new(veh, cyc, Some(params));
- assert!(sim.walk().is_err());
+ assert!(sim.run().is_err());
}
// TODO: why does sim.cyc.speed have spikes? sim.veh.history.speed_ach seems reasonable
@@ -344,6 +344,6 @@ mod tests {
};
let cyc = crate::drive_cycle::CYC_ACCEL.clone();
let mut sim = SimDrive::new(veh, cyc, Some(params));
- sim.walk().unwrap();
+ sim.run().unwrap();
}
}
diff --git a/fastsim-core/src/simdrivelabel/mod.rs b/fastsim-core/src/simdrivelabel/mod.rs
index 46f46829a..42ce6f4f0 100644
--- a/fastsim-core/src/simdrivelabel/mod.rs
+++ b/fastsim-core/src/simdrivelabel/mod.rs
@@ -73,9 +73,9 @@ pub fn run_accel(
sim_params.get("accel").cloned(),
);
sd_accel.sim_params.trace_miss_opts = TraceMissOptions::Allow;
- sd_accel.walk_once().map_err(|e| {
+ sd_accel.run_once().map_err(|e| {
anyhow!(
- "Acceleration simdrive walk_once failed at line {} with originating error [{}]",
+ "Acceleration simdrive run_once failed at line {} with originating error [{}]",
format_dbg!(),
e
)
@@ -98,9 +98,9 @@ pub fn run_accel(
/// Returns time [s] for 0-60 mph acceleration at max power
pub fn get_0_to_60_time(sd_accel: &mut SimDrive) -> anyhow::Result {
sd_accel.sim_params.trace_miss_opts = TraceMissOptions::Allow;
- sd_accel.walk_once().map_err(|e| {
+ sd_accel.run_once().map_err(|e| {
anyhow!(
- "Acceleration simdrive walk_once failed at line {} with originating error [{}]",
+ "Acceleration simdrive run_once failed at line {} with originating error [{}]",
format_dbg!(),
e
)
@@ -1003,7 +1003,7 @@ fn run_simdrive_with_init_soc(
sd.reset_cumulative(|| format_dbg!())?;
sd.reset_step(|| format_dbg!())?;
sd.clear();
- sd.walk_once().map_err(|e| {
+ sd.run_once().map_err(|e| {
anyhow!(
"run_simdrive_with_init_soc failed at line {} with originating error [{}]",
format_dbg!(),
@@ -1063,7 +1063,7 @@ pub fn run_label_simulations(
);
for (k, val) in sd.iter_mut() {
- val.walk().map_err(|e| {
+ val.run().map_err(|e| {
anyhow!(
"run_label_simulations failed for key {} at line {} with originating error [{}]",
k,
@@ -1491,7 +1491,7 @@ pub fn get_label_fe_phev(
// This runs 1 cycle starting at max SOC then runs 1 cycle starting at min SOC.
// By assuming that the battery SOC depletion per mile is constant across cycles,
// the first cycle can be extrapolated until charge sustaining kicks in.
- sd.walk()?;
+ sd.run()?;
let mut phev_calc = PHEVCycleCalc::default();
// charge depletion cycle has already been simulated
@@ -1575,9 +1575,9 @@ pub fn get_label_fe_phev(
sd.reset_cumulative(|| format_dbg!())?;
sd.reset_step(|| format_dbg!())?;
sd.clear();
- sd.walk_once().map_err(|err| {
+ sd.run_once().map_err(|err| {
anyhow!(
- "walk_once failed at line {} with originating error {}",
+ "run_once failed at line {} with originating error {}",
format_dbg!(),
err
)
@@ -1597,9 +1597,9 @@ pub fn get_label_fe_phev(
sd.reset_cumulative(|| format_dbg!())?;
sd.reset_step(|| format_dbg!())?;
sd.clear();
- sd.walk_once().map_err(|err| {
+ sd.run_once().map_err(|err| {
anyhow!(
- "walk_once failed at line {} with originating error {}",
+ "run_once failed at line {} with originating error {}",
format_dbg!(),
err
)
diff --git a/fastsim-core/src/vehicle/hev.rs b/fastsim-core/src/vehicle/hev.rs
index 8c9ee7cf7..b5c88b44b 100644
--- a/fastsim-core/src/vehicle/hev.rs
+++ b/fastsim-core/src/vehicle/hev.rs
@@ -32,7 +32,7 @@ pub struct HybridElectricVehicle {
/// vector of SOC balance iterations
#[serde(default)]
pub soc_bal_iter_history: Vec,
- /// Number of `walk` iterations required to achieve SOC balance (i.e. SOC
+ /// Number of `run` iterations required to achieve SOC balance (i.e. SOC
/// ends at same starting value, ensuring no net [ReversibleEnergyStorage] usage)
#[serde(default)]
pub soc_bal_iters: TrackedState,
diff --git a/fastsim-core/src/vehicle/vehicle_model.rs b/fastsim-core/src/vehicle/vehicle_model.rs
index bcc32cc1b..d54dfe375 100644
--- a/fastsim-core/src/vehicle/vehicle_model.rs
+++ b/fastsim-core/src/vehicle/vehicle_model.rs
@@ -1797,11 +1797,11 @@ pub(crate) mod tests {
let veh = veh_result.unwrap();
let cyc = crate::drive_cycle::Cycle::from_resource("udds.csv", false).unwrap();
let mut sd = crate::simdrive::SimDrive::new(veh, cyc, Default::default());
- let walk_result = sd.walk();
- if let Err(err) = walk_result {
+ let run_result = sd.run();
+ if let Err(err) = run_result {
panic!("Error: {}", err);
}
- assert!(walk_result.is_ok());
+ assert!(run_result.is_ok());
}
fn accumulate_for_zero_speed(speeds_mps: &[f64], fuels_mj: &[f64]) -> f64 {
@@ -1825,13 +1825,13 @@ pub(crate) mod tests {
let veh_conv = veh_conv_result.unwrap();
let cyc = crate::drive_cycle::Cycle::from_resource("udds.csv", false).unwrap();
let mut sd_uhev = crate::simdrive::SimDrive::new(veh_uhev, cyc.clone(), Default::default());
- let result_uhev = sd_uhev.walk();
+ let result_uhev = sd_uhev.run();
if let Err(err) = result_uhev {
panic!("Error: {}", err);
}
assert!(result_uhev.is_ok());
let mut sd_conv = crate::simdrive::SimDrive::new(veh_conv, cyc.clone(), Default::default());
- let result_conv = sd_conv.walk();
+ let result_conv = sd_conv.run();
assert!(result_conv.is_ok());
let speeds_mps: Vec = cyc
.speed
@@ -1882,13 +1882,13 @@ pub(crate) mod tests {
let veh_conv = veh_conv_result.unwrap();
let cyc = crate::drive_cycle::Cycle::from_resource("udds.csv", false).unwrap();
let mut sd_ss = crate::simdrive::SimDrive::new(veh_ss, cyc.clone(), Default::default());
- let result_ss = sd_ss.walk();
+ let result_ss = sd_ss.run();
if let Err(err) = result_ss {
panic!("Error: {}", err);
}
assert!(result_ss.is_ok());
let mut sd_conv = crate::simdrive::SimDrive::new(veh_conv, cyc.clone(), Default::default());
- let result_conv = sd_conv.walk();
+ let result_conv = sd_conv.run();
assert!(result_conv.is_ok());
let speeds_mps: Vec = cyc
.speed
@@ -2018,13 +2018,13 @@ pub(crate) mod tests {
let veh_dfco = veh_dfco_result.unwrap();
let cyc = crate::drive_cycle::Cycle::from_resource("udds.csv", false).unwrap();
let mut sd = crate::simdrive::SimDrive::new(veh, cyc.clone(), Default::default());
- let sd_result = sd.walk();
+ let sd_result = sd.run();
if let Err(err) = sd_result {
panic!("Error: {}", err);
}
assert!(sd_result.is_ok());
let mut sd_dfco = crate::simdrive::SimDrive::new(veh_dfco, cyc.clone(), Default::default());
- let sd_dfco_result = sd_dfco.walk();
+ let sd_dfco_result = sd_dfco.run();
assert!(sd_dfco_result.is_ok());
let fc = sd.veh.pt_type.fc().unwrap();
let fc_dfco = sd_dfco.veh.pt_type.fc().unwrap();
diff --git a/python/fastsim/__init__.py b/python/fastsim/__init__.py
index 306c47493..900439986 100644
--- a/python/fastsim/__init__.py
+++ b/python/fastsim/__init__.py
@@ -93,7 +93,7 @@ def cyc_keys() -> list[str]:
]
-def to_pydict(self, data_fmt: str = "msg_pack", flatten: bool = False) -> dict:
+def to_dict(self, data_fmt: str = "msg_pack", flatten: bool = False) -> dict:
"""
Return self converted to pure python dictionary with no nested Rust objects
@@ -188,7 +188,7 @@ def get_flattened(obj: dict | list, hist_len: int | None, prepend_str: str = "")
@classmethod # type: ignore[misc]
-def from_pydict(cls, pydict: dict, data_fmt: str = "msg_pack", skip_init: bool = False) -> Self: # type: ignore[misc]
+def from_dict(cls, pydict: dict, data_fmt: str = "msg_pack", skip_init: bool = False) -> Self: # type: ignore[misc]
"""
Instantiate Self from pure python dictionary
@@ -217,6 +217,27 @@ def from_pydict(cls, pydict: dict, data_fmt: str = "msg_pack", skip_init: bool =
return obj
+def to_pydict(self, data_fmt: str = "msg_pack", flatten: bool = False) -> dict:
+ """Use `to_dict` instead; deprecated."""
+ warnings.warn(
+ "`to_pydict` is deprecated; use `to_dict` instead.",
+ DeprecationWarning,
+ stacklevel=2,
+ )
+ return self.to_dict(data_fmt=data_fmt, flatten=flatten)
+
+
+@classmethod # type: ignore[misc]
+def from_pydict(cls, pydict: dict, data_fmt: str = "msg_pack", skip_init: bool = False) -> Self: # type: ignore[misc]
+ """Use `from_dict` instead; deprecated."""
+ warnings.warn(
+ "`from_pydict` is deprecated; use `from_dict` instead.",
+ DeprecationWarning,
+ stacklevel=2,
+ )
+ return cls.from_dict(pydict, data_fmt=data_fmt, skip_init=skip_init)
+
+
def to_dataframe(
self,
backend: str = "pandas",
@@ -253,7 +274,7 @@ def to_dataframe(
use_pandas = backend == "pandas"
- obj_dict = self.to_pydict(flatten=True)
+ obj_dict = self.to_dict(flatten=True)
history_keys = ["history.", "cyc."]
hist_len = get_hist_len(obj_dict)
@@ -301,7 +322,7 @@ def to_dataframe(
def _plot_cycle(
self: Cycle, x="time_seconds", y="speed_meters_per_second", show=True
) -> go._figure.Figure:
- cyc_dict = self.to_pydict()
+ cyc_dict = self.to_dict()
if x not in cyc_dict:
raise ValueError(f"Column '{x}' not found in the drive cycle data")
if y not in cyc_dict:
@@ -401,6 +422,8 @@ def _vehicle_from_db(
# adds variable_path_list() and history_path_list() as methods to all classes in
# ACCEPTED_RUST_STRUCTS
for item in ACCEPTED_RUST_STRUCTS:
+ setattr(getattr(fastsim, item), "to_dict", to_dict)
+ setattr(getattr(fastsim, item), "from_dict", from_dict)
setattr(getattr(fastsim, item), "to_pydict", to_pydict)
setattr(getattr(fastsim, item), "from_pydict", from_pydict)
setattr(getattr(fastsim, item), "to_dataframe", to_dataframe)
diff --git a/python/fastsim/fastsim.pyi b/python/fastsim/fastsim.pyi
index 4f7ac247a..f5fa5a811 100644
--- a/python/fastsim/fastsim.pyi
+++ b/python/fastsim/fastsim.pyi
@@ -15,13 +15,25 @@ class SerdeAPI:
def from_resource(cls, resource_path: str | Path, skip_init: bool = False) -> Self: ...
@classmethod
def from_url(cls, url: str, skip_init: bool = False) -> Self: ...
- def to_pydict(self, data_fmt: str = "msg_pack", flatten: bool = False) -> dict: ...
+ def to_pydict(self, data_fmt: str = "msg_pack", flatten: bool = False) -> dict:
+ """Use `to_dict` instead; deprecated."""
+ ...
@classmethod
def from_pydict(
cls,
pydict: dict,
data_fmt: str = "msg_pack",
skip_init: bool = False,
+ ) -> Self:
+ """Use `from_dict` instead; deprecated."""
+ ...
+ def to_dict(self, data_fmt: str = "msg_pack", flatten: bool = False) -> dict: ...
+ @classmethod
+ def from_dict(
+ cls,
+ pydict: dict,
+ data_fmt: str = "msg_pack",
+ skip_init: bool = False,
) -> Self: ...
def to_str(self, str_fmt: str) -> str: ...
@classmethod
@@ -243,8 +255,14 @@ class Vehicle(SerdeAPI):
class SimDrive(SerdeAPI):
def __new__(cls, veh: Vehicle, cyc: Cycle, sim_params: SimParams | None = None) -> SimDrive: ...
- def walk_once(self) -> bool: ...
- def walk(self) -> bool: ...
+ def run_once(self) -> bool: ...
+ def run(self) -> bool: ...
+ def walk_once(self) -> bool:
+ """Deprecated: use `run_once` instead."""
+ ...
+ def walk(self) -> bool:
+ """Deprecated: use `run` instead."""
+ ...
def to_dataframe(
self,
backend: str = "pandas",
diff --git a/python/fastsim/pymoo_api.py b/python/fastsim/pymoo_api.py
index 57c3ef8c3..3d3bb0441 100644
--- a/python/fastsim/pymoo_api.py
+++ b/python/fastsim/pymoo_api.py
@@ -163,7 +163,7 @@ def update_params(self, xs: list[Any]):
for key, pydict in self.models.items():
try:
- sim_drives[key] = fsim.SimDrive.from_pydict(pydict, skip_init=False)
+ sim_drives[key] = fsim.SimDrive.from_dict(pydict, skip_init=False)
except Exception as err:
sim_drives[key] = err
t1 = time.perf_counter()
@@ -207,21 +207,21 @@ def get_errors(
# continue
if return_mods:
- unsolved_mods[key] = sd.to_pydict()
+ unsolved_mods[key] = sd.to_dict()
try:
t0 = time.perf_counter()
- sd.walk_once() # type: ignore
+ sd.run_once() # type: ignore
t1 = time.perf_counter()
- sd_dict = sd.to_pydict()
- walk_success = True
+ sd_dict = sd.to_dict()
+ run_success = True
except RuntimeError as err:
t1 = time.perf_counter()
- sd_dict = sd.to_pydict()
- walk_success = True
+ sd_dict = sd.to_dict()
+ run_success = True
print(err)
if len(sd_dict["veh"]["history"]["time_seconds"]) < np.floor(len(df_exp) / 2):
- walk_success = False
+ run_success = False
if self.verbose:
print(f"Time to simulate {key}: {t1 - t0:.3g}")
@@ -253,7 +253,7 @@ def get_errors(
time_s = sd_dict["veh"]["history"]["time_seconds"]
# TODO: provision for incomplete simulation in here somewhere
- if not walk_success:
+ if not run_success:
objectives[key].append(1.02e12)
else:
try:
diff --git a/python/fastsim/tests/test_serde.py b/python/fastsim/tests/test_serde.py
index c1bf320ae..1b2764a21 100644
--- a/python/fastsim/tests/test_serde.py
+++ b/python/fastsim/tests/test_serde.py
@@ -1,4 +1,7 @@
import time
+
+import pytest
+
import fastsim as fsim
@@ -16,24 +19,24 @@ def get_solved_sd():
sd = fsim.SimDrive(veh, cyc)
# run simulation
- sd.walk()
+ sd.run()
return sd
-def test_pydict():
+def test_dict():
sd = get_solved_sd()
t0 = time.perf_counter_ns()
- sd_dict_msg = sd.to_pydict(flatten=False, data_fmt="msg_pack")
- sd_msg = fsim.SimDrive.from_pydict(sd_dict_msg, data_fmt="msg_pack")
+ sd_dict_msg = sd.to_dict(flatten=False, data_fmt="msg_pack")
+ sd_msg = fsim.SimDrive.from_dict(sd_dict_msg, data_fmt="msg_pack")
t1 = time.perf_counter_ns()
t_msg = t1 - t0
print(f"\nElapsed time for MessagePack: {t_msg:.3e} ns ")
t0 = time.perf_counter_ns()
- sd_dict_yaml = sd.to_pydict(flatten=False, data_fmt="yaml")
- sd_yaml = fsim.SimDrive.from_pydict(sd_dict_yaml, data_fmt="yaml")
+ sd_dict_yaml = sd.to_dict(flatten=False, data_fmt="yaml")
+ sd_yaml = fsim.SimDrive.from_dict(sd_dict_yaml, data_fmt="yaml")
t1 = time.perf_counter_ns()
t_yaml = t1 - t0
print(f"Elapsed time for YAML: {t_yaml:.3e} ns ")
@@ -41,16 +44,26 @@ def test_pydict():
# NOTE: this is commented out because of sketchy NAN/null handling
# t0 = time.perf_counter_ns()
- # sd_dict_json = sd.to_pydict(flatten=False, data_fmt="json")
- # _sd_json = fsim.SimDrive.from_pydict(sd_dict_json, data_fmt="json", skip_init=True)
+ # sd_dict_json = sd.to_dict(flatten=False, data_fmt="json")
+ # _sd_json = fsim.SimDrive.from_dict(sd_dict_json, data_fmt="json", skip_init=True)
# t1 = time.perf_counter_ns()
# t_json = t1 - t0
# print(f"Elapsed time for json: {t_json:.3e} ns ")
# print(f"JSON time per MessagePack time: {(t_json / t_msg):.3e} ")
# these fail because of nan and other stuff that does not matter
- # assert sd_msg.to_pydict(data_fmt="msg_pack") == sd.to_pydict(data_fmt="msg_pack")
- # assert sd_yaml.to_pydict(data_fmt="yaml") == sd.to_pydict(data_fmt="yaml")
+ # assert sd_msg.to_dict(data_fmt="msg_pack") == sd.to_dict(data_fmt="msg_pack")
+ # assert sd_yaml.to_dict(data_fmt="yaml") == sd.to_dict(data_fmt="yaml")
+
+
+def test_pydict_deprecated():
+ """`to_pydict`/`from_pydict` are deprecated aliases for `to_dict`/`from_dict`."""
+ sd = get_solved_sd()
+
+ with pytest.deprecated_call():
+ sd_dict_msg = sd.to_pydict(flatten=False, data_fmt="msg_pack")
+ with pytest.deprecated_call():
+ fsim.SimDrive.from_pydict(sd_dict_msg, data_fmt="msg_pack")
def test_dataframe():