Skip to content

Your first model

This tutorial takes about ten minutes. You create a small model from a template, look at it on the schematic, change a value with a form, run it and chart the results. It uses a Pywr v2 model; the steps are the same for Pywr v1.

Before you start, install the extension.

  1. Create an empty folder for the model and open it in VS Code with File > Open Folder….

  2. Open the Command Palette with Ctrl Shift P (Cmd Shift P on macOS) and run Pywr: New model.

  3. Pick Pywr v2 model, then the River with an abstraction template.

    The list of templates of the New model command: Empty model, One reservoir and River with an abstraction.The list of templates of the New model command: Empty model, One reservoir and River with an abstraction.
  4. Save the file as model.json in your folder.

The model opens in the editor and its schematic opens in a second tab.

The template is a river that flows to the sea. An abstraction, limited by a licence, takes water from the river to supply a demand.

The schematic of the template: a catchment flows into a river, which flows to the sea and to an abstraction that supplies a demand.The schematic of the template: a catchment flows into a river, which flows to the sea and to an abstraction that supplies a demand.
  • Each circle is a node and each arrow is an edge. Water flows in the direction of the arrows.
  • The Pywr sidebar on the left lists the same components: five nodes, four edges and one parameter.
  • Drag a node to move it. Its new position is saved in model.json.

The abstraction can take up to 8 units of water a day. This limit is the parameter named Licence. Raise it to 12.

  1. In the Model view of the sidebar, open Parameters and click Licence. Its form opens next to the editor.

  2. Change the value from 8 to 12.

    The form of the Licence parameter, a constant with the value 12.The form of the Licence parameter, a constant with the value 12.
  3. Press Save. The value changes in model.json.

Running a model needs a Python environment. If you have not created one yet, follow Set up Python to run models.

  1. Click the tab of model.json, or of its schematic.

  2. Press the Run button, the triangle at the top right of the editor.

  3. Wait for the message that the run completed. For this model it takes a moment.

    A notification saying the run completed, with the buttons Open results, Show summary and Open output folder.A notification saying the run completed, with the buttons Open results, Show summary and Open output folder.

The results are saved in a new folder, named after the date and the time of the run, inside a results folder next to your model.

  1. Press Open results in the message. The results viewer opens.

  2. In the Metrics list on the left, tick Inflow under Demand, the water the demand received, and Outflow under Abstraction.

    The results viewer charting the inflow of the demand and the outflow of the abstraction as two flat lines.The results viewer charting the inflow of the demand and the outflow of the abstraction as two flat lines.
  3. Drag on the chart to zoom in, and double-click to zoom out.

Both lines are flat at 12: the demand asks for 15 a day, but the licence you set limits the abstraction to 12. Set the licence to 20, run again and the demand receives its 15.