TorchLean API

NN.Runtime.External.Process

External process helpers #

TorchLean frequently calls out to external tools (Python, Julia, ...), typically in the “untrusted producer, trusted checker” pattern:

This file centralizes utilities shared across wrappers:

It intentionally does not provide any claims of correctness about the external tool. It only keeps subprocess handling consistent and non-duplicated.

Executable resolution #

Resolve an executable command name, allowing an environment-variable override.

Example:

  • resolveCmdFromEnv "TORCHLEAN_JULIA" "julia" uses $TORCHLEAN_JULIA if set, otherwise "julia".
Instances For

    Availability checks #

    Check whether a command is available by running it with lightweight version-style arguments.

    Any exception (including “executable not found”) is treated as false. This helper is for optional dependencies; callers that require the command should use ensureCmdAvailable so users get a helpful message.

    Instances For
      def Runtime.External.Process.ensureCmdAvailable (toolName cmd : String) (args : Array String := #["--version"]) (envVar : Option String := none) :

      Require a command to be available and return the command name/path.

      The toolName and envVar fields are only used in error messages. Wrappers such as Julia or Python oracles use this to keep optional-dependency diagnostics consistent across the codebase.

      Instances For

        Running a subprocess and parsing JSON #

        Run a subprocess and return its captured stdout.

        On nonzero exit code, raises IO.userError including stderr. Any exception thrown by the process runner (e.g. executable not found) is propagated to the caller.

        Instances For

          Run a subprocess, treat its stdout as a single JSON payload, and parse it.

          On nonzero exit code, raises IO.userError. If JSON parsing fails, raises IO.userError including the raw stdout (which is usually the most helpful debug output).

          Instances For