Skip to content

Commit

Permalink
Merge pull request #27 from openEDI/large_feeder
Browse files Browse the repository at this point in the history
Use sparse matrices to cut down on memory usage
  • Loading branch information
josephmckinsey authored Oct 7, 2022
2 parents 367e36b + 0b28801 commit cca7b09
Show file tree
Hide file tree
Showing 9 changed files with 520 additions and 28 deletions.
3 changes: 3 additions & 0 deletions AWSFeeder/FeederSimulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class FeederConfig(BaseModel):
increment_value: int # increment in seconds
number_of_timesteps: int
topology_output: str = "topology.json"
use_sparse_admittance = False


class FeederSimulator(object):
Expand Down Expand Up @@ -165,6 +166,8 @@ def get_node_names(self):
return self._AllNodeNames

def load_feeder(self):
dss.Basic.LegacyModels(True)
dss.run_command("clear")
result = dss.run_command("redirect " + self._feeder_file)
if not result == '':
raise ValueError("Feeder not loaded: "+result)
Expand Down
39 changes: 26 additions & 13 deletions AWSFeeder/sender_cosim.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from typing import List, Tuple
import numpy as np
from datetime import datetime, timedelta
from gadal.gadal_types.data_types import Complex,Topology,VoltagesReal,VoltagesImaginary,PowersReal,PowersImaginary, AdmittanceMatrix, VoltagesMagnitude, VoltagesAngle
from gadal.gadal_types.data_types import Complex,Topology,VoltagesReal,VoltagesImaginary,PowersReal,PowersImaginary, AdmittanceMatrix, VoltagesMagnitude, VoltagesAngle, AdmittanceSparse

logger = logging.getLogger(__name__)
logger.addHandler(logging.StreamHandler())
Expand All @@ -26,6 +26,13 @@ def numpy_to_y_matrix(array):
for row in array
]

def sparse_to_admittance_sparse(array, unique_ids):
return AdmittanceSparse(
from_equipment = [unique_ids[i] for i in array.row],
to_equipment = [unique_ids[i] for i in array.col],
admittance_list = [(data.real, data.imag) for data in array.data]
)


def setup_sim(config: FeederConfig):
sim = FeederSimulator(config)
Expand Down Expand Up @@ -76,9 +83,23 @@ def go_cosim(sim, config: FeederConfig):
h.helicsFederateEnterExecutingMode(vfed)

Y = sim.get_y_matrix()
logger.debug("Eigenvalues and vectors")
logger.debug(np.linalg.eig(Y.toarray()))
y_matrix = numpy_to_y_matrix(Y.toarray())
#logger.debug("Eigenvalues and vectors")
#logger.debug(np.linalg.eig(Y.toarray()))
unique_ids = sim._AllNodeNames

if config.use_sparse_admittance:
admittancematrix = sparse_to_admittance_sparse(
Y,
unique_ids
)
else:
admittancematrix = AdmittanceMatrix(
admittance_matrix= numpy_to_y_matrix(
Y.toarray()
),
ids=unique_ids
)

def get_phase(name):
_, end = name.split('.')
if end == '1':
Expand All @@ -99,10 +120,7 @@ def get_phase(name):
)
]

unique_ids = sim._AllNodeNames

logger.debug("y-matrix")
logger.debug(y_matrix)
logger.debug("phases")
logger.debug(phases)
logger.debug("base_voltages")
Expand All @@ -111,12 +129,7 @@ def get_phase(name):
logger.debug(slack_bus)
logger.debug("unique_ids")
logger.debug(unique_ids)


admittancematrix = AdmittanceMatrix(
admittance_matrix = y_matrix,
ids = unique_ids
)


