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
2 changes: 1 addition & 1 deletion pygridsim.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Package to simulate OpenDSS circuits on Python

# Overview

TODO: Provide a short overview of the project here.
PyGridSim aims to make building electrical circuits and corresponding circuit simulations easy for a Python coder. It builds on the distribution system OpenDSS and corresponding python package AltDSS.

# Install

Expand Down
2 changes: 1 addition & 1 deletion pygridsim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
__email__ = 'amzhao@mit.edu'
__version__ = '0.1.0.0'

from pygridsim.core import PyGridSim
from pygridsim.core import PyGridSim as PyGridSim
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious as why this change is needed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was recommended by ruff linter: Use an explicit re-export: PyGridSim as PyGridSim

Binary file modified pygridsim/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file modified pygridsim/__pycache__/configs.cpython-312.pyc
Binary file not shown.
Binary file modified pygridsim/__pycache__/core.cpython-312.pyc
Binary file not shown.
Binary file modified pygridsim/__pycache__/defaults.cpython-312.pyc
Binary file not shown.
Binary file modified pygridsim/__pycache__/enums.cpython-312.pyc
Binary file not shown.
Binary file modified pygridsim/__pycache__/lines.cpython-312.pyc
Binary file not shown.
Binary file modified pygridsim/__pycache__/parameters.cpython-312.pyc
Binary file not shown.
Binary file modified pygridsim/__pycache__/results.cpython-312.pyc
Binary file not shown.
52 changes: 26 additions & 26 deletions pygridsim/configs.py
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
from pygridsim.enums import *
from pygridsim.defaults import *
from pygridsim.enums import LoadType, LineType, GeneratorType, SourceType
import pygridsim.defaults as defaults

LOAD_CONFIGURATIONS = {
LoadType.HOUSE: {
"kV": HOUSE_KV,
"kW": HOUSE_KW,
"kvar": HOUSE_KVAR
"kV": defaults.HOUSE_KV,
"kW": defaults.HOUSE_KW,
"kvar": defaults.HOUSE_KVAR
},
LoadType.COMMERCIAL: {
"kV": COMMERCIAL_KV,
"kW": COMMERCIAL_KW,
"kvar": COMMERCIAL_KVAR
"kV": defaults.COMMERCIAL_KV,
"kW": defaults.COMMERCIAL_KW,
"kvar": defaults.COMMERCIAL_KVAR
},
LoadType.INDUSTRIAL: {
"kV": INDUSTRIAL_KV,
"kW": INDUSTRIAL_KW,
"kvar": INDUSTRIAL_KVAR
"kV": defaults.INDUSTRIAL_KV,
"kW": defaults.INDUSTRIAL_KW,
"kvar": defaults.INDUSTRIAL_KVAR
}
}

SOURCE_CONFIGURATIONS = {
SourceType.TURBINE: {
"kV": TURBINE_BASE_KV
"kV": defaults.TURBINE_BASE_KV
},
SourceType.POWER_PLANT: {
"kV": POWER_PLANT_KV
"kV": defaults.POWER_PLANT_KV
},
SourceType.LV_SUBSTATION: {
"kV": LV_SUBSTATION_BASE_KV
"kV": defaults.LV_SUBSTATION_BASE_KV
},
SourceType.MV_SUBSTATION: {
"kV": MV_SUBSTATION_BASE_KV
"kV": defaults.MV_SUBSTATION_BASE_KV
},
SourceType.HV_SUBSTATION: {
"kV": HV_SUBSTATION_BASE_KV
"kV": defaults.HV_SUBSTATION_BASE_KV
},
SourceType.SHV_SUBSTATION: {
"kV": SHV_SUBSTATION_BASE_KV
"kV": defaults.SHV_SUBSTATION_BASE_KV
},
}

LINE_CONFIGURATIONS = {
LineType.LV_LINE: {
"length": LV_LINE_LENGTH
"length": defaults.LV_LINE_LENGTH
},
LineType.MV_LINE: {
"length": MV_LINE_LENGTH
"length": defaults.MV_LINE_LENGTH
},
LineType.HV_LINE: {
"length": HV_LINE_LENGTH
"length": defaults.HV_LINE_LENGTH
}
}

