Skip to content

Commit

Permalink
removed all rust-side logging because it causes net trouble
Browse files Browse the repository at this point in the history
  • Loading branch information
calbaker committed Jan 9, 2025
1 parent ccc110d commit 77024af
Show file tree
Hide file tree
Showing 21 changed files with 8 additions and 120 deletions.
7 changes: 5 additions & 2 deletions python/altrios/demos/demo_logging.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"""
This demo is currently deprecated because all logging functionality has been
removed from altrios-core due to the fact that it was unwieldy and in recent
versions of pyo3, Rust's `println` macro works through pyo3.
"""
from altrios import ConsistSimulation
from altrios.utilities import set_log_level

import logging

log = logging.getLogger(__name__)
set_log_level(logging.INFO)


if __name__ == "__main__":
c = ConsistSimulation.default()

Expand Down
4 changes: 0 additions & 4 deletions python/altrios/demos/set_speed_simple_corr_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@

SAVE_INTERVAL = 1

# Uncomment and run `maturin develop --release --features logging` to enable logging,
# which is needed because logging bogs the CPU and is off by default.
# alt.utils.set_log_level("DEBUG")

# Build the train config
rail_vehicle_loaded = alt.RailVehicle.from_file(
alt.resources_root() / "rolling_stock/Manifest_Loaded.yaml")
Expand Down
4 changes: 0 additions & 4 deletions python/altrios/demos/set_speed_train_sim_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
import altrios as alt
sns.set_theme()

# Uncomment and run `maturin develop --release --features logging` to enable logging,
# which is needed because logging bogs the CPU and is off by default.
# alt.utils.set_log_level("DEBUG")

SHOW_PLOTS = alt.utils.show_plots()
PYTEST = os.environ.get("PYTEST", "false").lower() == "true"

Expand Down
4 changes: 0 additions & 4 deletions python/altrios/demos/speed_limit_simple_corr_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@

SAVE_INTERVAL = 1

# Uncomment and run `maturin develop --release --features logging` to enable logging,
# which is needed because logging bogs the CPU and is off by default.
# alt.utils.set_log_level("DEBUG")

# Build the train config
rail_vehicle_loaded = alt.RailVehicle.from_file(
alt.resources_root() / "rolling_stock/Manifest_Loaded.yaml")
Expand Down
3 changes: 0 additions & 3 deletions python/altrios/demos/speed_limit_train_sim_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,6 @@
link_path = alt.LinkPath([x.link_idx for x in timed_link_path.tolist()])
link_path.to_csv_file(alt.resources_root() / "demo_data/link_path.csv")

# uncomment this line to see example of logging functionality
# alt.utils.set_log_level("DEBUG")

