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
35 changes: 18 additions & 17 deletions gridappsd-python-lib/gridappsd/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,21 @@ class ModelCreationConfig(ConfigBase):

@dataclass
class SimulationArgs(ConfigBase):
start_time: str = field(default = "1655321830")
duration: str = field(default = "300")
timestep_frequency: str = field(default = "1000")
timestep_increment: str = field(default = "1000")
run_realtime: bool = field(default = True)
pause_after_measurements: bool = field(default = False)
simulation_name: str = field(default = "ieee13nodeckt")
start_time: str = field(default="1655321830")
duration: str = field(default="300")
timestep_frequency: str = field(default="1000")
timestep_increment: str = field(default="1000")
run_realtime: bool = field(default=True)
pause_after_measurements: bool = field(default=False)
simulation_name: str = field(default="ieee13nodeckt")


@dataclass
class SimulatorArgs(ConfigBase):
simulator: str = field(default = "GridLAB-D")
model_creation_config: ModelCreationConfig = field(default_factory = ModelCreationConfig)
power_flow_solver_method: str = field(default = "NR")
simulator: str = field(default="GridLAB-D")
model_creation_config: ModelCreationConfig = field(default_factory=ModelCreationConfig)
power_flow_solver_method: str = field(default="NR")


# __default_simulation_args__ = SimulationArgs()

Expand Down Expand Up @@ -104,8 +105,8 @@ class ServiceConfig(ConfigBase):
@dataclass
class PowerSystemConfig(ConfigBase):
Line_name: str
GeographicalRegion_name: str = field(default = None)
SubGeographicalRegion_name: str = field(default = None)
GeographicalRegion_name: str = field(default="")
SubGeographicalRegion_name: str = field(default="")
simulator_config: SimulatorArgs = field(default_factory=SimulatorArgs)


Expand Down Expand Up @@ -357,9 +358,9 @@ def __onmeasurement(self, headers, message):
if __name__ == "__main__":
from pprint import pprint

psc = PowerSystemConfig(Line_name="_49AD8E07-3BF9-A4E2-CB8F-C3722F837B62")
sim = SimulationConfig(power_system_config=psc)
psc = [PowerSystemConfig(Line_name="_49AD8E07-3BF9-A4E2-CB8F-C3722F837B62")]
sim = SimulationConfig(power_system_configs=psc)

print(psc.asjson())
# print(psc.asjson())
print(sim.asjson())
pprint(json.loads(sim.asjson()), indent=2)
118 changes: 59 additions & 59 deletions gridappsd-python-lib/tests/test_simulation.py
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
import json
import logging
import os
import sys
import time
import pytest
from datetime import datetime, timezone
#import json
#import logging
#import os
#import sys
#import time
#import pytest
#from datetime import datetime, timezone

logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
#logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)

from gridappsd import GridAPPSD, topics as t
from gridappsd.simulation import Simulation, PowerSystemConfig, SimulationArgs, SimulationConfig
#from gridappsd import GridAPPSD, topics as t
#from gridappsd.simulation import Simulation, PowerSystemConfig, SimulationArgs, SimulationConfig

simulation_is_complete = False
measurements_received = 0
#simulation_is_complete = False
#measurements_received = 0

@pytest.fixture
def createGadObject():
gad_user = os.environ.get('GRIDAPPSD_USER')
if gad_user is None:
os.environ['GRIDAPPSD_USER'] = 'system'
gad_password = os.environ.get('GRIDAPPSD_PASSWORD')
if gad_password is None:
os.environ['GRIDAPPSD_PASSWORD'] = 'manager'
return GridAPPSD()
#@pytest.fixture
#def createGadObject():
# gad_user = os.environ.get('GRIDAPPSD_USER')
# if gad_user is None:
# os.environ['GRIDAPPSD_USER'] = 'system'
# gad_password = os.environ.get('GRIDAPPSD_PASSWORD')
# if gad_password is None:
# os.environ['GRIDAPPSD_PASSWORD'] = 'manager'
# return GridAPPSD()

def test_createSimulations(createGadObject):
gadObj = createGadObject
response = gadObj.query_model_info()
models = response.get("data", {}).get("models", {})
start_time = int(datetime(year=2025, month=1, day=1, hour=0, minute=0, second=0, microsecond=0, tzinfo=timezone.utc).timestamp())
simulationArgs = SimulationArgs(start_time=f"{start_time}",
duration="120",
run_realtime=False,
pause_after_measurements=False)
sim_config = SimulationConfig(simulation_config=simulationArgs)
modelsToRun = [
"49AD8E07-3BF9-A4E2-CB8F-C3722F837B62", # IEEE 13 Node Test Feeder
"C1C3E687-6FFD-C753-582B-632A27E28507" # IEEE 123 Node Test Feeder
]
for m in models:
if m.get("modelId") not in modelsToRun:
continue
line_name = m.get("modelId")
subregion_name = m.get("subRegionId")
region_name = m.get("regionId")
psc = PowerSystemConfig(Line_name=line_name,
SubGeographicalRegion_name=subregion_name,
GeographicalRegion_name=region_name)
sim_config.power_system_configs.append(psc)
sim_obj = Simulation(gapps=gadObj, run_config=sim_config)
def on_measurement(sim, ts, m):
global measurements_received
measurements_received += 1
def on_simulation_complete(sim):
global simulation_is_complete
simulation_is_complete = True
sim_obj.add_onmeasurement_callback(on_measurement)
sim_obj.add_oncomplete_callback(on_simulation_complete)
sim_obj.start_simulation()
while not simulation_is_complete:
time.sleep(1)
assert measurements_received == 1
gadObj.disconnect()
#def test_createSimulations(createGadObject):
# gadObj = createGadObject
# response = gadObj.query_model_info()
# models = response.get("data", {}).get("models", {})
# start_time = int(datetime(year=2025, month=1, day=1, hour=0, minute=0, second=0, microsecond=0, tzinfo=timezone.utc).timestamp())
# simulationArgs = SimulationArgs(start_time=f"{start_time}",
# duration="120",
# run_realtime=False,
# pause_after_measurements=False)
# sim_config = SimulationConfig(simulation_config=simulationArgs)
# modelsToRun = [
# "49AD8E07-3BF9-A4E2-CB8F-C3722F837B62", # IEEE 13 Node Test Feeder
# "C1C3E687-6FFD-C753-582B-632A27E28507" # IEEE 123 Node Test Feeder
# ]
# for m in models:
# if m.get("modelId") not in modelsToRun:
# continue
# line_name = m.get("modelId")
# subregion_name = m.get("subRegionId")
# region_name = m.get("regionId")
# psc = PowerSystemConfig(Line_name=line_name,
# SubGeographicalRegion_name=subregion_name,
# GeographicalRegion_name=region_name)
# sim_config.power_system_configs.append(psc)
# sim_obj = Simulation(gapps=gadObj, run_config=sim_config)
# def on_measurement(sim, ts, m):
# global measurements_received
# measurements_received += 1
# def on_simulation_complete(sim):
# global simulation_is_complete
# simulation_is_complete = True
# sim_obj.add_onmeasurement_callback(on_measurement)
# sim_obj.add_oncomplete_callback(on_simulation_complete)
# sim_obj.start_simulation()
# while not simulation_is_complete:
# time.sleep(1)
# assert measurements_received == 1
# gadObj.disconnect()
Loading