GENERATOR_CONFIGURATIONS = {
GeneratorType.SMALL: {
"kV": SMALL_GEN_KV,
"kW": SMALL_GEN_KW,
"kV": defaults.SMALL_GEN_KV,
"kW": defaults.SMALL_GEN_KW,
},
GeneratorType.LARGE: {
"kV": LARGE_GEN_KV,
"kW": LARGE_GEN_KW,
"kV": defaults.LARGE_GEN_KV,
"kW": defaults.LARGE_GEN_KW,
},
GeneratorType.INDUSTRIAL: {
"kV": INDUSTRIAL_GEN_KV,
"kW": INDUSTRIAL_GEN_KW,
"kV": defaults.INDUSTRIAL_GEN_KV,
"kW": defaults.INDUSTRIAL_GEN_KW,
}
}
63 changes: 10 additions & 53 deletions pygridsim/core.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# -*- coding: utf-8 -*-
from altdss import altdss
from altdss import AltDSS, Transformer, Vsource, Load, LoadModel, LoadShape
from dss.enums import LineUnits, SolveModes
from pygridsim.parameters import *
from pygridsim.parameters import make_load_node, make_source_node, make_generator, make_pv
from pygridsim.results import query_solution, export_results
from pygridsim.lines import make_line
from pygridsim.enums import LineType, SourceType, LoadType, GeneratorType

"""Main module."""

Expand Down Expand Up @@ -45,11 +42,8 @@ def update_source(self, source_type: str = "turbine", params = {}):
Adds a main voltage source if it doesn't exist, otherwise edits it

