ExpertOp4Grid v0.3.1 — Code Quality & Maintainability Overhaul
Highlights
This release is a major code quality and maintainability milestone. Six pull requests across a focused sprint bring ExpertOp4Grid's core codebase from a prototype-grade state to a well-structured, statically-analysable library:
- Structured logging replaces all 101
print()calls — embedders now control verbosity - Type annotations across ~220 function signatures — mypy and radon added to CI
- Architecture cleanup — the 2295-line
graphsAndPaths.pymonolith split into 8 focused modules with a backward-compatible shim - Complexity reduction — four critical high-complexity functions (CC up to 68) decomposed into composable, testable helpers
- Safer encoding — twin-node string-prefix hack (
"666" + str(id)) replaced by an offset-based scheme that fixes silent collisions - Packaging refresh — correct
python_requires, updated dependency floors, duplicate license removed
What's Changed
PR #67 — Code quality cleanup: pyflakes, bare excepts, mutable defaults
- Replaced all 9 bare
except:clauses with specific exception types - Removed 15+ unused imports and dead local variables across
alphadeesp.py,graphsAndPaths.py,printer.py,Grid2opSimulation.py,PypownetSimulation.py - Replaced
from alphaDeesp.core.elements import *with explicit imports in three modules (star-import cleanup) - Fixed two mutable default arguments in
AlphaDeesp.__init__andrank_current_topo_at_node_x - Added
pyflakeslint step to CircleCI — 0 findings on the full CI scope - Gated
print(df)inSimulation.create_dfbehind a debug flag
PR #68 — Short-term code quality improvements: logging, docstrings, packaging
- Logging migration: all 101
print()calls converted tologger.info/warning/debugacross 10 modules;main.pyinstallsbasicConfigonly for CLI entry point, leaving embedders in control - Abstract method documentation: replaced all 9
"""TODO"""stubs inSimulationwith full Sphinx-style docstrings including contracts and backend-specific notes - CI re-enablement: replaced
--ignoreflags withpytest.importorskipguards — optional test suites now run automatically when optional dependencies are present - Packaging cleanup: added
python_requires=">=3.9", bumpedGrid2Op>=1.12.1andlightsim2grid>=0.10.3, removed stalepathlibbackport and dead commented-out dependencies, deleted duplicateLICENSE.md
PR #69 — Refactor four high-complexity functions into composable helpers
AlphaDeesp.rank_current_topo_at_node_x: CC 68 → 7, extracted six scoring helpersAlphaDeesp.apply_new_topo_to_graph: CC 36 → 7, extracted five topology-pipeline helpersOverFlowGraph.detect_edges_to_keep: CC 46 → 2, fully orchestrating main function with four path-classification helpersOverFlowGraph.add_relevant_null_flow_lines: CC 44 → 7, extracted five null-flow helpers- New module
core/twin_nodes.py: offset-based twin-node scheme (TWIN_NODE_OFFSET = 10_000_000) replacing fragile"666" + str(id)encoding — fixes silent collisions for substation ids ≥ 1000 - 21 new unit tests in
test_alphadeesp_unit.py; 30+ new tests intest_graphs_and_paths_unit.py; total: 130 passing
PR #70 — Add type hints to core base classes and fix mutable defaults
- Fully annotated
core/elements.py(all four element dataclasses:Production,Consumption,OriginLine,ExtremityLine) - Fully annotated
core/simulation.pyabstract base class — all 10 abstract methods, all helper methods, factory method - Exported
SubstationElementtype alias (Union[Production, Consumption, OriginLine, ExtremityLine]) - Fixed mutable defaults
ltc=[9]/other_ltc=[]inGrid2opSimulation.__init__andPypownetSimulation.__init__
PR #71 — Add type hints propagation and mypy/radon to CI
- Signature-level type annotations added to six previously untyped modules:
core/alphadeesp.py(~38 signatures),core/graphsAndPaths.py(~76 signatures),core/network.py,core/printer.py,core/grid2op/Grid2opSimulation.py(~33 signatures),core/pypownet/PypownetSimulation.py(~27 signatures) - Type-annotated functions: 36 → ~220
- Mypy added to CircleCI: strict mode on seed modules (
simulation.py,elements.py) blocks the build on failure; permissive mode on remaining modules is informational - Radon added to CircleCI: cyclomatic complexity, maintainability index, and raw metrics reported on every build
PR #72 — Refactor: Split graphsAndPaths monolith into focused graphs package
alphaDeesp/core/graphsAndPaths.py(2295 lines) split intoalphaDeesp/core/graphs/package with 8 focused modules:power_flow_graph.py,overflow_graph.py,structured_overload_graph.py,constrained_path.py,graph_utils.py,shortest_paths.py,null_flow.py,constants.py- Zero breaking changes:
graphsAndPaths.pyreduced to a 49-line backward-compatible shim re-exporting all 16 public symbols - Explicit
__all__defines the committed public API - 443 lines of new tests in
test_graphs_package.pycovering structural invariants, import acyclicity, and algorithmic correctness - Architecture documentation added in
docs/refactor-graphs-package.md
Upgrade Notes
- No breaking changes to the public API. All existing
from alphaDeesp.core.graphsAndPaths import ...imports continue to work unchanged. - Embedders using
Grid2opSimulation(ltc=[...])orPypownetSimulation(ltc=[...])are unaffected — keyword-argument callers remain compatible. - Console output is now suppressed by default. To restore verbose output, configure logging before calling the library:
logging.basicConfig(level=logging.INFO). - Minimum Python version is now officially 3.9 (up from the stale 3.6/3.7 classifiers in
setup.py).
Full Changelog: v0.3.0.post1...v0.3.1