Skip to content

[FEATURE] Replace the stdin/stdout JSON hand-off between Python and Julia OPF with file-based exchange #698

Description

@joda9

Current state

pm_optimize writes the network as one JSON line to the Julia subprocess's stdin; Main.jl
prints the result JSON to stdout, interleaved with debug logs, printlns and Gurobi
banners. Python identifies the result line by out.rstrip().startswith('{"name"').

Why this is fragile

  1. Result detection depends on unguaranteed JSON key order. JSON.json(::Dict) serializes
    in hash/iteration order — "name" being the first key is coincidence, not contract. If the
    result line ever starts with another key (different Julia/JSON.jl version, changed key set),
    the startswith branch misses it: from_powermodels is never called, no results are
    written to the eDisGo object
    , the raw JSON is echoed to stdout, and the run still logs
    "Julia process was successful." — silent loss of results on a successful solve.
  2. Logs and payload share one channel, separated only by prefix heuristics ("Set parameter",
    "Academic").
  3. The input contract ("exactly one JSON line on stdin", read via readline) is implicit and
    unenforced; large inputs are written in full before stdout is drained (OS pipe-buffer
    deadlock risk for very large networks).

Proposal

Exchange input and result as files (paths passed as arguments, e.g. into the existing
results directory or a temp dir): Python writes <run>_input.json, Julia writes
<run>_result.json; stdout remains purely a log channel. This removes the key-order trap, the
log/payload mixing and the pipe-buffer risk in one step.

Interim hardening (if stdout must stay temporarily): wrap the result in an unambiguous sentinel
(e.g. ###RESULT###{…}) instead of keying on {"name".

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: opfOptimal power flow / Julia side (eDisGo_OPF.jl, powermodels_io)effort: largeLarge / multi-week effort or requires domain expertise — not a starter taskenhancementpriority: medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions