Skip to content

fix(pscad): reliable runs + working .psout reader (release 0.1.4)#48

Merged
qian-harvard merged 1 commit into
mainfrom
fix/pscad-run-and-psout-reader
Jun 23, 2026
Merged

fix(pscad): reliable runs + working .psout reader (release 0.1.4)#48
qian-harvard merged 1 commit into
mainfrom
fix/pscad-run-and-psout-reader

Conversation

@qian-harvard

Copy link
Copy Markdown
Contributor

Summary

The PSCAD MCP server could not run a simulation or read its results end-to-end. This PR fixes the blocking defects and bumps powermcp to 0.1.4. Verified by running PSCAD/data/MMC/MMC_HalfBridge_Bipole.pscx (a 5 s MMC-HVDC bipole) entirely through the MCP, producing a 42 MB .psout (364 channels) that the new reader analyzes.

Fixes

  • Non-blocking runrun_project now uses Project.start() + get_run_status polling (building/running/idle_or_finished). The old blocking Project.run() timed out under the 30 s watchdog and held the single-worker executor for the whole run, so status polling was impossible.
  • Working results reader — rewrote read_output_file to the real mhi.psout 1.3 API (the previous mhi.psout.open()/channels()/values() API does not exist). Added list_output_channels and read_output_channels (listing, selective reads, summary stats, downsampling) so files with hundreds of channels x tens of thousands of samples are usable; the .psout is auto-located via Project.temp_folder.
  • Project settingsget/set_project_settings now use Project.parameters() (the project.settings attribute does not exist); this is what enables setting PlotType=PSOUT.
  • Executor COM lifecycle — initialize COM once for the single worker thread; the previous per-call CoInitialize/CoUninitialize invalidated mhi's cached WMI object ("object invoked has disconnected from its clients") on the 2nd+ launch. Added an opt-in _timeout override for long load/build calls.
  • Connection robustnessattach_local scrubs NoDefaultCurrentDirectoryInExePath before launching PSCAD (when set, PSCAD's generated EMTDC run batch cannot find its own solver: "<project>.exe is not recognized"), uses a 120 s attach timeout, and falls back to mhi.pscad.launch() when no attachable instance is running.
  • Build pre-flight — new build_project and get_build_messages tools surface compiler/link errors before a long run.

Tests

  • PSCAD unittest suite: 17/17 pass.
  • Reader validated against a real .psout.
  • Root tests/ unaffected (changes confined to PSCAD/).

🤖 Generated with Claude Code

The PSCAD MCP could not run a simulation or read results end-to-end.
This fixes the blocking issues and bumps powermcp to 0.1.4.

- run_project: use non-blocking Project.start() + get_run_status polling
  (building/running/idle_or_finished) instead of the blocking run() that
  timed out under the 30s watchdog and wedged the single-worker executor.
- data_tools: rewrite the results reader to the real mhi.psout 1.3 API
  (the old mhi.psout.open()/channels() API does not exist). Add
  list_output_channels and read_output_channels (listing, selective reads,
  summary stats, downsampling) so files with 100s of channels x 25k samples
  are usable; auto-locate the .psout via project.temp_folder.
- get/set_project_settings: use Project.parameters() (project.settings does
  not exist), which enables setting PlotType=PSOUT etc.
- executor: initialize COM once for the single worker (per-call
  CoInitialize/CoUninitialize invalidated mhi's cached WMI object); add an
  opt-in _timeout override for long load/build calls.
- connection_manager: scrub NoDefaultCurrentDirectoryInExePath before
  launching PSCAD (it made PSCAD's EMTDC run batch fail to find its own
  solver), give attach a 120s timeout, and fall back to mhi.pscad.launch()
  when no attachable instance is running.
- add build_project + get_build_messages for compile pre-flight; update tests.

Verified end-to-end: ran data/MMC/MMC_HalfBridge_Bipole.pscx (5 s) through the
MCP, producing a 42 MB .psout (364 channels) analyzed via the new reader.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@qian-harvard
qian-harvard merged commit 0a3919d into main Jun 23, 2026
2 checks passed
@qian-harvard
qian-harvard deleted the fix/pscad-run-and-psout-reader branch June 23, 2026 23:07
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.

1 participant