Open Jiadalee opened 5 years ago
Hi Jiadalee,
Thanks for reaching out. The main result that the current version of the code produces is a csv file in the results_dir
(an input to the run_swmm_mpc
function). The csv file is titled [start datetime]_ctl_results_[run_suffix]
where run_suffix
is another parameter of the run_swmm_mpc
function. After you run your code do you see that file?
Hi Jeff:
No. Basically, I wrote the 'my_swmm_mpc.py'file and created a 'result' folder. After that, I run my_swmm_mpc.py in Linux system. This shows running is successful but there is nothing in the 'results 'folder. Can you help me check the 'my_swmm_mpc.py' file? I can share it with you.
Hi Jeff:
What does 'To add to the path, add this line to your .bashrc' mean? Is .bashrc a file?
Hi @Jiadalee , I can definitely look at your my_swmm_mpc.py
file. What is output to the shell when you run it? Do you see some information about the the genetic algorithm generations? And yeah. The .bashrc
is a file. It's should be in your home directory if you are running Linux.
Thanks!. I added 'print(MPC is great)'at the end of the my_swmm_mpc.py file. So the output to my shell is only'MPC is great'. I didn't see any info about GA generators. I'm wondering if there are problems in the setting-up before running.
Below is the my_swmm_mpc codes:
from swmm_mpc import run_swmm_mpc
input_file = "/uufs/chpc.utah.edu/common/home/u1147017/RL/flux_version_system_run/swmm_mpc/swmm_mpc/sample.inp" control_horizon = 1. #hr control_time_step = 900. #sec control_str_ids = ["ORFICE R1", "ORIFICE R2"] results_dir = "/uufs/chpc.utah.edu/common/home/u1147017/RL/flux_version_system_run/swmm_mpc/swmm_mpc/results/" work_dir = "/uufs/chpc.utah.edu/common/home/u1147017/RL/flux_version_system_run/swmm_mpc/swmm_mpc/" ngen = 4 nindividuals = 300
target_depth_dict = {'St1':{'target':1, 'weight':0.1}, 'St2':{'target':1.5, 'weight':0.1}}
def main(): run_swmm_mpc(inp_file, control_horizon, control_time_step, work_dir, target_depth_dict = target_depth_dict, ngen = ngen, nindividuals = nindividuals ) if name == "main": main()
How long does it take to run that?
just two seconds. Very short
Hmm. When I run it, it usually takes at least 10 minutes. Where in the above code do you have your print statement? I don't see it. Also, do you mind using the markdown code block feature so it's easier to read?
Hi:
No problem! Sorry, I put the code in the swmm_mpc.py. Did you mean create an MD file?
Jiada
Can I email this code to you?
Sure. You can email me OR maybe it would be easier to send on Research Gate. I just replied to your thread about sharing the paper. Let me know if that works. If not, I can give you my email address.
Just got your code file. Which version of Python are you running? Also, I think one of your problems is in the last part of your script. You have
if _name_ == "_main_":
What I think you need to have is
if __name__ == "__main__":
(add another underscore before and after name
and main
)
Also, although you have the results_dir
variable at the top of your script, you do not include that as an input parameter when you are actually calling the run_swmm_mpc
method.
Hi Jeff:
I use Python 3.6.7 to run my codes.
Oh! I see. I have changed the codes and also added the results_dir to the input variable(see the screenshot). Still, same problem....
underscore to 'nam'e was also added ..
from swmm_mpc import run_swmm_mpc
input_file = "/uufs/chpc.utah.edu/common/home/u1147017/MPC/swmm_mpc/swmm_mpc/sample.inp"
control_horizon = 1. #hr
control_time_step = 900. #sec
control_str_ids = ["ORFICE R1", "ORIFICE R2"]
results_dir = "/uufs/chpc.utah.edu/common/home/u1147017/MPC/swmm_mpc/swmm_mpc/results/"
work_dir = "/uufs/chpc.utah.edu/common/home/u1147017/MPC/swmm_mpc/swmm_mpc/"
ngen = 4
nindividuals = 300
target_depth_dict = {'St1':{'target':1, 'weight':0.1}, 'St2':{'target':1.5, 'weight':0.1}}
def main():
run_swmm_mpc(input_file,
control_horizon,
control_time_step,
work_dir,
results_dir,
target_depth_dict = target_depth_dict,
ngen = ngen,
nindividuals = nindividuals
)
if __name__ == "__main__":
main()
Okay. I've only been running this on Python 2.7. I haven't tried on Python 3. So I would first suggest to try running on Python 2.7. After that, I'm still a little unsure that it is running at all. Could you put a print statement in your code? like this:
def main():
run_swmm_mpc(input_file,
control_horizon,
control_time_step,
work_dir,
results_dir,
target_depth_dict = target_depth_dict,
ngen = ngen,
nindividuals = nindividuals
)
print 'yep. my code is running'
if name == "main":
main()
Sure! Let me have a try
Sorry. I got the same error. ...
Actually, I double checked the codes like swmm_mpc.py and run_ea.py file. I found it seems they are written in Python 3 since they use syntax such as print (' xxx ') but not print ' '. If so, I think running them in Python 3 is a correct way.
Can I run these codes in Windows system? If so, how should I do? Thanks
Jiada
Ah....I think I have compiled it to my Local PC. But I got an ImportWarning.
Ok, I fixed this local PC 'deap' problem of swmm_mpc. So here comes the same question just same as I run it in Linux system: I can run it but no output in 'results' folder.....
Currently, running on Windows is not supported.
I am trying your code on my computer to see if I can reproduce the behavior your seeing
@Jiadalee, I ran your code and found a couple problems.
control_str_ids
in your function callif __name__ ...
line is outside your main()
functionSt1
and St2
in the target_depth_dict
(this was a problem in my example in the readme which has been fixed now. After changing all those thing, I got it to work.
Thanks. I will check it out.
I modified my codes. This time I got a log file in my 'results' folder. I passed this file to you via researchgate
Oh. I fixed the last question
Here comes another one:
when I include the ifname...line inside the main() function, then, I run the codes. Finally, there is no error and I also got a newly-produced .inp file which is called 'simple_processed'. However, nothing in the results folder....
I can get a new .rpt file now after running it in python3
Hi:
Do you know how to solve the time_step problem?
Awesome. So you are getting it to run. That is actually a known bug with a simple fix that I've neglected to push. I will push that today.
I just pushed the commit that should fix that. After you run the code, it should update the control rules of the .inp
file that you gave it. https://github.com/UVAdMIST/swmm_mpc/commit/3dd16c6e0ae4a9b6770089151e4016d41b584219
I'm testing it now.
Yes. It basically can run in the Linux system now.
I just ran it with the latest commit and there was no error. Pls let me know if you still have an error.
so you added a line '''python sim_start_dt = pd.to_datetime(sim_start_time) ''' before 'ct1_settings_df.....'
Hi:
I still got this error. Actually, I have adjusted the code to make it run in Python3. So, could you let me know where you modify the code to fix the last error? so I can also do this in my side. Thanks
Hi yes. If you just make the changes from this commit in your code, it should work: https://github.com/UVAdMIST/swmm_mpc/commit/3dd16c6e0ae4a9b6770089151e4016d41b584219 . Let me know if that makes sense.
And that's cool you got it to run in Python3. What changes did you have to make?
Hi Jeff:
Sorry for the late reply.
Basically, I modified the tabs and indentations. I will send you the updated scripts for running in Python3 Linux system soon.
Hi: I test these modified codes in python 3 again. I used the simple.inp model and only got 15-min simulation results. Can this code only run 15 mins?
minhhai@MInhHai:/mnt/c/swmmmpc/models/runs$ python hgv11.py {'optimization_params': {u'num_cores': 20, u'nindividuals': 20, u'ngen': 5}, 'n_ctl_steps': 2, 'ctl_horizon': 0.5, 'work_dir': u'/mnt/c/swmmmpc/models/runs/work', 'inp_file_dir': u'/mnt/c/swmmmpc/models/runs', 'flood_weight': 1, 'inp_file_path': u'/mnt/c/swmmmpc/models/runs/hague_v11_template.inp', 'results_dir': u'/mnt/c/swmmmpc/models/runs/rtc_output', 'opt_method': u'genetic_algorithm', 'run_suffix': u'hgv11_base_00_2yr12hr_gate_ga', 'ctl_str_ids': [u'PUMP P0', u'WEIR W0', u'ORIFICE R2'], 'target_depth_dict': None, 'ctl_time_step': 900, 'dev_weight': 0, 'log_file': u'/mnt/c/swmmmpc/models/runs/rtc_output/log_hgv11_base_00_2yr12hr_gate_ga', 'inp_process_file_path': u'/mnt/c/swmmmpc/models/runs/work/hague_v11_template_process.inp', 'node_flood_weight_dict': None} Simulation start: 2021.02.09.16.04 2016-10-08 00:15:01
Thank you very much in advance. Regards, Dang Minh Hai
@DangMH-TLU It seems the working directory is not correct. Can you introduce which programming environment are you using and how did you navigate to your working dir?
Hi Jiadalee, I run Swmm_mpc on python 2.7 on Ubuntu 18.04. I navigate to the working directory as follows:cd /mnt/c/swmmmpc/models/runs/ Thank you very much. Regards, Dang Minh Hai
Hi @DangMH-TLU - sorry for the slow reply. I think your error means that you haven't installed swmm5 correctly or it's not in your path. Did you follow this step in the readme? https://github.com/UVAdMIST/swmm_mpc#2-install-epaswmm5
@bdb3m - didn't you have a similar problem? Were you able to fix that?
@jsadler2 I'm fuzzy on the details since it's been a while but that sounds right. I'll see if I can find anything in my notes.
@DangMH-TLU I hope jsadler2's response can help you get it working!
@jsadler2 : Thank you very much. I fixed sucessfully the error which originated from the wrong working directory in the .bashrc file. Again, thank you very much!
@bdb3m Thank you very much!
Glad you got it working!
Hi :
I can run your codes but I didn't get any results. Have you ever encounter this problem?