"# Script to optimize the simulation parameters for a water quality model in MIKE+\n",
"\n",
"The nevergrad package is used for optimization.\n",
"\n",
"Note: \n",
"- mikepluspy requires a full license for mike+ to run. In many cases the seat of the license is not properly released; closing python and waiting some time should fix this.\n",
"- With multithreading results may take some time to show up in the output, even if the cell is supposed to be completed.\n",
"\n",
"Other scripts to run:\n",
"- first run optim_prep if wanted\n",
"- scripts creates the reference data and also the optimn_parts excel which contains the timeframes for the optimization\n",
"\n",
"Things to do in MIKE+:\n",
"\n",
"Water quality models:\n",
"- activate Transport in \"Model Type\"\n",
"- Set at least one WQ component\n",
"- Set the SWQ advanced methods\n",
"- double check on the method unter Build up wash off\n",
"- check WQ boundary conditions and that the WQ component is the WQ component set above\n",
"- activate Transport in Simulation setup\n",
"\n",
"\n",
"Sediment transport models:\n",
"- activate Sediment Transport in \"Model Type\"\n",
"- set all relevant parameters under sediment transport \n",
" General Parameters: Density and porosity \n",
" Sediment fractions: Insert a new Fraction and use a cohesive sediment fraction as non cohesive are not fully supported yet \n",
"- change WQ boundary conditions to type \"Sediment concentration\" and type in the name of the sediment transport component defined above\n",
"- under SWQ advanced methods: Change surface load type to \"Sediment\" and choose the method you want to use\n",
"- check that the result files of ST save the concentration\n",
"- run all models with the ST results to get the test results for the script below\n",
"- check the optimn_parts excel and make sure the results files are the ST files and that the column name is changed to concentration\n",
"- activate Sediment Transport in Simulation setup"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# import packages\n",
"import typing\n",
"import datetime\n",
"import shutil\n",
"from time import sleep\n",
"from warnings import warn\n",
"from pathlib import Path\n",
"import typing\n",
"import mikeio\n",
"import numpy as np\n",
"import pandas as pd\n",
"import nevergrad as ng\n",
"import matplotlib as mpl\n",
"import matplotlib.pyplot as plt\n",
"from tqdm.notebook import tqdm\n",
"import IPython.display as idsp\n",
"\n",
"# import simulation scripts from the project ENTfrachtEN\n",
# Script to optimize the simulation parameters for a water quality model in MIKE+
The nevergrad package is used for optimization.
Note:
- mikepluspy requires a full license for mike+ to run. In many cases the seat of the license is not properly released; closing python and waiting some time should fix this.
- With multithreading results may take some time to show up in the output, even if the cell is supposed to be completed.
Other scripts to run:
- first run optim_prep if wanted
- scripts creates the reference data and also the optimn_parts excel which contains the timeframes for the optimization
Things to do in MIKE+:
Water quality models:
- activate Transport in "Model Type"
- Set at least one WQ component
- Set the SWQ advanced methods
- double check on the method unter Build up wash off
- check WQ boundary conditions and that the WQ component is the WQ component set above
- activate Transport in Simulation setup
Sediment transport models:
- activate Sediment Transport in "Model Type"
- set all relevant parameters under sediment transport
General Parameters: Density and porosity
Sediment fractions: Insert a new Fraction and use a cohesive sediment fraction as non cohesive are not fully supported yet
- change WQ boundary conditions to type "Sediment concentration" and type in the name of the sediment transport component defined above
- under SWQ advanced methods: Change surface load type to "Sediment" and choose the method you want to use
- check that the result files of ST save the concentration
- run all models with the ST results to get the test results for the script below
- check the optimn_parts excel and make sure the results files are the ST files and that the column name is changed to concentration
- activate Sediment Transport in Simulation setup
%% Cell type:code id: tags:
``` python3
# import packages
import typing
import datetime
import shutil
from time import sleep
from warnings import warn
from pathlib import Path
import typing
import mikeio
import numpy as np
import pandas as pd
import nevergrad as ng
import matplotlib as mpl
import matplotlib.pyplot as plt
from tqdm.notebook import tqdm
import IPython.display as idsp
# import simulation scripts from the project ENTfrachtEN
from entfrachten.optim import simulation, loss_functions, optim_dumper
```
%% Cell type:markdown id: tags:
## Constants, you should not need to adjust these, unless you are debugging.
%% Cell type:code id: tags:
``` python3
# output heaps of additional data, may be useful for debugging
VERBOSE_OUTPUT = False
# delete the temp folder at end
DELETE_TEMP = True
```
%% Cell type:markdown id: tags:
## Constants, you should adjust
%% Cell type:code id: tags:
``` python3
# Number of simulations allowed for optimization
optimization_budget = 100
# Number of seats for the Engine, limits amount of simulations we can run at once. Default of MIKE+ Licence is 4
engine_seats = 4
# set a correation factor to multiply the data of the measurements if necessary. Default 1. ENTfrachtEN wastewater = 3.3757
factor_underestimation = 1
# time string for temp and output folder
# if temp_folder exists, this script tries to continue the optimization.
# Note that continuing the optimization does not check whether settings match;
# do not change anything when continuing an optimization run!