distgridforge 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- distgridforge-0.3.0.dist-info/METADATA +266 -0
- distgridforge-0.3.0.dist-info/RECORD +38 -0
- distgridforge-0.3.0.dist-info/WHEEL +5 -0
- distgridforge-0.3.0.dist-info/licenses/LICENCE.txt +21 -0
- distgridforge-0.3.0.dist-info/top_level.txt +1 -0
- gridforge/__init__.py +32 -0
- gridforge/case_study/config.py +158 -0
- gridforge/case_study/dickert_lv_network_script.py +109 -0
- gridforge/case_study/mv_lv_feeder.py +314 -0
- gridforge/case_study/simbench_network_test_case.py +168 -0
- gridforge/core/__init__.py +0 -0
- gridforge/core/constraints.py +421 -0
- gridforge/core/cost_model.py +363 -0
- gridforge/core/grid_enhancement.py +1932 -0
- gridforge/core/power_flow.py +1146 -0
- gridforge/core/strategy.py +297 -0
- gridforge/engines/__init__.py +0 -0
- gridforge/engines/gridlabd_engine.py +527 -0
- gridforge/engines/opendss_engine.py +885 -0
- gridforge/engines/pandapower_engine.py +3766 -0
- gridforge/engines/roseau_engine.py +1234 -0
- gridforge/examples/__init__.py +0 -0
- gridforge/examples/quick_start.py +85 -0
- gridforge/main.py +0 -0
- gridforge/strategies/__init__.py +0 -0
- gridforge/strategies/flexibility.py +1476 -0
- gridforge/strategies/line_upgrade.py +1846 -0
- gridforge/strategies/path_to_source.py +596 -0
- gridforge/strategies/sizing.py +210 -0
- gridforge/strategies/step_check.py +183 -0
- gridforge/strategies/tap_change.py +267 -0
- gridforge/strategies/transformer_upgrade.py +622 -0
- gridforge/utils/__init__.py +0 -0
- gridforge/utils/config.py +55 -0
- gridforge/utils/interactive_plot.py +700 -0
- gridforge/utils/logging.py +86 -0
- gridforge/utils/plot.py +1078 -0
- gridforge/utils/reporting.py +0 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Logging utilities for gridforge.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
import os
|
|
7
|
+
import sys
|
|
8
|
+
from typing import TYPE_CHECKING
|
|
9
|
+
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from gridforge.core.constraints import ConstraintViolation
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def setup_logging(
|
|
15
|
+
log_level: int = logging.INFO, log_file: str | None = None
|
|
16
|
+
) -> logging.Logger:
|
|
17
|
+
"""
|
|
18
|
+
Set up logging for the gridforge package.
|
|
19
|
+
|
|
20
|
+
Configures the root 'gridforge' logger with a stream handler and an optional file handler.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
log_level (int, optional): Logging level (e.g., logging.INFO, logging.DEBUG). Defaults to logging.INFO.
|
|
24
|
+
log_file (Optional[str], optional): Path to a log file. If provided, logs will also be written to this file. Defaults to None.
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
logging.Logger: The configured logger object.
|
|
28
|
+
"""
|
|
29
|
+
# Create logger
|
|
30
|
+
logger = logging.getLogger("gridforge")
|
|
31
|
+
logger.setLevel(log_level)
|
|
32
|
+
logger.handlers = [] # Clear existing handlers
|
|
33
|
+
|
|
34
|
+
# Create formatter
|
|
35
|
+
formatter = logging.Formatter(
|
|
36
|
+
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
# Create console handler
|
|
40
|
+
console_handler = logging.StreamHandler(sys.stdout)
|
|
41
|
+
console_handler.setFormatter(formatter)
|
|
42
|
+
logger.addHandler(console_handler)
|
|
43
|
+
|
|
44
|
+
# Create file handler if requested
|
|
45
|
+
if log_file:
|
|
46
|
+
# Create directory if it doesn't exist
|
|
47
|
+
log_dir = os.path.dirname(log_file)
|
|
48
|
+
if log_dir and not os.path.exists(log_dir):
|
|
49
|
+
os.makedirs(log_dir)
|
|
50
|
+
|
|
51
|
+
file_handler = logging.FileHandler(log_file)
|
|
52
|
+
file_handler.setFormatter(formatter)
|
|
53
|
+
logger.addHandler(file_handler)
|
|
54
|
+
|
|
55
|
+
return logger
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _format_grid_state(violations: list["ConstraintViolation"]) -> str:
|
|
59
|
+
"""
|
|
60
|
+
Format a list of constraint violations into a readable string summary.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
violations (List[ConstraintViolation]): A list of ConstraintViolation objects.
|
|
64
|
+
|
|
65
|
+
Returns:
|
|
66
|
+
str: A string summarizing the count of each type of violation (e.g., "2 Over Voltage violations, 1 Line Loading violation").
|
|
67
|
+
Returns "Normal" if the list is empty.
|
|
68
|
+
"""
|
|
69
|
+
if not violations:
|
|
70
|
+
return "Normal"
|
|
71
|
+
|
|
72
|
+
counts = {}
|
|
73
|
+
for v in violations:
|
|
74
|
+
counts[v.constraint_type.value] = counts.get(v.constraint_type.value, 0) + 1
|
|
75
|
+
|
|
76
|
+
parts = []
|
|
77
|
+
for constraint_type, count in counts.items():
|
|
78
|
+
# Convert snake_case to readable English
|
|
79
|
+
readable_type = constraint_type.replace("_", " ").title()
|
|
80
|
+
parts.append(f"{count} {readable_type} violation{'s' if count > 1 else ''}")
|
|
81
|
+
|
|
82
|
+
return ", ".join(parts)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
# Create a default logger
|
|
86
|
+
logger = logging.getLogger("gridforge")
|