Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 34 additions & 34 deletions .github/workflows/docker-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,39 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: ['3.10']
python-version: ["3.10"]
steps:
- uses: actions/checkout@v2
- name: build docker container
shell: bash
run: |
docker build --progress=plain -t oedisi-example:0.0.0 .
env:
SSH_KEY: ${{secrets.SGIDAL_CLONE_KEY}}
DOCKER_BUILDKIT: '1'
- name: run docker continaer
shell: bash
run: |
mkdir outputs_build
docker volume create --name oedisi_output --opt type=none --opt device=$(pwd)/outputs_build --opt o=bind
docker run --rm --mount source=oedisi_output,target=/simulation/outputs oedisi-example:0.0.0
- name: Set up Python ${{ matrix.python-version }}
uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}
- name: Run plots
shell: bash -l {0}
run: |
pip install matplotlib pyarrow numpy matplotlib pandas
pip install oedisi==1.2.1
- uses: actions/checkout@v2
- name: build docker container
shell: bash
run: |
docker build --progress=plain -t oedisi-example:0.0.0 .
env:
SSH_KEY: ${{secrets.SGIDAL_CLONE_KEY}}
DOCKER_BUILDKIT: "1"
- name: run docker continaer
shell: bash
run: |
mkdir outputs_build
docker volume create --name oedisi_output --opt type=none --opt device=$(pwd)/outputs_build --opt o=bind
docker run --rm --mount source=oedisi_output,target=/simulation/outputs oedisi-example:0.0.0
- name: Set up Python ${{ matrix.python-version }}
uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}
- name: Run plots
shell: bash -l {0}
run: |
pip install matplotlib pyarrow numpy matplotlib pandas
pip install oedisi~=3.0

