swmm_mpc
swmm_mpc copied to clipboard
running with no results
Hi :
I can run your codes but I didn't get any results. Have you ever encounter this problem?
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.
- In line 6 you spell "ORIFICE" wrong
- You didn't include
control_str_idsin your function call - make sure your
if __name__ ...line is outside yourmain()function - you need to include "Node" in front of
St1andSt2in thetarget_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 if_name_...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?
