Skip to content

Commit

Permalink
Merge pull request #263 from snek5000/remaining-clock-time
Browse files Browse the repository at this point in the history
Using remaining clock time code from fluidsim_core
  • Loading branch information
paugier committed Jan 5, 2023
2 parents 4fd6c9b + f085db0 commit 1a20abe
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 47 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ Security in case of vulnerabilities.
### Added

- {func}`snek5000.output.base.Output.post_init_create_additional_source_files`,
{func}`snek5000.resources.get_base_templates` and {func}`snek5000.resources.get_base_template`.
{func}`snek5000.resources.get_base_templates` and
{func}`snek5000.resources.get_base_template`.

## [0.9.0rc0]

Expand Down
48 changes: 31 additions & 17 deletions docs/examples/snek5000-tgv/src/snek5000_tgv/tgv.usr.f
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ subroutine userchk()
! for remaining_clock_time
character*28 rct_file_name
real rct_seconds_between_save
real remaining_clock_time
real remaining_clock_time, remaining_eq_time, delta_clock_time

period_save = real(UPARAM(11))

Expand All @@ -132,7 +132,9 @@ subroutine userchk()
if (.not. exist) then
if (nid.eq.0) then
open(11, File=rct_file_name)
write(11,'(a)') 'it,time,dt,remaining_clock_time'
write(11,'(a,a)')
& 'it,equation_times,dt,delta_clock_times,',
& 'remaining_equation_times,remaining_clock_times'
close(11)
endif
endif
Expand All @@ -149,13 +151,22 @@ subroutine userchk()
c iostep_full = iostep
c call full_restart_save(iostep_full)

if ((nid .eq. 0) .and. (istep > 0)) then
if (nid .eq. 0) then
call compute_remaining_clock_time(
& rct_seconds_between_save, remaining_clock_time)
if (remaining_clock_time >= 0.0) then
& rct_seconds_between_save, remaining_clock_time,
& remaining_eq_time, delta_clock_time)
if (istep == 0) then
open(10, File=rct_file_name, position='append')
write(10,'(I12,A,g14.8,A,g14.8,A,g14.8)')
& istep,',',time,',',dt,',',remaining_clock_time
write(10,'(I12,A,g14.8,A,g14.8,A,g14.8,A)')
& istep,',',time,',',dt,',',delta_clock_time,
& ',nan,nan'
close(10)
elseif (remaining_clock_time >= 0.0) then
open(10, File=rct_file_name, position='append')
write(10,'(I12,A,g14.8,A,g14.8,A,g14.8,A,g14.8,A,g14.8)')
& istep,',',time,',',dt,',',delta_clock_time,
& ',',remaining_eq_time,
& ',',remaining_clock_time
close(10)
endif
endif
Expand Down Expand Up @@ -241,15 +252,15 @@ subroutine compute_energy_enstrophy(e1,e2,u,v,w)
end
c-----------------------------------------------------------------------
subroutine compute_remaining_clock_time(
& seconds_between_save, remaining_clock_time)
& seconds_between_save, remaining_clock_time, remaining_eq_time,
& delta_clock_time)
implicit none

include 'SIZE'
include 'TOTAL'

real seconds_between_save
real remaining_clock_time
real remaining_eq_time
real remaining_clock_time, remaining_eq_time

real clock_time, delta_clock_time, delta_eq_time

