From e835f20bc85802ffc31e8e603fdfcda7471eeb1a Mon Sep 17 00:00:00 2001 From: Chad Baker Date: Fri, 27 Oct 2023 16:17:51 -0600 Subject: [PATCH 1/7] better doc string --- rust/altrios-core/src/consist/locomotive/locomotive_model.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/altrios-core/src/consist/locomotive/locomotive_model.rs b/rust/altrios-core/src/consist/locomotive/locomotive_model.rs index f0d7ca32..f76777c8 100644 --- a/rust/altrios-core/src/consist/locomotive/locomotive_model.rs +++ b/rust/altrios-core/src/consist/locomotive/locomotive_model.rs @@ -389,8 +389,8 @@ pub struct Locomotive { pub assert_limits: bool, /// constant aux load pub pwr_aux_offset: si::Power, - /// gain for linear model on traciton hp use to compute linear aux - /// load + /// gain for linear model on traction power used to compute traction-power-dependent component + /// of aux load, in terms of ratio of aux power per tractive power pub pwr_aux_traction_coeff: si::Ratio, /// maximum tractive force #[api(skip_get, skip_set)] From c84e2dbee55a9db9ef14eb17b38e0941c199d739 Mon Sep 17 00:00:00 2001 From: Chad Baker Date: Mon, 30 Oct 2023 12:02:43 -0600 Subject: [PATCH 2/7] changed str to Path --- applications/calibration/cleaning_traction.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/applications/calibration/cleaning_traction.py b/applications/calibration/cleaning_traction.py index 99106da1..c12975c5 100644 --- a/applications/calibration/cleaning_traction.py +++ b/applications/calibration/cleaning_traction.py @@ -4,7 +4,10 @@ import re import numpy as np -directory = 'C:\\Users\\phartnett\\Altrios_private\\altrios-private\\data\\trips\\ZANZEFF Data - v5.1 1-27-23 ALTRIOS Confidential\\ZANZEFF Data - v5 1-27-23 ALTRIOS Confidential\\' +directory = Path().home() /\ + 'Altrios_private/altrios-private/data/trips/ZANZEFF Data - v5.1 1-27-23 ALTRIOS Confidential' /\ + 'ZANZEFF Data - v5 1-27-23 ALTRIOS Confidential/' + pathlist = Path(directory).glob('*.csv') paths=[] os.makedirs('traction/trips', exist_ok=True) From a5503a12519f7d02e13d6079e9f4e1a1c711afa3 Mon Sep 17 00:00:00 2001 From: Chad Baker Date: Mon, 30 Oct 2023 12:04:37 -0600 Subject: [PATCH 3/7] added todo comment --- applications/demos/set_speed_train_sim_demo.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/demos/set_speed_train_sim_demo.py b/applications/demos/set_speed_train_sim_demo.py index de27b597..85d7439c 100644 --- a/applications/demos/set_speed_train_sim_demo.py +++ b/applications/demos/set_speed_train_sim_demo.py @@ -71,7 +71,7 @@ init_train_state=init_train_state, ) -# make sure rail_vehicle_map can be constructed from yaml file and such +# TODO: make sure rail_vehicle_map can be constructed from yaml file and such rail_vehicle_file = "rolling_stock/rail_vehicles.csv" rail_vehicle_map = alt.import_rail_vehicles( str(alt.resources_root() / rail_vehicle_file) From deed4eb1be6cddf3a7de3e43fa04baecad847a44 Mon Sep 17 00:00:00 2001 From: Chad Baker Date: Tue, 31 Oct 2023 15:05:33 -0600 Subject: [PATCH 4/7] propagated authors to workspace level --- rust/altrios-core-py/Cargo.toml | 14 ++++++++++++++ rust/altrios-core/Cargo.toml | 15 ++++++++++++++- rust/altrios-core/altrios-proc-macros/Cargo.toml | 15 ++++++++++++++- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/rust/altrios-core-py/Cargo.toml b/rust/altrios-core-py/Cargo.toml index b265401e..6e095d5c 100644 --- a/rust/altrios-core-py/Cargo.toml +++ b/rust/altrios-core-py/Cargo.toml @@ -1,5 +1,19 @@ [package] name = "altrios-core-py" +authors = [ + "ALTRIOS Team ", + "Chad Baker, Lead Developer", + "Nick Reinicke, Developer", + "Matt Bruchon, Developer", + "Jinghu Hu, Developer", + "Grant Payne, Developer", + "Jason Lustbader, PI", + "Garrett Anderson, Developer", + "Joel Allardyce, Developer", + "Prativa Hartnett, Developer", + "Steve Fritz, SwRI Lead", + "Tyler Dick, Co-PI", +] version = "0.1.0" edition = "2021" license = "BSD-3-Clause" diff --git a/rust/altrios-core/Cargo.toml b/rust/altrios-core/Cargo.toml index 0c71159f..e9c61f2a 100644 --- a/rust/altrios-core/Cargo.toml +++ b/rust/altrios-core/Cargo.toml @@ -1,9 +1,22 @@ [package] name = "altrios-core" +authors = [ + "ALTRIOS Team ", + "Chad Baker, Lead Developer", + "Nick Reinicke, Developer", + "Matt Bruchon, Developer", + "Jinghu Hu, Developer", + "Grant Payne, Developer", + "Jason Lustbader, PI", + "Garrett Anderson, Developer", + "Joel Allardyce, Developer", + "Prativa Hartnett, Developer", + "Steve Fritz, SwRI Lead", + "Tyler Dick, Co-PI", +] version = "0.1.2" edition = "2021" license = "BSD-3-Clause" -authors = ["NREL/MTES/CIMS/MBAP Group"] description = "ALTRIOS Core model for train simulation" homepage = "https://www.nrel.gov/transportation/altrios.html" readme = "README.md" diff --git a/rust/altrios-core/altrios-proc-macros/Cargo.toml b/rust/altrios-core/altrios-proc-macros/Cargo.toml index b3001ce5..b9c5c65f 100644 --- a/rust/altrios-core/altrios-proc-macros/Cargo.toml +++ b/rust/altrios-core/altrios-proc-macros/Cargo.toml @@ -1,9 +1,22 @@ [package] name = "altrios-proc-macros" +authors = [ + "ALTRIOS Team ", + "Chad Baker, Lead Developer", + "Nick Reinicke, Developer", + "Matt Bruchon, Developer", + "Jinghu Hu, Developer", + "Grant Payne, Developer", + "Jason Lustbader, PI", + "Garrett Anderson, Developer", + "Joel Allardyce, Developer", + "Prativa Hartnett, Developer", + "Steve Fritz, SwRI Lead", + "Tyler Dick, Co-PI", +] version = "0.1.2" edition = "2021" license = "BSD-3-Clause" -authors = ["NREL/MTES/CIMS/MBAP Group"] description = "ALTRIOS procedural macros" homepage = "https://www.nrel.gov/transportation/altrios.html" readme = "README.md" From 5e98ce2dee39902a0797aa58fcf33a975ef3a30c Mon Sep 17 00:00:00 2001 From: Chad Baker Date: Tue, 31 Oct 2023 15:09:55 -0600 Subject: [PATCH 5/7] propagated more things to workspace level --- rust/Cargo.toml | 20 ++++++++++++++++ rust/altrios-core-py/Cargo.toml | 21 ++++------------- rust/altrios-core/Cargo.toml | 23 ++++--------------- .../altrios-proc-macros/Cargo.toml | 23 ++++--------------- 4 files changed, 35 insertions(+), 52 deletions(-) diff --git a/rust/Cargo.toml b/rust/Cargo.toml index df77a9fd..a688ae20 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -5,6 +5,26 @@ members = [ ] resolver = "2" +[workspace.package] +authors = [ + "ALTRIOS Team ", + "Chad Baker, Lead Developer", + "Nick Reinicke, Developer", + "Matt Bruchon, Developer", + "Jinghu Hu, Developer", + "Grant Payne, Developer", + "Jason Lustbader, PI", + "Garrett Anderson, Developer", + "Joel Allardyce, Developer", + "Prativa Hartnett, Developer", + "Steve Fritz, SwRI Lead", + "Tyler Dick, Co-PI", +] +license = "BSD-3-Clause" +edition = "2021" +homepage = "https://www.nrel.gov/transportation/altrios.html" +repository = "https://github.com/NREL/altrios" + [profile.dev] opt-level = 0 diff --git a/rust/altrios-core-py/Cargo.toml b/rust/altrios-core-py/Cargo.toml index 6e095d5c..992118fc 100644 --- a/rust/altrios-core-py/Cargo.toml +++ b/rust/altrios-core-py/Cargo.toml @@ -1,22 +1,11 @@ [package] name = "altrios-core-py" -authors = [ - "ALTRIOS Team ", - "Chad Baker, Lead Developer", - "Nick Reinicke, Developer", - "Matt Bruchon, Developer", - "Jinghu Hu, Developer", - "Grant Payne, Developer", - "Jason Lustbader, PI", - "Garrett Anderson, Developer", - "Joel Allardyce, Developer", - "Prativa Hartnett, Developer", - "Steve Fritz, SwRI Lead", - "Tyler Dick, Co-PI", -] +authors = { workspace = true } +edition = { workspace = true } +license = { workspace = true } +homepage = { workspace = true } +repository = { workspace = true } version = "0.1.0" -edition = "2021" -license = "BSD-3-Clause" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/rust/altrios-core/Cargo.toml b/rust/altrios-core/Cargo.toml index e9c61f2a..8b41d43b 100644 --- a/rust/altrios-core/Cargo.toml +++ b/rust/altrios-core/Cargo.toml @@ -1,26 +1,13 @@ [package] name = "altrios-core" -authors = [ - "ALTRIOS Team ", - "Chad Baker, Lead Developer", - "Nick Reinicke, Developer", - "Matt Bruchon, Developer", - "Jinghu Hu, Developer", - "Grant Payne, Developer", - "Jason Lustbader, PI", - "Garrett Anderson, Developer", - "Joel Allardyce, Developer", - "Prativa Hartnett, Developer", - "Steve Fritz, SwRI Lead", - "Tyler Dick, Co-PI", -] +authors = { workspace = true } +edition = { workspace = true } +license = { workspace = true } +homepage = { workspace = true } +repository = { workspace = true } version = "0.1.2" -edition = "2021" -license = "BSD-3-Clause" description = "ALTRIOS Core model for train simulation" -homepage = "https://www.nrel.gov/transportation/altrios.html" readme = "README.md" -repository = "https://github.com/NREL/altrios" [dependencies] csv = "1.1.6" diff --git a/rust/altrios-core/altrios-proc-macros/Cargo.toml b/rust/altrios-core/altrios-proc-macros/Cargo.toml index b9c5c65f..4ab381cc 100644 --- a/rust/altrios-core/altrios-proc-macros/Cargo.toml +++ b/rust/altrios-core/altrios-proc-macros/Cargo.toml @@ -1,26 +1,13 @@ [package] name = "altrios-proc-macros" -authors = [ - "ALTRIOS Team ", - "Chad Baker, Lead Developer", - "Nick Reinicke, Developer", - "Matt Bruchon, Developer", - "Jinghu Hu, Developer", - "Grant Payne, Developer", - "Jason Lustbader, PI", - "Garrett Anderson, Developer", - "Joel Allardyce, Developer", - "Prativa Hartnett, Developer", - "Steve Fritz, SwRI Lead", - "Tyler Dick, Co-PI", -] +authors = { workspace = true } +edition = { workspace = true } +license = { workspace = true } +homepage = { workspace = true } +repository = { workspace = true } version = "0.1.2" -edition = "2021" -license = "BSD-3-Clause" description = "ALTRIOS procedural macros" -homepage = "https://www.nrel.gov/transportation/altrios.html" readme = "README.md" -repository = "https://github.com/NREL/altrios" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html From 53317dba264c5a2d661d23cd6edc0d7fe03fc346 Mon Sep 17 00:00:00 2001 From: Chad Baker Date: Tue, 31 Oct 2023 15:10:27 -0600 Subject: [PATCH 6/7] added test trigger --- .github/workflows/tests.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 5f8f36ae..f9dbeb67 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -4,6 +4,7 @@ on: push: branches: [ main ] pull_request: + workflow_dispatch: jobs: test: From 103b658135913ad8ffd6d4b469fe71416a0c4267 Mon Sep 17 00:00:00 2001 From: Chad Baker Date: Wed, 1 Nov 2023 13:45:27 -0600 Subject: [PATCH 7/7] figured out mechanism of using PyAny to get around traits not working, but it is somewhat clunky --- .../locomotive/battery_electric_loco.rs | 1 + .../consist/locomotive/conventional_loco.rs | 1 + .../src/consist/locomotive/hybrid_loco.rs | 1 + .../consist/locomotive/locomotive_model.rs | 55 ++++++++++++++++++- rust/altrios-core/src/pyo3.rs | 2 +- 5 files changed, 57 insertions(+), 3 deletions(-) diff --git a/rust/altrios-core/src/consist/locomotive/battery_electric_loco.rs b/rust/altrios-core/src/consist/locomotive/battery_electric_loco.rs index 4f503079..29c2ee3f 100644 --- a/rust/altrios-core/src/consist/locomotive/battery_electric_loco.rs +++ b/rust/altrios-core/src/consist/locomotive/battery_electric_loco.rs @@ -5,6 +5,7 @@ use super::LocoTrait; use crate::imports::*; #[derive(Default, Clone, Debug, PartialEq, Serialize, Deserialize, HistoryMethods, SerdeAPI)] +#[altrios_api] /// Battery electric locomotive pub struct BatteryElectricLoco { #[has_state] diff --git a/rust/altrios-core/src/consist/locomotive/conventional_loco.rs b/rust/altrios-core/src/consist/locomotive/conventional_loco.rs index 2fae15a6..bd4c632b 100644 --- a/rust/altrios-core/src/consist/locomotive/conventional_loco.rs +++ b/rust/altrios-core/src/consist/locomotive/conventional_loco.rs @@ -6,6 +6,7 @@ use super::LocoTrait; use crate::imports::*; #[derive(Default, Clone, Debug, PartialEq, Serialize, Deserialize, HistoryMethods, SerdeAPI)] +#[altrios_api] /// Conventional locomotive pub struct ConventionalLoco { #[has_state] diff --git a/rust/altrios-core/src/consist/locomotive/hybrid_loco.rs b/rust/altrios-core/src/consist/locomotive/hybrid_loco.rs index b129c979..5025295a 100644 --- a/rust/altrios-core/src/consist/locomotive/hybrid_loco.rs +++ b/rust/altrios-core/src/consist/locomotive/hybrid_loco.rs @@ -10,6 +10,7 @@ use super::LocoTrait; use crate::imports::*; #[derive(Clone, Debug, PartialEq, Deserialize, Serialize, HistoryMethods)] +#[altrios_api] /// Hybrid locomotive with both engine and reversible energy storage (aka battery) /// This type of locomotive is not likely to be widely prevalent due to modularity of consists. pub struct HybridLoco { diff --git a/rust/altrios-core/src/consist/locomotive/locomotive_model.rs b/rust/altrios-core/src/consist/locomotive/locomotive_model.rs index f76777c8..22871d4e 100644 --- a/rust/altrios-core/src/consist/locomotive/locomotive_model.rs +++ b/rust/altrios-core/src/consist/locomotive/locomotive_model.rs @@ -13,6 +13,39 @@ pub enum LocoType { Dummy, } +impl From for LocoType { + fn from(value: HybridLoco) -> Self { + Self::from(Box::new(value)) + } +} + +impl TryFrom<&PyAny> for LocoType { + type Error = PyErr; + /// This allows us to construct LocoType any struct that can be converted into LocoType + fn try_from(value: &PyAny) -> std::result::Result { + value + .extract::() + .map(LocoType::from) + .or_else(|_| { + value + .extract::() + .map(LocoType::from) + .or_else(|_| { + value + .extract::() + .map(LocoType::from) + .or_else(|_| value.extract::().map(LocoType::from)) + }) + }) + .map_err(|_| { + pyo3::PyErr::new::(format!( + "{}\nMust provide ConventionalLoco, HybridLoco, BatteryElectricLoco, or Dummy", + format_dbg!() + )) + }) + } +} + impl Default for LocoType { fn default() -> Self { Self::ConventionalLoco(Default::default()) @@ -89,6 +122,7 @@ impl Default for LocoParams { } #[derive(Clone, Default, Debug, Serialize, Deserialize, PartialEq, SerdeAPI)] +#[altrios_api] pub struct Dummy {} impl LocoTrait for Dummy { @@ -107,6 +141,24 @@ impl LocoTrait for Dummy { } #[altrios_api( + #[new] + fn __new__( + loco_type: &PyAny, + loco_params: LocoParams, + save_interval: Option, + ) -> PyResult { + Ok(Self { + loco_type: LocoType::try_from(loco_type)?, + state: Default::default(), + save_interval, + assert_limits: true, + pwr_aux_offset: loco_params.pwr_aux_offset, + pwr_aux_traction_coeff: loco_params.pwr_aux_traction_coeff, + force_max: Some(loco_params.force_max), + ..Default::default() + }) + } + #[allow(clippy::too_many_arguments)] #[classmethod] fn build_conventional_loco( @@ -186,9 +238,8 @@ impl LocoTrait for Dummy { Ok(Self::default_battery_electric_loco()) } - #[classmethod] + #[staticmethod] fn build_battery_electric_loco ( - _cls: &PyType, reversible_energy_storage: ReversibleEnergyStorage, drivetrain: ElectricDrivetrain, loco_params: LocoParams, diff --git a/rust/altrios-core/src/pyo3.rs b/rust/altrios-core/src/pyo3.rs index d1f6a004..e35217b8 100644 --- a/rust/altrios-core/src/pyo3.rs +++ b/rust/altrios-core/src/pyo3.rs @@ -4,4 +4,4 @@ pub use pyo3::exceptions::{ }; pub use pyo3::ffi::{getter, setter}; pub use pyo3::prelude::*; -pub use pyo3::types::{PyBytes, PyDict, PyType}; +pub use pyo3::types::{PyAny, PyBytes, PyDict, PyType};