Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/speed trace from slts in ssts #63

Merged
merged 45 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
e02ccf0
doc strings and better variable names
calbaker Apr 24, 2024
0ffb162
added commented code for overwriting files
calbaker Apr 24, 2024
9e06308
minor doc change
calbaker Apr 24, 2024
c39713b
propagated constant
calbaker Apr 24, 2024
31ff413
struggling to understand why speed trace from speed limit train sim f…
calbaker Apr 24, 2024
78681d8
Revert "struggling to understand why speed trace from speed limit tra…
calbaker Apr 24, 2024
52dc327
added `__eq__` magic method
calbaker Apr 25, 2024
5ccdc7c
added `PartialEq` to numerous structs
calbaker Apr 25, 2024
4c19885
made it so that `to_csv_file` methods will create files if they do no…
calbaker Apr 25, 2024
80590ec
prepared example of failure for Garrett
calbaker Apr 25, 2024
d4efaa5
added debugging scaffolding
calbaker Apr 25, 2024
f863b0d
plot formatting
calbaker Apr 25, 2024
be52766
fixed typo
calbaker Apr 25, 2024
0ce16a7
fixed botched header handling
calbaker Apr 25, 2024
c890dc0
demonstrates that even with same train resistance model, slts and sst…
calbaker Apr 25, 2024
107c3ff
more plotting
calbaker Apr 25, 2024
5ca2383
further into the rabbit hole of debugging
calbaker Apr 25, 2024
a160fbd
fixed function chain
calbaker Apr 25, 2024
dd5b9c6
doc string added
calbaker Apr 25, 2024
0f539f6
Revert "fixed function chain" because it broke things
calbaker Apr 25, 2024
4b58055
`set_speed_train_sim_demo.py` can now run using artifacts from `speed…
calbaker Apr 25, 2024
f76117e
cleaned up plots
calbaker Apr 25, 2024
5fbce6b
fuel energy between `speed_limit_train_sim_demo.py` and `set_speed_tr…
calbaker Apr 25, 2024
e87bdc8
demonstrated that small energy differences between set speed and spee…
calbaker Apr 25, 2024
636d849
plot cleanup
calbaker Apr 25, 2024
25e5992
added doc strings explaining minor discrepancies
calbaker Apr 25, 2024
71736c5
Merge branch 'main' into fix/speed-trace-from-slts-in-ssts
calbaker May 13, 2024
7203d63
Merge branch 'main' of github.com:NREL/altrios into fix/speed-trace-f…
calbaker May 13, 2024
4b06e78
fixed index shift problem in error messages
calbaker May 14, 2024
547473b
Merge branch 'main' of github.com:NREL/altrios into fix/speed-trace-f…
calbaker May 14, 2024
97397ac
Merge branch 'main' into fix/speed-trace-from-slts-in-ssts
calbaker May 14, 2024
1a79a05
Merge branch 'main' into fix/speed-trace-from-slts-in-ssts
calbaker Jun 20, 2024
002fd43
Merge branch 'main' of github.com:NREL/altrios into fix/speed-trace-f…
calbaker Jun 27, 2024
972c416
Merge branch 'main' of github.com:NREL/altrios into fix/speed-trace-f…
calbaker Aug 9, 2024
8c61cbc
added a bunch of comments that are quite informal to set_speed_train_…
SWRIganderson Aug 27, 2024
783039e
part way through speed limit train sim comment, but I have something …
SWRIganderson Aug 27, 2024
3bb4710
added a few more comments to speed limit train sim.
SWRIganderson Aug 27, 2024
0fb1208
Merge branch 'main' into fix/speed-trace-from-slts-in-ssts
calbaker Sep 3, 2024
b1e10d9
Merge branch 'fix/speed-trace-from-slts-in-ssts' of github.com:NREL/a…
calbaker Sep 3, 2024
ec7161d
fixed conflicting trait impls
calbaker Sep 3, 2024
fde8489
all tests now pass
calbaker Sep 3, 2024
83820db
added leading space
calbaker Sep 11, 2024
48cd117
cleaned up comments
calbaker Sep 11, 2024
6a4cf54
Merge branch 'main' into fix/speed-trace-from-slts-in-ssts
calbaker Sep 12, 2024
953d709
fixed all the failing tests and added environment variables to make f…
calbaker Sep 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 80 additions & 8 deletions python/altrios/demos/set_speed_train_sim_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@
alt.resources_root() / rail_vehicle_file)

