Skip to content

plt.savefig() Fails on Windows When Output File Path is Too Long #185

@ejtmaravillas

Description

@ejtmaravillas

plt.savefig() in disco/extensions/upgrade_simulation/upgrades/voltage_upgrade_functions.py fails on windows output file path is too long

Summary

When running DISCO on Windows, simulations with longer job names can cause the full file path used in matplotlib.pyplot.savefig() to exceed the Windows MAX_PATH limit (~260 characters), resulting in a FileNotFoundError.

Error

FileNotFoundError: [Errno 2] No such file or directory:
'custom_output\\job-outputs\\PV_Deployment_3.0_rdt2250-rdt2251xx_MIN\\VoltageUpgrades\\interim\\bus_violations_for_cluster_option_1_voltage_regulators_0.pdf'

Cause

On Windows, the default path limit in 260 characters unless long path support is explicitly enabled (which is often not the case).

  • While this error was caused in part by a long job name, the simulation should ideally fail gracefully or preemptively detect when the output path will exceed safe limits

My Environment

  • OS: Windows 11
  • Python: 3.x
  • DISCO version: latest based on this post

Temporary Workaround

Manually shortened the job name and reduced the filename length in plot_voltage_violations(). This resolved the issue.

Suggested Enhancements

  • Auto-truncate long job names or use a hash-based fallback
  • Warn users if job names are too long and may cause issues in downstream plotting or file saving
  • Check total path length before calling plt.savefig() and raise a more user-friendly error if the path is too long
  • Optionally allow users to configure an output filename limit in the config or scenario setup

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions