-
Notifications
You must be signed in to change notification settings - Fork 11
investigate and maybe fix some unexpected behavior with derating in Hybrid #126
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
Open
calbaker
wants to merge
1
commit into
main
Choose a base branch
from
fix/derate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,24 +47,24 @@ | |
fc_with_derate.set_default_elev_and_temp_derate() | ||
fc_with_derate_dict = fc_with_derate.to_pydict() | ||
|
||
hel_new_dict = copy(hel_dict) | ||
hel_new_dict['loco_type']['HybridLoco']['fc'] = fc_with_derate_dict | ||
hel_with_derate = alt.Locomotive.from_pydict(hel_new_dict) | ||
hel_with_derate_dict = copy(hel_dict) | ||
hel_with_derate_dict['loco_type']['HybridLoco']['fc'] = fc_with_derate_dict | ||
hel_with_derate = alt.Locomotive.from_pydict(hel_with_derate_dict) | ||
|
||
conv_new_dict = alt.Locomotive.default().to_pydict() | ||
conv_new_dict['loco_type']['ConventionalLoco']['fc'] = fc_with_derate_dict | ||
conv_with_derate = alt.Locomotive.from_pydict(conv_new_dict) | ||
conv_with_derate_dict = alt.Locomotive.default().to_pydict() | ||
conv_with_derate_dict['loco_type']['ConventionalLoco']['fc'] = fc_with_derate_dict | ||
conv_with_derate = alt.Locomotive.from_pydict(conv_with_derate_dict) | ||
|
||
# construct a vector of one BEL, one HEL, and several conventional locomotives | ||
loco_vec = ( | ||
[hel.clone()] | ||
+ [alt.Locomotive.default()] * 1 | ||
[alt.Locomotive.default()] * 2 | ||
# + [hel.clone()] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @FDsteven uncomment this |
||
) | ||
|
||
# construct a vector of one BEL, one HEL, and several conventional locomotives | ||
loco_vec_with_derating = ( | ||
[hel_with_derate.clone()] | ||
+ [conv_with_derate] * 1 | ||
[conv_with_derate] * 2 | ||
# + [hel_with_derate.clone()] | ||
) | ||
|
||
# instantiate consist | ||
|
@@ -476,10 +476,10 @@ def plot_bel_pwr_and_soc(ts: alt.SpeedLimitTrainSim, mod_str: str) -> Tuple[plt. | |
ax[0].plot( | ||
df_with_derate['history.time_seconds'], | ||
df_with_derate['loco_con.history.energy_fuel_joules'] / 1e9, | ||
label='with derate', | ||
label='with derate',u | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
) | ||
ax[0].legend() | ||
ax[0].set_ylabel("Cumulative Fuel [GJ]") | ||
ax[0].set_ylabel("Cumu. Fuel [GJ]") | ||
|
||
ax[1].plot( | ||
df_no_derate['history.time_seconds'], | ||
|
@@ -492,7 +492,7 @@ def plot_bel_pwr_and_soc(ts: alt.SpeedLimitTrainSim, mod_str: str) -> Tuple[plt. | |
label='with derate pwr max', | ||
) | ||
ax[1].legend() | ||
ax[1].set_ylabel("Engine Power [MW]") | ||
ax[1].set_ylabel("Eng. Pwr. [MW]") | ||
|
||
ax[2].plot( | ||
df_no_derate['history.time_seconds'], | ||
|
@@ -512,41 +512,19 @@ def plot_bel_pwr_and_soc(ts: alt.SpeedLimitTrainSim, mod_str: str) -> Tuple[plt. | |
fig0, ax0 = plot_train_level_powers(train_sim, "No Derating") | ||
fig1, ax1 = plot_train_network_info(train_sim, "No Derating") | ||
fig2, ax2 = plot_consist_pwr(train_sim, "No Derating") | ||
fig3, ax3 = plot_hel_pwr_and_soc(train_sim, "No Derating") | ||
# fig3, ax3 = plot_hel_pwr_and_soc(train_sim, "No Derating") | ||
# fig3.savefig("plots/hel with buffers.svg") | ||
# fig4, ax4 = plot_bel_pwr_and_soc(train_sim, "No Derating") | ||
|
||
fig0_sans_buffers, ax0_sans_buffers = plot_train_level_powers(train_sim_with_derating, "With Altitude and Temperature Derating") | ||
fig1_sans_buffers, ax1_sans_buffers = plot_train_network_info(train_sim_with_derating, "With Altitude and Temperature Derating") | ||
fig2_sans_buffers, ax2_sans_buffers = plot_consist_pwr(train_sim_with_derating, "With Altitude and Temperature Derating") | ||
fig3_sans_buffers, ax3_sans_buffers = plot_hel_pwr_and_soc(train_sim_with_derating, "With Altitude and Temperature Derating") | ||
# fig3_sans_buffers, ax3_sans_buffers = plot_hel_pwr_and_soc(train_sim_with_derating, "With Altitude and Temperature Derating") | ||
# fig3_sans_buffers.savefig("plots/hel sans buffers.svg") | ||
# fig4_sans_buffers, ax4_sans_buffers = plot_bel_pwr_and_soc(train_sim_sans_buffers, "With Altitude and Temperature Derating") | ||
|
||
if SHOW_PLOTS: | ||
plt.tight_layout() | ||
plt.show() | ||
# Impact of sweep of battery capacity TODO: make this happen | ||
|
||
# whether to run assertions, enabled by default | ||
ENABLE_ASSERTS = os.environ.get("ENABLE_ASSERTS", "true").lower() == "true" | ||
# whether to override reference files used in assertions, disabled by default | ||
ENABLE_REF_OVERRIDE = os.environ.get( | ||
"ENABLE_REF_OVERRIDE", "false").lower() == "true" | ||
# directory for reference files for checking sim results against expected results | ||
ref_dir = alt.resources_root() / "demo_data/speed_limit_train_sim_demo/" | ||
|
||
if ENABLE_REF_OVERRIDE: | ||
ref_dir.mkdir(exist_ok=True, parents=True) | ||
df: pl.DataFrame = train_sim.to_dataframe().lazy().collect()[-1] | ||
df.write_csv(ref_dir / "to_dataframe_expected.csv") | ||
if ENABLE_ASSERTS: | ||
print("Checking output of `to_dataframe`") | ||
to_dataframe_expected = pl.scan_csv( | ||
ref_dir / "to_dataframe_expected.csv").collect()[-1] | ||
assert to_dataframe_expected.equals(train_sim.to_dataframe()[-1]), \ | ||
f"to_dataframe_expected: \n{to_dataframe_expected}\ntrain_sim.to_dataframe()[-1]: \n{train_sim.to_dataframe()[-1]}" + \ | ||
"\ntry running with `ENABLE_REF_OVERRIDE=True`" | ||
print("Success!") | ||
|
||
# %% | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@FDsteven this
fc_with_derate_dict
is the conventional FC. We need to make an equivalent for the hybrid and set the derate on it instead!set_...derate
method