Skip to content
Open
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 docs/source/computational_implementation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ The Temoa model code is organized into clear, purpose-driven packages:
* ``modeling_to_generate_alternatives`` - MGA analysis for exploring near-optimal solutions ([!] untested in v4.0)
* ``method_of_morris`` - Sensitivity analysis ([!] untested in v4.0)
* ``monte_carlo`` - :doc:`monte_carlo` (Uncertainty quantification)
* ``myopic`` - Sequential decision making with limited foresight
* ``myopic`` - :doc:`myopic` (Sequential decision making with limited foresight)
* ``single_vector_mga`` - Focused MGA on specific variables ([!] untested in v4.0)
* ``stochastics`` - :doc:`stochastics` (Stochastic programming capabilities)

Expand Down
1 change: 1 addition & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ Temoa Project Documentation

Documentation
monte_carlo
myopic
unit_checking
stochastics
83 changes: 83 additions & 0 deletions docs/source/myopic.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@

.. _myopic:

Myopic Optimization
===================

Myopic (or sequential) optimization in Temoa provides a way to solve the model in a series of smaller, sequential time windows. This is often used to simulate decision-making with limited foresight, where the model only "sees" a limited number of future time periods at any given step.

Overall Framework
-----------------

The Myopic extension in Temoa is designed to:

* Solve the model for a sequence of overlapping or non-overlapping time windows.
* Limit the foresight of the model to a user-specified number of future periods.
* Persist the capacity investment decisions from previous windows as "initial capacity" for subsequent windows.
* Automatically manage the ``myopic_efficiency`` table to filter active technologies based on their remaining lifetime and previous investment decisions.

Configuration
-------------

To enable Myopic mode, set the ``scenario_mode`` to ``"myopic"`` in your configuration TOML file and provide the required settings under a ``[myopic]`` section:

.. code-block:: toml

scenario_mode = "myopic"

[myopic]
view_depth = 2
step_size = 1

Settings
~~~~~~~~

* **view_depth**: The number of future time periods visible to the model in each iteration. For example, a ``view_depth`` of 2 means the model will optimize over the current period and the next one.
* **step_size**: The number of periods to advance the "base year" in each subsequent iteration. A ``step_size`` of 1 means the base year will move forward by one time period at a time.

.. important::
Myopic mode requires that the ``input_database`` and ``output_database`` in your configuration point to the same file. This is because the sequencer needs to write intermediate results (like the ``myopic_efficiency`` table and capacity decisions) back to the database to inform subsequent windows.

How it Works
------------

When running in Myopic mode, Temoa performs the following steps:

1. **Initialization**: It identifies all future time periods and sets up a queue of "optimization windows" based on the ``view_depth`` and ``step_size``.
2. **Initial Setup**: It creates the ``myopic_efficiency`` table and pre-loads it with any existing capacity from the input database.
3. **Sequential Solve**: For each window in the queue:
a. **Update Efficiency Table**: The ``myopic_efficiency`` table is updated to include only technologies that are still within their lifetime or were built in previous windows. Any "planned" technologies not built in the previous window's look-ahead are removed to prevent "ghost" capacity.
b. **Data Loading**: Data is loaded specifically for the current window's time range, using the ``myopic_efficiency`` table as a filter.
c. **Model Solve**: A standard Temoa model instance is built and solved for the current window.
d. **Result Persistence**: Investment decisions (built and retired capacity) are saved back to the database. These decisions are treated as fixed constraints in all future windows.
4. **Final Reporting**: Once all windows are solved, a total system cost is calculated as the sum of discounted costs across all periods.

Myopic Efficiency Table
-----------------------

The ``myopic_efficiency`` table is a key internal component of the myopic sequencer. It acts as a dynamic version of the standard ``efficiency`` table, filtered for each optimization window.

* It is "actively maintained" during the run.
* Items not built in a previous window's visibility window are removed.
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Consider using consistent terminology.

The phrase "visibility window" on line 61 is the only occurrence of this term. For consistency with terminology used elsewhere in the document (e.g., "view_depth", "optimization windows"), consider using "look-ahead window" or simply "window" instead.