base_voltagemagnitude = VoltagesMagnitude(
values = [abs(i) for i in base_voltages],
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN --mount=type=secret,id=gadal_github_key pip install git+ssh://[email protected]
WORKDIR /simulation

COPY test_full_systems.py .
COPY docker_system.json .
COPY scenarios/docker_system.json docker_system.json
COPY AWSFeeder AWSFeeder
COPY LocalFeeder LocalFeeder
COPY README.md .
Expand Down
File renamed without changes.
151 changes: 151 additions & 0 deletions scenarios/large_aws_feeder.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
{
"name": "test_state_estimator",
"components": [
{
"name": "recorder_voltage_real",
"type": "Recorder",
"parameters": {"feather_filename": "../../outputs/voltage_real.feather",
"csv_filename": "../../outputs/voltage_real.csv"
}
},
{
"name": "recorder_voltage_imag",
"type": "Recorder",
"parameters": {"feather_filename": "../../outputs/voltage_imag.feather",
"csv_filename": "../../outputs/voltage_imag.csv"
}
},
{
"name": "recorder_voltage_mag",
"type": "Recorder",
"parameters": {"feather_filename": "../../outputs/voltage_mag.feather",
"csv_filename": "../../outputs/voltage_mag.csv"
}
},
{
"name": "recorder_voltage_angle",
"type": "Recorder",
"parameters": {"feather_filename": "../../outputs/voltage_angle.feather",
"csv_filename": "../../outputs/voltage_angle.csv"
}
},
{
"name": "state_estimator",
"type": "StateEstimatorComponent",
"parameters": {
"algorithm_parameters": {"tol": 1e-5}
}
},
{
"name": "feeder",
"type": "AWSFeeder",
"parameters": {
"smartds_region": "P9U",
"smartds_feeder": "p9uhs16_1247/p9uhs16_1247--p9udt12866/",
"smartds_scenario": "solar_medium_batteries_none_timeseries",
"smartds_year": "2017",
"start_date": "2017-05-01 00:00:00",
"increment_value": 900,
"number_of_timesteps": 2,
"topology_output": "../../outputs/topology.json",
"use_sparse_admittance": true
}
},
{
"name": "sensor_voltage_magnitude",
"type": "MeasurementComponent",
"parameters": {
"gaussian_variance": 0.0,
"random_percent": 0.0,
"measurement_file": "../feeder/voltage_ids.json"
}
},
{
"name": "sensor_power_real",
"type": "MeasurementComponent",
"parameters": {
"gaussian_variance": 0.0,
"random_percent": 0.0,
"measurement_file": "../feeder/real_ids.json"
}
},
{
"name": "sensor_power_imaginary",
"type": "MeasurementComponent",
"parameters": {
"gaussian_variance": 0.0,
"random_percent": 0.0,
"measurement_file": "../feeder/reactive_ids.json"
}
}

],
"links": [
{
"source": "feeder",
"source_port": "voltages_magnitude",
"target": "sensor_voltage_magnitude",
"target_port": "subscription"
},
{
"source": "feeder",
"source_port": "powers_real",
"target": "sensor_power_real",
"target_port": "subscription"
},
{
"source": "feeder",
"source_port": "powers_imag",
"target": "sensor_power_imaginary",
"target_port": "subscription"
},
{
"source": "feeder",
"source_port": "topology",
"target": "state_estimator",
"target_port": "topology"
},
{
"source": "sensor_voltage_magnitude",
"source_port": "publication",
"target": "state_estimator",
"target_port": "voltages_magnitude"
},
{
"source": "sensor_power_real",
"source_port": "publication",
"target": "state_estimator",
"target_port": "powers_real"
},
{
"source": "sensor_power_imaginary",
"source_port": "publication",
"target": "state_estimator",
"target_port": "powers_imaginary"
},
{
"source": "feeder",
"source_port": "voltages_real",
"target": "recorder_voltage_real",
"target_port": "subscription"
},
{
"source": "feeder",
"source_port": "voltages_imag",
"target": "recorder_voltage_imag",
"target_port": "subscription"
},
{
"source": "state_estimator",
"source_port": "voltage_angle",
"target": "recorder_voltage_angle",
"target_port": "subscription"
},
{
"source": "state_estimator",
"source_port": "voltage_mag",
"target": "recorder_voltage_mag",
"target_port": "subscription"
}
]
}
Loading

0 comments on commit cca7b09

Please sign in to comment.