Skip to content

Commit

Permalink
Fix docs precommit errors (#2711)
Browse files Browse the repository at this point in the history
* Fix pre-commit errors in the documentation

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
nightlark and pre-commit-ci[bot] authored Dec 6, 2024
1 parent c7af509 commit 6febab5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion docs/references/publications.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Y. Liu, R. Huang, W. Du, A. Singhal and Z. Huang, "High-Performance Transmission
Narayanan, Anantha, and Hardy, Trevor. "Synthetic Data Generation for Machine Learning Model Training for Energy Theft Scenarios Ssing Cosimulation". United Kingdom: N. p., 2022. Web. doi:10.1049/gtd2.12619, available at [https://ietresearch.onlinelibrary.wiley.com/doi/10.1049/gtd2.12619](https://ietresearch.onlinelibrary.wiley.com/doi/10.1049/gtd2.12619).

Jing Wang, Prateek Munankarmi, Jeff Maguire, Chengnan Shi, Wangda Zuo, David Roberts, Xin Jin. "Carbon emission responsive building control: A case study with an all-electric residential community in a cold climate". Applied Energy, Volume 314,2022, 118910,
doi: 10.1016/j.apenergy.2022.118910, available at (https://www.sciencedirect.com/science/article/pii/S0306261922003336)[https://www.sciencedirect.com/science/article/pii/S0306261922003336].
doi: 10.1016/j.apenergy.2022.118910, available at [https://www.sciencedirect.com/science/article/pii/S0306261922003336](https://www.sciencedirect.com/science/article/pii/S0306261922003336).

A. Singhal, T. L. Vu and W. Du, "Consensus Control for Coordinating Grid-Forming and Grid-Following Inverters in Microgrids," in IEEE Transactions on Smart Grid, vol. 13, no. 5, pp. 4123-4133, Sept. 2022, doi: 10.1109/TSG.2022.3158254, available at [https://ieeexplore.ieee.org/document/9732444](https://ieeexplore.ieee.org/document/9732444).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ The only difference between the federation as defined in the "advanced default"

The match-file can be specified either using a plain textfile or JSON. The simplest format specifies the individual connections between federates, one connection per line:

```
```text
Charger/EV1_output_voltage Battery/EV1_input_voltage from_to
Charger/EV2_output_voltage Battery/EV2_input_voltage from_to
Charger/EV3_output_voltage Battery/EV3_input_voltage from_to
Expand Down Expand Up @@ -103,7 +103,7 @@ The "from-to" or "to-from" is used to indicate which side of the connection is u

Alternatively, the match-file can be specified using regular expressions. This can be a convenient way to specify a large number of interface connections if they follow a naming convention. The regular expression format takes advantage of the ability to name terms in the expression, allowing terms in one part of the expression to be used later on in the expression. In the case, the above match-file looks like this:

```
```text
# this is a comment
REGEX:Charger/EV(?<ev_num>\d*)_output_voltage, REGEX:Battery/EV(?<ev_num>)_input_voltage, from_to
REGEX:Charger/EV(?<ev_num>\d*)_input_current, REGEX:Battery/EV(?<ev_num>)_output_current, from_to
Expand Down Expand Up @@ -148,15 +148,18 @@ class UserData(object):
The function that is called when the query is made. In our example, we called it "query_callback" and it has a decorator of the callback function in C that must match the signture of said function.

```python
@h.ffi.callback("void query(const char *query, int querySize, HelicsQueryBuffer buffer, void *user_data)")
def query_callback(query_ptr, size:int, query_buffer_ptr, user_data):
@h.ffi.callback(
"void query(const char *query, int querySize, HelicsQueryBuffer buffer, void *user_data)"
)
def query_callback(query_ptr, size: int, query_buffer_ptr, user_data):
...
```

The query being sent to this federate is defined in the "query_buffer_ptr" variable but must be decoded into a string by declaring it a HELICS buffer object and then decoding it into a string:

```python
query_buffer = h.HelicsQueryBuffer(query_buffer_ptr)
query_str = h.ffi.string(query_ptr,size).decode()
query_str = h.ffi.string(query_ptr, size).decode()
```

After doing all this work, we can see that the query sent is "potential_interfaces"; this is the query sent by helics_connector to find out what potential interfaces each federate can create. To answer this query we need to pull in the number of EVs passed in through the UserData object
Expand All @@ -171,11 +174,7 @@ The query response is a JSON dictionary composed of three lists: the federates p
for EVnum in range(1, num_EVs + 1):
pubs.append(f"Battery/EV{EVnum}_output_current")
inputs.append(f"Battery/EV{EVnum}_input_voltage")
response_dict = {
"publications": pubs,
"inputs": inputs,
"endpoints": []
}
response_dict = {"publications": pubs, "inputs": inputs, "endpoints": []}
query_response = json.dumps(response_dict)
h.helicsQueryBufferFill(query_buffer, query_response)
```
Expand Down Expand Up @@ -216,11 +215,11 @@ The example code checks to make sure the interfaces are provided as lists and th

```python
if isinstance(cmd["publications"], list):
for pub in cmd["publications"]:
h.helicsFederateRegisterGlobalPublication(fed, pub, h.HELICS_DATA_TYPE_DOUBLE)
for pub in cmd["publications"]:
h.helicsFederateRegisterGlobalPublication(fed, pub, h.HELICS_DATA_TYPE_DOUBLE)
if isinstance(cmd["inputs"], list):
for inp in cmd["inputs"]:
h.helicsFederateRegisterGlobalInput(fed, inp, h.HELICS_DATA_TYPE_DOUBLE)
for inp in cmd["inputs"]:
h.helicsFederateRegisterGlobalInput(fed, inp, h.HELICS_DATA_TYPE_DOUBLE)
```

##### Interface creation timing
Expand All @@ -233,14 +232,14 @@ h.helicsFederateEnterInitializingModeIterative(fed)
# available earlier. Callback responds whenever the query comes in.
h.helicsFederateEnterInitializingModeIterative(fed)
command = h.helicsFederateGetCommand(fed)
if len(command) == 0:
raise TypeError("Empty command.")
try:
logger.debug(f"command string: {command}")
cmd = json.loads(command)
except:
raise TypeError("Not able to convert command string to JSON.")
register_interfaces_from_command(fed, cmd) # custom function
if len(command) == 0:
raise TypeError("Empty command.")
try:
logger.debug(f"command string: {command}")
cmd = json.loads(command)
except:
raise TypeError("Not able to convert command string to JSON.")
register_interfaces_from_command(fed, cmd) # custom function
h.helicsFederateEnterExecutingMode(fed)
```

Expand Down

0 comments on commit 6febab5

Please sign in to comment.