t0 = time.perf_counter()
train_sim.walk_timed_path(
network=network,
Expand Down
2 changes: 0 additions & 2 deletions python/altrios/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,6 @@ def set_log_level(level: str | int) -> int:
python_logger = logging.getLogger("altrios")
previous_level = python_logger .level
python_logger .setLevel(level)
rust_logger = logging.getLogger("altrios_core")
rust_logger.setLevel(level)
return previous_level

def disable_logging():
Expand Down
1 change: 0 additions & 1 deletion rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions rust/altrios-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,12 @@ project-root = "0.2.2"
eng_fmt = { workspace = true }
directories = "5.0.1"
tempfile = "3.10.1"
derive_more = { version = "1.0.0", features = ["from_str", "from", "is_variant", "try_into"] }

[features]
default = ["logging"]
default = []
## Exposes ALTRIOS structs, methods, and functions to Python.
pyo3 = ["dep:pyo3"]
## Enables logging messages that can be passed to Python if `pyo3` is also
## enabled.
logging = ["dep:log"]

[lints.rust]
# `'cfg(debug_advance_rewind)'` is expected for debugging in `advance_rewind.rs`
Expand Down
6 changes: 0 additions & 6 deletions rust/altrios-core/src/consist/consist_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,6 @@ impl Consist {
// maybe put logic for toggling `engine_on` here

for (i, (loco, pwr_out)) in self.loco_vec.iter_mut().zip(pwr_out_vec.iter()).enumerate() {
#[cfg(feature = "logging")]
log::info!(
"Solving locomotive #{}\n`pwr_out: `{} MW",
i,
pwr_out.get::<si::megawatt>().format_eng(None)
);
loco.solve_energy_consumption(*pwr_out, dt, engine_on)
.map_err(|err| {
err.context(format!(
Expand Down
2 changes: 0 additions & 2 deletions rust/altrios-core/src/consist/consist_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ impl ConsistSimulation {
}

pub fn solve_step(&mut self) -> anyhow::Result<()> {
#[cfg(feature = "logging")]
log::info!("Solving time step #{}", self.i);
self.loco_con.set_pwr_aux(Some(true))?;
self.loco_con
.set_cur_pwr_max_out(None, self.power_trace.dt(self.i))?;
Expand Down
4 changes: 0 additions & 4 deletions rust/altrios-core/src/consist/locomotive/loco_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,6 @@ impl LocomotiveSimulation {
}

pub fn solve_step(&mut self) -> anyhow::Result<()> {
#[cfg(feature = "logging")]
log::info!("Solving time step #{}", self.i);
// linear aux model
let engine_on = self.power_trace.engine_on[self.i];
self.loco_unit.set_pwr_aux(engine_on);
Expand Down Expand Up @@ -328,8 +326,6 @@ impl LocomotiveSimulationVec {
.par_iter_mut()
.enumerate()
.try_for_each(|(i, loco_sim)| {
#[cfg(feature = "logging")]
log::info!("Solving locomotive #{i}");
loco_sim
.walk()
.map_err(|err| err.context(format!("loco_sim idx:{}", i)))
Expand Down
6 changes: 0 additions & 6 deletions rust/altrios-core/src/consist/locomotive/locomotive_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,10 +651,6 @@ impl Mass for Locomotive {
Some(new_mass) => {
if let Some(dm) = derived_mass {
if dm != new_mass {
#[cfg(feature = "logging")]
log::warn!(
"Derived mass does not match provided mass, setting `{}` consituent mass fields to `None`",
stringify!(Locomotive));
self.expunge_mass_fields();
}
}
Expand All @@ -668,8 +664,6 @@ impl Mass for Locomotive {
)
})?),
};
#[cfg(feature = "logging")]
log::info!("Updating `force_max` to correspond to new mass.");
self.force_max = self
.mu()
.with_context(|| format_dbg!())?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,6 @@ impl Mass for FuelConverter {
let derived_mass = self.derived_mass().with_context(|| format_dbg!())?;
if let (Some(derived_mass), Some(new_mass)) = (derived_mass, new_mass) {
if derived_mass != new_mass {
#[cfg(feature = "logging")]
log::info!(
"Derived mass from `self.specific_pwr` and `self.pwr_out_max` does not match {}",
"provided mass. Updating based on `side_effect`"
);
match side_effect {
MassSideEffect::Extensive => {
self.pwr_out_max = self.specific_pwr.ok_or_else(|| {
Expand All @@ -138,8 +133,6 @@ impl Mass for FuelConverter {
}
}
} else if new_mass.is_none() {
#[cfg(feature = "logging")]
log::debug!("Provided mass is None, setting `self.specific_pwr` to None");
self.specific_pwr = None;
}
self.mass = new_mass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,6 @@ impl Mass for Generator {
let derived_mass = self.derived_mass().with_context(|| format_dbg!())?;
if let (Some(derived_mass), Some(new_mass)) = (derived_mass, new_mass) {
if derived_mass != new_mass {
#[cfg(feature = "logging")]
log::info!(
"Derived mass from `self.specific_pwr` and `self.pwr_out_max` does not match {}",
"provided mass. Updating based on `side_effect`"
);
match side_effect {
MassSideEffect::Extensive => {
self.pwr_out_max = self.specific_pwr.with_context(|| {
Expand All @@ -154,8 +149,6 @@ impl Mass for Generator {
}
}
} else if new_mass.is_none() {
#[cfg(feature = "logging")]
log::debug!("Provided mass is None, setting `self.specific_pwr` to None");
self.specific_pwr = None;
}
self.mass = new_mass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,6 @@ impl Mass for ReversibleEnergyStorage {
let derived_mass = self.derived_mass().with_context(|| format_dbg!())?;
if let (Some(derived_mass), Some(new_mass)) = (derived_mass, new_mass) {
if derived_mass != new_mass {
#[cfg(feature = "logging")]
log::info!(
"Derived mass from `self.specific_energy` and `self.energy_capacity` does not match {}",
"provided mass. Updating based on `side_effect`"
);
match side_effect {
MassSideEffect::Extensive => {
self.energy_capacity = self.specific_energy.ok_or_else(|| {
Expand All @@ -231,8 +226,6 @@ impl Mass for ReversibleEnergyStorage {
}
}
} else if new_mass.is_none() {
#[cfg(feature = "logging")]
log::debug!("Provided mass is None, setting `self.specific_energy` to None");
self.specific_energy = None;
}
self.mass = new_mass;
Expand Down
13 changes: 0 additions & 13 deletions rust/altrios-core/src/meet_pass/est_times/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -541,8 +541,6 @@ pub fn make_est_times<N: AsRef<[Link]>>(
// Push initial "fake" nodes.
// These help define the start of our `EstTime` sequence.
// -----------------------------------------------------------------------
#[cfg(feature = "logging")]
log::debug!("{}", format_dbg!("Push initial fake nodes."));
est_times.push(EstTime {
idx_next: 1,
..Default::default()
Expand All @@ -558,8 +556,6 @@ pub fn make_est_times<N: AsRef<[Link]>>(
// For each origin, we ensure offset=0, is_front_end=false, and a real link_idx.
// Then create two `EstTime` events: (Arrive + Clear) for the train's tail and head.
// -----------------------------------------------------------------------
#[cfg(feature = "logging")]
log::debug!("{}", format_dbg!("Add origin estimated times."));
for orig in origs {
ensure!(
orig.offset == si::Length::ZERO,
Expand All @@ -578,9 +574,6 @@ pub fn make_est_times<N: AsRef<[Link]>>(
..Default::default()
};

#[cfg(feature = "logging")]
log::debug!("{}", format_dbg!());

// Arrive event
insert_est_time(
&mut est_times,
Expand All @@ -597,8 +590,6 @@ pub fn make_est_times<N: AsRef<[Link]>>(
..Default::default()
},
);
#[cfg(feature = "logging")]
log::debug!("{}", format_dbg!());

// Clear event
insert_est_time(
Expand Down Expand Up @@ -635,8 +626,6 @@ pub fn make_est_times<N: AsRef<[Link]>>(
// Reset distance to zero for any alternate "fake" nodes.
// This helps unify distance offsets for subsequent processing.
// -----------------------------------------------------------------------
#[cfg(feature = "logging")]
log::debug!("{}", format_dbg!("Fix distances for different origins"));
{
let mut est_idx_fix = 1;
while est_idx_fix != EST_IDX_NA {
Expand All @@ -654,8 +643,6 @@ pub fn make_est_times<N: AsRef<[Link]>>(
// -----------------------------------------------------------------------
// Main loop: process each saved simulation until `saved_sims` is empty.
// -----------------------------------------------------------------------
#[cfg(feature = "logging")]
log::debug!("{}", format_dbg!("Iterate and process all saved sims"));
while let Some(mut sim) = saved_sims.pop() {
let mut has_split = false;
ensure!(
Expand Down
2 changes: 0 additions & 2 deletions rust/altrios-core/src/train/set_speed_train_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,6 @@ impl SetSpeedTrainSim {
/// Solves time step.
pub fn solve_step(&mut self) -> anyhow::Result<()> {
// checking on speed trace to ensure it is at least stopped or moving forward (no backwards)
#[cfg(feature = "logging")]
log::info!("Solving time step #{}", self.state.i);
ensure!(
self.speed_trace.speed[self.state.i] >= si::Velocity::ZERO,
format_dbg!(self.speed_trace.speed[self.state.i] >= si::Velocity::ZERO)
Expand Down
21 changes: 0 additions & 21 deletions rust/altrios-core/src/train/speed_limit_train_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,6 @@ impl SpeedLimitTrainSim {

pub fn solve_step(&mut self) -> anyhow::Result<()> {
// set catenary power limit
#[cfg(feature = "logging")]
log::info!("Solving time step #{}", self.state.i);
self.loco_con
.set_cat_power_limit(&self.path_tpc, self.state.offset);
// set aux power for the consist
Expand All @@ -304,12 +302,6 @@ impl SpeedLimitTrainSim {
.update_res(&mut self.state, &self.path_tpc, &Dir::Fwd)?;
// solve the required power
self.solve_required_pwr()?;
#[cfg(feature = "logging")]
log::debug!(
"{}\ntime step: {}",
format_dbg!(),
self.state.time.get::<si::second>().format_eng(Some(9))
);

self.loco_con.solve_energy_consumption(
self.state.pwr_whl_out,
Expand All @@ -336,15 +328,6 @@ impl SpeedLimitTrainSim {
|| (self.state.offset < self.path_tpc.offset_end()
&& self.state.speed != si::Velocity::ZERO)
{
#[cfg(feature = "logging")]
log::debug!(
"{}",
format_dbg!(
self.state.offset < self.path_tpc.offset_end() - 1000.0 * uc::FT
|| (self.state.offset < self.path_tpc.offset_end()
&& self.state.speed != si::Velocity::ZERO)
)
);
self.step()?;
}
Ok(())
Expand Down Expand Up @@ -374,8 +357,6 @@ impl SpeedLimitTrainSim {
let mut idx_prev = 0;
while idx_prev != timed_path.len() - 1 {
let mut idx_next = idx_prev + 1;
#[cfg(feature = "logging")]
log::debug!("Solving idx: {}", idx_next);
while idx_next + 1 < timed_path.len() - 1 && timed_path[idx_next].time < self.state.time
{
idx_next += 1;
Expand Down Expand Up @@ -484,8 +465,6 @@ impl SpeedLimitTrainSim {
.min(pwr_pos_max / speed_target.min(v_max));
// Verify that train has sufficient power to move
if self.state.speed < uc::MPH * 0.1 && f_pos_max <= res_net {
#[cfg(feature = "logging")]
log::debug!("{}", format_dbg!(self.path_tpc));
bail!(
"{}\nTrain does not have sufficient power to move!\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}", // ,\nlink={:?}
format_dbg!(),
Expand Down
8 changes: 1 addition & 7 deletions rust/altrios-core/src/train/train_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,6 @@ impl TrainSimBuilder {
* uc::R)
},
)?);
#[cfg(feature = "logging")]
log::debug!("{}", format_dbg!(&res_rolling));
let davis_b = res_kind::davis_b::Basic::new(rvs.iter().try_fold(
0.0 * uc::S / uc::M,
|acc, rv| -> anyhow::Result<si::InverseVelocity> {
Expand All @@ -483,11 +481,7 @@ impl TrainSimBuilder {
)?);
let res_aero =
res_kind::aerodynamic::Basic::new(match &self.train_config.cd_area_vec {
Some(dave) => {
#[cfg(feature = "logging")]
log::info!("Using `cd_area_vec` to calculate aero resistance.");
dave.iter().fold(0. * uc::M2, |acc, dc| *dc + acc)
}
Some(dave) => dave.iter().fold(0. * uc::M2, |acc, dc| *dc + acc),
None => rvs.iter().fold(0.0 * uc::M2, |acc, rv| -> si::Area {
acc + rv.cd_area
* *self.train_config.n_cars_by_type.get(&rv.car_type).unwrap() as f64
Expand Down
6 changes: 0 additions & 6 deletions rust/altrios-py/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ rust-version = { workspace = true }
[dependencies]
altrios-core = { workspace = true, features = ["pyo3"] }
pyo3 = { workspace = true, features = ["extension-module", "anyhow"] }
pyo3-log = { workspace = true, optional=true }
polars = { workspace = true }
polars-lazy = { workspace = true }
pyo3-polars = { workspace = true }
Expand All @@ -25,8 +24,3 @@ name = "altrios_pyo3"
crate-type = ["cdylib"]

[features]
default = ["logging"]
## The `logging` feature enables "altrios-core/logging" and enables it to log
## to python. This feature is disabled by default because enabling it causes a
## significant performance hit, even if nothing is actually logged.
logging = ["altrios-core/logging", "dep:pyo3-log"]
8 changes: 0 additions & 8 deletions rust/altrios-py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@ fn altrios_pyo3(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_function(wrap_pyfunction!(check_od_pair_valid, m)?)?;
m.add_function(wrap_pyfunction!(build_speed_limit_train_sims, m)?)?;
m.add_function(wrap_pyfunction!(run_speed_limit_train_sims, m)?)?;
#[cfg(feature = "logging")]
m.add_function(wrap_pyfunction!(pyo3_log_init, m)?)?;

Ok(())
}

#[cfg(feature = "logging")]
#[cfg_attr(feature = "logging", pyfunction)]
fn pyo3_log_init() {
pyo3_log::init();
}

0 comments on commit 77024af

Please sign in to comment.