Skip to content

Commit 4b49909

Browse files
authored
Merge pull request #248 from TemoaProject/docs/mermaid_diagrams
Improve the docs by adding a sequence diagram that describes execution flow and an ERD for the database schema
2 parents 39c85fe + ca0cc4f commit 4b49909

File tree

7 files changed

+994
-2
lines changed

7 files changed

+994
-2
lines changed

docs/source/computational_implementation.rst

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,86 @@ understanding of what a constraint does requires only the last line of code:
331331
"Supply must meet demand."
332332

333333

334+
Execution Flow
335+
--------------
336+
337+
The Temoa execution flow is designed to be modular and consistent across different modeling modes. It begins with the Command Line Interface (CLI), which parses user input and sets up the execution environment. The following sequence diagram illustrates the execution flow of a Temoa run, from the initial command-line invocation to the final processing of results.
338+
339+
.. mermaid::
340+
:alt: Temoa Execution Flow
341+
:zoom:
342+
343+
sequenceDiagram
344+
participant User
345+
participant CLI as temoa/cli.py
346+
participant Config as TemoaConfig
347+
participant Sequencer as TemoaSequencer
348+
participant HL as HybridLoader
349+
participant Model as TemoaModel Instance
350+
participant RA as run_actions.py
351+
participant DB as Database
352+
353+
rect rgb(220,230,250)
354+
Note over CLI: User invokes CLI (run/validate)
355+
User->>CLI: temoa run/validate config.toml
356+
end
357+
358+
rect rgb(230,250,220)
359+
Note over CLI: Environment Setup
360+
CLI->>CLI: _create_output_folder()
361+
CLI->>CLI: _setup_logging()
362+
CLI->>Config: build_config(config_file, output_path, silent)
363+
Config-->>CLI: TemoaConfig instance
364+
end
365+
366+
rect rgb(250,240,220)
367+
Note over CLI,Sequencer: Sequencer Initialization
368+
CLI->>Sequencer: TemoaSequencer(config, mode_override?)
369+
Sequencer-->>CLI: Ready
370+
end
371+
372+
rect rgb(240,220,250)
373+
Note over Sequencer: Model Building & Execution
374+
alt build-only / validate
375+
CLI->>Sequencer: build_model()
376+
Sequencer->>Sequencer: _run_preliminary_checks()
377+
Sequencer->>RA: check_database_version()
378+
Sequencer->>HL: HybridLoader(db_con, config)
379+
HL->>HL: load_data_portal()
380+
Sequencer->>RA: build_instance(data_portal)
381+
RA-->>Sequencer: TemoaModel instance
382+
Sequencer-->>CLI: TemoaModel instance
383+
else full run (e.g., perfect_foresight)
384+
CLI->>Sequencer: start()
385+
Sequencer->>Sequencer: _run_preliminary_checks()
386+
Sequencer->>Sequencer: _run_perfect_foresight()
387+
Sequencer->>HL: HybridLoader(db_con, config)
388+
HL->>HL: load_data_portal()
389+
Sequencer->>RA: build_instance(data_portal)
390+
RA-->>Sequencer: instance
391+
Sequencer->>RA: solve_instance(instance, solver_name)
392+
RA->>RA: check_solve_status(results)
393+
Sequencer->>RA: handle_results(instance, results, config)
394+
RA->>DB: Persist results
395+
Sequencer-->>CLI: Success / Error
396+
end
397+
end
398+
399+
rect rgb(220,250,240)
400+
CLI->>User: report log path and output folder
401+
end
402+
403+
The execution flow involves several key stages:
404+
405+
1. **CLI Entry**: The user interacts with :file:`temoa/cli.py` to initiate a run or validation.
406+
2. **Environment Setup**: The CLI creates a timestamped output directory, initializes logging, and uses :class:`TemoaConfig` to parse the provided TOML configuration file. This includes checking for the availability of the specified optimization solver.
407+
3. **Sequencing**: A :class:`TemoaSequencer` is created. This object is the main coordinator, selecting the appropriate execution path based on the modeling mode (e.g., Perfect Foresight, Myopic, MGA).
408+
4. **Data Loading**: The sequencer uses a :class:`HybridLoader` to pull data from the SQLite database. This data is organized into a Pyomo :class:`DataPortal`.
409+
5. **Model Construction**: Using the :class:`DataPortal`, Temoa constructs a :class:`TemoaModel` instance. This stage builds all the mathematical sets, parameters, variables, and constraints.
410+
6. **Solving**: The model instance is passed to :func:`solve_instance`, which invokes the chosen solver (like HiGHS, CBC, or Gurobi).
411+
7. **Result Processing**: After the solver completes, :func:`handle_results` extracts the solution, checks for optimality, and persists the results back to the database. It also generates any requested auxiliary outputs like Excel files or network plots.
412+
413+
334414
Project Structure
335415
-----------------
336416

docs/source/conf.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
'sphinx.ext.ifconfig',
6161
'sphinx.ext.viewcode',
6262
'myst_parser', # Enable Markdown support
63+
'sphinxcontrib.mermaid', # Enable Mermaid diagrams
6364
]
6465

6566
# Add any paths that contain templates here, relative to this directory.
@@ -141,3 +142,12 @@ def setup(app: Any) -> None:
141142
html_theme = 'sphinx_rtd_theme'
142143
html_logo = 'images/Temoa_logo_color_small.png'
143144
latex_logo = 'images/TemoaLogo_grayscale.png'
145+
146+
147+
myst_enable_extensions = ['amsmath', 'colon_fence', 'dollarmath', 'html_image']
148+
myst_fence_as_directive = ['mermaid']
149+
150+
mermaid_d3_zoom = True
151+
mermaid_fullscreen = True
152+
mermaid_include_elk = True
153+
mermaid_include_mindmap = True

0 commit comments

Comments
 (0)