{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module Mcmc.Settings
(
AnalysisName (..),
HasAnalysisName (..),
BurnInSettings (..),
burnInIterations,
Iterations (..),
TraceLength (..),
ExecutionMode (..),
HasExecutionMode (..),
openWithExecutionMode,
ParallelizationMode (..),
SaveMode (..),
LogMode (..),
Verbosity (..),
Settings (..),
settingsSave,
settingsLoad,
settingsCheck,
settingsPrettyPrint,
)
where
import Data.Aeson
import Data.Aeson.TH
import qualified Data.ByteString.Builder as BB
import qualified Data.ByteString.Lazy.Char8 as BL
import Mcmc.Logger
import System.Directory
import System.IO
bsInt :: Int -> BL.ByteString
bsInt :: Int -> ByteString
bsInt = Builder -> ByteString
BB.toLazyByteString forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Builder
BB.intDec
newtype AnalysisName = AnalysisName {AnalysisName -> [Char]
fromAnalysisName :: String}
deriving (AnalysisName -> AnalysisName -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AnalysisName -> AnalysisName -> Bool
$c/= :: AnalysisName -> AnalysisName -> Bool
== :: AnalysisName -> AnalysisName -> Bool
$c== :: AnalysisName -> AnalysisName -> Bool
Eq, ReadPrec [AnalysisName]
ReadPrec AnalysisName
Int -> ReadS AnalysisName
ReadS [AnalysisName]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [AnalysisName]
$creadListPrec :: ReadPrec [AnalysisName]
readPrec :: ReadPrec AnalysisName
$creadPrec :: ReadPrec AnalysisName
readList :: ReadS [AnalysisName]
$creadList :: ReadS [AnalysisName]
readsPrec :: Int -> ReadS AnalysisName
$creadsPrec :: Int -> ReadS AnalysisName
Read, Int -> AnalysisName -> ShowS
[AnalysisName] -> ShowS
AnalysisName -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [AnalysisName] -> ShowS
$cshowList :: [AnalysisName] -> ShowS
show :: AnalysisName -> [Char]
$cshow :: AnalysisName -> [Char]
showsPrec :: Int -> AnalysisName -> ShowS
$cshowsPrec :: Int -> AnalysisName -> ShowS
Show)
deriving (Semigroup AnalysisName
AnalysisName
[AnalysisName] -> AnalysisName
AnalysisName -> AnalysisName -> AnalysisName
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
mconcat :: [AnalysisName] -> AnalysisName
$cmconcat :: [AnalysisName] -> AnalysisName
mappend :: AnalysisName -> AnalysisName -> AnalysisName
$cmappend :: AnalysisName -> AnalysisName -> AnalysisName
mempty :: AnalysisName
$cmempty :: AnalysisName
Monoid, NonEmpty AnalysisName -> AnalysisName
AnalysisName -> AnalysisName -> AnalysisName
forall b. Integral b => b -> AnalysisName -> AnalysisName
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
stimes :: forall b. Integral b => b -> AnalysisName -> AnalysisName
$cstimes :: forall b. Integral b => b -> AnalysisName -> AnalysisName
sconcat :: NonEmpty AnalysisName -> AnalysisName
$csconcat :: NonEmpty AnalysisName -> AnalysisName
<> :: AnalysisName -> AnalysisName -> AnalysisName
$c<> :: AnalysisName -> AnalysisName -> AnalysisName
Semigroup) via String
$(deriveJSON defaultOptions ''AnalysisName)
class HasAnalysisName s where
getAnalysisName :: s -> AnalysisName
data BurnInSettings
=
NoBurnIn
|
BurnInWithoutAutoTuning Int
|
BurnInWithAutoTuning Int Int
|
BurnInWithCustomAutoTuning [Int] [Int]
deriving (BurnInSettings -> BurnInSettings -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BurnInSettings -> BurnInSettings -> Bool
$c/= :: BurnInSettings -> BurnInSettings -> Bool
== :: BurnInSettings -> BurnInSettings -> Bool
$c== :: BurnInSettings -> BurnInSettings -> Bool
Eq, ReadPrec [BurnInSettings]
ReadPrec BurnInSettings
Int -> ReadS BurnInSettings
ReadS [BurnInSettings]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BurnInSettings]
$creadListPrec :: ReadPrec [BurnInSettings]
readPrec :: ReadPrec BurnInSettings
$creadPrec :: ReadPrec BurnInSettings
readList :: ReadS [BurnInSettings]
$creadList :: ReadS [BurnInSettings]
readsPrec :: Int -> ReadS BurnInSettings
$creadsPrec :: Int -> ReadS BurnInSettings
Read, Int -> BurnInSettings -> ShowS
[BurnInSettings] -> ShowS
BurnInSettings -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [BurnInSettings] -> ShowS
$cshowList :: [BurnInSettings] -> ShowS
show :: BurnInSettings -> [Char]
$cshow :: BurnInSettings -> [Char]
showsPrec :: Int -> BurnInSettings -> ShowS
$cshowsPrec :: Int -> BurnInSettings -> ShowS
Show)
$(deriveJSON defaultOptions ''BurnInSettings)
burnInPrettyPrint :: BurnInSettings -> BL.ByteString
burnInPrettyPrint :: BurnInSettings -> ByteString
burnInPrettyPrint BurnInSettings
NoBurnIn =
ByteString
"None."
burnInPrettyPrint (BurnInWithoutAutoTuning Int
x) =
Int -> ByteString
bsInt Int
x forall a. Semigroup a => a -> a -> a
<> ByteString
" iterations; no auto tune."
burnInPrettyPrint (BurnInWithAutoTuning Int
x Int
y) =
Int -> ByteString
bsInt Int
x forall a. Semigroup a => a -> a -> a
<> ByteString
" iterations; auto tune with a period of " forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
bsInt Int
y forall a. Semigroup a => a -> a -> a
<> ByteString
"."
burnInPrettyPrint (BurnInWithCustomAutoTuning [Int]
xs [Int]
ys) =
Int -> ByteString
bsInt (forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum [Int]
xs) forall a. Semigroup a => a -> a -> a
<> ByteString
" fast, " forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
bsInt (forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum [Int]
ys) forall a. Semigroup a => a -> a -> a
<> ByteString
" slow iterations; custom auto tune periods."
burnInValid :: BurnInSettings -> Bool
burnInValid :: BurnInSettings -> Bool
burnInValid BurnInSettings
NoBurnIn = Bool
True
burnInValid (BurnInWithoutAutoTuning Int
n) = Int
n forall a. Ord a => a -> a -> Bool
> Int
0
burnInValid (BurnInWithAutoTuning Int
n Int
t) = Int
n forall a. Ord a => a -> a -> Bool
> Int
0 Bool -> Bool -> Bool
&& Int
t forall a. Ord a => a -> a -> Bool
> Int
0
burnInValid (BurnInWithCustomAutoTuning [Int]
xs [Int]
ys) = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (forall a. Ord a => a -> a -> Bool
> Int
0) [Int]
xs Bool -> Bool -> Bool
&& Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Int]
ys) Bool -> Bool -> Bool
&& forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all (forall a. Ord a => a -> a -> Bool
> Int
0) [Int]
ys
burnInIterations :: BurnInSettings -> Int
burnInIterations :: BurnInSettings -> Int
burnInIterations BurnInSettings
NoBurnIn = Int
0
burnInIterations (BurnInWithoutAutoTuning Int
n) = Int
n
burnInIterations (BurnInWithAutoTuning Int
n Int
_) = Int
n
burnInIterations (BurnInWithCustomAutoTuning [Int]
xs [Int]
ys) = forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum [Int]
xs forall a. Num a => a -> a -> a
+ forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
sum [Int]
ys
newtype Iterations = Iterations {Iterations -> Int
fromIterations :: Int}
deriving (Iterations -> Iterations -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Iterations -> Iterations -> Bool
$c/= :: Iterations -> Iterations -> Bool
== :: Iterations -> Iterations -> Bool
$c== :: Iterations -> Iterations -> Bool
Eq, ReadPrec [Iterations]
ReadPrec Iterations
Int -> ReadS Iterations
ReadS [Iterations]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Iterations]
$creadListPrec :: ReadPrec [Iterations]
readPrec :: ReadPrec Iterations
$creadPrec :: ReadPrec Iterations
readList :: ReadS [Iterations]
$creadList :: ReadS [Iterations]
readsPrec :: Int -> ReadS Iterations
$creadsPrec :: Int -> ReadS Iterations
Read, Int -> Iterations -> ShowS
[Iterations] -> ShowS
Iterations -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [Iterations] -> ShowS
$cshowList :: [Iterations] -> ShowS
show :: Iterations -> [Char]
$cshow :: Iterations -> [Char]
showsPrec :: Int -> Iterations -> ShowS
$cshowsPrec :: Int -> Iterations -> ShowS
Show)
$(deriveJSON defaultOptions ''Iterations)
data TraceLength
=
TraceAuto
|
TraceMinimum Int
deriving (TraceLength -> TraceLength -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TraceLength -> TraceLength -> Bool
$c/= :: TraceLength -> TraceLength -> Bool
== :: TraceLength -> TraceLength -> Bool
$c== :: TraceLength -> TraceLength -> Bool
Eq, Int -> TraceLength -> ShowS
[TraceLength] -> ShowS
TraceLength -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [TraceLength] -> ShowS
$cshowList :: [TraceLength] -> ShowS
show :: TraceLength -> [Char]
$cshow :: TraceLength -> [Char]
showsPrec :: Int -> TraceLength -> ShowS
$cshowsPrec :: Int -> TraceLength -> ShowS
Show)
$(deriveJSON defaultOptions ''TraceLength)
traceLengthPrettyPrint :: TraceLength -> BL.ByteString
traceLengthPrettyPrint :: TraceLength -> ByteString
traceLengthPrettyPrint TraceLength
TraceAuto = ByteString
"Determined automatically."
traceLengthPrettyPrint (TraceMinimum Int
x) = ByteString
"Minimum length of " forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
bsInt Int
x forall a. Semigroup a => a -> a -> a
<> ByteString
"."
validTraceLength :: TraceLength -> Bool
validTraceLength :: TraceLength -> Bool
validTraceLength (TraceMinimum Int
n) = Int
n forall a. Ord a => a -> a -> Bool
> Int
0
validTraceLength TraceLength
_ = Bool
True
data ExecutionMode
=
Fail
|
Overwrite
|
Continue
deriving (ExecutionMode -> ExecutionMode -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ExecutionMode -> ExecutionMode -> Bool
$c/= :: ExecutionMode -> ExecutionMode -> Bool
== :: ExecutionMode -> ExecutionMode -> Bool
$c== :: ExecutionMode -> ExecutionMode -> Bool
Eq, ReadPrec [ExecutionMode]
ReadPrec ExecutionMode
Int -> ReadS ExecutionMode
ReadS [ExecutionMode]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ExecutionMode]
$creadListPrec :: ReadPrec [ExecutionMode]
readPrec :: ReadPrec ExecutionMode
$creadPrec :: ReadPrec ExecutionMode
readList :: ReadS [ExecutionMode]
$creadList :: ReadS [ExecutionMode]
readsPrec :: Int -> ReadS ExecutionMode
$creadsPrec :: Int -> ReadS ExecutionMode
Read, Int -> ExecutionMode -> ShowS
[ExecutionMode] -> ShowS
ExecutionMode -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [ExecutionMode] -> ShowS
$cshowList :: [ExecutionMode] -> ShowS
show :: ExecutionMode -> [Char]
$cshow :: ExecutionMode -> [Char]
showsPrec :: Int -> ExecutionMode -> ShowS
$cshowsPrec :: Int -> ExecutionMode -> ShowS
Show)
$(deriveJSON defaultOptions ''ExecutionMode)
class HasExecutionMode s where
getExecutionMode :: s -> ExecutionMode
executionModePrettyPrint :: ExecutionMode -> BL.ByteString
executionModePrettyPrint :: ExecutionMode -> ByteString
executionModePrettyPrint ExecutionMode
Fail = ByteString
"Fail if output files exist."
executionModePrettyPrint ExecutionMode
Overwrite = ByteString
"Overwrite existing output files."
executionModePrettyPrint ExecutionMode
Continue = ByteString
"Expect output files exist."
openWithExecutionMode :: ExecutionMode -> FilePath -> IO Handle
openWithExecutionMode :: ExecutionMode -> [Char] -> IO Handle
openWithExecutionMode ExecutionMode
em [Char]
fn = do
Bool
fe <- [Char] -> IO Bool
doesFileExist [Char]
fn
case (ExecutionMode
em, Bool
fe) of
(ExecutionMode
Continue, Bool
False) ->
forall a. HasCallStack => [Char] -> a
error forall a b. (a -> b) -> a -> b
$ [Char]
"openWithExecutionMode: Cannot continue; file does not exist: " forall a. [a] -> [a] -> [a]
++ [Char]
fn forall a. [a] -> [a] -> [a]
++ [Char]
"."
(ExecutionMode
Continue, Bool
True) ->
[Char] -> IOMode -> IO Handle
openFile [Char]
fn IOMode
AppendMode
(ExecutionMode
Fail, Bool
True) ->
forall a. HasCallStack => [Char] -> a
error forall a b. (a -> b) -> a -> b
$ [Char]
"openWithExecutionMode: File exists: " forall a. [a] -> [a] -> [a]
++ [Char]
fn forall a. [a] -> [a] -> [a]
++ [Char]
"; use 'Overwrite'?"
(ExecutionMode, Bool)
_ -> do
Handle
h <- [Char] -> IOMode -> IO Handle
openFile [Char]
fn IOMode
WriteMode
Handle -> BufferMode -> IO ()
hSetBuffering Handle
h BufferMode
LineBuffering
forall (m :: * -> *) a. Monad m => a -> m a
return Handle
h
data ParallelizationMode
= Sequential
| Parallel
deriving (ParallelizationMode -> ParallelizationMode -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ParallelizationMode -> ParallelizationMode -> Bool
$c/= :: ParallelizationMode -> ParallelizationMode -> Bool
== :: ParallelizationMode -> ParallelizationMode -> Bool
$c== :: ParallelizationMode -> ParallelizationMode -> Bool
Eq, ReadPrec [ParallelizationMode]
ReadPrec ParallelizationMode
Int -> ReadS ParallelizationMode
ReadS [ParallelizationMode]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ParallelizationMode]
$creadListPrec :: ReadPrec [ParallelizationMode]
readPrec :: ReadPrec ParallelizationMode
$creadPrec :: ReadPrec ParallelizationMode
readList :: ReadS [ParallelizationMode]
$creadList :: ReadS [ParallelizationMode]
readsPrec :: Int -> ReadS ParallelizationMode
$creadsPrec :: Int -> ReadS ParallelizationMode
Read, Int -> ParallelizationMode -> ShowS
[ParallelizationMode] -> ShowS
ParallelizationMode -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [ParallelizationMode] -> ShowS
$cshowList :: [ParallelizationMode] -> ShowS
show :: ParallelizationMode -> [Char]
$cshow :: ParallelizationMode -> [Char]
showsPrec :: Int -> ParallelizationMode -> ShowS
$cshowsPrec :: Int -> ParallelizationMode -> ShowS
Show)
$(deriveJSON defaultOptions ''ParallelizationMode)
data SaveMode
=
NoSave
|
Save
deriving (SaveMode -> SaveMode -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: SaveMode -> SaveMode -> Bool
$c/= :: SaveMode -> SaveMode -> Bool
== :: SaveMode -> SaveMode -> Bool
$c== :: SaveMode -> SaveMode -> Bool
Eq, ReadPrec [SaveMode]
ReadPrec SaveMode
Int -> ReadS SaveMode
ReadS [SaveMode]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SaveMode]
$creadListPrec :: ReadPrec [SaveMode]
readPrec :: ReadPrec SaveMode
$creadPrec :: ReadPrec SaveMode
readList :: ReadS [SaveMode]
$creadList :: ReadS [SaveMode]
readsPrec :: Int -> ReadS SaveMode
$creadsPrec :: Int -> ReadS SaveMode
Read, Int -> SaveMode -> ShowS
[SaveMode] -> ShowS
SaveMode -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [SaveMode] -> ShowS
$cshowList :: [SaveMode] -> ShowS
show :: SaveMode -> [Char]
$cshow :: SaveMode -> [Char]
showsPrec :: Int -> SaveMode -> ShowS
$cshowsPrec :: Int -> SaveMode -> ShowS
Show)
$(deriveJSON defaultOptions ''SaveMode)
saveModePrettyPrint :: SaveMode -> BL.ByteString
saveModePrettyPrint :: SaveMode -> ByteString
saveModePrettyPrint SaveMode
NoSave = ByteString
"Do not save analysis."
saveModePrettyPrint SaveMode
Save = ByteString
"Save analysis."
data Settings = Settings
{ Settings -> AnalysisName
sAnalysisName :: AnalysisName,
Settings -> BurnInSettings
sBurnIn :: BurnInSettings,
Settings -> Iterations
sIterations :: Iterations,
Settings -> TraceLength
sTraceLength :: TraceLength,
Settings -> ExecutionMode
sExecutionMode :: ExecutionMode,
Settings -> ParallelizationMode
sParallelizationMode :: ParallelizationMode,
Settings -> SaveMode
sSaveMode :: SaveMode,
Settings -> LogMode
sLogMode :: LogMode,
Settings -> Verbosity
sVerbosity :: Verbosity
}
deriving (Settings -> Settings -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Settings -> Settings -> Bool
$c/= :: Settings -> Settings -> Bool
== :: Settings -> Settings -> Bool
$c== :: Settings -> Settings -> Bool
Eq, Int -> Settings -> ShowS
[Settings] -> ShowS
Settings -> [Char]
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
showList :: [Settings] -> ShowS
$cshowList :: [Settings] -> ShowS
show :: Settings -> [Char]
$cshow :: Settings -> [Char]
showsPrec :: Int -> Settings -> ShowS
$cshowsPrec :: Int -> Settings -> ShowS
Show)
instance HasAnalysisName Settings where
getAnalysisName :: Settings -> AnalysisName
getAnalysisName = Settings -> AnalysisName
sAnalysisName
instance HasExecutionMode Settings where
getExecutionMode :: Settings -> ExecutionMode
getExecutionMode = Settings -> ExecutionMode
sExecutionMode
instance HasLogMode Settings where
getLogMode :: Settings -> LogMode
getLogMode = Settings -> LogMode
sLogMode
instance HasVerbosity Settings where
getVerbosity :: Settings -> Verbosity
getVerbosity = Settings -> Verbosity
sVerbosity
$(deriveJSON defaultOptions ''Settings)
settingsFn :: String -> FilePath
settingsFn :: ShowS
settingsFn [Char]
n = [Char]
n forall a. [a] -> [a] -> [a]
++ [Char]
".mcmc.settings"
settingsSave :: Settings -> IO ()
settingsSave :: Settings -> IO ()
settingsSave Settings
s = [Char] -> ByteString -> IO ()
BL.writeFile [Char]
fn forall a b. (a -> b) -> a -> b
$ forall a. ToJSON a => a -> ByteString
encode Settings
s
where
fn :: [Char]
fn = ShowS
settingsFn forall a b. (a -> b) -> a -> b
$ AnalysisName -> [Char]
fromAnalysisName forall a b. (a -> b) -> a -> b
$ Settings -> AnalysisName
sAnalysisName Settings
s
settingsLoad :: AnalysisName -> IO Settings
settingsLoad :: AnalysisName -> IO Settings
settingsLoad (AnalysisName [Char]
n) = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either forall a. HasCallStack => [Char] -> a
error forall a. a -> a
id forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. FromJSON a => ByteString -> Either [Char] a
eitherDecode forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Char] -> IO ByteString
BL.readFile [Char]
fn
where
fn :: [Char]
fn = ShowS
settingsFn [Char]
n
settingsError :: Settings -> Int -> String -> a
settingsError :: forall a. Settings -> Int -> [Char] -> a
settingsError Settings
s Int
i [Char]
err =
forall a. HasCallStack => [Char] -> a
error forall a b. (a -> b) -> a -> b
$
forall a. Show a => a -> [Char]
show Settings
s
forall a. [a] -> [a] -> [a]
++ [Char]
"\n"
forall a. [a] -> [a] -> [a]
++ [Char]
"Current iteration: "
forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> [Char]
show Int
i
forall a. [a] -> [a] -> [a]
++ [Char]
"\n"
forall a. [a] -> [a] -> [a]
++ [Char]
"settingsError: "
forall a. [a] -> [a] -> [a]
++ [Char]
err
settingsCheck ::
Settings ->
Int ->
IO ()
settingsCheck :: Settings -> Int -> IO ()
settingsCheck s :: Settings
s@(Settings AnalysisName
nm BurnInSettings
bi Iterations
i TraceLength
tl ExecutionMode
em ParallelizationMode
_ SaveMode
_ LogMode
_ Verbosity
_) Int
iCurrent
| forall (t :: * -> *) a. Foldable t => t a -> Bool
null (AnalysisName -> [Char]
fromAnalysisName AnalysisName
nm) = forall {a}. [Char] -> a
serr [Char]
"Analysis name is the empty string."
| BurnInSettings -> Int
burnInIterations BurnInSettings
bi forall a. Ord a => a -> a -> Bool
< Int
0 = forall {a}. [Char] -> a
serr [Char]
"Number of burn in iterations is negative."
| Bool -> Bool
not forall a b. (a -> b) -> a -> b
$ BurnInSettings -> Bool
burnInValid BurnInSettings
bi = forall {a}. [Char] -> a
serr forall a b. (a -> b) -> a -> b
$ [Char]
"Burn in setting invalid: " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> [Char]
show BurnInSettings
bi forall a. Semigroup a => a -> a -> a
<> [Char]
"."
| Iterations -> Int
fromIterations Iterations
i forall a. Ord a => a -> a -> Bool
< Int
0 = forall {a}. [Char] -> a
serr [Char]
"Number of iterations is negative."
| BurnInSettings -> Int
burnInIterations BurnInSettings
bi forall a. Num a => a -> a -> a
+ Iterations -> Int
fromIterations Iterations
i forall a. Num a => a -> a -> a
- Int
iCurrent forall a. Ord a => a -> a -> Bool
< Int
0 =
forall {a}. [Char] -> a
serr [Char]
"Current iteration is larger than the total number of iterations."
| Bool -> Bool
not forall a b. (a -> b) -> a -> b
$ TraceLength -> Bool
validTraceLength TraceLength
tl = forall {a}. [Char] -> a
serr forall a b. (a -> b) -> a -> b
$ [Char]
"Trace length invalid: " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> [Char]
show TraceLength
tl forall a. Semigroup a => a -> a -> a
<> [Char]
"."
| Int
iCurrent forall a. Eq a => a -> a -> Bool
/= Int
0 Bool -> Bool -> Bool
&& ExecutionMode
em forall a. Eq a => a -> a -> Bool
/= ExecutionMode
Continue =
forall {a}. [Char] -> a
serr [Char]
"Current iteration is non-zero but execution mode is not 'Continue'."
| Int
iCurrent forall a. Eq a => a -> a -> Bool
== Int
0 Bool -> Bool -> Bool
&& ExecutionMode
em forall a. Eq a => a -> a -> Bool
== ExecutionMode
Continue =
forall {a}. [Char] -> a
serr [Char]
"Current iteration is zero but execution mode is 'Continue'."
| Bool
otherwise = forall (m :: * -> *) a. Monad m => a -> m a
return ()
where
serr :: [Char] -> a
serr = forall a. Settings -> Int -> [Char] -> a
settingsError Settings
s Int
iCurrent
logModePrettyPrint :: LogMode -> BL.ByteString
logModePrettyPrint :: LogMode -> ByteString
logModePrettyPrint LogMode
LogStdOutAndFile = ByteString
"Log to standard output and file."
logModePrettyPrint LogMode
LogStdOutOnly = ByteString
"Log to standard output only."
logModePrettyPrint LogMode
LogFileOnly = ByteString
"Log to file only."
settingsPrettyPrint :: Settings -> BL.ByteString
settingsPrettyPrint :: Settings -> ByteString
settingsPrettyPrint (Settings AnalysisName
nm BurnInSettings
bi Iterations
is TraceLength
tl ExecutionMode
em ParallelizationMode
pm SaveMode
sm LogMode
lm Verbosity
vb) =
[ByteString] -> ByteString
BL.unlines
[ ByteString
"The MCMC settings are:",
ByteString
" Analysis name: " forall a. Semigroup a => a -> a -> a
<> [Char] -> ByteString
BL.pack (AnalysisName -> [Char]
fromAnalysisName AnalysisName
nm) forall a. Semigroup a => a -> a -> a
<> ByteString
".",
ByteString
" Burn in: " forall a. Semigroup a => a -> a -> a
<> BurnInSettings -> ByteString
burnInPrettyPrint BurnInSettings
bi,
ByteString
" Iterations: " forall a. Semigroup a => a -> a -> a
<> Int -> ByteString
bsInt (Iterations -> Int
fromIterations Iterations
is) forall a. Semigroup a => a -> a -> a
<> ByteString
" iterations.",
ByteString
" Trace length: " forall a. Semigroup a => a -> a -> a
<> TraceLength -> ByteString
traceLengthPrettyPrint TraceLength
tl,
ByteString
" Execution mode: " forall a. Semigroup a => a -> a -> a
<> ExecutionMode -> ByteString
executionModePrettyPrint ExecutionMode
em,
ByteString
" Parallelization mode: " forall a. Semigroup a => a -> a -> a
<> [Char] -> ByteString
BL.pack (forall a. Show a => a -> [Char]
show ParallelizationMode
pm) forall a. Semigroup a => a -> a -> a
<> ByteString
".",
ByteString
" Save mode: " forall a. Semigroup a => a -> a -> a
<> SaveMode -> ByteString
saveModePrettyPrint SaveMode
sm,
ByteString
" Log mode: " forall a. Semigroup a => a -> a -> a
<> LogMode -> ByteString
logModePrettyPrint LogMode
lm,
ByteString
" Verbosity: " forall a. Semigroup a => a -> a -> a
<> [Char] -> ByteString
BL.pack (forall a. Show a => a -> [Char]
show Verbosity
vb) forall a. Semigroup a => a -> a -> a
<> ByteString
"."
]