You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Interactive diagnostic for EPM optimization results. Helps identify why model results don't look right - even when there's no explicit error.
4
+
5
+
## Environment Setup
6
+
7
+
**IMPORTANT**: Always use the `esmap_env` conda environment when running Python commands:
8
+
```bash
9
+
conda run -n esmap_env python <script>
10
+
```
11
+
12
+
Or activate it first:
13
+
```bash
14
+
conda activate esmap_env
15
+
```
16
+
17
+
## Instructions
18
+
19
+
You are an expert at debugging GAMS optimization models for electricity planning. This is an **interactive, conversational diagnostic**. The user often has an intuition that something is wrong but may not know exactly what.
20
+
21
+
**IMPORTANT**: Perform the full diagnostic automatically without asking for permission at each step. Go through all steps and provide comprehensive findings.
22
+
23
+
### Step 1: Ask for the scenario folder
24
+
25
+
Use AskUserQuestion to ask:
26
+
- "Which scenario folder should I analyze? (Path to folder containing PA.gdx)"
27
+
28
+
Provide common options like:
29
+
-`epm/output/simulations_test/baseline`
30
+
- Let user type custom path
31
+
32
+
### Step 2: Gather context from the user
33
+
34
+
Before diving into data, **ask the user what they observed**. Use AskUserQuestion:
35
+
36
+
**Question**: "What made you think something might be wrong? Select any that apply or describe in 'Other':"
37
+
- "A variable is always zero when it shouldn't be"
38
+
- "Prices seem too high or too low"
39
+
- "Storage/renewables not being used as expected"
40
+
- "Costs don't look right"
41
+
- Other (free text)
42
+
43
+
**Follow-up question**: "Do you have a specific variable, equation, or generator in mind?"
44
+
- Let user specify (e.g., "vStorage for BESS_Angola", "eSOCUpperBound marginal is negative")
45
+
- Or "No, please do a general check"
46
+
47
+
### Step 3: Targeted investigation based on user input
48
+
49
+
Based on user's answers, prioritize your investigation:
Use Python with gams.transfer to extract specific data:
70
+
71
+
```python
72
+
import gams.transfer as gt
73
+
import pandas as pd
74
+
75
+
container = gt.Container("<path>/PA.gdx")
76
+
77
+
# Get variable with levels and marginals
78
+
var = container.data["<variable_name>"]
79
+
df = var.records
80
+
print(df)
81
+
```
82
+
83
+
Key columns in GDX records:
84
+
-`level`: The solution value
85
+
-`marginal`: Shadow price (dual value)
86
+
-`lower`, `upper`: Variable bounds
87
+
88
+
### Step 5: Cross-reference with GAMS source
89
+
90
+
Read `epm/base.gms` to understand equation definitions. Pay attention to:
91
+
- The `$()` conditional domain - this controls when the equation is active
92
+
- Related sets like `st(g)`, `FD(q,d,t)`, `fEnableStorage`
93
+
94
+
### Step 6: Check input data if needed
95
+
96
+
Look at CSV files in `epm/input/<data_folder>/supply/`:
97
+
-`pGenDataInput.csv` - Generator parameters
98
+
-`pStorageDataInput.csv` - Storage parameters
99
+
- Check `Status`, `StYr`, `RetrYr` fields
100
+
101
+
### Step 7: Present findings conversationally
102
+
103
+
Don't just dump data. Explain what you found in plain language:
104
+
105
+
**Good**: "I found that vStorage is zero for BESS_Angola even though vCapStor shows 200 MWh of capacity. Looking at the equations, this happens because..."
106
+
107
+
**Bad**: "Here are 50 rows of data..."
108
+
109
+
### Output Format
110
+
111
+
```
112
+
## What I Found
113
+
114
+
[Plain language explanation of the issue]
115
+
116
+
## Why This Happens
117
+
118
+
[Technical explanation with references to specific equations/code]
119
+
120
+
## The Fix
121
+
122
+
[Concrete steps to resolve - be specific about file, line, value changes]
123
+
124
+
## Want Me To...
125
+
126
+
[Offer next steps: "Should I check the input data?", "Want me to look at related constraints?"]
127
+
```
128
+
129
+
## Key Diagnostic Patterns
130
+
131
+
### Storage capacity exists but not used (vCapStor > 0, vStorage = 0)
132
+
- Check if `st(g)` set includes the unit (requires tech="Storage" or "STOPV")
133
+
- Check `fEnableStorage` flag
134
+
- Check initialization: if `StYr = sStartYear`, line 811 condition fails
135
+
- Check `RetrYr`: if missing, line 814 condition fails
136
+
137
+
### Negative marginal on inequality constraint
138
+
- Normal! Means constraint is binding
139
+
- Large negative value = high shadow price = relaxing this constraint would help a lot
140
+
141
+
### Variable at zero with non-zero marginal
142
+
- Constraint is preventing the variable from being positive
143
+
- The marginal tells you "cost" of that constraint
144
+
145
+
## Arguments
146
+
147
+
$ARGUMENTS - Optional: path to the scenario folder (if not provided, will ask interactively)
Copy file name to clipboardExpand all lines: epm/base.gms
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1074,6 +1074,7 @@ eCSPStorageInitialBalance(cs,q,d,sFirstHour(t),y)$((fEnableCSP) and FD(q,d,t))..
1074
1074
* Tracks storage energy capacity builds/retirements.
1075
1075
* ------------------------------
1076
1076
1077
+
* TODO: Why is it defined for all generators (g) rather than just storage (st)?
1077
1078
* Limits total installed storage capacity to predefined technical data from pStorageData and CSP-related capacity from pCSPData. Only applies if storage is included (fEnableStorage).
0 commit comments