Skip to content

Replace main.py with self contained modules #4

Draft
asedlak-ucsd wants to merge 80 commits intopsernatorre:mainfrom
REAM-lab:main
Draft

Replace main.py with self contained modules #4
asedlak-ucsd wants to merge 80 commits intopsernatorre:mainfrom
REAM-lab:main

Conversation

@asedlak-ucsd
Copy link
Copy Markdown
Contributor

@asedlak-ucsd asedlak-ucsd commented Mar 30, 2026

As is, all modules feed into a single main.py script. This however introduces many inter module dependencies through the imports in main.py. Furthermore, this may not be the most intuitive user-interface as a single run script offers users less behind the scenes control (i.e., one run script does many different actions, reading, writing CSVs, running models, etc.) that are obscured from the user.

Can we replace main.py scripts with module specific methods?

In this manner we would transition to a UI closer to something that of sklearn where each module has predictable well defined methods---such as .train() and .predict(). However how to best do this is an open question. Many modules are related to one another (ACOPF --> SSM --> MOR) and need well defined interfaces to pass data between one another. Additionally some main scripts are across modules. And not all modules share the same methods. A few ideas for how to structure this are

  • Instantiation of each module just takes settings. A system object is not a module property and must be constructed separately. In this manner modules only perform actions on a data but do not store data. Storage of data is relegated to the system class.
  • Modules have methods like .run(), .write_csv(), and simulate() that accept a system object in their arguments.
  • Create a pipeline class to manage inter-module exchanges of data. pipe = Pipeline([ACOPF, SSM, EMT]); pipe.run(). If we can do this in a clean modular way I think it may have potential.

One optional point to consider in this refactor is if we should change some of the import paths to be more user friendly/shorter.

psernatorre and others added 30 commits March 3, 2026 10:56
…rated: nonvariable and variable.

feat: add output_directory to main.
feat: add_components in run_capex
feat: GFMIe added to system
adding gFMIe. Thank you Ruth.
@asedlak-ucsd
Copy link
Copy Markdown
Contributor Author

''Components define how but not what''.

This is a different approach and will likely require a large refactor. However, it solves the problem of clearly defining each module/objects bailiwick. Here the System and Component classes become frozen dataclasses. Mutable attributes like EMT and StateSpaceModels are instead moved to methods.

For example, a small single model would look like

class SmallSignalModel
    system
    state_space
    power_flow_sol

Then to get all component small_singal models, the class will call each components get method.

component.get_small_singal(pf_solution) -> StateSpaceModel

Thus we are not mutating a component it is simply defining how to construct the state-space model not what the state-space model actually is. "What" is the job of the SmallSingalModel.

Modules that modify the system can then be grouped into a system modifier class. These modules actual modify the raw system data

  • decompose_lines / combine shunts (kirchhoff reductions)
  • Kron reduction
  • model reduction
  • add_capex_built_capacities

A few related upgrades that could be helpful for system

  • index of components to stream from
  • network attribute to manage CCM interconnections and graph properties

psernatorre and others added 14 commits April 3, 2026 10:27
Add gfmi_e and corresponding test case. This gfmi_e models DC dynamics, including DC voltage source and current-constant load.
fix: remove inspect coefficient from capex module, and place in pyomo tools. This is because unit commitment can use it, too.
… storage. This factor increases deployed capacity for resources when they are then used for cost production model. This avoids infeasibility. These features were used for final runs in ucop project.

fix: conditional to make expandable true was commented for storage as for other generators.

Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
…example.

Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants