Copyright | Copyright (c) 2012-2017 David Sorokin <david.sorokin@gmail.com> |
---|---|
License | BSD3 |
Maintainer | David Sorokin <david.sorokin@gmail.com> |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Tested with: GHC 8.0.1
The module defines the simulation experiments. They automate the process of generating and analyzing the results. Moreover, this module is open to extensions, allowing you to define your own output views for the simulation results, for example, such views that would allow saving the results in PDF or as charts. To decrease the number of dependencies, such possible extenstions are not included in this package, although simple views are provided.
Synopsis
- data Experiment = Experiment {}
- defaultExperiment :: Experiment
- class ExperimentRendering r where
- data ExperimentContext r :: *
- type ExperimentEnvironment r :: *
- type ExperimentMonad r :: * -> *
- liftExperiment :: r -> ExperimentMonad r a -> IO a
- prepareExperiment :: Experiment -> r -> ExperimentMonad r (ExperimentEnvironment r)
- renderExperiment :: Experiment -> r -> [ExperimentReporter r] -> ExperimentEnvironment r -> ExperimentMonad r ()
- onExperimentCompleted :: Experiment -> r -> ExperimentEnvironment r -> ExperimentMonad r ()
- onExperimentFailed :: Exception e => Experiment -> r -> ExperimentEnvironment r -> e -> ExperimentMonad r ()
- data ExperimentGenerator r = ExperimentGenerator {
- generateReporter :: Experiment -> r -> ExperimentEnvironment r -> ExperimentMonad r (ExperimentReporter r)
- class ExperimentRendering r => ExperimentView v r where
- outputView :: v -> ExperimentGenerator r
- data ExperimentData = ExperimentData {}
- data ExperimentReporter r = ExperimentReporter {
- reporterInitialise :: ExperimentMonad r ()
- reporterFinalise :: ExperimentMonad r ()
- reporterSimulate :: ExperimentData -> Composite ()
- reporterContext :: ExperimentContext r
- runExperiment :: (ExperimentRendering r, Monad (ExperimentMonad r), MonadIO (ExperimentMonad r), MonadException (ExperimentMonad r)) => Experiment -> [ExperimentGenerator r] -> r -> Simulation Results -> IO (Either SomeException ())
- runExperimentParallel :: (ExperimentRendering r, Monad (ExperimentMonad r), MonadIO (ExperimentMonad r), MonadException (ExperimentMonad r)) => Experiment -> [ExperimentGenerator r] -> r -> Simulation Results -> IO (Either SomeException ())
- runExperimentWithExecutor :: (ExperimentRendering r, Monad (ExperimentMonad r), MonadIO (ExperimentMonad r), MonadException (ExperimentMonad r)) => ([IO ()] -> IO a) -> Experiment -> [ExperimentGenerator r] -> r -> Simulation Results -> IO (Either SomeException a)
Documentation
data Experiment Source #
It defines the simulation experiment with the specified rendering backend and its bound data.
Experiment | |
|
defaultExperiment :: Experiment Source #
The default experiment.
class ExperimentRendering r where Source #
It allows rendering the simulation results in an arbitrary way.
data ExperimentContext r :: * Source #
Defines a context used when rendering the experiment.
type ExperimentEnvironment r :: * Source #
Defines the experiment environment.
type ExperimentMonad r :: * -> * Source #
Defines the experiment monad type.
liftExperiment :: r -> ExperimentMonad r a -> IO a Source #
Lift the experiment computation.
prepareExperiment :: Experiment -> r -> ExperimentMonad r (ExperimentEnvironment r) Source #
Prepare before rendering the experiment.
renderExperiment :: Experiment -> r -> [ExperimentReporter r] -> ExperimentEnvironment r -> ExperimentMonad r () Source #
Render the experiment after the simulation is finished, for example,
creating the index.html
file in the specified directory.
onExperimentCompleted :: Experiment -> r -> ExperimentEnvironment r -> ExperimentMonad r () Source #
It is called when the experiment has been completed.
onExperimentFailed :: Exception e => Experiment -> r -> ExperimentEnvironment r -> e -> ExperimentMonad r () Source #
It is called when the experiment rendering has failed.
Instances
data ExperimentGenerator r Source #
This is a generator of the reporter with the specified rendering backend.
ExperimentGenerator | |
|
class ExperimentRendering r => ExperimentView v r where Source #
Defines a view in which the simulation results should be saved. You should extend this type class to define your own views such as the PDF document.
outputView :: v -> ExperimentGenerator r Source #
Create a generator of the reporter.
Instances
data ExperimentData Source #
It describes the source simulation data used in the experiment.
ExperimentData | |
|
data ExperimentReporter r Source #
Defines what creates the simulation reports by the specified renderer.
ExperimentReporter | |
|
:: (ExperimentRendering r, Monad (ExperimentMonad r), MonadIO (ExperimentMonad r), MonadException (ExperimentMonad r)) | |
=> Experiment | the simulation experiment to run |
-> [ExperimentGenerator r] | generators used for rendering |
-> r | the rendering backend |
-> Simulation Results | the simulation results received from the model |
-> IO (Either SomeException ()) |
Run the simulation experiment sequentially. For example,
it can be a Monte-Carlo simulation dependentent on the external
Parameter
values.
runExperimentParallel Source #
:: (ExperimentRendering r, Monad (ExperimentMonad r), MonadIO (ExperimentMonad r), MonadException (ExperimentMonad r)) | |
=> Experiment | the simulation experiment to run |
-> [ExperimentGenerator r] | generators used for rendering |
-> r | the rendering backend |
-> Simulation Results | the simulation results received from the model |
-> IO (Either SomeException ()) |
Run the simulation experiment in parallel.
Make sure that you compile with -threaded
and supply +RTS -N2 -RTS
to the generated Haskell executable on dual core processor,
or you won't get any parallelism. Generally, the mentioned
N
parameter should correspond to the number of cores for
your processor.
In case of need you might want to specify the number of
threads directly with help of experimentNumCapabilities
,
although the real number of parallel threads can depend on many
factors.
runExperimentWithExecutor Source #
:: (ExperimentRendering r, Monad (ExperimentMonad r), MonadIO (ExperimentMonad r), MonadException (ExperimentMonad r)) | |
=> ([IO ()] -> IO a) | an executor that allows parallelizing the simulation if required |
-> Experiment | the simulation experiment to run |
-> [ExperimentGenerator r] | generators used for rendering |
-> r | the rendering backend |
-> Simulation Results | the simulation results received from the model |
-> IO (Either SomeException a) |
Run the simulation experiment with the specified executor.