10.3. A Test Suite
Bob: Ah, but there is more! Not only can we safely put our a report
about energy conservation, any time we want, but we can even do a full
output, and then restart from that output, as often as we want, without
affecting the trajectories of any of the particles in the slightest.
Alice: Again, that is the claim. We'd better test that, too!
Of course, this idea only works for a full output, one that dumps the
whole internal data structure, for which we had the command line option
-r. Without that option, you get a synchronized snapshot, and
changing the frequency of synchronization will lead to the same problem
we saw above with the previous code.
Bob: Let's build a little test suite. We'll create an input file,
and then ask for output in different ways.
To start with, let's compare a run that directly integrates for two
time units with a run that restarts from a dump halfway. We can do
that comparison in two ways: compare a dump for each type of run,
direcly and in stages, and compare a snapshot output for each type of
run, where in the latter case of course the intermediate output still
has to be a dump.
Then, for good measure, let's integrate till three time units. We can
then compare a run that goes there non-stop with a run that makes one
stop, and with a run that makes two stops along the way. We'll make
those two comparisons on the dump level.
And since we require that everything should be unchanged, I want to
do more than measuring phase space distances: I'll do a diff on the
whole output file, to check whether any variable, important or not,
has any change whatsoever. Here is the test suite:
|gravity> kali mkplummer.rb -n 4 -s 1 | kali nbody_set_id.rb > tmp0
==> Plummer's Model Builder <==
Number of particles : N = 4
pseudorandom number seed given : 1
Floating point precision : precision = 16
Incremental indentation : add_indent = 2
Screen Output Verbosity Level : verbosity = 1
ACS Output Verbosity Level : acs_verbosity = 1
Floating point precision : precision = 16
Incremental indentation : add_indent = 2
==> Takes an N-body system, and gives each body a unique ID <==
value of @body_id for 1st body : n = 1
Floating point precision : precision = 16
Screen Output Verbosity Level : verbosity = 1
ACS Output Verbosity Level : acs_verbosity = 1
Floating point precision : precision = 16
Incremental indentation : add_indent = 2
actual seed used : 1
|gravity> kali world1.rb -t 1 -r < tmp0 | kali acstail.rb > tmp1w
==> Returns the last n chunks of ACS data <==
Number of last ACS data chunks returned: n = 1
Screen Output Verbosity Level : verbosity = 1
ACS Output Verbosity Level : acs_verbosity = 1
Floating point precision : precision = 16
Incremental indentation : add_indent = 2
==> Individual Time Step, Individual Integration Scheme Code <==
Determines the time step size : dt_param = 0.01
Duration of an era : dt_era = 0.01
Maximum time step (units dt_era): dt_max_param = 1.0
Diagnostics output interval : dt_dia = 1.0
Snapshot output interval : dt_out = 1.0
Duration of the integration : t = 1.0
World output format, instead of snapshot
Screen Output Verbosity Level : verbosity = 1
ACS Output Verbosity Level : acs_verbosity = 1
Floating point precision : precision = 16
Incremental indentation : add_indent = 2
at time t = 0 (from interpolation after 0 steps to time 0):
E_kin = 0.25 , E_pot = -0.5 , E_tot = -0.25
E_tot - E_init = 0
(E_tot - E_init) / E_init = -0
at time t = 1 (from interpolation after 4291 steps to time 1):
E_kin = 0.313 , E_pot = -0.563 , E_tot = -0.25
E_tot - E_init = -1.98e-10
(E_tot - E_init) / E_init = 7.92e-10
|gravity> kali world1.rb -t 1 -r < tmp1w | kali acstail.rb > tmp2ww
==> Individual Time Step, Individual Integration Scheme Code <==
Determines the time step size : dt_param = 0.01
Duration of an era : dt_era = 0.01
Maximum time step (units dt_era): dt_max_param = 1.0
Diagnostics output interval : dt_dia = 1.0
Snapshot output interval : dt_out = 1.0
Duration of the integration : t = 1.0
World output format, instead of snapshot
Screen Output Verbosity Level : verbosity = 1
ACS Output Verbosity Level : acs_verbosity = 1
Floating point precision : precision = 16
Incremental indentation : add_indent = 2
==> Returns the last n chunks of ACS data <==
Number of last ACS data chunks returned: n = 1
Screen Output Verbosity Level : verbosity = 1
ACS Output Verbosity Level : acs_verbosity = 1
Floating point precision : precision = 16
Incremental indentation : add_indent = 2
at time t = 1 (from interpolation after 4291 steps to time 0.99):
E_kin = 0.313 , E_pot = -0.563 , E_tot = -0.25
E_tot - E_init = -1.98e-10
(E_tot - E_init) / E_init = 7.92e-10
at time t = 2 (from interpolation after 6995 steps to time 2):
E_kin = 0.171 , E_pot = -0.421 , E_tot = -0.25
E_tot - E_init = -6.5e-11
(E_tot - E_init) / E_init = 2.6e-10
|gravity> kali world1.rb -t 2 -o 2 -r < tmp0 | kali acstail.rb > tmp2w
==> Individual Time Step, Individual Integration Scheme Code <==
Determines the time step size : dt_param = 0.01
Duration of an era : dt_era = 0.01
Maximum time step (units dt_era): dt_max_param = 1.0
Diagnostics output interval : dt_dia = 1.0
Snapshot output interval : dt_out = 2.0
Duration of the integration : t = 2.0
World output format, instead of snapshot
Screen Output Verbosity Level : verbosity = 1
ACS Output Verbosity Level : acs_verbosity = 1
Floating point precision : precision = 16
Incremental indentation : add_indent = 2
at time t = 0 (from interpolation after 0 steps to time 0):
E_kin = 0.25 , E_pot = -0.5 , E_tot = -0.25
E_tot - E_init = 0
(E_tot - E_init) / E_init = -0
==> Returns the last n chunks of ACS data <==
Number of last ACS data chunks returned: n = 1
Screen Output Verbosity Level : verbosity = 1
ACS Output Verbosity Level : acs_verbosity = 1
Floating point precision : precision = 16
Incremental indentation : add_indent = 2
at time t = 1 (from interpolation after 4291 steps to time 1):
E_kin = 0.313 , E_pot = -0.563 , E_tot = -0.25
E_tot - E_init = -1.98e-10
(E_tot - E_init) / E_init = 7.92e-10
at time t = 2 (from interpolation after 6995 steps to time 2):
E_kin = 0.171 , E_pot = -0.421 , E_tot = -0.25
E_tot - E_init = -6.5e-11
(E_tot - E_init) / E_init = 2.6e-10
|gravity> kali world1.rb -t 2 -o 2 < tmp0 | kali acstail.rb > tmp2s
==> Returns the last n chunks of ACS data <==
Number of last ACS data chunks returned: n = 1
Screen Output Verbosity Level : verbosity = 1
ACS Output Verbosity Level : acs_verbosity = 1
Floating point precision : precision = 16
Incremental indentation : add_indent = 2
==> Individual Time Step, Individual Integration Scheme Code <==
Determines the time step size : dt_param = 0.01
Duration of an era : dt_era = 0.01
Maximum time step (units dt_era): dt_max_param = 1.0
Diagnostics output interval : dt_dia = 1.0
Snapshot output interval : dt_out = 2.0
Duration of the integration : t = 2.0
Screen Output Verbosity Level : verbosity = 1
ACS Output Verbosity Level : acs_verbosity = 1
Floating point precision : precision = 16
Incremental indentation : add_indent = 2
at time t = 0 (from interpolation after 0 steps to time 0):
E_kin = 0.25 , E_pot = -0.5 , E_tot = -0.25
E_tot - E_init = 0
(E_tot - E_init) / E_init = -0
at time t = 1 (from interpolation after 4291 steps to time 1):
E_kin = 0.313 , E_pot = -0.563 , E_tot = -0.25
E_tot - E_init = -1.98e-10
(E_tot - E_init) / E_init = 7.92e-10
at time t = 2 (from interpolation after 6995 steps to time 2):
E_kin = 0.171 , E_pot = -0.421 , E_tot = -0.25
E_tot - E_init = -6.5e-11
(E_tot - E_init) / E_init = 2.6e-10
|gravity> kali world1.rb -t 1 < tmp1w | kali acstail.rb > tmp2ws
==> Returns the last n chunks of ACS data <==
Number of last ACS data chunks returned: n = 1
Screen Output Verbosity Level : verbosity = 1
ACS Output Verbosity Level : acs_verbosity = 1
Floating point precision : precision = 16
Incremental indentation : add_indent = 2
==> Individual Time Step, Individual Integration Scheme Code <==
Determines the time step size : dt_param = 0.01
Duration of an era : dt_era = 0.01
Maximum time step (units dt_era): dt_max_param = 1.0
Diagnostics output interval : dt_dia = 1.0
Snapshot output interval : dt_out = 1.0
Duration of the integration : t = 1.0
Screen Output Verbosity Level : verbosity = 1
ACS Output Verbosity Level : acs_verbosity = 1
Floating point precision : precision = 16
Incremental indentation : add_indent = 2
at time t = 1 (from interpolation after 4291 steps to time 0.99):
E_kin = 0.313 , E_pot = -0.563 , E_tot = -0.25
E_tot - E_init = -1.98e-10
(E_tot - E_init) / E_init = 7.92e-10
at time t = 2 (from interpolation after 6995 steps to time 2):
E_kin = 0.171 , E_pot = -0.421 , E_tot = -0.25
E_tot - E_init = -6.5e-11
(E_tot - E_init) / E_init = 2.6e-10
|gravity> kali world1.rb -t 1 -r < tmp2w | kali acstail.rb > tmp3ww
==> Individual Time Step, Individual Integration Scheme Code <==
Determines the time step size : dt_param = 0.01
Duration of an era : dt_era = 0.01
Maximum time step (units dt_era): dt_max_param = 1.0
Diagnostics output interval : dt_dia = 1.0
Snapshot output interval : dt_out = 1.0
Duration of the integration : t = 1.0
World output format, instead of snapshot
Screen Output Verbosity Level : verbosity = 1
ACS Output Verbosity Level : acs_verbosity = 1
Floating point precision : precision = 16
Incremental indentation : add_indent = 2
==> Returns the last n chunks of ACS data <==
Number of last ACS data chunks returned: n = 1
Screen Output Verbosity Level : verbosity = 1
ACS Output Verbosity Level : acs_verbosity = 1
Floating point precision : precision = 16
Incremental indentation : add_indent = 2
at time t = 2 (from interpolation after 6995 steps to time 1.99):
E_kin = 0.171 , E_pot = -0.421 , E_tot = -0.25
E_tot - E_init = -6.5e-11
(E_tot - E_init) / E_init = 2.6e-10
at time t = 3 (from interpolation after 11014 steps to time 3.01):
E_kin = 0.506 , E_pot = -0.756 , E_tot = -0.25
E_tot - E_init = -2.81e-09
(E_tot - E_init) / E_init = 1.13e-08
|gravity> kali world1.rb -t 3 -o 3 -r < tmp0 | kali acstail.rb > tmp3w
==> Individual Time Step, Individual Integration Scheme Code <==
Determines the time step size : dt_param = 0.01
Duration of an era : dt_era = 0.01
Maximum time step (units dt_era): dt_max_param = 1.0
Diagnostics output interval : dt_dia = 1.0
Snapshot output interval : dt_out = 3.0
Duration of the integration : t = 3.0
World output format, instead of snapshot
Screen Output Verbosity Level : verbosity = 1
ACS Output Verbosity Level : acs_verbosity = 1
Floating point precision : precision = 16
Incremental indentation : add_indent = 2
==> Returns the last n chunks of ACS data <==
Number of last ACS data chunks returned: n = 1
Screen Output Verbosity Level : verbosity = 1
ACS Output Verbosity Level : acs_verbosity = 1
Floating point precision : precision = 16
Incremental indentation : add_indent = 2
at time t = 0 (from interpolation after 0 steps to time 0):
E_kin = 0.25 , E_pot = -0.5 , E_tot = -0.25
E_tot - E_init = 0
(E_tot - E_init) / E_init = -0
at time t = 1 (from interpolation after 4291 steps to time 1):
E_kin = 0.313 , E_pot = -0.563 , E_tot = -0.25
E_tot - E_init = -1.98e-10
(E_tot - E_init) / E_init = 7.92e-10
at time t = 2 (from interpolation after 6995 steps to time 2):
E_kin = 0.171 , E_pot = -0.421 , E_tot = -0.25
E_tot - E_init = -6.5e-11
(E_tot - E_init) / E_init = 2.6e-10
at time t = 3 (from interpolation after 11014 steps to time 3.01):
E_kin = 0.506 , E_pot = -0.756 , E_tot = -0.25
E_tot - E_init = -2.81e-09
(E_tot - E_init) / E_init = 1.13e-08
|gravity> kali world1.rb -t 1 -r < tmp2ww | kali acstail.rb > tmp3www
==> Individual Time Step, Individual Integration Scheme Code <==
Determines the time step size : dt_param = 0.01
Duration of an era : dt_era = 0.01
Maximum time step (units dt_era): dt_max_param = 1.0
Diagnostics output interval : dt_dia = 1.0
Snapshot output interval : dt_out = 1.0
Duration of the integration : t = 1.0
World output format, instead of snapshot
Screen Output Verbosity Level : verbosity = 1
ACS Output Verbosity Level : acs_verbosity = 1
Floating point precision : precision = 16
Incremental indentation : add_indent = 2
==> Returns the last n chunks of ACS data <==
Number of last ACS data chunks returned: n = 1
Screen Output Verbosity Level : verbosity = 1
ACS Output Verbosity Level : acs_verbosity = 1
Floating point precision : precision = 16
Incremental indentation : add_indent = 2
at time t = 2 (from interpolation after 6995 steps to time 1.99):
E_kin = 0.171 , E_pot = -0.421 , E_tot = -0.25
E_tot - E_init = -6.5e-11
(E_tot - E_init) / E_init = 2.6e-10
at time t = 3 (from interpolation after 11014 steps to time 3.01):
E_kin = 0.506 , E_pot = -0.756 , E_tot = -0.25
E_tot - E_init = -2.81e-09
(E_tot - E_init) / E_init = 1.13e-08
|gravity> diff tmp2w tmp2ww | wc
0 0 0
|gravity> diff tmp2s tmp2ws | wc
0 0 0
|gravity> diff tmp3w tmp3ww | wc
0 0 0
|gravity> diff tmp3w tmp3www | wc
0 0 0
10.4. Using Snapshots Instead
Alice: Wonderful. That gives you confidence! We really seem to have
things under control now. But wouldn't it be nice to check that there
are still differences when you do not use a full dump at
intermediate times, but use snapshots instead?
Bob: Sure. Easy to add. And since we now expect differences, let me
do a phase space distance measurement at the end as well. Here you are:
|gravity> kali world1.rb -t 1 < tmp0 | kali acstail.rb > tmp1s
==> Returns the last n chunks of ACS data <==
Number of last ACS data chunks returned: n = 1
Screen Output Verbosity Level : verbosity = 1
ACS Output Verbosity Level : acs_verbosity = 1
Floating point precision : precision = 16
Incremental indentation : add_indent = 2
==> Individual Time Step, Individual Integration Scheme Code <==
Determines the time step size : dt_param = 0.01
Duration of an era : dt_era = 0.01
Maximum time step (units dt_era): dt_max_param = 1.0
Diagnostics output interval : dt_dia = 1.0
Snapshot output interval : dt_out = 1.0
Duration of the integration : t = 1.0
Screen Output Verbosity Level : verbosity = 1
ACS Output Verbosity Level : acs_verbosity = 1
Floating point precision : precision = 16
Incremental indentation : add_indent = 2
at time t = 0 (from interpolation after 0 steps to time 0):
E_kin = 0.25 , E_pot = -0.5 , E_tot = -0.25
E_tot - E_init = 0
(E_tot - E_init) / E_init = -0
at time t = 1 (from interpolation after 4291 steps to time 1):
E_kin = 0.313 , E_pot = -0.563 , E_tot = -0.25
E_tot - E_init = -1.98e-10
(E_tot - E_init) / E_init = 7.92e-10
|gravity> kali world1.rb -t 1 < tmp1s | kali acstail.rb > tmp2ss
==> Returns the last n chunks of ACS data <==
Number of last ACS data chunks returned: n = 1
Screen Output Verbosity Level : verbosity = 1
ACS Output Verbosity Level : acs_verbosity = 1
Floating point precision : precision = 16
Incremental indentation : add_indent = 2
==> Individual Time Step, Individual Integration Scheme Code <==
Determines the time step size : dt_param = 0.01
Duration of an era : dt_era = 0.01
Maximum time step (units dt_era): dt_max_param = 1.0
Diagnostics output interval : dt_dia = 1.0
Snapshot output interval : dt_out = 1.0
Duration of the integration : t = 1.0
Screen Output Verbosity Level : verbosity = 1
ACS Output Verbosity Level : acs_verbosity = 1
Floating point precision : precision = 16
Incremental indentation : add_indent = 2
at time t = 1 (from interpolation after 0 steps to time 1):
E_kin = 0.313 , E_pot = -0.563 , E_tot = -0.25
E_tot - E_init = 0
(E_tot - E_init) / E_init = -0
at time t = 2 (from interpolation after 2713 steps to time 2):
E_kin = 0.171 , E_pot = -0.421 , E_tot = -0.25
E_tot - E_init = -2.8e-10
(E_tot - E_init) / E_init = 1.12e-09
|gravity> diff tmp2ss tmp2s | wc
76 146 2262
|gravity> cat tmp2s | wc
74 128 2185
|gravity> cat tmp2ss tmp2s | kali nbody_diff.rb
==> 6N-dimensional phase space distance between two N-body systems <==
Floating point precision : precision = 2
Screen Output Verbosity Level : verbosity = 1
ACS Output Verbosity Level : acs_verbosity = 1
Floating point precision : precision = 16
Incremental indentation : add_indent = 2
6N-dim. phase space dist. for two 4-body systems: 2.2390038382354583e-08
Alice: As we expected, many lines are different, as you can see from
the wordcount wc after the diff, which is comparable in size to the file
itself. And in phase space there is a definite distance between the two
types of runs as well.