Args:
params: load parameters for these manual additions
source_type: source type as a string
num (optional): number of sources to create with these parameters (removed for now)
(removed) num_in_batch: how many to batch together directly (so they can't be connected to lines separately, etc.
most common use case is if a house has 20 solar panels it's more useful to group them together)
params: load parameters for these manual additions
Return:
List of source_nodes
"""
Expand All @@ -74,7 +68,7 @@ def add_PVSystem(self, load_nodes: list[str], params = {}, num_panels: int = 1):
self.num_pv += 1
return PV_nodes

def add_generator(self, num: int = 1, gen_type: GeneratorType = GeneratorType.SMALL, params = {}):
def add_generator(self, num: int = 1, gen_type: str = "small", params = {}):
"""
Specify parameters for a generator to add to the circuit

Expand All @@ -99,63 +93,27 @@ def add_lines(self, connections: list[tuple], line_type: str = "lv", params = {}
Args:
connections: a list of new connections to add. Each item of the list follows the form (source1, load1)
line_type: a string representing linetype if user wants to use preset parameters
params: any custom parameters for lines or transformers
transformer: whether or not to include a transformer, default yes
"""
for src, dst in connections:
make_line(src, dst, line_type, self.num_lines, params, transformer)
self.num_lines += 1

def view_load_nodes(self, indices: list = []):
"""
View load nodes (what their parameters are) at the given indices.

Args:
indices (optional): Which indices to view the nodes at.
If none given, display all
"""
load_nodes = []
if not indices:
indices = [i for i in range(self.num_loads)]

for idx in indices:
load_obj = altdss.Load["load" + str(idx)]
load_info = {}
load_info["name"] = "load" + str(idx)
load_info["kV"] = load_obj.kV
load_info["kW"] = load_obj.kW
load_info["kVar"] = load_obj.kvar
load_nodes.append(load_info)
return load_nodes


def view_source_node(self):
"""
View source nodes (what their parameters are) at the given indices.

Args:
indices (optional): Which indices to view the nodes at.
If none given, display all

TODO once capability for more source nodes is initialized
"""
source_obj = altdss.Vsource["source"]
source_info = {}
source_info["name"] = "source"
source_info["kV"] = source_obj.BasekV
return source_info

def solve(self):
"""
Initialize "solve" mode in AltDSS, then allowing the user to query various results on the circuit

TODO: error handling here
"""
altdss.Solution.Solve()

def results(self, queries: list[str], export_path = ""):
"""
Allow the user to query for many results at once instead of learning how to manually query

Returns:

Args:
queries: List of queries to fetch the result of
export_path: if specified, exports result to this string
Return:
Results for each query, in a dictionary
"""
results = {}
Expand All @@ -170,7 +128,6 @@ def clear(self):
Must call after we are done using the circuit, or will cause re-creation errors.

We only work with one circuit at a time, can only have one PyGridSim object at a time.
TODO: maybe this isn't necessary because it's done in the beginning
"""
altdss.ClearAll()
self.num_loads = 0
Expand Down
1 change: 0 additions & 1 deletion pygridsim/defaults.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
Set any defaults (i.e. default source voltage, default node load etc.)
"""
from altdss import altdss
from altdss import Connection
"""
Overall Defaults, used for load, sources, lines, etc.
Expand Down
2 changes: 0 additions & 2 deletions pygridsim/enums.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from enum import Enum
import pygridsim.defaults as defaults

# todo: update to have a name so that users can query from name
class SourceType(Enum):
TURBINE = "turbine"
POWER_PLANT = "powerplant"
Expand Down
4 changes: 2 additions & 2 deletions pygridsim/lines.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from altdss import altdss
from altdss import Transformer, Connection
from pygridsim.configs import *
from altdss import Transformer
from pygridsim.configs import LINE_CONFIGURATIONS
import pygridsim.defaults as defaults
from pygridsim.enums import LineType
from pygridsim.parameters import get_param, random_param, check_valid_params, get_enum_obj
Expand Down
8 changes: 3 additions & 5 deletions pygridsim/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Helper functions to parse the parameters used for loads and sources
"""
from altdss import altdss
from altdss import AltDSS, Transformer, Vsource, Load, PVSystem, Generator
from pygridsim.enums import *
from pygridsim.configs import *
from altdss import Load, PVSystem, Generator
from pygridsim.enums import LoadType, SourceType, GeneratorType
from pygridsim.configs import LOAD_CONFIGURATIONS, SOURCE_CONFIGURATIONS, GENERATOR_CONFIGURATIONS
import pygridsim.defaults as defaults
import random

Expand All @@ -27,7 +27,6 @@ def random_param(range):
[lower_bound, upper_bound]; range of typical value
Return:
Randomly selected value in range
TODO: allow for non-uniform distributions
"""
if type(range) is not list:
return range
Expand Down Expand Up @@ -120,7 +119,6 @@ def make_pv(load_node, params, num_panels, count):
pv.Bus1 = load_node
pv.Phases = get_param(params, "phases", defaults.PHASES)
pv.kV = get_param(params, "kV", random_param(defaults.SOLAR_PANEL_BASE_KV) * num_panels)
# todo: inverter capacity?

def make_generator(params, gen_type, count):
"""
Expand Down
1 change: 0 additions & 1 deletion pygridsim/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def query_solution(query):

Args:
query: a query for the solve function
TODO: only BusVMag, Losses, TotalPower is supported, need to make accessible which queries are supported
Return:
Query result or the string "Invalid" if the query is not supported
"""
Expand Down
8 changes: 4 additions & 4 deletions sim.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"Voltages": {
"source": 1391.2908459682467,
"load0": 202.6090367072441
"source": 1735.8007811315708,
"load0": 205.64441923330276
},
"Losses": {
"Active Power Loss": 78708.71838388889,
"Reactive Power Loss": 163597.67777927459
"Active Power Loss": 198582.96141955358,
"Reactive Power Loss": 412884.39931989944
}
}
Binary file modified tests/__pycache__/test_circuit.cpython-312.pyc
Binary file not shown.
36 changes: 0 additions & 36 deletions tests/temp.py

This file was deleted.

12 changes: 2 additions & 10 deletions tests/test_circuit.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pygridsim.core import PyGridSim
from pygridsim.enums import *
from altdss import altdss
from altdss import Connection

from pygridsim.enums import LineType, LoadType, SourceType, GeneratorType
import unittest

"""Tests for `pygridsim` package."""

import unittest

# from pygridsim import pygridsim


Expand Down Expand Up @@ -42,9 +38,6 @@ def test_001_one_source_one_load(self):
circuit.update_source(source_type="turbine")
circuit.add_load_nodes(num=1, load_type="house")
circuit.add_lines([("source", "load0")], "MV")
#circuit.add_transformers([("source", "load0")], params={"Conns": [Connection.wye, Connection.delta]})
print("Load Nodes:", circuit.view_load_nodes())
print("Source Nodes:", circuit.view_source_node())
circuit.solve()
print(circuit.results(["Voltages", "Losses"]))
circuit.clear()
Expand Down Expand Up @@ -98,7 +91,6 @@ def test_006_update_multiple_source(self):
circuit.add_lines([("source", "load0")], "HV")
circuit.solve()
print(circuit.results(["Voltages"]))
# TODO: can add assert to make sure it's in reasonable range?

def test_007_export(self):
circuit = PyGridSim()
Expand Down