network = alt.Network.from_file(
alt.resources_root() / "networks/Taconite.yaml")
alt.resources_root() / "networks/Taconite-NoBalloon.yaml")
network.set_speed_set_for_train_type(alt.TrainType.Freight)
# file created from ./speed_limit_train_sim_demo.py:L92
link_path = alt.LinkPath.from_csv_file(
alt.resources_root() / "demo_data/link_points_idx.csv"
alt.resources_root() / "demo_data/link_path.csv"
)

# file created from ./speed_limit_train_sim_demo.py:L105
speed_trace = alt.SpeedTrace.from_csv_file(
alt.resources_root() / "demo_data/speed_trace.csv"
)
Expand All @@ -89,7 +91,9 @@
t1 = time.perf_counter()
print(f'Time to simulate: {t1 - t0:.5g}')

fig, ax = plt.subplots(3, 1, sharex=True)
loco0: alt.Locomotive = train_sim.loco_con.loco_vec.tolist()[0]

fig, ax = plt.subplots(4, 1, sharex=True)
ax[0].plot(
np.array(train_sim.history.time_seconds) / 3_600,
np.array(train_sim.history.pwr_whl_out_watts) / 1e6,
Expand Down Expand Up @@ -126,17 +130,85 @@
ax[1].set_ylabel('Force [MN]')
ax[1].legend()

ax[2].plot(
np.array(train_sim.history.time_seconds) / 3_600,
np.array(loco0.res.history.soc)
)
ax[2].set_ylabel('SOC')

ax[-1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.speed_trace.speed_meters_per_second,
train_sim.history.speed_meters_per_second,
label='achieved'
)
ax[-1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.speed_limit_meters_per_second,
label='limit'
)
ax[-1].set_xlabel('Time [hr]')
ax[-1].set_ylabel('Speed [m/s]')
ax[-1].legend()
plt.suptitle("Set Speed Train Sim Demo")

fig1, ax1 = plt.subplots(3, 1, sharex=True)
ax1[0].plot(
np.array(train_sim.history.time_seconds) / 3_600,
np.array(train_sim.history.offset_in_link_meters) / 1_000,
label='current link',
)
ax1[0].plot(
np.array(train_sim.history.time_seconds) / 3_600,
np.array(train_sim.history.offset_meters) / 1_000,
label='overall',
)
ax1[0].legend()
ax1[0].set_ylabel('Net Dist. [km]')

ax1[1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.link_idx_front,
linestyle='',
marker='.',
)
ax1[1].set_ylabel('Link Idx Front')

ax1[-1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.speed_meters_per_second,
)
ax1[-1].set_xlabel('Time [hr]')
ax1[-1].set_ylabel('Speed [m/s]')

plt.suptitle("Set Speed Train Sim Demo")
plt.tight_layout()

if SHOW_PLOTS:
plt.tight_layout()
plt.show()

# %%

fig2, ax2 = plt.subplots(3, 1, sharex=True)
ax2[0].plot(
np.array(train_sim.history.time_seconds) / 3_600,
np.array(train_sim.history.pwr_whl_out_watts) / 1e6,
label="tract pwr",
)
ax2[0].set_ylabel('Power [MW]')
ax2[0].legend()

ax2[1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
np.array(train_sim.history.grade_front) * 100.,
)
ax2[1].set_ylabel('Grade [%] at\nHead End')

ax2[-1].plot(
np.array(train_sim.history.time_seconds) / 3_600,
train_sim.history.speed_meters_per_second,
)
ax2[-1].set_xlabel('Time [hr]')
ax2[-1].set_ylabel('Speed [m/s]')

plt.suptitle("Set Speed Train Sim Demo")
plt.tight_layout()

if SHOW_PLOTS:
plt.show()
18 changes: 15 additions & 3 deletions python/altrios/demos/speed_limit_train_sim_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

SHOW_PLOTS = alt.utils.show_plots()

SAVE_INTERVAL = 100
SAVE_INTERVAL = 1

# https://docs.rs/altrios-core/latest/altrios_core/train/struct.TrainConfig.html
train_config = alt.TrainConfig(
Expand Down Expand Up @@ -74,7 +74,7 @@
train_sim: alt.SpeedLimitTrainSim = tsb.make_speed_limit_train_sim(
rail_vehicle=rail_vehicle,
location_map=location_map,
save_interval=1,
save_interval=SAVE_INTERVAL,
)
train_sim.set_save_interval(SAVE_INTERVAL)

Expand All @@ -88,6 +88,10 @@
False,
)[0]

# Uncomment the following lines to overwrite `set_speed_train_sim_demo.py` `link_path`
# 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")

Expand All @@ -100,6 +104,15 @@
print(f'Time to simulate: {t1 - t0:.5g}')
assert len(train_sim.history) > 1

# Uncomment the following lines to overwrite `set_speed_train_sim_demo.py` `speed_trace`
speed_trace = alt.SpeedTrace(
train_sim.history.time_seconds.tolist(),
train_sim.history.speed_meters_per_second.tolist()
)
speed_trace.to_csv_file(
alt.resources_root() / "demo_data/speed_trace.csv"
)

loco0:alt.Locomotive = train_sim.loco_con.loco_vec.tolist()[0]

fig, ax = plt.subplots(4, 1, sharex=True)
Expand Down Expand Up @@ -220,6 +233,5 @@


if SHOW_PLOTS:
plt.tight_layout()
plt.show()
# Impact of sweep of battery capacity TODO: make this happen
14 changes: 10 additions & 4 deletions python/altrios/optimization/cal_and_val.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,12 @@ class ModelError(object):
"""
Dataclass class for calculating model error of various ALTRIOS objects w.r.t. test data.

Fields:
Attributes:
- `ser_model_dict`: `dict` variable in which:
- key: a `str` representing trip keyword string
- value: a `str` converted from Rust locomotive models' serialization method

- key: a `str` representing trip keyword string

- value: a `str` converted from Rust locomotive models' serialization method

- `model_type`: `str` that can only be `'ConsistSimulation'`, `'SetSpeedTrainSim'` or `'LocomotiveSimulation'`;
indicates which model to instantiate during optimization process
Expand All @@ -85,7 +87,11 @@ class ModelError(object):
- `params`: a tuple whose individual element is a `str` containing hierarchical paths to parameters
to manipulate starting from one of the 3 possible Rust model structs

- `verbose`: `bool`; if `True`, the verbose of error calculation will be printed
- `verbose`: `bool`: if `True`, the verbose of error calculation will be printed

- `debug`: `bool`: if `True`, prints more stuff

- `allow_partial`: whether to allow partial runs, if True, errors out whenever a run can't be completed
"""
# `ser_model_dict` and `dfs` should have the same keys
ser_model_dict: Dict[str, str]
Expand Down
92 changes: 92 additions & 0 deletions python/altrios/resources/demo_data/link_path.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
link_idx
71
70
69
72
164
163
74
67
608
895
167
170
168
169
172
76
78
77
80
362
180
179
79
371
75
82
183
186
83
372
375
48
84
47
227
229
621
616
909
722
623
595
656
620
622
625
782
785
598
891
780
778
779
781
776
777
927
936
913
916
540
1013
1007
1017
1015
1010
1012
1011
1008
1009
1016
553
1018
1014
986
983
1034
560
1053
508
502
505
504
507
510
513
521
558
559
556
557
85 changes: 0 additions & 85 deletions python/altrios/resources/demo_data/link_points_idx.csv

This file was deleted.

Loading
Loading