Pywr for VS Code

See your Pywr model as the network it is

Pywr for VS Code turns a long JSON file into a schematic you can draw on, forms you can fill in, a run you can follow and charts you can check, all in the editor. It works with Pywr v2 and Pywr v1.

Free, for VS Code 1.110 or later. Already in VS Code? Install it from there.

Pywr for VS Code: the sidebar lists the nodes and parameters of a model, and the schematic shows the results of a run on the network, with the volume of the reservoir and the flow of each node.Pywr for VS Code: the sidebar lists the nodes and parameters of a model, and the schematic shows the results of a run on the network, with the volume of the reservoir and the flow of each node.

Draw the network on a schematic

Open the schematic and every node and edge of your model is on the page. What you change on it is written to the model file.

  • Drag nodes, connect them to add edges and drop new ones from the toolbar
  • Nodes with coordinates are drawn on a map
  • Show the results of a run on the network, one time step at a time
Draw the schematic
The network of a model drawn on a map in VS Code: a catchment feeds a reservoir, which supplies a town through a treatment works, next to a river with an intake.The network of a model drawn on a map in VS Code: a catchment feeds a reservoir, which supplies a town through a treatment works, next to a river with an intake.

Edit a component in a form

Click a component to edit all its fields in one place. Saving the form writes the change back into the JSON file.

  • Pick names from lists and files with a file picker
  • Profiles, control curves and bathymetry are charted as you type
  • CSV tables and timeseries are previewed with their columns
Edit with forms
The form of a monthly profile parameter, with the twelve values and a chart of the profile.The form of a monthly profile parameter, with the twelve values and a chart of the profile.

Catch mistakes while you type

The model is checked against the Pywr schema as you edit it, and for the mistakes a schema cannot see.

  • A type that does not exist or a missing field is underlined at once
  • So is a name nothing defines, a node with no edges or a list of the wrong length
  • The light bulb offers the closest name, or creates the component
Check the model for mistakes
A misspelt parameter name underlined in the JSON editor, with a quick fix menu offering to replace it with the closest name or to create the parameter.A misspelt parameter name underlined in the JSON editor, with a quick fix menu offering to replace it with the closest name or to create the parameter.

Run the model with one button

Press Run and follow its progress, or run it live on the schematic and watch each time step. Each run saves its results in a new dated folder next to the model.

  • Pywr v2 is built in: you only need a Python environment
  • Pick the solver, the scenarios and the output folder without editing the model
  • See how long each part of the model took
Run the model
A live run on the schematic: a bar above the network steps through the dry scenario, at day 5 of 731, and each node shows its flow or volume for that day.A live run on the schematic: a bar above the network steps through the dry scenario, at day 5 of 731, and each node shows its flow or volume for that day.

Chart the results where you ran them

Open an HDF5 or CSV results file and tick what to plot, without Python or a notebook.

  • Time series, duration curves and percentile bands across scenarios
  • Aggregate by month or year, and read the statistics of each line
  • Compare two runs, then export the chart as PNG or the values as CSV
Chart the results
The results viewer charting the volume of a reservoir over two years for a dry, an average and a wet scenario.The results viewer charting the volume of a reservoir over two years for a dry, an average and a wet scenario.

Check the model still behaves

A QA report is a set of charts you define once and draw again after every change, such as a reservoir against its control curve.

  • Runs a copy of the model and exports only what is on your charts
  • Saved in a file next to the model, to commit and share with it
  • Exports the charts as a PDF document
Build a QA report
A QA report with three charts: the storage of a reservoir with its drought curve, the supply to a town against its demand, and the flow of a river at a gauge.A QA report with three charts: the storage of a reservoir with its drought curve, the supply to a town against its demand, and the flow of a river at a gauge.

Two versions of Pywr, one extension

The extension recognises which version a model is written for and shows it in the status bar. The sidebar, the forms, the schematic and the charts work the same way for both.

Pywr v2Pywr v1
Recognised byThe metadata, timestepper and network sectionsA timestepper section and a list of nodes
Checked againstThe Pywr schema, and rules the schema cannot expressIts own schema of the pywr types, and the rules pywr applies when it loads a model
Runs withThe Pywr engine built into the extensionpywr 1 installed in your Python environment
SolversCLP, HiGHS, CBC and microlpGLPK, GLPK edge and lp_solve
Results chartedHDF5 and CSV outputsFiles of the TablesRecorder and the CSVRecorder
SchematicPositions saved in the model, as a diagram or on a mapThe positions, icons and edge colours saved in the model are kept

Whether you read JSON or not

If you would rather not open the file

You can build and maintain a model from the sidebar, the forms and the schematic, and never write a brace.

  • A form for every node, parameter, table, timeseries and output
  • Search any component by name or by type
  • See what a component uses, and what uses it, before you change it
  • Rename or delete, and every reference follows

If you live in the JSON

The editor knows the components of your model, like it knows the symbols of code.

  • F2 renames a component everywhere it is used
  • F12 goes to a component, Shift F12 lists its usages
  • Names and types complete as you type, and hovering explains them
  • Links above each component open its form or show it on the schematic

The rest of VS Code works as usual around the model. You can commit it and compare its versions with Git, write its Python scripts with the Python extension, and use the terminal, the search across files and any other extension you have installed.

Install it, then open a model

  1. Install Pywr for VS Code, free, from the Extensions view of VS Code or with the button below.
  2. Open the folder with your model, then its JSON file. No model yet? Run Pywr: New model and pick a template.
  3. Open the schematic from the editor toolbar, or press Run.

Needs VS Code 1.110 or later. To run a model you also need a Python environment with Python 3.10 or later, and pywr 1 installed in it for Pywr v1 models. Charting results needs no Python.