The ParaMonte Documentation Website
Current view: top level - kernel/tests - Test_ParaDXXX_mod@Test_runSampler_smod.inc.f90 (source / functions) Hit Total Coverage
Test: ParaMonte 1.5.1 :: MPI Parallel Kernel - Code Coverage Report Lines: 242 242 100.0 %
Date: 2021-01-08 13:07:16 Functions: 44 44 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       2             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
       3             : !!!!
       4             : !!!!   MIT License
       5             : !!!!
       6             : !!!!   ParaMonte: plain powerful parallel Monte Carlo library.
       7             : !!!!
       8             : !!!!   Copyright (C) 2012-present, The Computational Data Science Lab
       9             : !!!!
      10             : !!!!   This file is part of the ParaMonte library.
      11             : !!!!
      12             : !!!!   Permission is hereby granted, free of charge, to any person obtaining a
      13             : !!!!   copy of this software and associated documentation files (the "Software"),
      14             : !!!!   to deal in the Software without restriction, including without limitation
      15             : !!!!   the rights to use, copy, modify, merge, publish, distribute, sublicense,
      16             : !!!!   and/or sell copies of the Software, and to permit persons to whom the
      17             : !!!!   Software is furnished to do so, subject to the following conditions:
      18             : !!!!
      19             : !!!!   The above copyright notice and this permission notice shall be
      20             : !!!!   included in all copies or substantial portions of the Software.
      21             : !!!!
      22             : !!!!   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
      23             : !!!!   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
      24             : !!!!   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
      25             : !!!!   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
      26             : !!!!   DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
      27             : !!!!   OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
      28             : !!!!   OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
      29             : !!!!
      30             : !!!!   ACKNOWLEDGMENT
      31             : !!!!
      32             : !!!!   ParaMonte is an honor-ware and its currency is acknowledgment and citations.
      33             : !!!!   As per the ParaMonte library license agreement terms, if you use any parts of
      34             : !!!!   this library for any purposes, kindly acknowledge the use of ParaMonte in your
      35             : !!!!   work (education/research/industry/development/...) by citing the ParaMonte
      36             : !!!!   library as described on this page:
      37             : !!!!
      38             : !!!!       https://github.com/cdslaborg/paramonte/blob/main/ACKNOWLEDGMENT.md
      39             : !!!!
      40             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      41             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      42             : 
      43             : !>  \brief This include file contains the body of the submodules
      44             : !>  [ParaDRAM_mod@Test_runSampler_smod](@ref paradram_mod@test_runsampler_smod) and
      45             : !>  [ParaDISE_mod@@Test_runSampler_smod](@ref paradise_mod@test_runsampler_smod).
      46             : !>  \author Amir Shahmoradi
      47             : 
      48             : !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      49             : 
      50             : contains
      51             : 
      52             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      53             : 
      54             :     !> \brief
      55             :     !> Test the ParaDXXX sampler with no input arguments or input file.
      56          12 :     module function test_runSampler_1() result(assertion)
      57             :         implicit none
      58             :         logical             :: assertion
      59           6 :         type(ParaDXXX_type) :: PD
      60           6 :         assertion = .true.
      61             : #if defined CODECOV_ENABLED || defined SAMPLER_TEST_ENABLED
      62             :         call PD%runSampler  ( ndim = 1_IK &
      63             :                             , getLogFunc = getLogFuncMVN &
      64             :                             , mpiFinalizeRequested = .false. &
      65             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_1" &
      66           6 :                             )
      67           6 :         assertion = assertion .and. .not. PD%Err%occurred
      68             : #endif
      69          66 :     end function test_runSampler_1
      70             : 
      71             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      72             : 
      73             :     !> \brief
      74             :     !> Test the ParaDXXX sampler with an internal input file.
      75           6 :     module function test_runSampler_2() result(assertion)
      76           6 :         use String_mod, only: num2str
      77             :         implicit none
      78             :         logical                 :: assertion
      79           6 :         type(ParaDXXX_type)     :: PD
      80             :         integer(IK) , parameter :: chainSize_ref = 100_IK
      81             :         integer(IK) , parameter :: userSeed_ref = 1111_IK
      82             : 
      83           6 :         assertion = .true.
      84             : #if defined CODECOV_ENABLED || defined SAMPLER_TEST_ENABLED
      85             :         call PD%runSampler  ( ndim = 1_IK &
      86             :                             , getLogFunc = getLogFuncMVN &
      87             :                             , mpiFinalizeRequested = .false. &
      88             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_2" &
      89             :                             , inputFile = ParaDXXX_NML//" randomSeed = "//num2str(userSeed_ref)//" chainSize = "//num2str(chainSize_ref)//" /" &
      90           6 :                             )
      91           6 :         assertion = assertion .and. .not. PD%Err%occurred .and. PD%SpecBase%RandomSeed%userSeed==userSeed_ref .and. PD%SpecMCMC%ChainSize%val==chainSize_ref
      92             :         ! LCOV_EXCL_START
      93             :         if (Test%isDebugMode .and. .not. assertion) then
      94             :             write(Test%outputUnit,"(*(g0))")
      95             :             write(Test%outputUnit,"(*(g0))") "Image%id, PD%Err%occurred                   = ", PD%Image%id, PD%Err%occurred
      96             :             write(Test%outputUnit,"(*(g0))") "Image%id, PD%Err%msg                        = ", PD%Image%id, PD%Err%msg
      97             :             write(Test%outputUnit,"(*(g0))") "Image%id, userSeed_ref                      = ", PD%Image%id, userSeed_ref
      98             :             write(Test%outputUnit,"(*(g0))") "Image%id, PD%SpecBase%RandomSeed%userSeed   = ", PD%Image%id, PD%SpecBase%RandomSeed%userSeed
      99             :             write(Test%outputUnit,"(*(g0))") "Image%id, chainSize_ref                     = ", PD%Image%id, chainSize_ref
     100             :             write(Test%outputUnit,"(*(g0))") "Image%id, PD%SpecMCMC%ChainSize%val         = ", PD%Image%id, PD%SpecMCMC%ChainSize%val
     101             :             write(Test%outputUnit,"(*(g0))")
     102             :         end if
     103             :         ! LCOV_EXCL_STOP
     104             : #endif
     105          66 :     end function test_runSampler_2
     106             : 
     107             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     108             : 
     109             :     !> \brief
     110             :     !> Test the ParaDXXX sampler with an external input file.
     111           6 :     module function test_runSampler_3() result(assertion)
     112             :         implicit none
     113             :         logical             :: assertion
     114           6 :         type(ParaDXXX_type) :: PD
     115           6 :         assertion = .true.
     116             : #if defined CODECOV_ENABLED || defined SAMPLER_TEST_ENABLED
     117             :         call PD%runSampler  ( ndim = 1_IK &
     118             :                             , getLogFunc = getLogFuncMVN &
     119             :                             , mpiFinalizeRequested = .false. &
     120             :                             , inputFile = Test%inDir//"/Test_ParaDXXX_mod@test_runSampler_3.in" &
     121             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_3" &
     122           6 :                             )
     123           6 :         assertion = assertion .and. .not. PD%Err%occurred
     124             : #endif
     125          72 :     end function test_runSampler_3
     126             : 
     127             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     128             : 
     129             :     !> \brief
     130             :     !> Test the ParaDXXX sampler with a path to a non-existing external input file.
     131           6 :     module function test_runSampler_4() result(assertion)
     132             :         implicit none
     133             :         logical             :: assertion
     134           6 :         type(ParaDXXX_type) :: PD
     135           6 :         assertion = .true.
     136             : #if defined CODECOV_ENABLED || defined SAMPLER_TEST_ENABLED
     137             :         call PD%runSampler  ( ndim = 1_IK &
     138             :                             , getLogFunc = getLogFuncMVN &
     139             :                             , mpiFinalizeRequested = .false. &
     140             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_4" &
     141             :                             , inputFile = " " &
     142           6 :                             )
     143           6 :         assertion = assertion .and. .not. PD%Err%occurred
     144             : #endif
     145          72 :     end function test_runSampler_4
     146             : 
     147             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     148             : 
     149             :     !> \brief
     150             :     !> Test the ParaDXXX sampler with wrong SpecBase input values.
     151           6 :     module function test_runSampler_5() result(assertion)
     152             :         implicit none
     153             :         logical             :: assertion
     154           6 :         type(ParaDXXX_type) :: PD
     155           6 :         assertion = .true.
     156             : #if defined CODECOV_ENABLED || defined SAMPLER_TEST_ENABLED
     157             :         call PD%runSampler  ( ndim = 1_IK &
     158             :                             , getLogFunc = getLogFuncMVN &
     159             :                             , mpiFinalizeRequested = .false. &
     160             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_5" &
     161             :                             , inputFile = Test%inDir//"/Test_ParaDXXX_mod@test_runSampler_5.in" &
     162           6 :                             )
     163           6 :         assertion = assertion .and. PD%Err%occurred
     164             : #endif
     165          12 :     end function test_runSampler_5
     166             : 
     167             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     168             : 
     169             :     !> \brief
     170             :     !> Test the ParaDXXX sampler to restart a complete simulation without an output sample file.
     171           6 :     module function test_runSampler_6() result(assertion)
     172             :         implicit none
     173             :         logical             :: assertion
     174           6 :         type(ParaDXXX_type) :: PD1, PD2
     175           6 :         assertion = .true.
     176             : #if defined CODECOV_ENABLED || defined SAMPLER_TEST_ENABLED
     177             : 
     178             :         ! Run the fresh simulation
     179             : 
     180             :         call PD1%runSampler ( ndim = 2_IK &
     181             :                             , getLogFunc = getLogFuncMVN &
     182             :                             , mpiFinalizeRequested = .false. &
     183             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_6" &
     184             :                             , outputRealPrecision = 16_IK &
     185             :                             , randomSeed = 12345_IK &
     186             :                             , sampleSize = 250_IK &
     187             :                             , chainSize = 500_IK &
     188           6 :                             )
     189             : 
     190           6 :         assertion = assertion .and. .not. PD1%Err%occurred
     191             : 
     192           6 :         if (.not. assertion) then
     193             :         ! LCOV_EXCL_START
     194             :             if (Test%isDebugMode) then
     195             :                 write(Test%outputUnit,"(*(g0,:,' '))")
     196             :                 write(Test%outputUnit,"(*(g0,:,' '))")   "process, PD1%Err%occurred(1)", Test%Image%id, PD1%Err%occurred
     197             :                 write(Test%outputUnit,"(*(g0,:,' '))")
     198             :             end if
     199             :             return
     200             :         end if
     201             :         ! LCOV_EXCL_STOP
     202             : 
     203           6 :         call Test%Image%sync()
     204             : 
     205             :         block
     206             :             use System_mod, only: removeFile
     207           6 :             call removeFile(PD1%SampleFile%Path%original, PD1%Err) ! delete the sample file
     208             :         end block
     209             : 
     210           6 :         call Test%Image%sync()
     211             : 
     212             :         ! restart the simulation with the same configuration
     213             : 
     214             :         call PD2%runSampler ( ndim = 2_IK &
     215             :                             , getLogFunc = getLogFuncMVN &
     216             :                             , mpiFinalizeRequested = .false. &
     217             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_6" &
     218             :                             , outputRealPrecision = 16_IK &
     219             :                             , randomSeed = 12345_IK &
     220             :                             , sampleSize = 250_IK &
     221             :                             , chainSize = 500_IK &
     222           6 :                             )
     223             : 
     224           6 :         assertion = assertion .and. .not. PD2%Err%occurred
     225             : 
     226           6 :         if (.not. assertion) then
     227             :         ! LCOV_EXCL_START
     228             :             if (Test%isDebugMode) then
     229             :                 write(Test%outputUnit,"(*(g0,:,' '))")
     230             :                 write(Test%outputUnit,"(*(g0,:,' '))")   "process, PD2%Err%occurred(1)", Test%Image%id, PD1%Err%occurred
     231             :                 write(Test%outputUnit,"(*(g0,:,' '))")
     232             :             end if
     233             :             return
     234             :         end if
     235             :         ! LCOV_EXCL_STOP
     236             : 
     237           6 :         if (PD2%Image%isLeader) then
     238             :         ! LCOV_EXCL_START
     239             :             assertion = assertion .and. all( abs(PD2%RefinedChain%LogFuncState - PD1%RefinedChain%LogFuncState) < 1.e-12_RK ) ! by default, the output precision is only 8 digits
     240             :             if (.not. assertion) then
     241             :                 if (Test%isDebugMode) then
     242             :                     write(Test%outputUnit,"(*(g0,:,' '))")
     243             :                     write(Test%outputUnit,"(*(g0,:,' '))")   "process, Difference:", Test%Image%id, abs(PD2%RefinedChain%LogFuncState - PD1%RefinedChain%LogFuncState)
     244             :                     write(Test%outputUnit,"(*(g0,:,' '))")
     245             :                 end if
     246             :                 return
     247             :             end if
     248             :         end if
     249             :         ! LCOV_EXCL_STOP
     250             : #endif
     251         140 :     end function test_runSampler_6
     252             : 
     253             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     254             : 
     255             :     !> \brief
     256             :     !> Test the ParaDXXX sampler with a wrong internal input namelist group:
     257             :     !> +    Infinity values for `domainLowerLimitVec` and `domainUpperLimitVec`.
     258           6 :     module function test_runSampler_7() result(assertion)
     259           6 :         use Constants_mod, only: IK, RK
     260             :         implicit none
     261             :         logical             :: assertion
     262           6 :         type(ParaDXXX_type) :: PD
     263           6 :         assertion = .true.
     264             : #if defined CODECOV_ENABLED || defined SAMPLER_TEST_ENABLED
     265             :         call PD%runSampler  ( ndim = 1_IK &
     266             :                             , getLogFunc = getLogFuncMVN &
     267             :                             , mpiFinalizeRequested = .false. &
     268             :                             , inputFile = "&ParaDXXX randomSeed = 1111 /" &
     269             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"@SpecBase/test_runSampler_7" &
     270           6 :                             )
     271           6 :         assertion = assertion .and. .not. PD%Err%occurred
     272             : #endif
     273          66 :     end function test_runSampler_7
     274             : 
     275             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     276             : 
     277             :     !> \brief
     278             :     !> Test the ParaDXXX sampler with a wrong internal input namelist group:
     279             :     !> +    Infinity values for `domainLowerLimitVec` and `domainUpperLimitVec`.
     280           6 :     module function test_runSampler_8() result(assertion)
     281           6 :         use Constants_mod, only: IK, RK
     282             :         implicit none
     283             :         logical             :: assertion
     284           6 :         type(ParaDXXX_type) :: PD
     285           6 :         assertion = .true.
     286             : #if defined CODECOV_ENABLED || defined SAMPLER_TEST_ENABLED
     287             :         call PD%runSampler  ( ndim = 1_IK &
     288             :                             , getLogFunc = getLogFuncMVN &
     289             :                             , mpiFinalizeRequested = .false. &
     290             :                             , inputFile = Test%inDir//"/Test_ParaDXXX_mod@test_runSampler_8.in" &
     291             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"@SpecBase/test_runSampler_8" &
     292           6 :                             )
     293           6 :         assertion = assertion .and. .not. PD%Err%occurred
     294             : #endif
     295          66 :     end function test_runSampler_8
     296             : 
     297             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     298             : 
     299             :     !> \brief
     300             :     !> Test the ParaDXXX sampler to restart a complete simulation without an output sample file.
     301           6 :     module function test_runSampler_9() result(assertion)
     302             :         implicit none
     303             :         logical             :: assertion
     304           6 :         type(ParaDXXX_type) :: PD1, PD2
     305           6 :         assertion = .true.
     306             : #if defined CODECOV_ENABLED || defined SAMPLER_TEST_ENABLED
     307             : 
     308             :         ! Run the fresh simulation as a reference run
     309             : 
     310             :         call PD1%runSampler ( ndim = 2_IK &
     311             :                             , getLogFunc = getLogFuncMVN &
     312             :                             , mpiFinalizeRequested = .false. &
     313             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_9.ref" &
     314             :                             , proposalModel = "uniform" &
     315             :                             , randomSeed = 12345_IK &
     316             :                             , sampleSize = 250_IK &
     317             :                             , chainSize = 500_IK &
     318           6 :                             )
     319           6 :         assertion = assertion .and. .not. PD1%Err%occurred
     320             : 
     321           6 :         if (.not. assertion) then
     322             :         ! LCOV_EXCL_START
     323             :             if (Test%isDebugMode) then
     324             :                 write(Test%outputUnit,"(*(g0,:,' '))")
     325             :                 write(Test%outputUnit,"(*(g0,:,' '))")   "process, PD1%Err%occurred(1)", Test%Image%id, PD1%Err%occurred
     326             :                 write(Test%outputUnit,"(*(g0,:,' '))")
     327             :             end if
     328             :             return
     329             :         end if
     330             :         ! LCOV_EXCL_STOP
     331             : 
     332           6 :         call Test%Image%sync()
     333             : 
     334             :         ! Run the fresh simulation
     335             : 
     336             :         call PD1%runSampler ( ndim = 2_IK &
     337             :                             , getLogFunc = getLogFuncMVN &
     338             :                             , mpiFinalizeRequested = .false. &
     339             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_9" &
     340             :                             , proposalModel = "uniform" &
     341             :                             , randomSeed = 12345_IK &
     342             :                             , sampleSize = 250_IK &
     343             :                             , chainSize = 500_IK &
     344           6 :                             )
     345             : 
     346           6 :         assertion = assertion .and. .not. PD1%Err%occurred
     347             : 
     348           6 :         if (.not. assertion) then
     349             :         ! LCOV_EXCL_START
     350             :             if (Test%isDebugMode) then
     351             :                 write(Test%outputUnit,"(*(g0,:,' '))")
     352             :                 write(Test%outputUnit,"(*(g0,:,' '))")   "process, PD1%Err%occurred(2)", Test%Image%id, PD1%Err%occurred
     353             :                 write(Test%outputUnit,"(*(g0,:,' '))")
     354             :             end if
     355             :             return
     356             :         end if
     357             :         ! LCOV_EXCL_STOP
     358             : 
     359           6 :         call Test%Image%sync()
     360             : 
     361             :         block
     362             :             use System_mod, only: removeFile
     363           6 :             call removeFile(PD1%SampleFile%Path%original, PD1%Err) ! delete the sample file
     364             :         end block
     365             : 
     366           6 :         call Test%Image%sync()
     367             : 
     368             :         ! restart the simulation with the same configuration
     369             : 
     370             :         call PD2%runSampler ( ndim = 2_IK &
     371             :                             , getLogFunc = getLogFuncMVN &
     372             :                             , mpiFinalizeRequested = .false. &
     373             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_9" &
     374             :                             , proposalModel = "uniform" &
     375             :                             , randomSeed = 12345_IK &
     376             :                             , sampleSize = 250_IK &
     377             :                             , chainSize = 500_IK &
     378           6 :                             )
     379             : 
     380           6 :         assertion = assertion .and. .not. PD2%Err%occurred
     381             : 
     382           6 :         if (.not. assertion) then
     383             :         ! LCOV_EXCL_START
     384             :             if (Test%isDebugMode) then
     385             :                 write(Test%outputUnit,"(*(g0,:,' '))")
     386             :                 write(Test%outputUnit,"(*(g0,:,' '))") "process, PD2%Err%occurred", Test%Image%id, PD2%Err%occurred
     387             :                 write(Test%outputUnit,"(*(g0,:,' '))")
     388             :             end if
     389             :             return
     390             :         end if
     391             :         ! LCOV_EXCL_STOP
     392             : 
     393           6 :         if (PD2%Image%isLeader) then
     394             :         ! LCOV_EXCL_START
     395             : 
     396             :             assertion = assertion .and. all(shape(PD2%RefinedChain%LogFuncState) == shape(PD1%RefinedChain%LogFuncState))
     397             : 
     398             :             if (.not. assertion) then
     399             :                 if (Test%isDebugMode) then
     400             :                     write(*,"(10(g0,:,', '))")
     401             :                     write(*,"(10(g0,:,', '))") "shape(PD1%RefinedChain%LogFuncState)", shape(PD1%RefinedChain%LogFuncState)
     402             :                     write(*,"(10(g0,:,', '))") "shape(PD2%RefinedChain%LogFuncState)", shape(PD2%RefinedChain%LogFuncState)
     403             :                     write(*,"(10(g0,:,', '))")
     404             :                 end if
     405             :                 return
     406             :             end if
     407             : 
     408             :             assertion = assertion .and. all( abs(PD2%RefinedChain%LogFuncState - PD1%RefinedChain%LogFuncState) < 1.e-6_RK ) ! by default, the output precision is only 8 digits
     409             : 
     410             :             if (.not. assertion) then
     411             :                 if (Test%isDebugMode) then
     412             :                     write(Test%outputUnit,"(*(g0,:,' '))")
     413             :                     write(Test%outputUnit,"(*(g0,:,' '))")   "process, Difference:", Test%Image%id, abs(PD2%RefinedChain%LogFuncState - PD1%RefinedChain%LogFuncState)
     414             :                     write(Test%outputUnit,"(*(g0,:,' '))")
     415             :                 end if
     416             :                 return
     417             :             end if
     418             : 
     419             :         end if
     420             :         ! LCOV_EXCL_STOP
     421             : #endif
     422         140 :     end function test_runSampler_9
     423             : 
     424             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     425             : 
     426             :     !> \brief
     427             :     !> Test the ParaDXXX sampler to restart a complete simulation without an output sample file, with an ASCII output file.
     428           6 :     module function test_runSampler_10() result(assertion)
     429             :         implicit none
     430             :         logical             :: assertion
     431           6 :         type(ParaDXXX_type) :: PD1, PD2
     432           6 :         assertion = .true.
     433             : #if defined CODECOV_ENABLED || defined SAMPLER_TEST_ENABLED
     434             : 
     435             :         ! Run the fresh simulation as a reference run
     436             : 
     437             :         call PD1%runSampler ( ndim = 2_IK &
     438             :                             , getLogFunc = getLogFuncMVN &
     439             :                             , mpiFinalizeRequested = .false. &
     440             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_10.ref" &
     441             :                             , restartFileFormat = "ascii" &
     442             :                             , proposalModel = "uniform" &
     443             :                             , randomSeed = 12345_IK &
     444             :                             , sampleSize = 50_IK &
     445             :                             , chainSize = 500_IK &
     446           6 :                             )
     447           6 :         assertion = assertion .and. .not. PD1%Err%occurred
     448             :         if (.not. assertion) return ! LCOV_EXCL_LINE
     449             : 
     450           6 :         call Test%Image%sync()
     451             : 
     452             :         ! Run the fresh simulation
     453             : 
     454             :         call PD1%runSampler ( ndim = 2_IK &
     455             :                             , getLogFunc = getLogFuncMVN &
     456             :                             , mpiFinalizeRequested = .false. &
     457             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_10" &
     458             :                             , restartFileFormat = "ascii" &
     459             :                             , proposalModel = "uniform" &
     460             :                             , randomSeed = 12345_IK &
     461             :                             , sampleSize = 50_IK &
     462             :                             , chainSize = 500_IK &
     463           6 :                             )
     464           6 :         assertion = assertion .and. .not. PD1%Err%occurred
     465             :         if (.not. assertion) return ! LCOV_EXCL_LINE
     466             : 
     467           6 :         call Test%Image%sync()
     468             : 
     469             :         block
     470             :             use System_mod, only: removeFile
     471           6 :             call removeFile(PD1%SampleFile%Path%original, PD1%Err) ! delete the sample file
     472             :         end block
     473             : 
     474           6 :         call Test%Image%sync()
     475             : 
     476             :         ! restart the simulation with the same configuration
     477             : 
     478             :         call PD2%runSampler ( ndim = 2_IK &
     479             :                             , getLogFunc = getLogFuncMVN &
     480             :                             , mpiFinalizeRequested = .false. &
     481             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_10" &
     482             :                             , restartFileFormat = "ascii" &
     483             :                             , proposalModel = "uniform" &
     484             :                             , randomSeed = 12345_IK &
     485             :                             , sampleSize = 50_IK &
     486             :                             , chainSize = 500_IK &
     487           6 :                             )
     488           6 :         assertion = assertion .and. .not. PD2%Err%occurred
     489             :         if (.not. assertion) return ! LCOV_EXCL_LINE
     490             : 
     491             :         if (PD2%Image%isLeader) assertion = assertion .and. all( abs(PD2%RefinedChain%LogFuncState - PD1%RefinedChain%LogFuncState) < 1.e-6_RK ) ! LCOV_EXCL_LINE ! by default, the output precision is only 8 digits
     492             : 
     493             : #endif
     494         140 :     end function test_runSampler_10
     495             : 
     496             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     497             : 
     498             :     !> \brief
     499             :     !> Test the ParaDXXX sampler to restart a complete simulation without an
     500             :     !> output sample file, with an ASCII output file but with binary chain file.
     501           6 :     module function test_runSampler_11() result(assertion)
     502             :         implicit none
     503             :         logical             :: assertion
     504           6 :         type(ParaDXXX_type) :: PD1, PD2
     505           6 :         assertion = .true.
     506             : #if defined CODECOV_ENABLED || defined SAMPLER_TEST_ENABLED
     507             : 
     508             :         ! Run the fresh simulation as a reference run
     509             : 
     510             :         call PD1%runSampler ( ndim = 2_IK &
     511             :                             , getLogFunc = getLogFuncMVN &
     512             :                             , mpiFinalizeRequested = .false. &
     513             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_11.ref" &
     514             :                             , restartFileFormat = "ascii" &
     515             :                             , chainFileFormat = "verbose" &
     516             :                             , proposalModel = "uniform" &
     517             :                             , randomSeed = 12345_IK &
     518             :                             , sampleSize = 250_IK &
     519             :                             , chainSize = 500_IK &
     520           6 :                             )
     521           6 :         assertion = assertion .and. .not. PD1%Err%occurred
     522             :         if (.not. assertion) return ! LCOV_EXCL_LINE
     523             : 
     524           6 :         call Test%Image%sync()
     525             : 
     526             :         ! Run the fresh simulation
     527             : 
     528             :         call PD1%runSampler ( ndim = 2_IK &
     529             :                             , getLogFunc = getLogFuncMVN &
     530             :                             , mpiFinalizeRequested = .false. &
     531             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_11" &
     532             :                             , restartFileFormat = "ascii" &
     533             :                             , chainFileFormat = "verbose" &
     534             :                             , proposalModel = "uniform" &
     535             :                             , randomSeed = 12345_IK &
     536             :                             , sampleSize = 250_IK &
     537             :                             , chainSize = 500_IK &
     538           6 :                             )
     539           6 :         assertion = assertion .and. .not. PD1%Err%occurred
     540             :         if (.not. assertion) return ! LCOV_EXCL_LINE
     541             : 
     542           6 :         call Test%Image%sync()
     543             : 
     544             :         block
     545             :             use System_mod, only: removeFile
     546           6 :             call removeFile(PD1%SampleFile%Path%original, PD1%Err) ! delete the sample file
     547             :         end block
     548             : 
     549           6 :         call Test%Image%sync()
     550             : 
     551             :         ! restart the simulation with the same configuration
     552             : 
     553             :         call PD2%runSampler ( ndim = 2_IK &
     554             :                             , getLogFunc = getLogFuncMVN &
     555             :                             , mpiFinalizeRequested = .false. &
     556             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_11" &
     557             :                             , restartFileFormat = "ascii" &
     558             :                             , chainFileFormat = "verbose" &
     559             :                             , proposalModel = "uniform" &
     560             :                             , randomSeed = 12345_IK &
     561             :                             , sampleSize = 250_IK &
     562             :                             , chainSize = 500_IK &
     563           6 :                             )
     564           6 :         assertion = assertion .and. .not. PD2%Err%occurred
     565             :         if (.not. assertion) return ! LCOV_EXCL_LINE
     566             : 
     567             :         if (PD2%Image%isLeader) assertion = assertion .and. all( abs(PD2%RefinedChain%LogFuncState - PD1%RefinedChain%LogFuncState) < 1.e-6_RK ) ! LCOV_EXCL_LINE ! by default, the output precision is only 8 digits
     568             : #endif
     569         140 :     end function test_runSampler_11
     570             : 
     571             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     572             : 
     573             :     !> \brief
     574             :     !> Test the ParaDXXX sampler to restart a complete simulation without an
     575             :     !> output sample file, with an ASCII output file but with binary chain file.
     576           6 :     module function test_runSampler_12() result(assertion)
     577             :         implicit none
     578             :         logical             :: assertion
     579           6 :         type(ParaDXXX_type) :: PD1, PD2
     580           6 :         assertion = .true.
     581             : #if defined CODECOV_ENABLED || defined SAMPLER_TEST_ENABLED
     582             : 
     583             :         ! Run the fresh simulation as a reference run
     584             : 
     585             :         call PD1%runSampler ( ndim = 2_IK &
     586             :                             , getLogFunc = getLogFuncMVN &
     587             :                             , mpiFinalizeRequested = .false. &
     588             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_12.ref" &
     589             :                             , restartFileFormat = "ascii" &
     590             :                             , chainFileFormat = "binary" &
     591             :                             , proposalModel = "uniform" &
     592             :                             , randomSeed = 12345_IK &
     593             :                             , sampleSize = 250_IK &
     594             :                             , chainSize = 500_IK &
     595           6 :                             )
     596           6 :         assertion = assertion .and. .not. PD1%Err%occurred
     597             :         if (.not. assertion) return ! LCOV_EXCL_LINE
     598             : 
     599           6 :         call Test%Image%sync()
     600             : 
     601             :         ! Run the fresh simulation
     602             : 
     603             :         call PD1%runSampler ( ndim = 2_IK &
     604             :                             , getLogFunc = getLogFuncMVN &
     605             :                             , mpiFinalizeRequested = .false. &
     606             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_12" &
     607             :                             , restartFileFormat = "ascii" &
     608             :                             , chainFileFormat = "binary" &
     609             :                             , proposalModel = "uniform" &
     610             :                             , randomSeed = 12345_IK &
     611             :                             , sampleSize = 250_IK &
     612             :                             , chainSize = 500_IK &
     613           6 :                             )
     614           6 :         assertion = assertion .and. .not. PD1%Err%occurred
     615             :         if (.not. assertion) return ! LCOV_EXCL_LINE
     616             : 
     617           6 :         call Test%Image%sync()
     618             : 
     619             :         block
     620             :             use System_mod, only: removeFile
     621           6 :             call removeFile(PD1%SampleFile%Path%original, PD1%Err) ! delete the sample file
     622             :         end block
     623             : 
     624           6 :         call Test%Image%sync()
     625             : 
     626             :         ! restart the simulation with the same configuration
     627             : 
     628             :         call PD2%runSampler ( ndim = 2_IK &
     629             :                             , getLogFunc = getLogFuncMVN &
     630             :                             , mpiFinalizeRequested = .false. &
     631             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_12" &
     632             :                             , restartFileFormat = "ascii" &
     633             :                             , chainFileFormat = "binary" &
     634             :                             , proposalModel = "uniform" &
     635             :                             , randomSeed = 12345_IK &
     636             :                             , sampleSize = 250_IK &
     637             :                             , chainSize = 500_IK &
     638           6 :                             )
     639           6 :         assertion = assertion .and. .not. PD2%Err%occurred
     640             :         if (.not. assertion) return ! LCOV_EXCL_LINE
     641             : 
     642             :         if (PD2%Image%isLeader) assertion = assertion .and. all( abs(PD2%RefinedChain%LogFuncState - PD1%RefinedChain%LogFuncState) < 1.e-6_RK ) ! LCOV_EXCL_LINE ! by default, the output precision is only 8 digits
     643             : 
     644             : #endif
     645         140 :     end function test_runSampler_12
     646             : 
     647             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     648             : 
     649             :     !> \brief
     650             :     !> Test the ParaDXXX sampler with an empty external input file.
     651             :     !> This should first search for the specific namelist, then for the generic namelist,
     652             :     !> then issues a warning and runs the simulation without setting the simulation specifications.
     653           6 :     module function test_runSampler_13() result(assertion)
     654             :         implicit none
     655             :         logical             :: assertion
     656           6 :         type(ParaDXXX_type) :: PD
     657           6 :         assertion = .true.
     658             : #if defined CODECOV_ENABLED || defined SAMPLER_TEST_ENABLED
     659             :         call PD%runSampler  ( ndim = 1_IK &
     660             :                             , getLogFunc = getLogFuncMVN &
     661             :                             , mpiFinalizeRequested = .false. &
     662             :                             , inputFile = Test%inDir//"/Test_ParaDXXX_mod@test_runSampler_13.in" &
     663             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_13" &
     664           6 :                             )
     665           6 :         assertion = assertion .and. .not. PD%Err%occurred
     666             : #endif
     667          72 :     end function test_runSampler_13
     668             : 
     669             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     670             : 
     671             :     !> \brief
     672             :     !> Test the ParaDXXX sampler with an empty external input file.
     673             :     !> This should first search for the specific namelist, then for the generic namelist,
     674             :     !> then issues a warning and runs the simulation without setting the simulation specifications.
     675           6 :     module function test_runSampler_14() result(assertion)
     676             :         implicit none
     677             :         logical             :: assertion
     678           6 :         type(ParaDXXX_type) :: PD
     679           6 :         assertion = .true.
     680             : #if defined CODECOV_ENABLED || defined SAMPLER_TEST_ENABLED
     681             :         call PD%runSampler  ( ndim = 1_IK &
     682             :                             , getLogFunc = getLogFuncMVN &
     683             :                             , mpiFinalizeRequested = .false. &
     684             :                             , inputFile = "&nonsense /" &
     685             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_14" &
     686           6 :                             )
     687           6 :         assertion = assertion .and. .not. PD%Err%occurred
     688             : #endif
     689          72 :     end function test_runSampler_14
     690             : 
     691             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     692             : 
     693             :     !> \brief
     694             :     !> Test whether the read method of the `ParaMCMCRefinedChain_type` class can successfully read an external sample file.
     695           6 :     module function test_runSampler_15() result(assertion)
     696           6 :         use ParaMCMCRefinedChain_mod, only: readRefinedChain, RefinedChain_type
     697             :         use Statistics_mod, only: flatten
     698             :         implicit none
     699             :         logical                 :: assertion
     700             :         real(RK)    , parameter :: tolerance = 1.e-10_RK
     701             :         character(*), parameter :: DELIM = "delim"
     702             :         integer(IK) , parameter :: NDIM = 2_IK
     703           6 :         type(ParaDXXX_type)     :: PD
     704           6 :         type(RefinedChain_type) :: RefinedChain
     705             :         real(RK), allocatable   :: Difference(:,:)
     706             :         real(RK), allocatable   :: FlattenedLogFuncState(:,:)
     707           6 :         assertion = .true.
     708             : #if defined CODECOV_ENABLED || defined SAMPLER_TEST_ENABLED
     709             : 
     710             :         call PD%runSampler  ( ndim = NDIM &
     711             :                             , getLogFunc = getLogFuncMVN &
     712             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_15" &
     713             :                             , mpiFinalizeRequested = .false. &
     714             :                             , outputRealPrecision = 15_IK &
     715             :                             , outputDelimiter = DELIM &
     716             :                             , sampleSize = 10_IK &
     717           6 :                             )
     718           6 :         assertion = assertion .and. .not. PD%Err%occurred
     719             :         if (.not. assertion) return ! LCOV_EXCL_LINE
     720             : 
     721           6 :         if (PD%Image%isLeader) then
     722             :         ! LCOV_EXCL_START
     723             : 
     724             :             RefinedChain = readRefinedChain( sampleFilePath = PD%SampleFile%Path%original, delimiter = PD%SpecBase%OutputDelimiter%val, ndim = PD%nd%val )
     725             : 
     726             :             assertion = assertion .and. RefinedChain%numRefinement == 0_IK
     727             : 
     728             :             if (.not. assertion) then
     729             :                 if (Test%isDebugMode) then
     730             :                     write(*,"(10(g0,:,', '))")
     731             :                     write(*,"(10(g0,:,', '))") "RefinedChain%numRefinement", RefinedChain%numRefinement
     732             :                     write(*,"(10(g0,:,', '))")
     733             :                 end if
     734             :                 return
     735             :             end if
     736             : 
     737             :             ! NOTE: Keep in mind that `PD%RefinedChain` is a weighted chain internally, but unweighted when read from the external file.
     738             :             FlattenedLogFuncState = flatten(nd = PD%nd%val + 1, np = PD%RefinedChain%Count(PD%RefinedChain%numRefinement)%compact, Point = PD%RefinedChain%LogFuncState, Weight = PD%RefinedChain%Weight)
     739             :             assertion = assertion .and. all( shape(FlattenedLogFuncState) == shape(RefinedChain%LogFuncState) )
     740             : 
     741             :             if (.not. assertion) then
     742             :                 if (Test%isDebugMode) then
     743             :                     write(*,"(10(g0,:,', '))")
     744             :                     write(*,"(10(g0,:,', '))") "shape(PD%RefinedChain%LogFuncState) ", shape(PD%RefinedChain%LogFuncState)
     745             :                     write(*,"(10(g0,:,', '))") "shape(RefinedChain%LogFuncState)    ", shape(RefinedChain%LogFuncState)
     746             :                     write(*,"(10(g0,:,', '))")
     747             :                     write(*,"(10(g0,:,', '))") "PD%RefinedChain%LogFuncState        ", PD%RefinedChain%LogFuncState
     748             :                     write(*,"(10(g0,:,', '))") "RefinedChain%LogFuncState           ", RefinedChain%LogFuncState
     749             :                     write(*,"(10(g0,:,', '))")
     750             :                 end if
     751             :                 return
     752             :             end if
     753             : 
     754             :             Difference = abs(FlattenedLogFuncState - RefinedChain%LogFuncState)
     755             :             assertion = assertion .and. all(Difference < tolerance)
     756             : 
     757             :             if (.not. assertion) then
     758             :                 if (Test%isDebugMode) then
     759             :                     write(*,"(10(g0,:,', '))")
     760             :                     write(*,"(10(g0,:,', '))") "PD%RefinedChain%LogFuncState", PD%RefinedChain%LogFuncState
     761             :                     write(*,"(10(g0,:,', '))") "RefinedChain%LogFuncState   ", RefinedChain%LogFuncState
     762             :                     write(*,"(10(g0,:,', '))") "Difference                  ", Difference
     763             :                     write(*,"(10(g0,:,', '))")
     764             :                 end if
     765             :                 return
     766             :             end if
     767             : 
     768             :         end if
     769             :         ! LCOV_EXCL_STOP
     770             : 
     771             : #endif
     772          80 :     end function test_runSampler_15
     773             : 
     774             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     775             : 
     776             :     !> \brief
     777             :     !> Test the ParaDXXX sampler to restart a complete simulation without an output sample file, in multichain parallelism.
     778           6 :     module function test_runSampler_16() result(assertion)
     779             :         implicit none
     780             :         logical             :: assertion
     781           6 :         type(ParaDXXX_type) :: PD1, PD2
     782           6 :         assertion = .true.
     783             : #if defined CODECOV_ENABLED || defined SAMPLER_TEST_ENABLED
     784             : 
     785             :         ! Run the fresh simulation
     786             : 
     787             :         call PD1%runSampler ( ndim = 2_IK &
     788             :                             , getLogFunc = getLogFuncMVN &
     789             :                             , mpiFinalizeRequested = .false. &
     790             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_16" &
     791             :                             , parallelizationModel = "multi chain" &
     792             :                             , outputRealPrecision = 16_IK &
     793             :                             , randomSeed = 12345_IK &
     794             :                             , sampleSize = 250_IK &
     795             :                             , chainSize = 500_IK &
     796           6 :                             )
     797           6 :         assertion = assertion .and. .not. PD1%Err%occurred
     798             : 
     799           6 :         if (.not. assertion) then
     800             :         ! LCOV_EXCL_START
     801             :             if (Test%isDebugMode) then
     802             :                 write(Test%outputUnit,"(*(g0,:,' '))")
     803             :                 write(Test%outputUnit,"(*(g0,:,' '))")   "process, PD1%Err%occurred(1)", Test%Image%id, PD1%Err%occurred
     804             :                 write(Test%outputUnit,"(*(g0,:,' '))")
     805             :             end if
     806             :             return
     807             :         end if
     808             :         ! LCOV_EXCL_STOP
     809             : 
     810           6 :         call Test%Image%sync()
     811             : 
     812             :         block
     813             :             use System_mod, only: removeFile
     814           6 :             call removeFile(PD1%SampleFile%Path%original, PD1%Err) ! delete the sample file
     815             :         end block
     816             : 
     817           6 :         call Test%Image%sync()
     818             : 
     819             :         ! restart the simulation with the same configuration
     820             : 
     821             :         call PD2%runSampler ( ndim = 2_IK &
     822             :                             , getLogFunc = getLogFuncMVN &
     823             :                             , mpiFinalizeRequested = .false. &
     824             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_16" &
     825             :                             , parallelizationModel = "multi chain" &
     826             :                             , outputRealPrecision = 16_IK &
     827             :                             , randomSeed = 12345_IK &
     828             :                             , sampleSize = 250_IK &
     829             :                             , chainSize = 500_IK &
     830           6 :                             )
     831             : 
     832           6 :         assertion = assertion .and. .not. PD2%Err%occurred
     833             : 
     834           6 :         if (.not. assertion) then
     835             :         ! LCOV_EXCL_START
     836             :             if (Test%isDebugMode) then
     837             :                 write(Test%outputUnit,"(*(g0,:,' '))")
     838             :                 write(Test%outputUnit,"(*(g0,:,' '))")   "process, PD2%Err%occurred(1)", Test%Image%id, PD1%Err%occurred
     839             :                 write(Test%outputUnit,"(*(g0,:,' '))")
     840             :             end if
     841             :             return
     842             :         end if
     843             :         ! LCOV_EXCL_STOP
     844             : 
     845           6 :         if (PD2%Image%isLeader) then
     846             :         ! LCOV_EXCL_START
     847             :             assertion = assertion .and. all( abs(PD2%RefinedChain%LogFuncState - PD1%RefinedChain%LogFuncState) < 1.e-12_RK ) ! by default, the output precision is only 8 digits
     848             :             if (.not. assertion) then
     849             :             ! LCOV_EXCL_START
     850             :                 if (Test%isDebugMode) then
     851             :                     write(Test%outputUnit,"(*(g0,:,' '))")
     852             :                     write(Test%outputUnit,"(*(g0,:,' '))")   "process, Difference:", Test%Image%id, abs(PD2%RefinedChain%LogFuncState - PD1%RefinedChain%LogFuncState)
     853             :                     write(Test%outputUnit,"(*(g0,:,' '))")
     854             :                 end if
     855             :                 return
     856             :             end if
     857             :         end if
     858             :         ! LCOV_EXCL_STOP
     859             : #endif
     860         180 :     end function test_runSampler_16
     861             : 
     862             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     863             : 
     864             :     !> \brief
     865             :     !> Test the ParaDXXX sampler to restart a complete simulation without an output sample file, in singlechain parallelism.
     866             :     !> Also, ensure the delayed rejection sampling is activated by setting a low value for `adaptiveUpdatePeriod` and
     867             :     !> a large value for `scaleFactor`.
     868           6 :     module function test_runSampler_17() result(assertion)
     869           6 :         use Constants_mod, only: RK
     870             :         implicit none
     871             :         logical             :: assertion
     872           6 :         type(ParaDXXX_type) :: PD1, PD2
     873             :         real(RK), parameter :: targetAcceptanceRate(*) = [0.2_RK, 0.23_RK]
     874           6 :         assertion = .true.
     875             : #if defined CODECOV_ENABLED || defined SAMPLER_TEST_ENABLED
     876             : 
     877             :         ! Run the fresh simulation
     878             : 
     879             :         call PD1%runSampler ( ndim = 2_IK &
     880             :                             , getLogFunc = getLogFuncMVN &
     881             :                             , mpiFinalizeRequested = .false. &
     882             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_17" &
     883             :                             , targetAcceptanceRate = targetAcceptanceRate &
     884             :                             , parallelizationModel = "single chain" &
     885             :                             , greedyAdaptationCount = 30_IK & ! This must remain larger than adaptiveUpdatePeriod
     886             :                             , delayedRejectionCount = 4_IK &
     887             :                             , adaptiveUpdatePeriod = 1_IK &
     888             :                             , outputRealPrecision = 16_IK &
     889             :                             , scaleFactor = "5 * gelman" &
     890             :                             , randomSeed = 12345_IK &
     891             :                             , sampleSize = 250_IK &
     892             :                             , chainSize = 500_IK &
     893           6 :                             )
     894           6 :         assertion = assertion .and. .not. PD1%Err%occurred
     895             : 
     896           6 :         if (.not. assertion) then
     897             :         ! LCOV_EXCL_START
     898             :             if (Test%isDebugMode) then
     899             :                 write(Test%outputUnit,"(*(g0,:,' '))")
     900             :                 write(Test%outputUnit,"(*(g0,:,' '))")   "process, PD1%Err%occurred(1)", Test%Image%id, PD1%Err%occurred
     901             :                 write(Test%outputUnit,"(*(g0,:,' '))")
     902             :             end if
     903             :             return
     904             :         end if
     905             :         ! LCOV_EXCL_STOP
     906             : 
     907           6 :         call Test%Image%sync()
     908             : 
     909             :         block
     910             :             use System_mod, only: removeFile
     911           6 :             call removeFile(PD1%SampleFile%Path%original, PD1%Err) ! delete the sample file
     912             :         end block
     913             : 
     914           6 :         call Test%Image%sync()
     915             : 
     916             :         ! restart the simulation with the same configuration
     917             : 
     918             :         call PD2%runSampler ( ndim = 2_IK &
     919             :                             , getLogFunc = getLogFuncMVN &
     920             :                             , mpiFinalizeRequested = .false. &
     921             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_17" &
     922             :                             , targetAcceptanceRate = targetAcceptanceRate &
     923             :                             , parallelizationModel = "single chain" &
     924             :                             , greedyAdaptationCount = 30_IK & ! This must remain larger than adaptiveUpdatePeriod
     925             :                             , delayedRejectionCount = 4_IK &
     926             :                             , adaptiveUpdatePeriod = 1_IK &
     927             :                             , outputRealPrecision = 16_IK &
     928             :                             , scaleFactor = "5 * gelman" &
     929             :                             , randomSeed = 12345_IK &
     930             :                             , sampleSize = 250_IK &
     931             :                             , chainSize = 500_IK &
     932           6 :                             )
     933             : 
     934           6 :         assertion = assertion .and. .not. PD2%Err%occurred
     935             : 
     936           6 :         if (.not. assertion) then
     937             :         ! LCOV_EXCL_START
     938             :             if (Test%isDebugMode) then
     939             :                 write(Test%outputUnit,"(*(g0,:,' '))")
     940             :                 write(Test%outputUnit,"(*(g0,:,' '))")   "process, PD2%Err%occurred(1)", Test%Image%id, PD1%Err%occurred
     941             :                 write(Test%outputUnit,"(*(g0,:,' '))")
     942             :             end if
     943             :             return
     944             :         end if
     945             :         ! LCOV_EXCL_STOP
     946             : 
     947           6 :         if (PD2%Image%isLeader) then
     948             :         ! LCOV_EXCL_START
     949             :             assertion = assertion .and. all( abs(PD2%RefinedChain%LogFuncState - PD1%RefinedChain%LogFuncState) < 1.e-12_RK ) ! by default, the output precision is only 8 digits
     950             :             if (.not. assertion) then
     951             :             ! LCOV_EXCL_START
     952             :                 if (Test%isDebugMode) then
     953             :                     write(Test%outputUnit,"(*(g0,:,' '))")
     954             :                     write(Test%outputUnit,"(*(g0,:,' '))")   "process, Difference:", Test%Image%id, abs(PD2%RefinedChain%LogFuncState - PD1%RefinedChain%LogFuncState)
     955             :                     write(Test%outputUnit,"(*(g0,:,' '))")
     956             :                 end if
     957             :                 return
     958             :             end if
     959             :         end if
     960             :         ! LCOV_EXCL_STOP
     961             : #endif
     962         134 :     end function test_runSampler_17
     963             : 
     964             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     965             : 
     966             :     !> \brief
     967             :     !> Test the ParaDXXX sampler to restart a complete simulation without an output sample file, in singlechain parallelism.
     968             :     !> Also, ensure the delayed rejection sampling is activated by setting a low value for `adaptiveUpdatePeriod` and
     969             :     !> a large value for `scaleFactor`.
     970             :     !> Also, use uniform proposal, as opposed to Normal in `test_runSampler_17()`.
     971           6 :     module function test_runSampler_18() result(assertion)
     972           6 :         use Constants_mod, only: RK
     973             :         implicit none
     974             :         logical             :: assertion
     975           6 :         type(ParaDXXX_type) :: PD1, PD2
     976             :         real(RK), parameter :: targetAcceptanceRate(*) = [0.2_RK, 0.23_RK]
     977           6 :         assertion = .true.
     978             : #if defined CODECOV_ENABLED || defined SAMPLER_TEST_ENABLED
     979             : 
     980             :         ! Run the fresh simulation
     981             : 
     982             :         call PD1%runSampler ( ndim = 2_IK &
     983             :                             , getLogFunc = getLogFuncMVN &
     984             :                             , mpiFinalizeRequested = .false. &
     985             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_18" &
     986             :                             , targetAcceptanceRate = targetAcceptanceRate &
     987             :                             , parallelizationModel = "single chain" &
     988             :                             , greedyAdaptationCount = 30_IK & ! This must remain larger than adaptiveUpdatePeriod
     989             :                             , delayedRejectionCount = 4_IK &
     990             :                             , adaptiveUpdatePeriod = 1_IK &
     991             :                             , outputRealPrecision = 16_IK &
     992             :                             , scaleFactor = "5 * gelman" &
     993             :                             , proposalModel = "uniform" &
     994             :                             , randomSeed = 12345_IK &
     995             :                             , sampleSize = 250_IK &
     996             :                             , chainSize = 500_IK &
     997           6 :                             )
     998           6 :         assertion = assertion .and. .not. PD1%Err%occurred
     999             : 
    1000           6 :         if (.not. assertion) then
    1001             :         ! LCOV_EXCL_START
    1002             :             if (Test%isDebugMode) then
    1003             :                 write(Test%outputUnit,"(*(g0,:,' '))")
    1004             :                 write(Test%outputUnit,"(*(g0,:,' '))")   "process, PD1%Err%occurred(1)", Test%Image%id, PD1%Err%occurred
    1005             :                 write(Test%outputUnit,"(*(g0,:,' '))")
    1006             :             end if
    1007             :             return
    1008             :         end if
    1009             :         ! LCOV_EXCL_STOP
    1010             : 
    1011           6 :         call Test%Image%sync()
    1012             : 
    1013             :         block
    1014             :             use System_mod, only: removeFile
    1015           6 :             call removeFile(PD1%SampleFile%Path%original, PD1%Err) ! delete the sample file
    1016             :         end block
    1017             : 
    1018           6 :         call Test%Image%sync()
    1019             : 
    1020             :         ! restart the simulation with the same configuration
    1021             : 
    1022             :         call PD2%runSampler ( ndim = 2_IK &
    1023             :                             , getLogFunc = getLogFuncMVN &
    1024             :                             , mpiFinalizeRequested = .false. &
    1025             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_18" &
    1026             :                             , targetAcceptanceRate = targetAcceptanceRate &
    1027             :                             , parallelizationModel = "singlechain" &
    1028             :                             , greedyAdaptationCount = 30_IK & ! This must remain larger than adaptiveUpdatePeriod
    1029             :                             , delayedRejectionCount = 4_IK &
    1030             :                             , adaptiveUpdatePeriod = 1_IK &
    1031             :                             , outputRealPrecision = 16_IK &
    1032             :                             , scaleFactor = "5 * gelman" &
    1033             :                             , proposalModel = "uniform" &
    1034             :                             , randomSeed = 12345_IK &
    1035             :                             , sampleSize = 250_IK &
    1036             :                             , chainSize = 500_IK &
    1037           6 :                             )
    1038             : 
    1039           6 :         assertion = assertion .and. .not. PD2%Err%occurred
    1040             : 
    1041           6 :         if (.not. assertion) then
    1042             :         ! LCOV_EXCL_START
    1043             :             if (Test%isDebugMode) then
    1044             :                 write(Test%outputUnit,"(*(g0,:,' '))")
    1045             :                 write(Test%outputUnit,"(*(g0,:,' '))")   "process, PD2%Err%occurred(1)", Test%Image%id, PD1%Err%occurred
    1046             :                 write(Test%outputUnit,"(*(g0,:,' '))")
    1047             :             end if
    1048             :             return
    1049             :         end if
    1050             :         ! LCOV_EXCL_STOP
    1051             : 
    1052           6 :         if (PD2%Image%isLeader) then
    1053             :         ! LCOV_EXCL_START
    1054             :             assertion = assertion .and. all( abs(PD2%RefinedChain%LogFuncState - PD1%RefinedChain%LogFuncState) < 1.e-12_RK ) ! by default, the output precision is only 8 digits
    1055             :             if (.not. assertion) then
    1056             :             ! LCOV_EXCL_START
    1057             :                 if (Test%isDebugMode) then
    1058             :                     write(Test%outputUnit,"(*(g0,:,' '))")
    1059             :                     write(Test%outputUnit,"(*(g0,:,' '))")   "process, Difference:", Test%Image%id, abs(PD2%RefinedChain%LogFuncState - PD1%RefinedChain%LogFuncState)
    1060             :                     write(Test%outputUnit,"(*(g0,:,' '))")
    1061             :                 end if
    1062             :                 return
    1063             :             end if
    1064             :         end if
    1065             :         ! LCOV_EXCL_STOP
    1066             : #endif
    1067         134 :     end function test_runSampler_18
    1068             : 
    1069             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1070             : 
    1071             :     !> \brief
    1072             :     !> Test the ParaDXXX sampler to restart a complete simulation without an output sample file, in multichain parallelism.
    1073             :     !> Also, ensure the delayed rejection sampling is activated by setting a low value for `adaptiveUpdatePeriod` and
    1074             :     !> a large value for `scaleFactor`.
    1075             :     !> Also, avoid delayed rejection, as opposed to what is done in `test_runSampler_17()`.
    1076             :     !> Also, request the `maxCumSum` sample refinement and count method.
    1077           6 :     module function test_runSampler_19() result(assertion)
    1078           6 :         use Constants_mod, only: RK
    1079             :         implicit none
    1080             :         logical             :: assertion
    1081           6 :         type(ParaDXXX_type) :: PD1, PD2
    1082             :         real(RK), parameter :: targetAcceptanceRate(*) = [0.2_RK, 0.23_RK]
    1083           6 :         assertion = .true.
    1084             : #if defined CODECOV_ENABLED || defined SAMPLER_TEST_ENABLED
    1085             : 
    1086             :         ! Run the fresh simulation
    1087             : 
    1088             :         call PD1%runSampler ( ndim = 2_IK &
    1089             :                             , getLogFunc = getLogFuncMVN &
    1090             :                             , mpiFinalizeRequested = .false. &
    1091             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_19" &
    1092             :                             , sampleRefinementMethod = "MaxCumSumAutoCorr-median" &
    1093             :                             , targetAcceptanceRate = targetAcceptanceRate &
    1094             :                             , parallelizationModel = "multi chain" &
    1095             :                             , greedyAdaptationCount = 2_IK & ! This must remain larger than adaptiveUpdatePeriod
    1096             :                             , adaptiveUpdatePeriod = 1_IK &
    1097             :                             , outputRealPrecision = 16_IK &
    1098             :                             , chainFileFormat = "verbose" &
    1099             :                             , scaleFactor = "5 * gelman" &
    1100             :                             , proposalModel = "uniform" &
    1101             :                             , randomSeed = 12345_IK &
    1102             :                             , sampleSize = -50_IK &
    1103             :                             , chainSize = 700_IK &
    1104           6 :                             )
    1105           6 :         assertion = assertion .and. .not. PD1%Err%occurred
    1106             : 
    1107           6 :         if (.not. assertion) then
    1108             :         ! LCOV_EXCL_START
    1109             :             if (Test%isDebugMode) then
    1110             :                 write(Test%outputUnit,"(*(g0,:,' '))")
    1111             :                 write(Test%outputUnit,"(*(g0,:,' '))")   "process, PD1%Err%occurred(1)", Test%Image%id, PD1%Err%occurred
    1112             :                 write(Test%outputUnit,"(*(g0,:,' '))")
    1113             :             end if
    1114             :             return
    1115             :         end if
    1116             :         ! LCOV_EXCL_STOP
    1117             : 
    1118           6 :         call Test%Image%sync()
    1119             : 
    1120             :         block
    1121             :             use System_mod, only: removeFile
    1122           6 :             call removeFile(PD1%SampleFile%Path%original, PD1%Err) ! delete the sample file
    1123             :         end block
    1124             : 
    1125           6 :         call Test%Image%sync()
    1126             : 
    1127             :         ! restart the simulation with the same configuration
    1128             : 
    1129             :         call PD2%runSampler ( ndim = 2_IK &
    1130             :                             , getLogFunc = getLogFuncMVN &
    1131             :                             , mpiFinalizeRequested = .false. &
    1132             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_19" &
    1133             :                             , sampleRefinementMethod = "MaxCumSumAutoCorr-median" &
    1134             :                             , targetAcceptanceRate = targetAcceptanceRate &
    1135             :                             , parallelizationModel = "multi chain" &
    1136             :                             , greedyAdaptationCount = 2_IK & ! This must remain larger than adaptiveUpdatePeriod
    1137             :                             , adaptiveUpdatePeriod = 1_IK &
    1138             :                             , outputRealPrecision = 16_IK &
    1139             :                             , chainFileFormat = "verbose" &
    1140             :                             , scaleFactor = "5 * gelman" &
    1141             :                             , proposalModel = "uniform" &
    1142             :                             , randomSeed = 12345_IK &
    1143             :                             , sampleSize = -50_IK &
    1144             :                             , chainSize = 700_IK &
    1145           6 :                             )
    1146             : 
    1147           6 :         assertion = assertion .and. .not. PD2%Err%occurred
    1148             : 
    1149           6 :         if (.not. assertion) then
    1150             :         ! LCOV_EXCL_START
    1151             :             if (Test%isDebugMode) then
    1152             :                 write(Test%outputUnit,"(*(g0,:,' '))")
    1153             :                 write(Test%outputUnit,"(*(g0,:,' '))")   "process, PD2%Err%occurred(1)", Test%Image%id, PD1%Err%occurred
    1154             :                 write(Test%outputUnit,"(*(g0,:,' '))")
    1155             :             end if
    1156             :             return
    1157             :         end if
    1158             :         ! LCOV_EXCL_STOP
    1159             : 
    1160           6 :         if (PD2%Image%isLeader) then
    1161             :         ! LCOV_EXCL_START
    1162             :             assertion = assertion .and. all( abs(PD2%RefinedChain%LogFuncState - PD1%RefinedChain%LogFuncState) < 1.e-12_RK ) ! by default, the output precision is only 8 digits
    1163             :             if (.not. assertion) then
    1164             :             ! LCOV_EXCL_START
    1165             :                 if (Test%isDebugMode) then
    1166             :                     write(Test%outputUnit,"(*(g0,:,' '))")
    1167             :                     write(Test%outputUnit,"(*(g0,:,' '))")   "process, Difference:", Test%Image%id, abs(PD2%RefinedChain%LogFuncState - PD1%RefinedChain%LogFuncState)
    1168             :                     write(Test%outputUnit,"(*(g0,:,' '))")
    1169             :                 end if
    1170             :                 return
    1171             :             end if
    1172             :         end if
    1173             :         ! LCOV_EXCL_STOP
    1174             : #endif
    1175         174 :     end function test_runSampler_19
    1176             : 
    1177             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1178             : 
    1179             :     !> \brief
    1180             :     !> Test the ParaDXXX sampler to restart a complete simulation without an output sample file, in multichain parallelism.
    1181             :     !> Also, ensure the delayed rejection sampling is activated by setting a low value for `adaptiveUpdatePeriod` and
    1182             :     !> a large value for `scaleFactor`.
    1183             :     !> Also, avoid delayed rejection, as opposed to what is done in `test_runSampler_17()`.
    1184             :     !> Also, request the `cutoffAutoCorr` sample refinement and count method.
    1185           6 :     module function test_runSampler_20() result(assertion)
    1186           6 :         use Constants_mod, only: RK
    1187             :         implicit none
    1188             :         logical             :: assertion
    1189           6 :         type(ParaDXXX_type) :: PD1, PD2
    1190             :         real(RK), parameter :: targetAcceptanceRate(*) = [0.2_RK, 0.23_RK]
    1191           6 :         assertion = .true.
    1192             : #if defined CODECOV_ENABLED || defined SAMPLER_TEST_ENABLED
    1193             : 
    1194             :         ! Run the fresh simulation
    1195             : 
    1196             :         call PD1%runSampler ( ndim = 2_IK &
    1197             :                             , getLogFunc = getLogFuncMVN &
    1198             :                             , mpiFinalizeRequested = .false. &
    1199             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_20" &
    1200             :                             , sampleRefinementMethod = "cutoffAutoCorr-maximum" &
    1201             :                             , targetAcceptanceRate = targetAcceptanceRate &
    1202             :                             , parallelizationModel = "multi chain" &
    1203             :                             , greedyAdaptationCount = 2_IK & ! This must remain larger than adaptiveUpdatePeriod
    1204             :                             , adaptiveUpdatePeriod = 1_IK &
    1205             :                             , outputRealPrecision = 16_IK &
    1206             :                             , chainFileFormat = "binary" &
    1207             :                             , scaleFactor = "5 * gelman" &
    1208             :                             , proposalModel = "uniform" &
    1209             :                             , randomSeed = 12345_IK &
    1210             :                             , sampleSize = -50_IK &
    1211             :                             , chainSize = 700_IK &
    1212           6 :                             )
    1213           6 :         assertion = assertion .and. .not. PD1%Err%occurred
    1214             : 
    1215           6 :         if (.not. assertion) then
    1216             :         ! LCOV_EXCL_START
    1217             :             if (Test%isDebugMode) then
    1218             :                 write(Test%outputUnit,"(*(g0,:,' '))")
    1219             :                 write(Test%outputUnit,"(*(g0,:,' '))")   "process, PD1%Err%occurred(1)", Test%Image%id, PD1%Err%occurred
    1220             :                 write(Test%outputUnit,"(*(g0,:,' '))")
    1221             :             end if
    1222             :             return
    1223             :         end if
    1224             :         ! LCOV_EXCL_STOP
    1225             : 
    1226           6 :         call Test%Image%sync()
    1227             : 
    1228             :         block
    1229             :             use System_mod, only: removeFile
    1230           6 :             call removeFile(PD1%SampleFile%Path%original, PD1%Err) ! delete the sample file
    1231             :         end block
    1232             : 
    1233           6 :         call Test%Image%sync()
    1234             : 
    1235             :         ! restart the simulation with the same configuration
    1236             : 
    1237             :         call PD2%runSampler ( ndim = 2_IK &
    1238             :                             , getLogFunc = getLogFuncMVN &
    1239             :                             , mpiFinalizeRequested = .false. &
    1240             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_20" &
    1241             :                             , sampleRefinementMethod = "cutoffAutoCorr-maximum" &
    1242             :                             , targetAcceptanceRate = targetAcceptanceRate &
    1243             :                             , parallelizationModel = "multi chain" &
    1244             :                             , greedyAdaptationCount = 2_IK & ! This must remain larger than adaptiveUpdatePeriod
    1245             :                             , adaptiveUpdatePeriod = 1_IK &
    1246             :                             , outputRealPrecision = 16_IK &
    1247             :                             , chainFileFormat = "binary" &
    1248             :                             , scaleFactor = "5 * gelman" &
    1249             :                             , proposalModel = "uniform" &
    1250             :                             , randomSeed = 12345_IK &
    1251             :                             , sampleSize = -50_IK &
    1252             :                             , chainSize = 700_IK &
    1253           6 :                             )
    1254             : 
    1255           6 :         assertion = assertion .and. .not. PD2%Err%occurred
    1256             : 
    1257           6 :         if (.not. assertion) then
    1258             :         ! LCOV_EXCL_START
    1259             :             if (Test%isDebugMode) then
    1260             :                 write(Test%outputUnit,"(*(g0,:,' '))")
    1261             :                 write(Test%outputUnit,"(*(g0,:,' '))")   "process, PD2%Err%occurred(1)", Test%Image%id, PD1%Err%occurred
    1262             :                 write(Test%outputUnit,"(*(g0,:,' '))")
    1263             :             end if
    1264             :             return
    1265             :         end if
    1266             :         ! LCOV_EXCL_STOP
    1267             : 
    1268           6 :         if (PD2%Image%isLeader) then
    1269             :         ! LCOV_EXCL_START
    1270             :             assertion = assertion .and. all( abs(PD2%RefinedChain%LogFuncState - PD1%RefinedChain%LogFuncState) < 1.e-12_RK ) ! by default, the output precision is only 8 digits
    1271             :             if (.not. assertion) then
    1272             :             ! LCOV_EXCL_START
    1273             :                 if (Test%isDebugMode) then
    1274             :                     write(Test%outputUnit,"(*(g0,:,' '))")
    1275             :                     write(Test%outputUnit,"(*(g0,:,' '))")   "process, Difference:", Test%Image%id, abs(PD2%RefinedChain%LogFuncState - PD1%RefinedChain%LogFuncState)
    1276             :                     write(Test%outputUnit,"(*(g0,:,' '))")
    1277             :                 end if
    1278             :                 return
    1279             :             end if
    1280             :         end if
    1281             :         ! LCOV_EXCL_STOP
    1282             : #endif
    1283         174 :     end function test_runSampler_20
    1284             : 
    1285             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1286             : 
    1287             :     !> \brief
    1288             :     !> Test whether the read method of the `ParaMCMCRefinedChain_type` class can successfully read an external sample file.
    1289             :     !> \remark
    1290             :     !> This is similar to test #15, except that it also verifies the functionality of the optional argument `tenabled` to `readRefinedChain()`.
    1291           6 :     module function test_runSampler_21() result(assertion)
    1292           6 :         use ParaMCMCRefinedChain_mod, only: readRefinedChain, RefinedChain_type
    1293             :         use Statistics_mod, only: flatten
    1294             :         implicit none
    1295             :         logical                 :: assertion
    1296             :         real(RK)    , parameter :: tolerance = 1.e-10_RK
    1297             :         character(*), parameter :: DELIM = "delim"
    1298             :         integer(IK) , parameter :: NDIM = 2_IK
    1299           6 :         type(ParaDXXX_type)     :: PD
    1300           6 :         type(RefinedChain_type) :: RefinedChain
    1301             :         real(RK), allocatable   :: Difference(:,:)
    1302             :         real(RK), allocatable   :: FlattenedLogFuncState(:,:)
    1303           6 :         assertion = .true.
    1304             : #if defined CODECOV_ENABLED || defined SAMPLER_TEST_ENABLED
    1305             : 
    1306             :         call PD%runSampler  ( ndim = NDIM &
    1307             :                             , getLogFunc = getLogFuncMVN &
    1308             :                             , mpiFinalizeRequested = .false. &
    1309             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_21" &
    1310             :                             , sampleRefineMentMethod = "batchMeans-med" &
    1311             :                             , parallelizationModel = "multichain" &
    1312             :                             , outputRealPrecision = 15_IK &
    1313             :                             , outputDelimiter = DELIM &
    1314             :                             , sampleSize = 10_IK &
    1315           6 :                             )
    1316           6 :         assertion = assertion .and. .not. PD%Err%occurred
    1317             :         if (.not. assertion) return ! LCOV_EXCL_LINE
    1318             : 
    1319           6 :         if (PD%Image%isLeader) then
    1320             : 
    1321             :             RefinedChain = readRefinedChain ( sampleFilePath = PD%SampleFile%Path%original & ! LCOV_EXCL_LINE
    1322             :                                             , delimiter = PD%SpecBase%OutputDelimiter%val & ! LCOV_EXCL_LINE
    1323             :                                             , tenabled = .true. & ! LCOV_EXCL_LINE
    1324             :                                             , ndim = PD%nd%val & ! LCOV_EXCL_LINE
    1325           6 :                                             )
    1326             : 
    1327             :             RefinedChain = readRefinedChain ( sampleFilePath = PD%SampleFile%Path%original & ! LCOV_EXCL_LINE
    1328             :                                             , delimiter = PD%SpecBase%OutputDelimiter%val & ! LCOV_EXCL_LINE
    1329             :                                             , tenabled = .false. & ! LCOV_EXCL_LINE
    1330             :                                             , ndim = PD%nd%val & ! LCOV_EXCL_LINE
    1331          30 :                                             )
    1332             : 
    1333           6 :             assertion = assertion .and. RefinedChain%numRefinement == 0_IK
    1334             : 
    1335           6 :             if (.not. assertion) then
    1336             :             ! LCOV_EXCL_START
    1337             :                 if (Test%isDebugMode) then
    1338             :                     write(*,"(10(g0,:,', '))")
    1339             :                     write(*,"(10(g0,:,', '))") "RefinedChain%numRefinement", RefinedChain%numRefinement
    1340             :                     write(*,"(10(g0,:,', '))")
    1341             :                 end if
    1342             :                 return
    1343             :             end if
    1344             :             ! LCOV_EXCL_STOP
    1345             : 
    1346             :             ! NOTE: Keep in mind that `PD%RefinedChain` is a weighted chain internally, but unweighted when read from the external file.
    1347         246 :             FlattenedLogFuncState = flatten(nd = PD%nd%val + 1, np = PD%RefinedChain%Count(PD%RefinedChain%numRefinement)%compact, Point = PD%RefinedChain%LogFuncState, Weight = PD%RefinedChain%Weight)
    1348          18 :             assertion = assertion .and. all( shape(FlattenedLogFuncState) == shape(RefinedChain%LogFuncState) )
    1349             : 
    1350           6 :             if (.not. assertion) then
    1351             :             ! LCOV_EXCL_START
    1352             :                 if (Test%isDebugMode) then
    1353             :                     write(*,"(10(g0,:,', '))")
    1354             :                     write(*,"(10(g0,:,', '))") "shape(PD%RefinedChain%LogFuncState) ", shape(PD%RefinedChain%LogFuncState)
    1355             :                     write(*,"(10(g0,:,', '))") "shape(RefinedChain%LogFuncState)    ", shape(RefinedChain%LogFuncState)
    1356             :                     write(*,"(10(g0,:,', '))")
    1357             :                     write(*,"(10(g0,:,', '))") "PD%RefinedChain%LogFuncState        ", PD%RefinedChain%LogFuncState
    1358             :                     write(*,"(10(g0,:,', '))") "RefinedChain%LogFuncState           ", RefinedChain%LogFuncState
    1359             :                     write(*,"(10(g0,:,', '))")
    1360             :                 end if
    1361             :                 return
    1362             :             end if
    1363             :             ! LCOV_EXCL_STOP
    1364             : 
    1365         246 :             Difference = abs(FlattenedLogFuncState - RefinedChain%LogFuncState)
    1366         246 :             assertion = assertion .and. all(Difference < tolerance)
    1367             : 
    1368           6 :             if (.not. assertion) then
    1369             :             ! LCOV_EXCL_START
    1370             :                 if (Test%isDebugMode) then
    1371             :                     write(*,"(10(g0,:,', '))")
    1372             :                     write(*,"(10(g0,:,', '))") "PD%RefinedChain%LogFuncState", PD%RefinedChain%LogFuncState
    1373             :                     write(*,"(10(g0,:,', '))") "RefinedChain%LogFuncState   ", RefinedChain%LogFuncState
    1374             :                     write(*,"(10(g0,:,', '))") "Difference                  ", Difference
    1375             :                     write(*,"(10(g0,:,', '))")
    1376             :                 end if
    1377             :                 return
    1378             :             end if
    1379             :             ! LCOV_EXCL_STOP
    1380             : 
    1381             :         end if
    1382             : 
    1383             : #endif
    1384         120 :     end function test_runSampler_21
    1385             : 
    1386             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    1387             : 
    1388             :     !> \brief
    1389             :     !> Test whether an object of [ChainFileContents_type](@ref paramcmcrefinedchain_mod::chainfilecontents_type)
    1390             :     !> class can handle zero-count input MCMC chain for refinement.
    1391             :     !> \remark
    1392           6 :     module function test_runSampler_22() result(assertion)
    1393           6 :         use ParaMCMCRefinedChain_mod, only: readRefinedChain, RefinedChain_type
    1394             :         implicit none
    1395             :         logical                 :: assertion
    1396             :         real(RK)    , parameter :: tolerance = 1.e-10_RK
    1397             :         character(*), parameter :: DELIM = "delim"
    1398             :         integer(IK) , parameter :: NDIM = 2_IK
    1399           6 :         type(ParaDXXX_type)     :: PD
    1400           6 :         type(RefinedChain_type) :: RefinedChain
    1401           6 :         assertion = .true.
    1402             : #if defined CODECOV_ENABLED || defined SAMPLER_TEST_ENABLED
    1403             : 
    1404             :         call PD%runSampler  ( ndim = NDIM &
    1405             :                             , getLogFunc = getLogFuncMVN &
    1406             :                             , mpiFinalizeRequested = .false. &
    1407             :                             , outputFileName = Test%outDir//"/"//MODULE_NAME//"/test_runSampler_22" &
    1408             :                             , sampleRefineMentMethod = "maxCumSumAutoCorr-minimum" &
    1409             :                             , parallelizationModel = "multi chain" &
    1410             :                             , chainSize = NDIM + 1_IK &
    1411           6 :                             )
    1412           6 :         assertion = assertion .and. .not. PD%Err%occurred
    1413             :         if (.not. assertion) return ! LCOV_EXCL_LINE
    1414             : 
    1415           6 :         if (PD%Image%isLeader) then
    1416             :         ! LCOV_EXCL_START
    1417             : 
    1418             :             ! Now, set PD%Chain%ndim and PD%Chain%Count%Compact and to zero. 
    1419             :             ! This should lead to the use of shape(PD%Chain%State(:,:)) to infer 
    1420             :             ! ndim and Compact chain length.
    1421             :             ! To test the behavior of the procedure in the presence of 1 point in the chain,
    1422             :             ! we will also resize the input PD%Chain%State(1:ndim,1:PD%Chain%Count%Compact) to PD%Chain%State(1:ndim,1:1)
    1423             : 
    1424             :             PD%Chain%ndim = 0
    1425             :             PD%Chain%Count%compact = 0
    1426             :             PD%Chain%State = PD%Chain%State(1:NDIM, 1:1)
    1427             : 
    1428             :             call PD%RefinedChain%get(CFC = PD%Chain, Err = PD%Err)
    1429             : 
    1430             :             assertion = assertion .and. .not. PD%Err%occurred .and. all(PD%RefinedChain%IAC==0_IK) .and. size(PD%RefinedChain%Count)==1_IK .and. PD%RefinedChain%numRefinement==0_IK
    1431             :             if (.not. assertion) return ! LCOV_EXCL_LINE
    1432             : 
    1433             :             if (.not. assertion) then
    1434             :                 if (Test%isDebugMode) then
    1435             :                     write(*,"(10(g0,:,', '))")
    1436             :                     write(*,"(10(g0,:,', '))") "Test%Image%id, RefinedChain%numRefinement", RefinedChain%numRefinement
    1437             :                     write(*,"(10(g0,:,', '))") "Test%Image%id, RefinedChain%IAC", RefinedChain%IAC
    1438             :                     write(*,"(10(g0,:,', '))")
    1439             :                 end if
    1440             :                 return
    1441             :             end if
    1442             : 
    1443             :         end if
    1444             :         ! LCOV_EXCL_STOP
    1445             : 
    1446             : #endif
    1447         102 :     end function test_runSampler_22
    1448             : 
    1449             : !%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

ParaMonte: Plain Powerful Parallel Monte Carlo Library 
The Computational Data Science Lab
© Copyright 2012 - 2021