diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 489be18e..8823a5a7 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -17,7 +17,7 @@ codegen-units = 1 # optimize connection between modules [workspace.dependencies] anyhow = "1.0.57" ndarray = { version = "0.15.4", features = ["serde"] } -pyo3 = "0.21" +pyo3 = "0.22.4" pyo3-log = "*" serde = "1.0.143" serde_json = "1.0.83" diff --git a/rust/fastsim-core/fastsim-proc-macros/src/add_pyo3_api/mod.rs b/rust/fastsim-core/fastsim-proc-macros/src/add_pyo3_api/mod.rs index f8899414..b6519add 100644 --- a/rust/fastsim-core/fastsim-proc-macros/src/add_pyo3_api/mod.rs +++ b/rust/fastsim-core/fastsim-proc-macros/src/add_pyo3_api/mod.rs @@ -215,6 +215,7 @@ pub fn add_pyo3_api(attr: TokenStream, item: TokenStream) -> TokenStream { #[cfg(feature = "resources")] #[staticmethod] #[pyo3(name = "from_resource")] + #[pyo3(signature = (filepath, skip_init=None))] pub fn from_resource_py(filepath: &Bound, skip_init: Option) -> PyResult { Self::from_resource( PathBuf::extract_bound(filepath)?, @@ -246,6 +247,7 @@ pub fn add_pyo3_api(attr: TokenStream, item: TokenStream) -> TokenStream { /// #[staticmethod] #[pyo3(name = "from_file")] + #[pyo3(signature = (filepath, skip_init=None))] pub fn from_file_py(filepath: &Bound, skip_init: Option) -> PyResult { Self::from_file( PathBuf::extract_bound(filepath)?, @@ -274,6 +276,7 @@ pub fn add_pyo3_api(attr: TokenStream, item: TokenStream) -> TokenStream { /// #[staticmethod] #[pyo3(name = "from_str")] + #[pyo3(signature = (contents, format, skip_init=None))] pub fn from_str_py(contents: &str, format: &str, skip_init: Option) -> PyResult { Self::from_str(contents, format, skip_init.unwrap_or_default()).map_err(|e| PyIOError::new_err(format!("{:?}", e))) } @@ -292,6 +295,7 @@ pub fn add_pyo3_api(attr: TokenStream, item: TokenStream) -> TokenStream { /// #[staticmethod] #[pyo3(name = "from_json")] + #[pyo3(signature = (json_str, skip_init=None))] pub fn from_json_py(json_str: &str, skip_init: Option) -> PyResult { Self::from_json(json_str, skip_init.unwrap_or_default()).map_err(|e| PyIOError::new_err(format!("{:?}", e))) } @@ -310,6 +314,7 @@ pub fn add_pyo3_api(attr: TokenStream, item: TokenStream) -> TokenStream { /// #[staticmethod] #[pyo3(name = "from_yaml")] + #[pyo3(signature = (yaml_str, skip_init=None))] pub fn from_yaml_py(yaml_str: &str, skip_init: Option) -> PyResult { Self::from_yaml(yaml_str, skip_init.unwrap_or_default()).map_err(|e| PyIOError::new_err(format!("{:?}", e))) } diff --git a/rust/fastsim-core/src/cycle.rs b/rust/fastsim-core/src/cycle.rs index b8114432..678bd906 100644 --- a/rust/fastsim-core/src/cycle.rs +++ b/rust/fastsim-core/src/cycle.rs @@ -487,6 +487,7 @@ impl RustCycleCache { #[staticmethod] #[pyo3(name = "from_csv")] + #[pyo3(signature = (filepath, skip_init=None))] pub fn from_csv_py(filepath: &Bound, skip_init: Option) -> anyhow::Result { Self::from_csv_file(PathBuf::extract_bound(filepath)?, skip_init.unwrap_or_default()) } @@ -496,6 +497,7 @@ impl RustCycleCache { } #[staticmethod] + #[pyo3(signature = (dict, skip_init=None))] pub fn from_dict(dict: &Bound, skip_init: Option) -> PyResult { let time_s = Array::from_vec(dict.get_item("time_s")?.with_context(|| format_dbg!())?.extract()?); let cyc_len = time_s.len(); @@ -520,17 +522,8 @@ impl RustCycleCache { } else { Array::default(cyc_len) }, - // name: PyAny::get_item(dict, "name").and_then(String::extract).unwrap_or_default(), name: if let Ok(Some(item_res)) = dict.get_item("name") { - if let Ok(name) = item_res.extract() { - if let Ok(name_str) = String::extract(name) { - name_str - } else { - Default::default() - } - } else { - Default::default() - } + String::extract_bound(&item_res).unwrap_or_default() } else { Default::default() }, @@ -569,6 +562,7 @@ impl RustCycleCache { } #[pyo3(name = "modify_with_braking_trajectory")] + #[pyo3(signature = (brake_accel_m_per_s2, idx, dts_m=None))] pub fn modify_with_braking_trajectory_py( &mut self, brake_accel_m_per_s2: f64, diff --git a/rust/fastsim-core/src/simdrive.rs b/rust/fastsim-core/src/simdrive.rs index 26fcf0b6..ef8fef82 100644 --- a/rust/fastsim-core/src/simdrive.rs +++ b/rust/fastsim-core/src/simdrive.rs @@ -198,6 +198,7 @@ impl Default for RustSimDriveParams { } #[pyo3(name = "sim_drive")] + #[pyo3(signature = (init_soc=None, aux_in_kw_override=None))] /// Initialize and run sim_drive_walk as appropriate for vehicle attribute vehPtType. /// Arguments /// ------------ @@ -213,6 +214,7 @@ impl Default for RustSimDriveParams { self.sim_drive(init_soc, aux_in_kw_override) } + #[pyo3(signature = (init_soc, aux_in_kw_override=None))] /// Receives second-by-second cycle information, vehicle properties, /// and an initial state of charge and runs sim_drive_step to perform a /// backward facing powertrain simulation. Method 'sim_drive' runs this @@ -233,6 +235,7 @@ impl Default for RustSimDriveParams { self.walk(init_soc, aux_in_kw_override) } + #[pyo3(signature = (by_microtrip=None, extend_fraction=None, blend_factor=None, min_target_speed_m_per_s=None))] /// Sets the intelligent driver model parameters for an eco-cruise driving trajectory. /// This is a convenience method instead of setting the sim_params.idm* parameters yourself. /// - by_microtrip: bool, if True, target speed is set by microtrip, else by cycle @@ -257,6 +260,7 @@ impl Default for RustSimDriveParams { } #[pyo3(name = "init_for_step")] + #[pyo3(signature = (init_soc, aux_in_kw_override=None))] /// This is a specialty method which should be called prior to using /// sim_drive_step in a loop. /// Arguments diff --git a/rust/fastsim-core/src/simdrive/simdrive_iter.rs b/rust/fastsim-core/src/simdrive/simdrive_iter.rs index 98c5e88a..7b8e08ea 100644 --- a/rust/fastsim-core/src/simdrive/simdrive_iter.rs +++ b/rust/fastsim-core/src/simdrive/simdrive_iter.rs @@ -11,6 +11,7 @@ use rayon::prelude::*; #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] #[add_pyo3_api( #[pyo3(name = "sim_drive")] + #[pyo3(signature = (parallelize=None))] /// Calls `sim_drive` method for each simdrive instance in vec. /// # Arguments: /// * parallelize: whether to parallelize `sim_drive` calls, defaults to `true` diff --git a/rust/fastsim-core/src/simdrivelabel.rs b/rust/fastsim-core/src/simdrivelabel.rs index 263d82d8..ea019e04 100644 --- a/rust/fastsim-core/src/simdrivelabel.rs +++ b/rust/fastsim-core/src/simdrivelabel.rs @@ -388,6 +388,7 @@ pub fn get_label_fe( #[cfg(feature = "pyo3")] #[pyfunction(name = "get_label_fe")] +#[pyo3(signature = (veh, full_detail=None, verbose=None))] /// pyo3 version of [get_label_fe] pub fn get_label_fe_py( veh: &vehicle::RustVehicle, diff --git a/rust/fastsim-core/src/thermal.rs b/rust/fastsim-core/src/thermal.rs index 794d04fe..c27e6801 100644 --- a/rust/fastsim-core/src/thermal.rs +++ b/rust/fastsim-core/src/thermal.rs @@ -14,6 +14,7 @@ use crate::vehicle_thermal::*; #[add_pyo3_api( /// method for instantiating SimDriveHot #[new] + #[pyo3(signature = (cyc, veh, vehthrm, init_state=None, amb_te_deg_c=None))] pub fn __new__( cyc: cycle::RustCycle, veh: vehicle::RustVehicle, @@ -30,6 +31,7 @@ use crate::vehicle_thermal::*; Ok(self.gap_to_lead_vehicle_m().to_vec()) } #[pyo3(name = "sim_drive")] + #[pyo3(signature = (init_soc=None, aux_in_kw_override=None))] /// Initialize and run sim_drive_walk as appropriate for vehicle attribute vehPtType. /// Arguments /// ------------ @@ -45,6 +47,7 @@ use crate::vehicle_thermal::*; self.sim_drive(init_soc, aux_in_kw_override) } + #[pyo3(signature = (init_soc, aux_in_kw_override=None))] /// Receives second-by-second cycle information, vehicle properties, /// and an initial state of charge and runs sim_drive_step to perform a /// backward facing powertrain simulation. Method 'sim_drive' runs this @@ -66,6 +69,7 @@ use crate::vehicle_thermal::*; } #[pyo3(name = "init_for_step")] + #[pyo3(signature = (init_soc, aux_in_kw_override=None))] /// This is a specialty method which should be called prior to using /// sim_drive_step in a loop. /// Arguments @@ -983,6 +987,13 @@ impl SimDriveHot { #[add_pyo3_api( #[new] + #[pyo3(signature = ( + amb_te_deg_c=None, + fc_te_deg_c_init=None, + cab_te_deg_c_init=None, + exhport_te_deg_c_init=None, + cat_te_deg_c_init=None, + ))] pub fn __new__( amb_te_deg_c: Option, fc_te_deg_c_init: Option, diff --git a/rust/fastsim-core/src/vehicle_import.rs b/rust/fastsim-core/src/vehicle_import.rs index dd8da853..18d907b0 100644 --- a/rust/fastsim-core/src/vehicle_import.rs +++ b/rust/fastsim-core/src/vehicle_import.rs @@ -286,6 +286,13 @@ pub struct VehicleDataEPA { impl SerdeAPI for VehicleDataEPA {} #[cfg_attr(feature = "pyo3", pyfunction)] +#[pyo3(signature = ( + year, + make, + model, + cache_url=None, + data_dir=None, +))] /// Gets options from fueleconomy.gov for the given vehicle year, make, and model /// /// Arguments: @@ -335,6 +342,12 @@ pub fn get_options_for_year_make_model( } #[cfg_attr(feature = "pyo3", pyfunction)] +#[pyo3(signature = ( + id, + year, + cache_url=None, + data_dir=None, +))] pub fn get_vehicle_data_for_id( id: i32, year: &str, @@ -720,6 +733,15 @@ fn match_epatest_with_fegov( #[derive(Default, PartialEq, Clone, Debug, Deserialize, Serialize)] #[add_pyo3_api( #[new] + #[pyo3(signature = ( + vehicle_width_in, + vehicle_height_in, + fuel_tank_gal, + ess_max_kwh, + mc_max_kw, + ess_max_kw, + fc_max_kw=None + ))] pub fn __new__( vehicle_width_in: f64, vehicle_height_in: f64, @@ -753,6 +775,13 @@ pub struct OtherVehicleInputs { impl SerdeAPI for OtherVehicleInputs {} #[cfg_attr(feature = "pyo3", pyfunction)] +#[pyo3(signature = ( + vehicle_id, + year, + other_inputs, + cache_url=None, + data_dir=None, +))] /// Creates RustVehicle for the given vehicle using data from fueleconomy.gov and EPA databases /// The created RustVehicle is also written as a yaml file /// @@ -1287,7 +1316,14 @@ fn load_fegov_data_for_given_years>( Ok(data) } #[cfg_attr(feature = "pyo3", pyfunction)] - +#[pyo3(signature = ( + year, + make, + model, + other_inputs, + cache_url=None, + data_dir=None, +))] /// Import All Vehicles for the given Year, Make, and Model and supplied other inputs pub fn import_all_vehicles( year: u32, diff --git a/rust/fastsim-core/src/vehicle_utils.rs b/rust/fastsim-core/src/vehicle_utils.rs index 0bdf4081..ad3615c2 100644 --- a/rust/fastsim-core/src/vehicle_utils.rs +++ b/rust/fastsim-core/src/vehicle_utils.rs @@ -27,6 +27,17 @@ pub const NETWORK_TEST_DISABLE_ENV_VAR_NAME: &str = "FASTSIM_DISABLE_NETWORK_TES #[cfg_attr(feature = "pyo3", pyfunction)] #[allow(clippy::too_many_arguments)] #[cfg(feature = "default")] +#[pyo3(signature = ( + veh, + a_lbf, + b_lbf__mph, + c_lbf__mph2, + custom_rho=None, + custom_rho_temp_degC=None, + custom_rho_elevation_m=None, + simdrive_optimize=None, + _show_plots=None, +))] pub fn abc_to_drag_coeffs( veh: &mut RustVehicle, a_lbf: f64,