python post_analysis.py outputs_build
- name: Archive logs
uses: actions/upload-artifact@v4
if: always()
with:
name: docker_logs
path: |
outputs_build/*.log
*.png
python post_analysis.py outputs_build
- name: Archive logs
uses: actions/upload-artifact@v4
if: always()
with:
name: docker_logs
path: |
outputs_build/*.log
*.png
2 changes: 1 addition & 1 deletion LocalFeeder/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ boto3
xarray
fastapi
uvicorn
oedisi>=2.0.2,<3
oedisi~=3.0
python-multipart
30 changes: 15 additions & 15 deletions LocalFeeder/sender_cosim.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def go_cosim(
h.helicsFederateEnterExecutingMode(vfed)
initial_data = get_initial_data(sim, config)

topology_dict = initial_data.topology.dict()
topology_dict = initial_data.topology.model_dump()
topology_dict["bus_coords"] = sim.get_bus_coords()
topology_json = json.dumps(topology_dict)
logger.info("Sending topology and saving to topology.json")
Expand All @@ -352,7 +352,7 @@ def go_cosim(
logger.info("Evaluating the forecasted PV")
forecast_data = sim.forcast_pv(int(config.number_of_timesteps))
PVforecast = [MeasurementArray(**xarray_to_dict(forecast),
units="kW").json() for forecast in forecast_data]
units="kW").model_dump_json() for forecast in forecast_data]
pub_pv_forecast.publish(json.dumps(PVforecast))

granted_time = -1
Expand All @@ -377,11 +377,11 @@ def go_cosim(
config.start_date, "%Y-%m-%d %H:%M:%S"
) + timedelta(seconds=current_index * config.run_freq_sec)

change_obj_cmds = CommandList.parse_obj(sub_command_set.json)
sim.change_obj(change_obj_cmds.__root__)
change_obj_cmds = CommandList.model_validate(sub_command_set.json)
sim.change_obj(change_obj_cmds.root)

inverter_controls = InverterControlList.parse_obj(sub_invcontrol.json)
for inv_control in inverter_controls.__root__:
inverter_controls = InverterControlList.model_validate(sub_invcontrol.json)
for inv_control in inverter_controls.root:
sim.apply_inverter_control(inv_control)

pv_sets = sub_pv_set.json
Expand Down Expand Up @@ -427,46 +427,46 @@ def go_cosim(
VoltagesMagnitude(
**xarray_to_dict(voltage_magnitudes),
time=current_timestamp,
).json()
).model_dump_json()
)
pub_voltages_real.publish(
VoltagesReal(
**xarray_to_dict(current_data.feeder_voltages.real),
time=current_timestamp,
).json()
).model_dump_json()
)
pub_voltages_imag.publish(
VoltagesImaginary(
**xarray_to_dict(current_data.feeder_voltages.imag),
time=current_timestamp,
).json()
).model_dump_json()
)
pub_powers_real.publish(
PowersReal(
**xarray_to_dict(current_data.PQ_injections_all.real),
time=current_timestamp,
).json()
).model_dump_json()
)
pub_powers_imag.publish(
PowersImaginary(
**xarray_to_dict(current_data.PQ_injections_all.imag),
time=current_timestamp,
).json()
).model_dump_json()
)
pub_injections.publish(current_data.injections.json())
pub_injections.publish(current_data.injections.model_dump_json())
pub_available_power.publish(
MeasurementArray(
**xarray_to_dict(sim.get_available_pv()),
time=current_timestamp,
units="kWA",
).json()
).model_dump_json()
)

if config.use_sparse_admittance:
pub_load_y_matrix.publish(
sparse_to_admittance_sparse(
current_data.load_y_matrix, sim._AllNodeNames
).json()
).model_dump_json()
)
else:
pub_load_y_matrix.publish(
Expand All @@ -475,7 +475,7 @@ def go_cosim(
current_data.load_y_matrix.toarray()
),
ids=sim._AllNodeNames,
).json()
).model_dump_json()
)

logger.info("end time: " + str(datetime.now()))
Expand Down
14 changes: 7 additions & 7 deletions LocalFeeder/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ async def timeout_middleware(request: Request, call_next):
if endpoint == "sensor":
response = ServerReply(
detail="Request processing time exceeded limit. Upload a model and associated profiles before simulation before starting the simulation."
).dict()
).model_dump()
return JSONResponse(response, 504)
else:
response = ServerReply(
detail="Request processing time exceeded limit"
).dict()
).model_dump()
return JSONResponse(response, 504)


@app.get("/")
def read_root():
hostname = socket.gethostname()
host_ip = socket.gethostbyname(hostname)
response = HeathCheck(hostname=hostname, host_ip=host_ip).dict()
response = HeathCheck(hostname=hostname, host_ip=host_ip).model_dump()

return JSONResponse(response, 200)

Expand Down Expand Up @@ -83,7 +83,7 @@ async def upload_profiles(file: UploadFile):
) and os.path.exists(os.path.join(profile_path, "pv_profiles")):
response = ServerReply(
detail=f"File uploaded to server: {file.filename}"
).dict()
).model_dump()
return JSONResponse(response, 200)
else:
HTTPException(
Expand Down Expand Up @@ -116,7 +116,7 @@ async def upload_model(file: UploadFile):
if os.path.exists(os.path.join(model_path, "master.dss")):
response = ServerReply(
detail=f"File uploaded to server: {file.filename}"
).dict()
).model_dump()
return JSONResponse(response, 200)

else:
Expand All @@ -132,7 +132,7 @@ async def run_feeder(
logging.info(broker_config)
try:
background_tasks.add_task(run_simulator, broker_config)
response = ServerReply(detail="Task sucessfully added.").dict()
response = ServerReply(detail="Task sucessfully added.").model_dump()

return JSONResponse(response, 200)
except Exception as e:
Expand All @@ -152,7 +152,7 @@ async def configure(component_struct:ComponentStruct):
json.dump(params , open(DefaultFileNames.STATIC_INPUTS.value, "w"))
response = ServerReply(
detail = f"Sucessfully updated configuration files."
).dict()
).model_dump()
return JSONResponse(response, 200)

if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion broker/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ helics>=3.4.0
pyyaml
fastapi
uvicorn
oedisi>=2.0.2,<3
oedisi~=3.0
grequests
python-multipart
14 changes: 7 additions & 7 deletions broker/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def read_root():
hostname = socket.gethostname()
host_ip = socket.gethostbyname(hostname)

response = HeathCheck(hostname=hostname, host_ip=host_ip).dict()
response = HeathCheck(hostname=hostname, host_ip=host_ip).model_dump()

return JSONResponse(response, 200)

Expand All @@ -99,7 +99,7 @@ async def upload_profiles(file: UploadFile):

files = {"file": open(file.filename, "rb")}
r = requests.post(url, files=files)
response = ServerReply(detail=r.text).dict()
response = ServerReply(detail=r.text).model_dump()
return JSONResponse(response, r.status_code)
raise HTTPException(status_code=404, detail="Unable to upload profiles")
except Exception as e:
Expand Down Expand Up @@ -128,7 +128,7 @@ async def upload_model(file: UploadFile):

files = {"file": open(file.filename, "rb")}
r = requests.post(url, files=files)
response = ServerReply(detail=r.text).dict()
response = ServerReply(detail=r.text).model_dump()
return JSONResponse(response, r.status_code)
raise HTTPException(status_code=404, detail="Unable to upload model")
except Exception as e:
Expand Down Expand Up @@ -222,7 +222,7 @@ def run_simulation():
async def run_feeder(background_tasks: BackgroundTasks):
try:
background_tasks.add_task(run_simulation)
response = ServerReply(detail="Task sucessfully added.").dict()
response = ServerReply(detail="Task sucessfully added.").model_dump()
return JSONResponse({"detail": response}, 200)
except Exception as e:
err = traceback.format_exc()
Expand All @@ -234,7 +234,7 @@ async def configure(wiring_diagram: WiringDiagram):
global WIRING_DIAGRAM
WIRING_DIAGRAM = wiring_diagram

json.dump(wiring_diagram.dict(), open(WIRING_DIAGRAM_FILENAME, "w"))
json.dump(wiring_diagram.model_dump(), open(WIRING_DIAGRAM_FILENAME, "w"))
for component in wiring_diagram.components:
component_model = ComponentStruct(component=component, links=[])
for link in wiring_diagram.links:
Expand All @@ -244,14 +244,14 @@ async def configure(wiring_diagram: WiringDiagram):
url = build_url(component.host, component.container_port, ["configure"])
logger.info(f"making a request to url - {url}")

r = requests.post(url, json=component_model.dict())
r = requests.post(url, json=component_model.model_dump())
assert (
r.status_code == 200
), f"POST request to update configuration failed for url - {url}"
return JSONResponse(
ServerReply(
detail="Sucessfully updated config files for all containers"
).dict(),
).model_dump(),
200,
)

Expand Down
Binary file modified errors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions lindistflow_federate/opf_federate.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,22 +112,22 @@ def run(self) -> None:
)
continue

topology = Topology.parse_obj(self.sub.topology.json)
topology = Topology.model_validate(self.sub.topology.json)
[branch_info, bus_info] = adapter.extract_info(topology)

slack = topology.slack_bus[0]
[slack_bus, phase] = slack.split(".")

area_branch, area_bus = area_info(branch_info, bus_info, slack_bus)

voltages_mag = VoltagesMagnitude.parse_obj(self.sub.voltages_mag.json)
voltages_mag = VoltagesMagnitude.model_validate(self.sub.voltages_mag.json)

area_bus = adapter.extract_voltages(area_bus, voltages_mag)

time = voltages_mag.time
logger.info(time)

injection = Injection.parse_obj(self.sub.injections.json)
injection = Injection.model_validate(self.sub.injections.json)
area_bus = adapter.extract_injection(area_bus, injection)

voltages, power_flow, control, conversion = lindistflow.optimal_power_flow(
Expand Down Expand Up @@ -179,10 +179,10 @@ def run(self) -> None:

logger.info(commands)
if commands:
self.pub_commands.publish(CommandList(__root__=commands).json())
self.pub_commands.publish(CommandList(root=commands).model_dump_json())

pub_mags = adapter.pack_voltages(voltages, time)
self.pub_voltages.publish(pub_mags.json())
self.pub_voltages.publish(pub_mags.model_dump_json())

self.stop()

Expand Down
4 changes: 2 additions & 2 deletions lindistflow_federate/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
helics>=3.4.0
pydantic>=1.7,<2
pydantic
cvxpy
numpy
networkx
oedisi>=2,<3
oedisi~=3.0
fastapi
uvicorn
6 changes: 3 additions & 3 deletions lindistflow_federate/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def read_root():
host_ip = socket.gethostbyname(socket.gethostname() + ".local")
except socket.gaierror:
pass
response = HeathCheck(hostname=hostname, host_ip=host_ip).dict()
response = HeathCheck(hostname=hostname, host_ip=host_ip).model_dump()
return JSONResponse(response, 200)


Expand All @@ -35,7 +35,7 @@ async def run_model(broker_config: BrokerConfig, background_tasks: BackgroundTas
federate = EchoFederate(broker_config)
try:
background_tasks.add_task(federate.run)
response = ServerReply(detail="Task sucessfully added.").dict()
response = ServerReply(detail="Task sucessfully added.").model_dump()
return JSONResponse(response, 200)
except Exception as _:
err = traceback.format_exc()
Expand All @@ -52,7 +52,7 @@ async def configure(component_struct: ComponentStruct):
links[link.target_port] = f"{link.source}/{link.source_port}"
json.dump(links, open(DefaultFileNames.INPUT_MAPPING.value, "w"))
json.dump(params, open(DefaultFileNames.STATIC_INPUTS.value, "w"))
response = ServerReply(detail="Sucessfully updated configuration files.").dict()
response = ServerReply(detail="Sucessfully updated configuration files.").model_dump()
return JSONResponse(response, 200)


Expand Down
2 changes: 1 addition & 1 deletion measuring_federate/generate_test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,5 @@ class MeasurementConfig(BaseModel):
voltage_ids=sample(BUSES, 3 * len(BUSES) // 4),
real_power_ids=sample(BUSES, 3 * len(BUSES) // 4),
reactive_power_ids=sample(BUSES, 3 * len(BUSES) // 4),
).json()
).model_dump_json()
)
Loading
Loading