Skip to content

8. Watching the run ​

The case foresight was built for: the job runs for hours, appending to its log, and you want to watch it converge.

In a browser ​

gnuplot
# Tutorial 8: the script foresight --watch re-renders while the solver writes run.dat.
set terminal html size 640,380
set output 'monitor.html'
set logscale y; set grid
plot 'run.dat' u 1:2 t 'continuity', '' u 1:3 t 'momentum'
bash
foresight --watch monitor.gp          # every second; --watch 10 for slow jobs

foresight runs the script, then polls the script and every data file it read; when one changes — the solver appended a line — it runs again and rewrites monitor.html. The page reloads itself at the same period and keeps your zoom: the view lives in the page URL as data values, not screen positions. Each rewrite is atomic, so a reload never sees half a page. An error in one cycle (a typo saved in the script) is reported, and watching goes on.

On the job side there is nothing to link: write the columns, one line per iteration, and flush.

Two keys of the page are made for a long run:

  • zoom to the last few hundred iterations and press f: at each reload the window follows the end of the data, keeping its width, with y fitted to what it shows — the newest iterations, always in view;
  • click a key entry to hide its series (and click again to show it): the energy residual, say, while you study the other two.

Both survive the reloads, in the page URL with the zoom.

Over ssh ​

The text terminal draws the plot with characters:

gnuplot
set terminal dumb size 72,22
set logscale y
plot 'run.dat' u 1:2 t 'continuity', '' u 1:3 t 'momentum'
text
$ foresight dumb.gp

  10.000000+---------+---------+--------+---------+--continuity******-+
           +                                           momentum###### +
   1.000000+**                                                        +
           +#***                                                      +
           + ###***                                                   +
   0.100000+   #######***                                             +
           +          #####                                           +
           +              ###*****                                    +
   0.010000+                 ########                                 +
           +                        ###***                            +
   0.001000+                           ####*                          +
           +                              ########                    +
           +                                     ####                 +
   0.000100+                                        ######            +
           +                                           ***#####       +
           +                                                  *###    +
   0.000010+                                                    **####+
           +                                                          +
   0.000001+---------+---------+--------+---------+---------+---------+
           0        20        40       60        80        100       120

foresight --watch dumb.gp clears the screen and redraws in place at each change: no browser, no X forwarding, no port to open. For smoother curves, set terminal block braille draws with Braille dots, 2 x 4 per character, and ansi colors the series: see the cookbook.

From the solver itself ​

The library can do the same without a script: re-save the figure every few iterations, and set the page to reload.

fortran
call fig%set_refresh(5)               ! the page reloads every 5 s, keeping the zoom
do it = 1, max_it
   ! ... solve, append to the history arrays ...
   if (mod(it, 50) == 0) then
      call fig%clear                  ! drop the series, keep the settings
      call fig%plot(its(1:it), res(1:it), title='continuity')
      call fig%save('monitor.html')
   endif
enddo

What you learned

Live monitoring in a browser or a terminal, from a script or from the solver; following the newest data, hiding a series. Reference: Live Monitoring, Interactive Viewer, Command Line.

That is the tour. The Cookbook has one recipe per task; the Reference the rest.

Released under the GPL v3, BSD 2-Clause, BSD 3-Clause or MIT License.