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

Issue deleting a node #352

Closed
uthmankareem opened this issue Jun 2, 2023 · 7 comments
Closed

Issue deleting a node #352

uthmankareem opened this issue Jun 2, 2023 · 7 comments

Comments

@uthmankareem
Copy link

Summary
Describe your question.

Example
[Optional] Include an example. The example can use INP files from the examples folder.
I was trying to remove negative nodes and pipes associated with them. This is being done in a control loop because I am running 1000 of it. I did the first simulation by removing some selected pipes and adding leaks to some. Then I found nodes with negative pressure so I can delete them including the pipes connected to them but I got "RuntimeError: Cannot remove node 187leak_node without first removing control/rule junction187leak_nodestart_leak_control". Firstly, there was no node 187 in the original network file so I assume this node name was automatically assigned when I added the leak. Apart from the error, I want to believe leak node will always have negative pressure. if this is true, I do not need to delete leak node then but how do I capture that the negative pressure node selected is a leaknode given that the simulation is run within a loop? How do I address the error as well?
Thank you.

Environment
[Optional] Provide information on your computing environment.

  • Operating system: 10
  • Python version: 3.5
  • WNTR version:0.4
@uthmankareem
Copy link
Author

I was able to address the above issue by getting a list for the leaknode and checking if it already exists. However, I am having error. I do not know the cause of this and what I can do to address it.

ndexError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_28132/2498113446.py in
94 wn.remove_node(j)
95 sim = wntr.sim.WNTRSimulator(wn)
---> 96 results = sim.run_sim(solver=wntr.sim.solvers.NewtonSolver, backup_solver=None, solver_options={'MAXITER':3000, 'TOL':0.0003, 'BT_MAXITER':200},
97 backup_solver_options=None, convergence_error=False, HW_approx='default',
98 diagnostics=False)

~\Anaconda3\lib\site-packages\wntr\sim\core.py in run_sim(self, solver, backup_solver, solver_options, backup_solver_options, convergence_error, HW_approx, diagnostics)
1242 results.network_name = self._wn.name
1243
-> 1244 self._initialize_internal_graph()
1245 self._change_tracker.set_reference_point('graph')
1246 self._change_tracker.set_reference_point('model')

~\Anaconda3\lib\site-packages\wntr\sim\core.py in _initialize_internal_graph(self)
1418 self._number_of_connections = [0 for i in range(self._wn.num_nodes)]
1419 for node_id in self._node_id_to_name.keys():
-> 1420 self._number_of_connections[node_id] = self._internal_graph.indptr[node_id+1] - self._internal_graph.indptr[node_id]
1421 self._number_of_connections = np.array(self._number_of_connections, dtype=self._int_dtype)
1422

IndexError: index 255 is out of bounds for axis 0 with size 255

@kaklise
Copy link
Collaborator

kaklise commented Jun 5, 2023

I'm happy to hear that you were able to get a list of leak nodes.

"RuntimeError: Cannot remove node..." indicates that the leak node is associated with a control and cannot be removed until the control is removed. This error is thrown anytime you try to remove an element with a control.

I'm not able to follow the third issue regarding index 255. Please post a complete example with a network from the examples folder.

@uthmankareem
Copy link
Author

uthmankareem commented Jun 6, 2023 via email

@kaklise
Copy link
Collaborator

kaklise commented Jun 6, 2023

If you get the control name using wn.control_name_list, you can remove the control using wn.remove_control("control name").

You can also remove the leak from the junction object using junction.remove_leak(). The junction object stores the control name and calls remove_control.

@uthmankareem
Copy link
Author

uthmankareem commented Jun 6, 2023 via email

@uthmankareem
Copy link
Author

uthmankareem commented Jun 7, 2023 via email

@kaklise
Copy link
Collaborator

kaklise commented Jun 9, 2023

Thanks @uthmankareem, Feel free update #342 with updates on using WNTR in Google Collab.

@kaklise kaklise closed this as completed Jun 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants