Skip to content

Commit

Permalink
Merge pull request #13 from NREL/api-cleanup
Browse files Browse the repository at this point in the history
various cleanup things
  • Loading branch information
calbaker authored Nov 2, 2023
2 parents 875eec9 + 103b658 commit aceefad
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 19 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches: [ main ]
pull_request:
workflow_dispatch:

jobs:
test:
Expand Down
5 changes: 4 additions & 1 deletion applications/calibration/cleaning_traction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion applications/demos/set_speed_train_sim_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,26 @@ members = [
]
resolver = "2"

[workspace.package]
authors = [
"ALTRIOS Team <altrios@nrel.gov>",
"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

Expand Down
7 changes: 5 additions & 2 deletions rust/altrios-core-py/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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

Expand Down
10 changes: 5 additions & 5 deletions rust/altrios-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
10 changes: 5 additions & 5 deletions rust/altrios-core/altrios-proc-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions rust/altrios-core/src/consist/locomotive/hybrid_loco.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
59 changes: 55 additions & 4 deletions rust/altrios-core/src/consist/locomotive/locomotive_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,39 @@ pub enum LocoType {
Dummy,
}

impl From<HybridLoco> 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<Self, Self::Error> {
value
.extract::<ConventionalLoco>()
.map(LocoType::from)
.or_else(|_| {
value
.extract::<HybridLoco>()
.map(LocoType::from)
.or_else(|_| {
value
.extract::<BatteryElectricLoco>()
.map(LocoType::from)
.or_else(|_| value.extract::<Dummy>().map(LocoType::from))
})
})
.map_err(|_| {
pyo3::PyErr::new::<pyo3::exceptions::PyTypeError, _>(format!(
"{}\nMust provide ConventionalLoco, HybridLoco, BatteryElectricLoco, or Dummy",
format_dbg!()
))
})
}
}

impl Default for LocoType {
fn default() -> Self {
Self::ConventionalLoco(Default::default())
Expand Down Expand Up @@ -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 {
Expand All @@ -107,6 +141,24 @@ impl LocoTrait for Dummy {
}

#[altrios_api(
#[new]
fn __new__(
loco_type: &PyAny,
loco_params: LocoParams,
save_interval: Option<usize>,
) -> PyResult<Self> {
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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)]
Expand Down
2 changes: 1 addition & 1 deletion rust/altrios-core/src/pyo3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

0 comments on commit aceefad

Please sign in to comment.