Expand All @@ -260,11 +271,10 @@ subroutine compute_remaining_clock_time(
save istep_next

remaining_clock_time = -1.0
if (istep .eq. 1) then
call cpu_time(clock_time_last)
delta_clock_time = 0.0
if (istep .eq. 0) then
eq_time_last = time
istep_last = 1
istep_next = 2
istep_next = 1
elseif ((istep .eq. istep_next) .or. (lastep .eq. 1)) then
call cpu_time(clock_time)
delta_clock_time = clock_time - clock_time_last
Expand All @@ -278,10 +288,14 @@ subroutine compute_remaining_clock_time(
else
remaining_eq_time = (nsteps - istep) * dt
endif
istep_next = istep + int((istep - istep_last) *
if (istep .eq. 1) then
istep_next = 2
else
istep_next = istep + int((istep - istep_last) *
& seconds_between_save / delta_clock_time)
if (istep_next .eq. istep) then
istep_next = istep_next + 1
if (istep_next .eq. istep) then
istep_next = istep_next + 1
endif
endif
istep_last = istep
remaining_clock_time = remaining_eq_time / delta_eq_time *
Expand Down
24 changes: 24 additions & 0 deletions docs/tuto_tgv.myst.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,24 @@ The command `snek-ipy-load` can be used to start a IPython session and load the
simulation saved in the current directory.
```

+++

## How long was the run?

`snek5000-tgv` saves a file `remaining_clock_time.csv` during the simulation. It can be
read manually,

```{code-cell} ipython3
!cat {path_run}/remaining_clock_time.csv
```

and there is also an object `sim.output.remaining_clock_time` to load and plot these
data (which is especially useful during the simulation!):

```{code-cell} ipython3
sim.output.remaining_clock_time.plot()
```

## Parse, load and plot information contained in the Nek5000 log

The object `sim.output.print_stdout` (see
Expand Down Expand Up @@ -273,3 +291,9 @@ ax.figure

Note that we use for this tutorial very small and coarse simulations, which explain the
differences between our results and the reference!

Let us see what gives the `remaining_clock_time` plot after the second simulation:

```{code-cell} ipython3
sim.output.remaining_clock_time.plot()
```
8 changes: 3 additions & 5 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --extra=dev --output-file=requirements/dev.txt --resolver=backtracking requirements/vcs_packages.in setup.cfg
Expand Down Expand Up @@ -127,8 +127,9 @@ fluiddyn==0.5.1
# fluidsim-core
# snek5000
# snek5000 (setup.cfg)
fluidsim-core==0.7.1
fluidsim-core @ hg+https://foss.heptapod.net/fluiddyn/fluidsim#subdirectory=lib
# via
# -r requirements/vcs_packages.in
# snek5000
# snek5000 (setup.cfg)
fonttools==4.38.0
Expand Down Expand Up @@ -161,12 +162,9 @@ imagesize==1.4.1
# via sphinx
importlib-metadata==5.1.0
# via
# fluidsim-core
# jupyter-cache
# keyring
# myst-nb
# nbconvert
# sphinx
# twine
inflection==0.5.1
# via
Expand Down
8 changes: 3 additions & 5 deletions requirements/docs.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --extra=docs --output-file=requirements/docs.txt --resolver=backtracking requirements/vcs_packages.in setup.cfg
Expand Down Expand Up @@ -94,8 +94,9 @@ fluiddyn==0.5.1
# fluidsim-core
# snek5000
# snek5000 (setup.cfg)
fluidsim-core==0.7.1
fluidsim-core @ hg+https://foss.heptapod.net/fluiddyn/fluidsim#subdirectory=lib
# via
# -r requirements/vcs_packages.in
# snek5000
# snek5000 (setup.cfg)
fonttools==4.38.0
Expand Down Expand Up @@ -124,11 +125,8 @@ imagesize==1.4.1
# via sphinx
importlib-metadata==5.1.0
# via
# fluidsim-core
# jupyter-cache
# myst-nb
# nbconvert
# sphinx
inflection==0.5.1
# via
# snek5000
Expand Down
6 changes: 1 addition & 5 deletions requirements/main.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --output-file=requirements/main.txt --resolver=backtracking setup.cfg
Expand Down Expand Up @@ -54,8 +54,6 @@ h5py==3.7.0
# h5netcdf
idna==3.4
# via requests
importlib-metadata==5.1.0
# via fluidsim-core
inflection==0.5.1
# via snek5000 (setup.cfg)
jinja2==3.1.2
Expand Down Expand Up @@ -160,5 +158,3 @@ xarray==2022.12.0
# via pymech
yte==1.5.1
# via snakemake
zipp==3.11.0
# via importlib-metadata
9 changes: 3 additions & 6 deletions requirements/tests-editable.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --extra=tests --output-file=requirements/tests.txt --resolver=backtracking requirements/vcs_packages.in setup.cfg
Expand Down Expand Up @@ -70,8 +70,9 @@ fluiddyn==0.5.1
# fluidsim-core
# snek5000
# snek5000 (setup.cfg)
fluidsim-core==0.7.1
fluidsim-core @ hg+https://foss.heptapod.net/fluiddyn/fluidsim#subdirectory=lib
# via
# -r requirements/vcs_packages.in
# snek5000
# snek5000 (setup.cfg)
fonttools==4.38.0
Expand All @@ -88,8 +89,6 @@ h5py==3.7.0
# h5netcdf
idna==3.4
# via requests
importlib-metadata==5.1.0
# via fluidsim-core
inflection==0.5.1
# via
# snek5000
Expand Down Expand Up @@ -267,5 +266,3 @@ xarray==2022.12.0
# via pymech
yte==1.5.1
# via snakemake
zipp==3.11.0
# via importlib-metadata
9 changes: 3 additions & 6 deletions requirements/tests.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# This file is autogenerated by pip-compile with Python 3.10
# by the following command:
#
# pip-compile --extra=tests --output-file=requirements/tests.txt --resolver=backtracking requirements/vcs_packages.in setup.cfg
Expand Down Expand Up @@ -70,8 +70,9 @@ fluiddyn==0.5.1
# fluidsim-core
# snek5000
# snek5000 (setup.cfg)
fluidsim-core==0.7.1
fluidsim-core @ hg+https://foss.heptapod.net/fluiddyn/fluidsim#subdirectory=lib
# via
# -r requirements/vcs_packages.in
# snek5000
# snek5000 (setup.cfg)
fonttools==4.38.0
Expand All @@ -88,8 +89,6 @@ h5py==3.7.0
# h5netcdf
idna==3.4
# via requests
importlib-metadata==5.1.0
# via fluidsim-core
inflection==0.5.1
# via
# snek5000
Expand Down Expand Up @@ -267,5 +266,3 @@ xarray==2022.12.0
# via pymech
yte==1.5.1
# via snakemake
zipp==3.11.0
# via importlib-metadata
2 changes: 1 addition & 1 deletion requirements/vcs_packages.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
snek5000-phill @ git+https://github.com/snek5000/snek5000-phill.git
snek5000-cbox @ git+https://github.com/snek5000/snek5000-cbox.git
# TODO before releases: comment out these 2 lines
# fluidsim-core @ hg+https://foss.heptapod.net/fluiddyn/fluidsim#subdirectory=lib
fluidsim-core @ hg+https://foss.heptapod.net/fluiddyn/fluidsim#subdirectory=lib
# pymech @ git+https://github.com/eX-Mech/pymech.git
29 changes: 28 additions & 1 deletion src/snek5000/output/remaining_clock_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,38 @@
"""

import numpy as np

from fluidsim_core.output.remaining_clock_time import RemainingClockTime as Base

from .simple_csv import OutputWithCsvFileAndParam


class RemainingClockTime(OutputWithCsvFileAndParam):
class RemainingClockTime(OutputWithCsvFileAndParam, Base):
INDEX_USERPARAM = 12
_tag = "remaining_clock_time"
_param_name = "period_save_in_seconds"
_param_default_value = 5.0

def _load_times(self):
df = self.load()
data = {key: df[key].values for key in df.keys()}
data["full_clock_time"] = np.nansum(data["delta_clock_times"])
data["equation_time_start"] = df.loc[0, "equation_times"]
return data

def load(self):
df = super().load()
df["delta_equation_times"] = df.equation_times.diff()
delta_time_inds = df.it.diff()
df["clock_times_per_timestep"] = df["delta_clock_times"] / delta_time_inds
keys = (
"delta_clock_times",
"delta_equation_times",
"clock_times_per_timestep",
)
df.loc[df["it"] == 0, keys] = np.nan
return df

def plot(self):
self.plot_clock_times()
2 changes: 2 additions & 0 deletions tests/test_tgv.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ def test_tgv(sim_tgv_executed):
df = sim.output.remaining_clock_time.load()
assert isinstance(df, pd.DataFrame)
assert len(df) >= 2

sim.output.remaining_clock_time.plot()

0 comments on commit 1a20abe

Please sign in to comment.