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.


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


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


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


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


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


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


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 v2 | Pywr v1 | |
|---|---|---|
| Recognised by | The metadata, timestepper and network sections | A timestepper section and a list of nodes |
| Checked against | The Pywr schema, and rules the schema cannot express | Its own schema of the pywr types, and the rules pywr applies when it loads a model |
| Runs with | The Pywr engine built into the extension | pywr 1 installed in your Python environment |
| Solvers | CLP, HiGHS, CBC and microlp | GLPK, GLPK edge and lp_solve |
| Results charted | HDF5 and CSV outputs | Files of the TablesRecorder and the CSVRecorder |
| Schematic | Positions saved in the model, as a diagram or on a map | The 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
- Install Pywr for VS Code, free, from the Extensions view of VS Code or with the button below.
- Open the folder with your model, then its JSON file. No model yet? Run Pywr: New model and pick a template.
- 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.