-
Notifications
You must be signed in to change notification settings - Fork 206
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
Batch request node and link properties #785
Comments
I believe if we added these new methods it would be the first API that returned an array of data. So we'd want to pick a convention that we could follow for any other future methods. I had a quick look through the documentation and Also just to play devils advocate, but is it worth adding a new method to the library when the end users could also ~10 LoC to their own application to extract results? You mentioned that there is an inefficiency in that the user would need to call Saying that, this would be a huge improvement for From my testing I could run a function like |
I dug up an old replit I made to test the performance of the API in C. The model is relatively small, only 2k nodes but the code extracts every simulation property for all nodes and links and it takes 0.0002 seconds. https://replit.com/@lbutler1/epanet-v22-performance#main.c Not to say these new functions your proposing aren't worthy, but maybe instead of inefficiency its about improving the convenience of the API |
@lbutler we have |
Hi Luke, Agreed, the source of the performance issues lies in the overhead of translating API calls from other languages, i.e. ctypes or wasm bindings, not in the way EPANET handles things. It is more of a convenience method then something that is strictly necessary. However, I'm fairly confident to assume that the (vast?) majority of users use some kind of scripting language such as MatLAB, Python, Javascript or R to interact with EPANET and to process, analyse and visualise the results, instead of communicating with the API using C. For our use-case, implementing these convenience methods will help speed up our Python based applications by a factor of ±30! |
@AbelHeinsbroek - Great we're on the same page then, sorry for being a bit pedantic with my response! I do think adding these methods would be beneficial for many of the downstream libraries that provide EPANET in other programming languages. |
Hi @AbelHeinsbroek, I agree with you! I think we don’t need to add new functions. Instead, we could modify the existing ones, such as |
@Mariosmsk I guess the hardest part of using the existing functions would be maintaining backwards compatibility. You could in theory pass a number like zero or some other constant in the index to signify you wanted all results. But I'm not sure if this would make things more complicated then having a second function? Very rough guess below of how it could be implemented
|
Sharing my 2 cents:
|
Thanks Lew, I've changed the name of the new functions. I've done some more testing with the new methods: from timeit import Timer
import epynet
net = epynet.Network('demo.inp')
net.solve()
l = len(net.nodes)
# get pressure for all nodes in the network
def a():
pres = []
for i in range(1,l+1):
pres.append(net.ep.ENgetnodevalue(i, 11))
return pres
def b():
pres = net.ep.ENgetnodevalues(11)[:l]
return pres
time_a = Timer(lambda: a()).timeit(number=1000)
time_b = Timer(lambda: b()).timeit(number=1000)
print(f"Number of nodes {l}")
print(f"Method result is equal: {a()==b()} ")
print()
print(f"Method a took {time_a:.3f} milliseconds")
print(f"Method b took {time_b:.3f} milliseconds")
print()
print(f"Method b is {(time_a/time_b):.1f} times faster") Which results in:
|
Hello,
When working with large models, getting all the required parameter values for all nodes and links can be relatively inefficient and time consuming if you make use of the
EN_getnodevalue
andEN_getlinkvalue
methods in a loop for all node and link indices and the parameters you're interested in.For example, getting all the pressures at all the nodes in a network requires you to make
EN_NODECOUNT
calls to the EPANET API.While yes, its possible to write all data to a binary output file and parse that file accordingly, that is still rather inefficient as you by default get all parameters for all nodes as well as links and other unwanted data. In addition, if you're not careful writing a binary file to disk and reopening that file for processing is much slower than reading from memory directly.
Therefore I propose adding two new methods to the EPANET API:
ENgetnodesvalues(EN_Project ph, int property, double *out_values)
ENgetlinksvalues(EN_Project ph, int property, double *out_values)
The text was updated successfully, but these errors were encountered: