Commit c9e0d309 authored by niklas.baumgarten's avatar niklas.baumgarten
Browse files

Merge branch 'feature' into 'master'

Feature

See merge request mpp/mlmc!27
parents bb84c0fa 5ffb5a1e
Pipeline #148475 passed with stages
in 65 minutes and 10 seconds
...@@ -53,24 +53,44 @@ mpitest-mlmc: ...@@ -53,24 +53,44 @@ mpitest-mlmc:
tags: [ docker ] tags: [ docker ]
elliptic-exercises-mlmc: elliptic-experiments-mlmc:
stage: experiments stage: experiments
variables: variables:
GIT_STRATEGY: none GIT_STRATEGY: none
RUN_EXPERIMENTS: '' RUN_EXPERIMENTS: ''
image: ${REGISTRY}/${IMAGE_NAME_MLMC} image: ${REGISTRY}/${IMAGE_NAME_MLMC}
timeout: '1h' timeout: '1h'
only: #only:
variables: [ $RUN_EXPERIMENTS == 'all', $RUN_EXPERIMENTS == 'elliptic' ] # variables: [ $RUN_EXPERIMENTS == 'all', $RUN_EXPERIMENTS == 'elliptic' ]
script: script:
- cd /mpp/notebooks - cd /mpp/notebooks
- ls -al - ls -al
- jupyter nbconvert --ExecutePreprocessor.timeout=2400 - jupyter nbconvert --ExecutePreprocessor.timeout=2400
--execute --to html Elliptic\ Experiments.ipynb --execute --to html Elliptic\ Experiments.ipynb
- cp Elliptic\ Experiments.html $CI_PROJECT_DIR/
dependencies: [ "build-mlmc" ] dependencies: [ "build-mlmc" ]
tags: [ docker ] tags: [ docker ]
artifacts: artifacts:
paths: [ notebooks/Elliptic\ Experiments.html ] paths: [ Elliptic\ Experiments.html ]
elliptic-experiments-mlmc2:
stage: experiments
variables:
GIT_STRATEGY: none
RUN_EXPERIMENTS: ''
image: ${REGISTRY}/${IMAGE_NAME_MLMC}
timeout: '1h'
script:
- cd /mpp/notebooks
- ls -al
- jupyter nbconvert --ExecutePreprocessor.timeout=2400
--execute --to html Elliptic\ Experiments\ 2.ipynb
- cp Elliptic\ Experiments\ 2.html $CI_PROJECT_DIR/
dependencies: [ "build-mlmc" ]
tags: [ docker ]
artifacts:
paths: [ Elliptic\ Experiments\ 2.html ]
deploy-mlmc: deploy-mlmc:
......
...@@ -2,9 +2,11 @@ cmake_minimum_required(VERSION 3.5.1) ...@@ -2,9 +2,11 @@ cmake_minimum_required(VERSION 3.5.1)
project(MLMC) project(MLMC)
set(SPACE_DIM 2 CACHE STRING "SPACE_DIM") set(SPACE_DIM 2 CACHE STRING "SPACE_DIM")
set(USE_FFTW ON CACHE STRING "USE_FFTW")
set(USE_SPLITTED_COMMS ON CACHE STRING "USE_SPLITTED_COMMS")
set(USE_SPACETIME OFF CACHE STRING "USE_SPACETIME") set(USE_SPACETIME OFF CACHE STRING "USE_SPACETIME")
set(COMPILER_OPTIMIZE -O0 CACHE STRING "COMPILER_OPTIMIZE") #set(COMPILER_OPTIMIZE -O0 CACHE STRING "COMPILER_OPTIMIZE")
#set(COMPILER_OPTIMIZE -O3 CACHE STRING "COMPILER_OPTIMIZE") set(COMPILER_OPTIMIZE -O3 CACHE STRING "COMPILER_OPTIMIZE")
set(NO_DEPRECATED OFF CACHE STRING "NO_DEPRECATED") set(NO_DEPRECATED OFF CACHE STRING "NO_DEPRECATED")
set(AFFINE_LINEAR_TRAFO ON CACHE STRING "AFFINE_LINEAR_TRAFO") set(AFFINE_LINEAR_TRAFO ON CACHE STRING "AFFINE_LINEAR_TRAFO")
set(BUILD_TESTS OFF CACHE STRING "BUILD_TESTS") set(BUILD_TESTS OFF CACHE STRING "BUILD_TESTS")
......
# ----- Problem Settings ----- # ----- Problem Settings -----
Experiment = MLMCExperiment
#Experiment = ConvergenceTest
#Problem = StochasticLaplace1D #Problem = StochasticLaplace1D
Problem = StochasticLaplace2D Problem = StochasticLaplace2D
Model = LagrangeElliptic Model = LagrangeElliptic
#Model = MixedElliptic #Model = MixedElliptic
#Model = HybridElliptic #Model = HybridElliptic
#Model = DGElliptic #Model = DGElliptic
degree = 1 degree = 1
plevel = 2 #degree = 2
Quantity = L2 Quantity = L2
#Functional = Energy #Functional = Energy
#Funcitonal = H1 #Funcitonal = H1
...@@ -21,44 +15,30 @@ Quantity = L2 ...@@ -21,44 +15,30 @@ Quantity = L2
# ----- Multilevel Monte Carlo ----- # ----- Multilevel Monte Carlo -----
maxLevel = 7 maxLevel = 7
MCParallel = false
epsilon = 0.01 epsilon = 0.01
onlyFine = false onlyFine = false
initLevels = [3, 4, 5] initLevels = [3, 4, 5]
initSampleAmount = [12, 6, 3] initSampleAmount = [12, 6, 3]
uniformSampleAmount = 500
# ----- Stochastic Field ----- # ----- Stochastic Field -----
StochasticField = LogNormal StochasticField = LogNormal
mean = 0.0 Mean = 0.0
sigma = 1.0 sigma = 1.0
norm_p = 2
lambda = [0.15, 0.15] lambda = [0.15, 0.15]
smoothing = 1.8 smoothing = 1.0
evtol = 1e-10
# ----- Solver -----
LinearReduction = 1e-12
LinearEpsilon = 1e-10
LinearSteps = 3000
NewtonSteps = 1
NewtonLineSearchSteps = 0
# ----- Plotting ----- # ----- Plotting -----
GeneratorPlotting = 0 PDESolverPlotting = 0
MCPlotting = 0
# ----- Verbose ----- # ----- Verbose -----
MCVerbose = 1 MCVerbose = 1
PDEVerbose = 1 MLMCVerbose = 1
MainVerbose = 1 MainVerbose = 1
MeshVerbose = 1 MeshVerbose = 1
MLMCVerbose = 1
ConfigVerbose = 1 ConfigVerbose = 1
LinearVerbose = 1 LinearVerbose = 0
NewtonVerbose = 1 NewtonVerbose = 0
AssembleVerbose = 0
PDESolverVerbose = 0
GeneratorVerbose = 0 GeneratorVerbose = 0
# ----- Logging -----
TimeLevel = -1
MuteLevel = -1
DebugLevel = -1
\ No newline at end of file
# ----- Problem Settings ----- # ----- Problem Settings -----
Experiment = MLMCExperiment
#Experiment = ConvergenceTest
#Problem = StochasticPollution1D #Problem = StochasticPollution1D
#Problem = StochasticPollutionCosHat1D #Problem = StochasticPollutionCosHat1D
#Problem = StochasticPollution2D #Problem = StochasticPollution2D
#Problem = StochasticPollutionCosHat2D #Problem = StochasticPollutionCosHat2D
Problem = StochasticPollutionMollifiedBar2D Problem = StochasticGaussHat2D
Model = DGTransport Model = DGTransport
#Model = PGTransport #Model = PGTransport
#degree = 0
#degree = 1
degree = 2
Functional = Mass
#Funcitonal = Energy
#Functional = Outflow
Overlap = dG1 Overlap = dG1
flux_alpha = 1 #Upwind: 1, Central: 0 flux_alpha = 1 #Upwind: 1, Central: 0
# Streamline diffusion parameter # Streamline diffusion parameter
degree = 2
plevel = 2
Functional = Mass
#Funcitonal = Energy
#Functional = Outflow
# ----- Time Series ----- # ----- Time Series -----
useDGTimeIntegrator = 0; useDGTimeIntegrator = 0;
...@@ -36,45 +34,30 @@ Keps = 1e-5 ...@@ -36,45 +34,30 @@ Keps = 1e-5
# ----- Multilevel Monte Carlo ----- # ----- Multilevel Monte Carlo -----
maxLevel = 7 maxLevel = 7
MCParallel = false
epsilon = 0.01 epsilon = 0.01
mcOnly = false onlyFine = false
initLevels = [4, 5, 6] initLevels = [3, 4, 5]
initSampleAmount = [8, 4, 2] initSampleAmount = [12, 6, 3]
uniformSampleAmount = 100
# ----- Stochastic Field ----- # ----- Stochastic Field -----
StochasticField = LogNormal StochasticField = LogNormal
mean = 1.0 Mean = 0.0
sigma = 1.0 sigma = 1.0
norm_p = 2 lambda = [0.15, 0.15]
lambda1 = 0.10 smoothing = 1.0
lambda2 = 0.10
smoothing = 1.9
evtol = 1e-10
# ----- Solver -----
LinearReduction = 1e-12
LinearEpsilon = 1e-10
LinearSteps = 3000
NewtonSteps = 1
NewtonLineSearchSteps = 0
# ----- Plotting ----- # ----- Plotting -----
GeneratorPlotting = 1 PDESolverPlotting = 1
MCPlotting = 1
# ----- Verbose ----- # ----- Verbose -----
MCVerbose = 1 MCVerbose = 1
PDEVerbose = 1
MainVerbose = 1
MLMCVerbose = 1 MLMCVerbose = 1
ConfigVerbose = 0 MainVerbose = 1
LinearVerbose = -1 MeshVerbose = 1
NewtonVerbose = 1 ConfigVerbose = 1
GeneratorVerbose = 1 LinearVerbose = 0
TimeIntegratorVerbose = 1 NewtonVerbose = 0
AssembleVerbose = 0
# ----- Logging ----- PDESolverVerbose = 0
TimeLevel = -1 GeneratorVerbose = 0
MuteLevel = -1
DebugLevel = -1
\ No newline at end of file
...@@ -47,8 +47,7 @@ NewtonSteps = 1 ...@@ -47,8 +47,7 @@ NewtonSteps = 1
NewtonLineSearchSteps = 0 NewtonLineSearchSteps = 0
# ----- Plotting ----- # ----- Plotting -----
GeneratorPlotting = 1 PDESolverPlotting = 1
MCPlotting = 1
# ----- Verbose ----- # ----- Verbose -----
MCVerbose = 1 MCVerbose = 1
......
...@@ -2,6 +2,7 @@ include_directories(basics) ...@@ -2,6 +2,7 @@ include_directories(basics)
add_subdirectory(basics) add_subdirectory(basics)
include_directories(generators) include_directories(generators)
include_directories(generators/algorithms)
add_subdirectory(generators) add_subdirectory(generators)
include_directories(problems) include_directories(problems)
......
#include "m++.hpp" #include "m++.hpp"
#include "Main.hpp" #include "Main.hpp"
#ifdef COMPLEX #ifdef COMPLEX
#error undef COMPLEX in src/Compiler.h #error undef COMPLEX in src/Compiler.h
#endif #endif
...@@ -10,6 +11,11 @@ int main(int argc, char **argv) { ...@@ -10,6 +11,11 @@ int main(int argc, char **argv) {
Config::setConfigFileName("m++.conf"); Config::setConfigFileName("m++.conf");
Mpp::initialize(&argc, argv); Mpp::initialize(&argc, argv);
if(!PowerOfTwo(PPM->Size(0))) {
Warning("Number of process is not a power of 2."
"This might lead to undefined behaviour.")
}
MainProgram mainProgram; MainProgram mainProgram;
return mainProgram.Run(); return mainProgram.Run();
} }
...@@ -4,6 +4,12 @@ ...@@ -4,6 +4,12 @@
#include "montecarlo/MultilevelMonteCarlo.hpp" #include "montecarlo/MultilevelMonteCarlo.hpp"
bool PowerOfTwo(int n) {
if(n==0) return false;
return (ceil(log2(n)) == floor(log2(n)));
}
class MainProgram { class MainProgram {
private: private:
int verbose = 1; int verbose = 1;
...@@ -11,11 +17,12 @@ private: ...@@ -11,11 +17,12 @@ private:
public: public:
MultilevelMonteCarlo mlmc; MultilevelMonteCarlo mlmc;
MainProgram() : mlmc(MultilevelMonteCarlo()){ MainProgram() : mlmc(MultilevelMonteCarlo()) {
config.get("MainVerbose", verbose); config.get("MainVerbose", verbose);
} }
int Run() { int Run() {
config.PrintInfo();
mout.StartBlock("MLMC Experiment"); mout.StartBlock("MLMC Experiment");
mout << "Run" << endl; mout << "Run" << endl;
mlmc.Method(); mlmc.Method();
......
add_library(BASICS STATIC add_library(BASICS STATIC
Level.cpp Level.cpp
Sample.cpp
PlotMap.cpp
Utilities.cpp Utilities.cpp
) )
target_link_libraries(BASICS fftw3 MPP_LIBRARIES) target_link_libraries(BASICS MPP_LIBRARIES)
\ No newline at end of file \ No newline at end of file
#include "Level.hpp" #include "Level.hpp"
void Level::Update(int level) {
fine = level;
coarse = level - 1;
if (coarse < 0) coarse = 0;
pLevel = coarse;
}
bool Level::operator==(const Level &level) const {
if (this->fine != level.fine)
return false;
if (this->coarse != level.coarse)
return false;
if (this->pLevel != level.pLevel)
return false;
return true;
}
bool Level::operator==(int level) const {
if (this->fine != level)
return false;
return true;
}
bool Level::operator!=(const Level &level) const {
return !(*this == level);
}
bool Level::operator!=(int level) const {
return !(*this == level);
}
bool Level::operator<=(const Level &level) const {
if (this->fine < level.fine) return true;
else return false;
}
bool Level::operator>=(const Level &level) const {
if (this->fine > level.fine) return true;
else return false;
}
bool Level::operator<(const Level &level) const {
if (this->fine < level.fine) return true;
else return false;
}
bool Level::operator>(const Level &level) const {
if (this->fine > level.fine) return true;
else return false;
}
bool Level::operator<(int level) const {
if (this->fine < level) return true;
else return false;
}
bool Level::operator>(int level) const {
if (this->fine > level) return true;
else return false;
}
bool Level::operator<=(int level) const {
if (this->fine <= level) return true;
else return false;
}
bool Level::operator>=(int level) const {
if (this->fine >= level) return true;
else return false;
}
#ifndef LEVEL_HPP #ifndef LEVEL_HPP
#define LEVEL_HPP #define LEVEL_HPP
#include "Logging.hpp"
#include <vector> #include <vector>
#include <map> #include <map>
/*
* Todo
* Only Fine true: pLevel = fine = coarse
* Only Fine false: plevel = coarse, fine = coarse + 1
*
* Add commSplit to Level
*/
struct Level {
int fine;
int coarse;
int pLevel;
Level() {}
explicit Level(int level) {
Update(level);
}
void Update(int level);
int ActualLevel(bool getCoarse) const {
if (!getCoarse) return fine;
else return coarse;
};
bool operator==(const Level &level) const;
bool operator==(int level) const;
bool operator!=(const Level &level) const;
bool operator!=(int level) const;
bool operator<=(const Level &level) const;
bool operator>=(const Level &level) const;
bool operator<(const Level &level) const;
bool operator>(const Level &level) const;
bool operator<(int level) const;
bool operator>(int level) const;
bool operator<=(int level) const;
bool operator>=(int level) const;
};
/* /*
* Todo: * Todo:
* * make second key template for degree * * idea: make second key template for degree
* to realize MultidegreeMonteCarlo * to realize MultidegreeMonteCarlo
* * also key (thus Level) should include proc information * && ?
*/ */
template<typename T> template<typename T>
struct LevelMap { struct LevelMap {
protected: protected:
std::map<Level, T> _levelMap; std::map<int, T> _levelMap;
public: public:
LevelMap() {}; LevelMap() {};
LevelMap(std::initializer_list<std::pair<Level, T>> levelMap) { LevelMap(std::initializer_list<std::pair<int, T>> levelMap) {
for (std::pair<Level, T> pair : levelMap) { for (std::pair<int, T> pair : levelMap) {
_levelMap.emplace(pair.first, T(pair.second)); _levelMap.emplace(pair.first, T(pair.second));
} }
} }
...@@ -80,7 +30,7 @@ public: ...@@ -80,7 +30,7 @@ public:
std::vector<int> GetLevelVector() const { std::vector<int> GetLevelVector() const {
std::vector<int> levelVector; std::vector<int> levelVector;
for (auto &&[level, entry]: _levelMap) for (auto &&[level, entry]: _levelMap)
levelVector.push_back(level.fine); levelVector.push_back(level);
return levelVector; return levelVector;
} }
...@@ -123,7 +73,7 @@ public: ...@@ -123,7 +73,7 @@ public:
auto clear() { _levelMap.clear(); } auto clear() { _levelMap.clear(); }
auto insert(std::pair<Level, T> pair) { _levelMap.insert(pair); } auto insert(std::pair<int, T> pair) { _levelMap.insert(pair); }
auto begin() { return _levelMap.begin(); } auto begin() { return _levelMap.begin(); }
...@@ -141,11 +91,20 @@ public: ...@@ -141,11 +91,20 @@ public:
auto rend() const { return _levelMap.end(); } auto rend() const { return _levelMap.end(); }
auto operator[](Level level) { return _levelMap[level]; } auto operator[](int level) { return _levelMap[level]; }
auto at(Level level) { return _levelMap.at(level); } auto at(int level) { return _levelMap.at(level); }
auto find(Level level) { return _levelMap.find(level); } auto find(int level) { return _levelMap.find(level); }