dss-extensions / DSS-Python

Native, "direct" Python bindings (interface) and misc tools for a custom implementation of OpenDSS (EPRI Distribution System Simulator). Based on CFFI, DSS C-API, aiming for full COM API-level compatibility on Windows, Linux and MacOS, while providing various extensions.
https://dss-extensions.org/DSS-Python/
BSD 3-Clause "New" or "Revised" License
60 stars 4 forks source link

Publish the base code for Python user-models #14

Closed PMeira closed 1 year ago

PMeira commented 6 years ago

The Python user-models wrap a C DLL (built with CFFI currently) and provide a Pythonic and more approachable way of creating user-models for the following components, with no need to write a DLL in Pascal/Delphi or C:

So far we tested it mostly with generators.

These models can be used with either a COM instance (with limitations due to a bug) or DSS Python's instance.

Other tasks:

PMeira commented 5 years ago

Pushing this to 0.11.

f-rosato commented 5 years ago

Can you please provide a minimal example of usermodel definition for a generator and the following circuit solution?

PMeira commented 5 years ago

Hi @f-rosato, I started working on a full example for the generator, I'll try to finish tomorrow.

PMeira commented 5 years ago

@f-rosato Please check this notebook and the files in that folder:

https://github.com/dss-extensions/dss_python/blob/master/docs/examples/UserModels/PyIndMach012/README.ipynb

It's not a step-by-step manual but I tried to comment most of code to illustrate how to use it.

I found some issues with recent versions of OpenDSS 8 to handle later. I left some comments about them.

Funnily enough, I also found an issue with IndMach012 class in DSS C-API to investigate later, https://github.com/dss-extensions/dss_capi/issues/62. For now, if you're running on Linux/macOS, just comment the bad plots (plt.plot(time, outputs_pas[ch_pas], label='IndMach012', lw=3). Actually it was an issue with the Monitors, missing a copy in the Channel function. Fixed in master, will be available on the next release.

PMeira commented 3 years ago

It's been a couple of years. Since the official OpenDSS still has bugs/incomplete support for user-models (including still v7 vs v8+ issues), we'll abandon the idea of supporting the same models as EPRI's official OpenDSS, releasing an alternative approach in the coming months.

utamrakar commented 2 years ago

@PMeira I am trying to adapt this to write a Storage User-Model. Since, you mentioned there are some issues and this idea has been abandon are there any updates in future directions you are taking? I was wondering if you have tested this for other components apart from the Gen models.

PMeira commented 2 years ago

@utamrakar Sorry about the extended delay on this topic. I was supposed to have at least one student to help on this, but my local team has been short-staffed for a while (mostly due to the pandemic).

I personally only used the Generator and CapControl user-models. I've seen some brief mentions of inverters (e.g. see slide 12 in https://documents.pserc.wisc.edu/documents/general_information/presentations/pserc_seminars/webinars_2021/Webinar_Slides_Ayyanar_Yang_Chongfuangprinya_8_31_21.pdf ), but it's unclear which kind of base model was used.

For the next release (0.12.0), only the Generator user-model will be left enabled on DSS Python. The low-level headers in DSS C-API are still there and are updated in the current beta releases, but you need conditional compilation (i.e. define DSS_CAPI_DLL when targeting DSS C-API) for some models due some internal changes in DSS C-API -- the generator model doesn't need that, so we can leave it enabled in DSS Python without extra work.

In 2021, we decided to move the base library (DSS C-API) from Pascal to C++. The results of that should be out still in this semester (we already have some results in a private branch). I shouldn't say too much since it's still in flux, but the new approach for user-models will be based on that, and the new/rewritten property system coming in v0.12.

For a general overview of the current development, please see also the main v0.12 PR at https://github.com/dss-extensions/dss_capi/pull/109