-
Notifications
You must be signed in to change notification settings - Fork 4
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
Immediate Result and Global Result usage in Python #45
Comments
Hi, Felipe,
The minimal examples at https://github.com/dss-extensions/dss_capi/tree/master/examples illustrate the basic usage. Basically, most of the API functions do something like:
In terms of operation, there are no differences. This is an API-only aspect. In fact, all GR functions just call the IR functions with the matching pointers. The only difference is where vector/array results are stored.
On the Python side, right now we always copy the buffer into a new "native" buffer (e.g. through NumPy), independent of GR or IR usage. Same is valid for the other DSS Extensions. Since DSS C-API version 0.10.0, the buffers can be reused since we introduced a capacity value besides the current size value (hence the usage of
That's up to the DSS C-API users. On DSS Python, I left the GR as a default to check if anybody would complain. A few years later, so far nothing -- thus, either the IR bindings in DSS Python will be removed by version 1.0 or we will track the memory better and avoid the extra copies and migrate the default back to the IR functions, then removing the GR usage. Some decisions will depend on how much better/faster is CPython 3.11. Nowadays, DSS Sharp and DSS MATLAB are already using or have open PRs to migrate to the GR API. OpenDSSDirect.py probably will be migrated soon, too, getting it closer to DSS Python. For OpenDSSDirect.jl, we should benchmark a couple of things first before deciding how to handle this and the topic of your next question.
You can with the next version of DSS C-API since most of the global state in the OpenDSS engine was encapsulated in a new DSSContext class. See the latest beta versions at https://pypi.org/project/dss-python/#history On the official OpenDSS, even the latest versions, you can't create multiple instances, all you have is the actor/PM mechanism, which is limited. Some more notes at: #42 (comment) Please also check the pull requests for the source code and other notes: Besides some minor final tweaks, we're finishing the initial documentation for this new release before publishing the new docs repo and the final version. Implementation-wise, all functions need to pass the DSS context as a pointer. To reduce the overhead in both run-time and programming time, DSS Python just uses Threading in Python is not always that useful (due to the GIL), but since the CFFI releases the GIL, it can still help. And multiple DSS engines can still be useful in single-threaded scenarios. As always, Python is still great for prototyping. By the way, I don't recommend instantiating throw-away instances since it would be heavy. I'd say creating a pool of instances and reusing them as necessary is the best way to go. |
Ok Paulo! Thanks! I'll wait until the release of the next version of DSS C-API. |
Hi!
I have a question about the two ways to use DSS's APIs.
The
dss_capi
provides two modes of usage: Immediate Result (IR) and Global Result (GR).These two modes are also imported on
dss_python
, but by default, only the Global Result is used:https://github.com/dss-extensions/dss_python/blob/2dbc72ed875108d3f98d21cb0a488bab6b0d7f4c/dss/v7.py#L22-L24
In the same documentation of
dss_capi
is cited that:But, what are the differences between these two modes of usage?
When is the IR more appropriate instead of GR?
And, for the last, is there a way to create a local instance of DSS? For example, that I can instantiate inside a function and don't changes others? If not, is there a way to implement it?
Thanks in advance!
The text was updated successfully, but these errors were encountered: