Skip to content

Commit

Permalink
adding shell scripts for one line execution of pre and post processin…
Browse files Browse the repository at this point in the history
…g steps
  • Loading branch information
ebalogun01 committed Dec 26, 2023
1 parent e24c0b2 commit f41ea6c
Show file tree
Hide file tree
Showing 13 changed files with 2,994 additions and 3,551 deletions.
32 changes: 20 additions & 12 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""

import sys
import argparse
sys.path.append('./charging_sim')
import os
from charging_sim.orchestrator import ChargingSim
Expand Down Expand Up @@ -46,7 +47,7 @@ def create_results_folder():
os.mkdir('analysis/results')


def load_default_input():
def load_input():
"""
Loads the default user input skeleton.
Expand Down Expand Up @@ -84,7 +85,7 @@ def make_month_str(month_int: int):
# user_inputs = load_default_input()


def simulate(user_inputs, sequential_run=True, parallel_run=False, test=False):
def simulate(user_inputs, sequential_run=True, parallel_run=False, testing=False):
# Updating the user inputs based on frontend inputs.
create_results_folder() # Make a results folder if it does not exist.

Expand Down Expand Up @@ -221,11 +222,11 @@ def make_scenarios():
voltage_idx += 1
return scenarios_list

def run(scenario, testing=False):
def run(scenario, is_test=False):
"""
Runs a scenario and updates the scenario JSON to reflect main properties of that scenario.
:param testing:
:param is_test:
:param scenario: The scenario dictionary that would be run.
:return: None.
"""
Expand All @@ -234,17 +235,17 @@ def run(scenario, testing=False):
if not os.path.exists(save_folder_prefix):
os.mkdir(save_folder_prefix)
EV_charging_sim.setup(dcfc_dicts_list + l2_dicts_list, scenario=scenario)
print('multistep')
if testing:
if is_test:
print("Basic testing passed!")
return True
print('multistep begin...')
EV_charging_sim.multistep()
print('multistep done')
EV_charging_sim.load_results_summary(save_folder_prefix)
with open(f'{save_folder_prefix}scenario.json', "w") as outfile:
json.dump(scenario, outfile, indent=1)

def run_scenarios_sequential(testing=False):
def run_scenarios_sequential(is_test=testing):
"""
Creates scenarios based on the energy and c-rate lists/vectors and runs each of the scenarios,
which is a combination of all the capacities and c-rates.
Expand All @@ -265,17 +266,24 @@ def run_scenarios_sequential(testing=False):
scenario["dcfc_caps"] = [station["DCFC"] for station in dcfc_dicts_list]
if l2_dicts_list:
scenario["l2_caps"] = [station["L2"] for station in l2_dicts_list]
run(scenario, testing=testing)
print(is_test)
run(scenario, is_test=is_test)

if sequential_run:
print("Running scenarios sequentially...")
run_scenarios_sequential(testing=test)
run_scenarios_sequential(is_test=test)
print("Simulation complete!")

return


if __name__ == '__main__':
test = False
USER_INPUTS = load_default_input()
simulate(USER_INPUTS, test=test)
parser = argparse.ArgumentParser()
parser.add_argument('--test', type=bool, default=False,
help='This flag only included for testing deployment, do not change.')

args = parser.parse_args()
test = args.test

USER_INPUTS = load_input()
simulate(USER_INPUTS, testing=test)
41 changes: 41 additions & 0 deletions evecosim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
This file runs the evecosim.py file with optional arguments. It uses the shell scripts to run the desired
simulations. The shell scripts are located in the same directory as this file. This file requires WSL2 to run without errors.
"""

import subprocess
import argparse


def run_mpc_grid_centralized():
subprocess.call(['sh', './run-mpc-grid-central.sh'])
return


def run_mpc_grid_collocated():
subprocess.call(['sh', './run-mpc-grid.sh'])
return


def run_oneshot_opt():
subprocess.call(['sh', './run-oneshot.sh'])
return


def main(mode):
if mode == 'oneshot':
run_oneshot_opt()
elif mode == 'mpc-grid':
run_mpc_grid_collocated()
elif mode == 'mpc-grid-central':
raise NotImplementedError
else:
raise ValueError(f'Invalid mode: {mode}. Please choose from: oneshot, mpc-grid')


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--mode', type=str, default='oneshot',
help='This flag only included for testing deployment, do not change.')
args = parser.parse_args()
main(args.mode)
36 changes: 36 additions & 0 deletions shell_scripts/run-mpc-grid-central.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh


cd ../test_cases/battery/feeder_population || exit

python_file="feeder_population_centralized.py"
text_file="config.txt"

timestamp_file="exec_timestamp_cen.txt"

# Function to get the last run time
get_last_run_time() {
if [ -e "$timestamp_file" ]; then
cat "$timestamp_file"
else
echo 0
fi
}

# Get the modification times of the files
text_file_time=$(stat -c %Y "$text_file")
last_run_time=$(get_last_run_time)
#printf "Text file time: %s\n" "$(date -d @"$text_file_time")"
#printf "Last run time: %s\n" "$(date -d @"$last_run_time")"

# Compare the modification times
if [ "$text_file_time" -gt "$last_run_time" ]; then
echo "Feeder config text file has been modified. Running central feeder population..."
date +%s > "$timestamp_file"
python3 "$python_file"
else
echo "No feeder pop config changes detected. Feeder population will not be run."
fi

cd .. || exit
gridlabd python scenarios.py --scenario 1
36 changes: 36 additions & 0 deletions shell_scripts/run-mpc-grid.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh


cd ../test_cases/battery/feeder_population || exit

python_file="feeder_population_collocated.py"
text_file="config.txt"

timestamp_file="exec_timestamp_coll.txt"

# Function to get the last run time
get_last_run_time() {
if [ -e "$timestamp_file" ]; then
cat "$timestamp_file"
else
echo 0
fi
}

# Get the modification times of the files
text_file_time=$(stat -c %Y "$text_file")
last_run_time=$(get_last_run_time)
#printf "Text file time: %s\n" "$(date -d @"$text_file_time")"
#printf "Last run time: %s\n" "$(date -d @"$last_run_time")"

# Compare the modification times
if [ "$text_file_time" -gt "$last_run_time" ]; then
echo "Feeder config text file has been modified. Running feeder population..."
date +%s > "$timestamp_file"
python3 "$python_file"
else
echo "No feeder pop config changes detected. Feeder population will not be run."
fi

cd .. || exit
gridlabd python scenarios.py --scenario 1
6 changes: 6 additions & 0 deletions shell_scripts/run-oneshot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

cd ..
python3 app.py
cd analysis || exit
python3 load_post_opt_costs.py
2 changes: 1 addition & 1 deletion test_cases/battery/IEEE123_populated.glm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#set minimum_timestep=60

clock {
starttime '2018-07-01 00:00:00';
starttime '2018-07-07 00:00:00';
stoptime '2018-07-30 23:59:00';
}

Expand Down
Loading

0 comments on commit f41ea6c

Please sign in to comment.