Skip to content

Commit

Permalink
update examples to 0.11.0 and bump version number
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-haessig committed Jul 30, 2024
1 parent ee94358 commit 26de0de
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 47 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "Microgrids"
uuid = "bd581358-d3fa-499e-a26e-e70307242c03"
authors = ["Pierre Haessig <pierre.haessig@centralesupelec.fr>",
"evelisea <59697806+evelisea@users.noreply.github.com>"]
version = "0.11.0-dev"
version = "0.11.0"

[compat]
julia = "1.6"
18 changes: 9 additions & 9 deletions examples/Microgrid_Wind-Solar.ipynb

Large diffs are not rendered by default.

81 changes: 44 additions & 37 deletions examples/Microgrid_sizing_optimization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"## Load Microgrid project data\n",
"\n",
"Loading parameters and time series for a Microgrid project with *wind* and *solar* sources, plus a *battery* and a *dispatchable generator*. \n",
"Values gathered from the [Microgrid_Wind-Solar.ipynb]((Microgrid_Wind-Solar.ipynb)) notebook."
"Values gathered from the [Microgrid_Wind-Solar.ipynb](Microgrid_Wind-Solar.ipynb) notebook."
]
},
{
Expand Down Expand Up @@ -91,9 +91,9 @@
"source": [
"## Setting up the cost function (criterion) to be optimized\n",
"\n",
"The key coding objective is to **encapsulate** the microgrid simulators (`simulate` function of `Microgrids.jl` package) into an objective function that can be called by the optimization algorithm, that is which respects its expected interface (here NLopt).\n",
"The key coding objective is to **encapsulate** the microgrid simulator (`simulate` function of `Microgrids.jl` package) into an objective function that can be called by the optimization algorithm, that is which respects its expected interface (here NLopt).\n",
"\n",
"To increase the modularity which facilites using optimization solvers others that NLopt's we implement the encapsulation by **3 nested functions**:\n",
"To increase the modularity which facilitates using optimization solvers others that NLopt's we implement the encapsulation by **3 nested functions**:\n",
"\n",
"1. Simulation of Microgrid project described by a sizing vector `x` (vector input) → returns all simulation statistics\n",
"2. Extract KPIs of interest to build a multi-objective criterion: here lcoe and shedding rate\n",
Expand Down Expand Up @@ -239,7 +239,7 @@
" stats, costs = simulate_microgrid(x)\n",
" # Extract KPIs of interest\n",
" lcoe = costs.lcoe # $/kWh\n",
" shed_rate = stats.shed_rate; # in [0,1]\n",
" shed_rate = stats.shed_rate # in [0,1]\n",
" return lcoe, shed_rate\n",
"end"
]
Expand All @@ -266,7 +266,7 @@
"\n",
"with signature adapted to NLopt with `grad` as 2nd argument\n",
"\n",
"load shedding penalty threshold `shed_max` should be in [0,1[\n",
"load shedding penalty threshold `shed_max` should be in [0,1[\n",
"\"\"\"\n",
"function obj(x, grad, shed_max, w_shed_max=1e5)\n",
" lcoe, shed_rate = obj_multi(x)\n",
Expand Down Expand Up @@ -473,7 +473,7 @@
"Problem bounds are taken as the global variables `xmin`, `xmax`,\n",
"but could be added to the parameters as well.\n",
"\"\"\"\n",
"function optim_mg(x0, shed_max, algo=:LN_SBPLX, maxeval=1000, xtol_rel=1e-4, srand=1)\n",
"function optim_mg(x0, shed_max, algo=:GN_CRS2_LM, maxeval=1000, xtol_rel=1e-4, srand=1)\n",
" nx = length(x0) # number of optim variables\n",
" opt = Opt(algo, nx)\n",
" NLopt.srand(srand)\n",
Expand Down Expand Up @@ -708,7 +708,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
" 1.967928 seconds (1.46 M allocations: 7.884 GiB, 6.18% gc time)\n"
" 2.021157 seconds (1.50 M allocations: 7.882 GiB, 3.09% gc time)\n"
]
},
{
Expand Down Expand Up @@ -746,7 +746,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
" 162.559 μs (143 allocations: 826.58 KiB)\n"
" 168.679 μs (147 allocations: 826.34 KiB)\n"
]
},
{
Expand All @@ -773,12 +773,12 @@
"\n",
"As demonstrated in our conference article:\n",
"\n",
"de Godoy Antunes, P. Haessig, C. Wang, and R. Chouhy Leborgne, “Optimal Microgrid Sizing using Gradient-based Algorithms with Automatic Differentiation,” ISGT Europe 2022, Novi Sad, Serbia, 2022. https://dx.doi.org/10.1109/ISGT-Europe54678.2022.9960498 https://hal.archives-ouvertes.fr/hal-03370004\n",
"de Godoy Antunes, P. Haessig, C. Wang, and R. Chouhy Leborgne, “Optimal Microgrid Sizing using Gradient-based Algorithms with Automatic Differentiation,” ISGT Europe 2022, Novi Sad, Serbia, 2022. https://dx.doi.org/10.1109/ISGT-Europe54678.2022.9960498, Archived at https://hal.archives-ouvertes.fr/hal-03370004\n",
"\n",
"Gradient of optimization criteria computed with [ForwardDiff.jl](https://juliadiff.org/ForwardDiff.jl/stable/).\n",
"This allows using **gradient-based optimization algorithms** like LBFGS or SLSQP (the latter supports constraints) which converge in less iterations.\n",
"\n",
"This requires using the \"relaxation parameter\" `ε` of the Microgrid simulator to smooth out some discontinuities.\n",
"This requires using the `smoothing` parameter (ε in the article is `Smoothing.transition`) of the Microgrid simulator to smooth out some discontinuities.\n",
"\n",
"DOCUMENTATION TO BE WRITTEN"
]
Expand All @@ -793,58 +793,65 @@
"name": "stdout",
"output_type": "stream",
"text": [
"search: \u001b[0m\u001b[1ma\u001b[22m\u001b[0m\u001b[1mg\u001b[22m\u001b[0m\u001b[1mg\u001b[22m\u001b[0m\u001b[1mr\u001b[22m\u001b[0m\u001b[1me\u001b[22m\u001b[0m\u001b[1mg\u001b[22m\u001b[0m\u001b[1ma\u001b[22m\u001b[0m\u001b[1mt\u001b[22m\u001b[0m\u001b[1mi\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1mn\u001b[22m \u001b[0m\u001b[1ma\u001b[22m\u001b[0m\u001b[1mg\u001b[22m\u001b[0m\u001b[1mg\u001b[22m\u001b[0m\u001b[1mr\u001b[22m\u001b[0m\u001b[1me\u001b[22m\u001b[0m\u001b[1mg\u001b[22m\u001b[0m\u001b[1ma\u001b[22m\u001b[0m\u001b[1mt\u001b[22me\n",
"search: \u001b[0m\u001b[1ms\u001b[22m\u001b[0m\u001b[1mi\u001b[22m\u001b[0m\u001b[1mm\u001b[22m\u001b[0m\u001b[1mu\u001b[22m\u001b[0m\u001b[1ml\u001b[22m\u001b[0m\u001b[1ma\u001b[22m\u001b[0m\u001b[1mt\u001b[22m\u001b[0m\u001b[1me\u001b[22m \u001b[0m\u001b[1ms\u001b[22m\u001b[0m\u001b[1mi\u001b[22m\u001b[0m\u001b[1mm\u001b[22m\u001b[0m\u001b[1mu\u001b[22m\u001b[0m\u001b[1ml\u001b[22m\u001b[0m\u001b[1ma\u001b[22m\u001b[0m\u001b[1mt\u001b[22m\u001b[0m\u001b[1me\u001b[22m_microgrid\n",
"\n"
]
},
{
"data": {
"text/latex": [
"\\begin{verbatim}\n",
"aggregation(mg::Microgrid, oper_traj::OperationTraj, ε::Real=1.0)\n",
"simulate(mg::Microgrid, smoothing::Smoothing=NoSmoothing)\n",
"\\end{verbatim}\n",
"Aggregates operation time series \\texttt{oper\\_traj} into yearly statistics for the the microgrid \\texttt{mg} (returned as an \\texttt{OperationStats} object).\n",
"Simulate the technical and economic performance of a Microgrid \\texttt{mg}.\n",
"\n",
"Discontinuous statistics can optionally be relaxed (smoothed) using the relaxation parameter \\texttt{ε}:\n",
"Discontinuous computations can optionally be smoothed (relaxed) using the \\texttt{Smoothing} parameters \\texttt{transition} and \\texttt{gain} (see their doc). Smoothing is recommended when using gradient-based optimization.\n",
"\n",
"Returns:\n",
"\n",
"\\begin{itemize}\n",
"\\item 0.0 means no relaxation (default value)\n",
"\\item Operational trajectories from \\texttt{sim\\_operation} (should be optional in future version)\n",
"\n",
"\n",
"\\item Operational statistics from \\texttt{sim\\_operation}\n",
"\n",
"\\item 1.0 yields the strongest relaxation\n",
"\n",
"\\end{itemize}\n",
"when using relaxation, a value between 0.05 and 0.30 is suggested\n",
"\n"
"\\item Microgrid project costs from \\texttt{sim\\_economics}\n",
"\n",
"\\end{itemize}\n"
],
"text/markdown": [
"```\n",
"aggregation(mg::Microgrid, oper_traj::OperationTraj, ε::Real=1.0)\n",
"simulate(mg::Microgrid, smoothing::Smoothing=NoSmoothing)\n",
"```\n",
"\n",
"Aggregates operation time series `oper_traj` into yearly statistics for the the microgrid `mg` (returned as an `OperationStats` object).\n",
"Simulate the technical and economic performance of a Microgrid `mg`.\n",
"\n",
"Discontinuous statistics can optionally be relaxed (smoothed) using the relaxation parameter `ε`:\n",
"Discontinuous computations can optionally be smoothed (relaxed) using the `Smoothing` parameters `transition` and `gain` (see their doc). Smoothing is recommended when using gradient-based optimization.\n",
"\n",
" * 0.0 means no relaxation (default value)\n",
" * 1.0 yields the strongest relaxation\n",
"Returns:\n",
"\n",
"when using relaxation, a value between 0.05 and 0.30 is suggested\n"
" * Operational trajectories from `sim_operation` (should be optional in future version)\n",
" * Operational statistics from `sim_operation`\n",
" * Microgrid project costs from `sim_economics`\n"
],
"text/plain": [
"\u001b[36m aggregation(mg::Microgrid, oper_traj::OperationTraj, ε::Real=1.0)\u001b[39m\n",
"\u001b[36m simulate(mg::Microgrid, smoothing::Smoothing=NoSmoothing)\u001b[39m\n",
"\n",
" Simulate the technical and economic performance of a Microgrid \u001b[36mmg\u001b[39m.\n",
"\n",
" Aggregates operation time series \u001b[36moper_traj\u001b[39m into yearly statistics for the\n",
" the microgrid \u001b[36mmg\u001b[39m (returned as an \u001b[36mOperationStats\u001b[39m object).\n",
" Discontinuous computations can optionally be smoothed (relaxed) using the\n",
" \u001b[36mSmoothing\u001b[39m parameters \u001b[36mtransition\u001b[39m and \u001b[36mgain\u001b[39m (see their doc). Smoothing is\n",
" recommended when using gradient-based optimization.\n",
"\n",
" Discontinuous statistics can optionally be relaxed (smoothed) using the\n",
" relaxation parameter \u001b[36mε\u001b[39m:\n",
" Returns:\n",
"\n",
" • 0.0 means no relaxation (default value)\n",
" • Operational trajectories from \u001b[36msim_operation\u001b[39m (should be optional in\n",
" future version)\n",
"\n",
"1.0 yields the strongest relaxation\n",
"Operational statistics from \u001b[36msim_operation\u001b[39m\n",
"\n",
" when using relaxation, a value between 0.05 and 0.30 is suggested"
" • Microgrid project costs from \u001b[36msim_economics\u001b[39m"
]
},
"execution_count": 18,
Expand All @@ -853,7 +860,7 @@
}
],
"source": [
"?aggregation"
"?simulate"
]
},
{
Expand Down Expand Up @@ -898,15 +905,15 @@
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.9.2",
"display_name": "Julia 1.10.4",
"language": "julia",
"name": "julia-1.9"
"name": "julia-1.10"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.9.2"
"version": "1.10.4"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 26de0de

Please sign in to comment.