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: 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) 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) 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 b265401e..992118fc 100644 --- a/rust/altrios-core-py/Cargo.toml +++ b/rust/altrios-core-py/Cargo.toml @@ -1,8 +1,11 @@ [package] name = "altrios-core-py" +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 0c71159f..8b41d43b 100644 --- a/rust/altrios-core/Cargo.toml +++ b/rust/altrios-core/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "altrios-core" +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" -authors = ["NREL/MTES/CIMS/MBAP Group"] 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 b3001ce5..4ab381cc 100644 --- a/rust/altrios-core/altrios-proc-macros/Cargo.toml +++ b/rust/altrios-core/altrios-proc-macros/Cargo.toml @@ -1,13 +1,13 @@ [package] name = "altrios-proc-macros" +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" -authors = ["NREL/MTES/CIMS/MBAP Group"] 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 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 f0d7ca32..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, @@ -389,8 +440,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)] 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};