♻️ Proposed terminology alignment
-* Items not built in a previous window's visibility window are removed.
+* Items not built in a previous window's look-ahead period are removed.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
* Items not built in a previous window's visibility window are removed.
* Items not built in a previous window's look-ahead period are removed.
🤖 Prompt for AI Agents
In `@docs/source/myopic.rst` at line 61, The term "visibility window" appears only
once in the text (line containing "* Items not built in a previous window's
visibility window are removed.") and is inconsistent with the rest of the doc;
replace that phrase with the established terminology used elsewhere (e.g.,
"look-ahead window" or simply "window") so the line reads "* Items not built in
a previous window's look-ahead window are removed." (or "* Items not built in a
previous window are removed.") and scan the surrounding paragraphs to ensure the
chosen term matches uses of "view_depth" and "optimization windows".

* Items that reach the end of their technical lifetime are retired and removed from the table.
* The table includes a computed ``lifetime`` field used internally to screen active technologies.

Backtracking and Roll-back
--------------------------

If the solver fails to find an optimal solution for a given window (e.g., due to infeasibility caused by previous decisions), the Myopic sequencer has a built-in roll-back mechanism. It will attempt to back up to the previous window and re-solve with an expanded ``view_depth`` to find a feasible path forward. If it cannot back up further, the run will abort with an error.

Notes and Caveats
-----------------

Performance and Discounting
~~~~~~~~~~~~~~~~~~~~~~~~~~~

* **Reduced Compute**: Myopic mode dramatically reduces compute requirements compared to perfect foresight by using a "divide and conquer" approach, solving several smaller problems instead of one large global optimization.
* **Discounting**: All costs are discounted to the first optimization period in the database (period ``p0`` of the first myopic window).

Modeling Considerations
~~~~~~~~~~~~~~~~~~~~~~~

* **Investment Amortization**: Investment costs in Temoa are amortized over the useful life of a built technology. This harmonizes how the model perceives costs and benefits within the ``view_depth``: since the model only sees the benefits of a technology for the portion of its life that falls within the current window, the costs are similarly distributed. Consequently, discounted investment costs reported in summary logs may be significantly higher than those reported in the ``output_cost`` table.
* **Limited Foresight**: Myopic mode cannot see beyond the specified ``view_depth``, including constraints. If a constraint only becomes active later in the planning horizon, the model may make "stupid but cost-saving" decisions in early windows. This can lead to unexpected rollbacks when those constraints finally enter the visibility window, which can complicate the interpretation of the results. Modeler caution is advised when setting the ``view_depth`` relative to known future constraints.
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

Consider more formal phrasing (optional).

The phrase "stupid but cost-saving" effectively conveys the concept of locally optimal but globally suboptimal decisions. However, for more formal technical documentation, you might consider alternatives like "locally optimal but globally suboptimal" or "short-sighted but cost-effective".

♻️ Proposed more formal phrasing
-If a constraint only becomes active later in the planning horizon, the model may make "stupid but cost-saving" decisions in early windows.
+If a constraint only becomes active later in the planning horizon, the model may make locally optimal but globally suboptimal decisions in early windows.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
* **Limited Foresight**: Myopic mode cannot see beyond the specified ``view_depth``, including constraints. If a constraint only becomes active later in the planning horizon, the model may make "stupid but cost-saving" decisions in early windows. This can lead to unexpected rollbacks when those constraints finally enter the visibility window, which can complicate the interpretation of the results. Modeler caution is advised when setting the ``view_depth`` relative to known future constraints.
* **Limited Foresight**: Myopic mode cannot see beyond the specified ``view_depth``, including constraints. If a constraint only becomes active later in the planning horizon, the model may make locally optimal but globally suboptimal decisions in early windows. This can lead to unexpected rollbacks when those constraints finally enter the visibility window, which can complicate the interpretation of the results. Modeler caution is advised when setting the ``view_depth`` relative to known future constraints.
🤖 Prompt for AI Agents
In `@docs/source/myopic.rst` at line 83, The wording in the "Limited Foresight"
bullet uses an informal phrase ("stupid but cost-saving"); replace it with a
more formal alternative such as "locally optimal but globally suboptimal" or
"short-sighted but cost-effective" and update the sentence around the
``view_depth`` reference so it reads: Myopic mode cannot see beyond the
specified ``view_depth``, which can lead the model to make locally optimal but
globally suboptimal (short-sighted but cost-effective) decisions in early
windows and cause rollbacks when later constraints enter the visibility
window—advise caution when setting ``view_depth`` relative to known future
constraints.