Skip to content
Merged
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
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,24 @@ Nothing calls OpenAI until you set `DRY_RUN` to false. In a dry run, `make embed

`make eval DRY_RUN=false` puts six questions to the real agent. It prints each answer, the result of each check, and the tokens and cost. The checks test, for example, that the agent used the right tool, stated the right count, and didn't present one line of a report as a project's total. Four checks compare answers with the extracted costs. Until there are costs to compare with, the evaluation skips these checks and says so, rather than passing them. One of them is about AF1-236, whose report isn't in the default sample, so it stays skipped until you add that report and extract its costs (see the Quickstart). The wind question's check follows the panel too: until a wind project's extracted cost is above $300 per kW, it expects the answer to say there is none. I haven't run the evaluation yet, because it needs the paid steps first.

`python -m src.extract --validate` sets each extracted cost per kW beside the one in Berkeley Lab's [PJM cost data](https://emp.lbl.gov/publications/interconnection-cost-analysis-pjm), which its researchers read by hand from PJM's studies. It calls no model. The file covers 13 of the 25 default projects, and AF1-236. For each of these with an extracted cost, it prints the two costs, the difference, the megawatts each was divided by, and the study Berkeley Lab read. The first time it has a cost to compare, it downloads Berkeley Lab's file and checks that it's the expected copy. Until the paid extraction runs, it has nothing to compare, and says so. The two costs are defined differently (see [Limitations](#limitations)), so they can differ even when both are read correctly. For AF1-236, the cost I read from its report by hand comes to $391.35 per kW, and Berkeley Lab's to $418.46. Most of that gap is Berkeley Lab's conversion to 2022 dollars ([more](docs/decisions.md#checking-the-extracted-costs-against-berkeley-labs)).

## Limitations

- **Study costs are preliminary estimates, not final bills.** They are the grid operator's estimates at the time of the study, and a later study can change them.
- **PJM only.** The panel holds PJM's projects, and the reports are PJM's.
- **`make fetch` only looks for reports of projects in the AG1 window or an earlier one, and the default sample is narrow.** See [What the data holds now](#what-the-data-holds-now).
- **The paid steps haven't run yet.** Embedding the reports, extracting their costs, asking the agent questions and the evaluation all call OpenAI's paid models, and I haven't run any of them. The agent and the extraction use `gpt-6-luna` ([why](docs/decisions.md#the-models-gpt-6-luna-with-reasoning-off)), and no request has gone to it yet. So I haven't confirmed that OpenAI accepts the settings the code sends, or that the costs the code reports match OpenAI's bill. Nor have I measured how accurately the model extracts costs, how well the agent answers, or what either costs. The offline tests use a stand-in for OpenAI, so they check what the code sends, not what OpenAI does with it.
- **The model can misread a report.** It can miss or misread a figure, and its output can vary between runs, so check any cost that matters against its report.
- **My cost per kW is defined differently from Berkeley Lab's.** Berkeley Lab counts every cost except attachment facilities as network cost, divides by the plant's nameplate capacity (its rated maximum output) and converts to 2022 dollars. I use the report's own network upgrade total, or if it gives none, its total minus the cost of the physical connection. Either can leave out connection work that Berkeley Lab counts. I divide by the megawatts the study assessed, or by the panel's capacity if it gives none, and don't adjust for inflation.
- **My cost per kW is defined differently from Berkeley Lab's.** Berkeley Lab counts every cost except attachment facilities as network cost, divides by the plant's nameplate capacity (its rated maximum output) and converts to 2022 dollars. I use the report's own network upgrade total, or if it gives none, its total minus the cost of the physical connection. Either can leave out connection work that Berkeley Lab counts. I divide by the megawatts the study assessed, or by the panel's capacity if it gives none, and don't adjust for inflation. `--validate` shows both costs for each project Berkeley Lab covers, once its cost is extracted.
- **Withdrawal risk is reasoning, not prediction.** The agent weighs a project's costs against four research findings, each with its source ([what it is told](docs/decisions.md#what-the-agent-is-told-about-withdrawals)), and describes the risk. It is told never to say a project will certainly withdraw. It isn't a statistical model trained on past withdrawals.

## Project layout

```
src/
config.py every setting, path, model name and price
fetch_queue.py downloads Berkeley Lab's queue spreadsheet
fetch_queue.py downloads Berkeley Lab's queue spreadsheet and its PJM cost data
ingest_queue.py builds the panel, and runs the agent's SQL safely
fetch_pdfs.py downloads PJM's study reports
ingest_pdfs.py splits the reports into passages and embeds them
Expand All @@ -154,6 +156,7 @@ Python 3.11 to 3.14, LangChain and LangGraph for the agent, and OpenAI's models:
| Data | What I use it for | Licence and terms |
|---|---|---|
| [Berkeley Lab, Queued Up: 2026 Edition](https://emp.lbl.gov/publications/queued-2026-edition-characteristics) ([data file](https://eta-publications.lbl.gov/sites/default/files/2026-05/lbnl_ix_queue_data_file_thru2025.xlsx)) | The panel, and the national figures on completion and withdrawal | [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), credited to Lawrence Berkeley National Laboratory and GridTracker. `make data` downloads it, and Git ignores it. |
| [Berkeley Lab, PJM interconnection cost data](https://emp.lbl.gov/publications/interconnection-cost-analysis-pjm) ([data file](https://eta-publications.lbl.gov/sites/default/files/pjm_costs_2022_clean_data.xlsx)), by Seel and others, with Exeter Associates (January 2023) | The costs `--validate` compares with: network costs read by hand from PJM's studies of 1,127 projects | It states no open licence. Its copyright notice only reserves a licence for the US government to publish or reproduce it. `--validate` downloads it for your own use, and Git ignores it. |
| PJM study reports, such as [AC2-093's](https://www.pjm.com/pjmfiles/pub/planning/project-queues/impact_studies/ac2093_imp.pdf) | The passages the agent reads, and the costs | © PJM Interconnection, all rights reserved. `make fetch` downloads them for your own use, and Git ignores them. |
| PJM's live queue, through [gridstatus](https://github.com/gridstatus/gridstatus) (optional) | An alternative to Berkeley Lab's data | PJM's terms apply (see its [legal page](https://www.pjm.com/about-pjm/legal.aspx)). The data stays on your computer. |

Expand Down
29 changes: 28 additions & 1 deletion docs/decisions.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Tests check that each finding ends with its source, and that the findings keep t

**Evidence.** A test rebuilds the panel after extracting three projects and checks that their costs come back unchanged, whether the study gives its megawatts, omits them or gives zero.

**Trade-off.** The ratio is written twice, once in Python and once in SQL. That test keeps the two in step.
**Trade-off.** The ratio is written twice, once in Python and once in SQL, and `--validate` repeats its choice of megawatts in SQL. Tests keep all three in step.

## Queue age ends when a project leaves the queue

Expand Down Expand Up @@ -246,6 +246,33 @@ Tests check that each finding ends with its source, and that the findings keep t
- If PJM publishes later windows' reports at these addresses, `pdf_last_window` has to be moved on by hand.
- A passing error, such as a request to slow down, stops the fetch too. Running it again carries on, skipping the reports already downloaded.

## Checking the extracted costs against Berkeley Lab's

**Decision.** `python -m src.extract --validate` sets each extracted cost per kW beside the one in Berkeley Lab's PJM cost data, which its researchers read by hand from PJM's studies of 1,127 projects. For each project in both, it prints the two costs, the difference (the extracted cost minus Berkeley Lab's), the megawatts each was divided by, and the study Berkeley Lab read. Like the Queued Up spreadsheet, the file is pinned by its address and SHA-256 checksum in `src/config.py` (`lbnl_costs_url` and `lbnl_costs_sha256`). It is downloaded into `data/raw/costs/` the first time it's needed. The command calls no model.

**Why.**
- **An independent check on more projects.** The file covers 13 of the 25 default projects, and AF1-236. I read three reports by hand.
- **The same studies.** For all 14, the report `make fetch` or `--ids` downloads is the study Berkeley Lab read: the same type and the same month. So a gap comes from the definitions or from a misread, not from comparing different studies.
- **The megawatts matter as much as the dollars.** AF1-236's report gives 1,210 MW of output, of which PJM counts 459.8 MW as capacity, and Berkeley Lab divides by the 1,210. Divided by 459.8 MW, the same cost would be $1,029.86 per kW. Showing the megawatts each side used makes a gap like this easy to trace.

**Alternatives.**
- **Only the three projects I read by hand** (AC2-093, AF1-236 and AF2-353). That check stays, but three projects that I chose say little about the rest.
- **Converting both costs to one definition first,** for example mine to 2022 dollars. It would hide where the two differ. And Berkeley Lab says only that it converts with a GDP deflator, an index of prices across the economy, not what factor it applies to each study, so my conversion could differ from its own. Settling the definition is [future work](future_work.md).
- **The Queued Up spreadsheet.** It holds no costs.
- **Committing the file.** It states no open licence, so, like PJM's reports, it is downloaded for local use and kept out of Git.

**Evidence.**
- On 1 December 2026 I ran `--validate` on a copy of the panel holding only the cost I read by hand from AF1-236's report. It downloaded the file, matched its checksum, and printed $391.35 per kW beside Berkeley Lab's $418.46, a difference of −$27.11, both divided by 1,210 MW.
- I set the first page of each of the 14 reports beside the study type and date Berkeley Lab gives. Seven of the default projects' reports are system impact studies, and six combine a feasibility study with a system impact study, which Berkeley Lab lists as system impact. AF1-236's is a system impact study.
- Berkeley Lab's figures come back to the reports' own. For AF1-236, its $418.46 is the report's $473,529,878 of network upgrades plus $2,400,000 for two substation breakers, which the report counts as part of the physical connection, divided by 1,210 MW and raised by 6.4% to 2022 dollars. So of the gap of $27.11 per kW, $1.98 is the breakers and $25.13 the conversion. For the 2021 studies I checked, the rise is 2.1%.
- For four default projects, AG1-330, AG1-335, AG1-336 and AG1-337, the report's cost summary gives "Total System Network Upgrade Costs $0" and lists the substation and line work as part of the physical connection. Berkeley Lab counts most of that work as network cost: $405.43, $928.25, $1,638.58 and $575.47 per kW. So for these, a correct extraction will show all of Berkeley Lab's figure as the gap.
- Tests check that only projects in both are compared, that the megawatts shown follow the same rule as the cost, that the file's own sheet and column names are read, and that nothing is downloaded when there are no extracted costs. They also check that a failed download, or a file with another checksum, is reported rather than used, and that running it without a panel says to build one.

**Trade-offs.**
- A gap isn't by itself a mistake, because the definitions differ. The output says so.
- The file only covers projects that applied by 31 March 2021, with studies up to September 2022, so it can't check later projects.
- If Berkeley Lab replaces the file, the address and checksum have to be updated by hand.

## The chat page

**Decision.** Alongside the terminal chat, the agent has a chat page in the browser, started with `make app`.
Expand Down
7 changes: 3 additions & 4 deletions docs/future_work.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ Changes I plan or propose, starting with the most urgent.

## Next

- **Run the paid steps.** Embed the reports, extract their costs and run the evaluation. Then add the reports of AC2-093, AF1-236 and AF2-353, which aren't in the default sample, and check their extracted costs against the figures I read from them by hand. This needs OpenAI credits.
- **Run the paid steps.** Embed the reports, extract their costs and run the evaluation. Then add the reports of AC2-093, AF1-236 and AF2-353, which aren't in the default sample, check their extracted costs against the figures I read from them by hand, and compare the 14 projects that Berkeley Lab covers (13 of the default 25, and AF1-236) with its costs (`python -m src.extract --validate`). This needs OpenAI credits.

## Method

- **Choose a more varied sample of reports.** Of the default 25, 22 applied on the same day, and 12 are 5 MW or smaller. A better rule could set a minimum size, prefer system impact studies and spread the choice across queue windows.
- **Compare the extracted costs with Berkeley Lab's.** Its [PJM cost data](https://eta-publications.lbl.gov/sites/default/files/pjm_costs_2022_clean_data.xlsx) has costs read by hand for 1,127 projects, including AF1-236 and 13 of the default 25. `python -m src.extract --validate` looks for these costs in the Queued Up spreadsheet, which doesn't have them, so it never compares anything.
- **Settle the cost definition.** Either match Berkeley Lab's (every cost except attachment facilities, divided by nameplate capacity, in 2022 dollars) or keep mine and show the difference.
- **Check which megawatts the extraction copies.** AC2-093's report gives 675 MW of output, of which PJM counts 429.4 MW as capacity. Its cost per kW depends on which one the model takes.
- **Settle the cost definition.** Either match Berkeley Lab's (every cost except attachment facilities, divided by nameplate capacity, in 2022 dollars) or keep mine. For four of the default projects, a correct extraction gives $0 per kW, where Berkeley Lab gives $405 to $1,639 ([why](decisions.md#checking-the-extracted-costs-against-berkeley-labs)). `--validate` will show how far apart the two are once costs are extracted.
- **Check which megawatts the extraction copies.** AF1-236's report gives 1,210 MW of output, of which PJM counts 459.8 MW as capacity, so its cost is $391.35 or $1,029.86 per kW, depending on which one the model takes. `--validate` shows the megawatts used beside Berkeley Lab's.
- **Compare PDF readers.** On my laptop, PyMuPDF took about 140 seconds to read AG1-321's 65-page report with its tables added in Markdown, a simple text format, and gave 365,148 characters. Without the Markdown tables it took under half a second and gave 133,495. I haven't measured whether the tables help the extraction.

## Scope
Expand Down
13 changes: 13 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,15 @@ class Settings(BaseSettings):
# release needs its own date, and so does a workbook passed with --file (set LBNL_DATA_END).
lbnl_data_end: date = date(2025, 12, 31)

# the reference for --validate, Berkeley Lab's PJM cost data (January 2023,
# https://emp.lbl.gov/publications/interconnection-cost-analysis-pjm), with costs read by hand
# from PJM's studies of 1,127 projects. it states no open licence, so it is downloaded for local
# use, never committed.
lbnl_costs_url: str = (
"https://eta-publications.lbl.gov/sites/default/files/pjm_costs_2022_clean_data.xlsx"
)
lbnl_costs_sha256: str = "50a363318b18e36418ac1af4f7afb923998c0863d990a73b59816d014c0af245"

# cost caps. dry_run true means no paid call runs until it is flipped on a small sample.
max_pdfs: int = 25
dry_run: bool = True
Expand Down Expand Up @@ -189,6 +198,10 @@ def lbnl_workbook_path(self) -> Path:
# named after the file in the url, so a newly pinned release keeps its own name.
return self.queue_raw_dir / self.lbnl_workbook_url.rsplit("/", 1)[-1]

@property
def lbnl_costs_path(self) -> Path:
return self.raw_dir / "costs" / self.lbnl_costs_url.rsplit("/", 1)[-1]

@property
def pdf_raw_dir(self) -> Path:
return self.raw_dir / "pdfs"
Expand Down
Loading