Skip to content

Commit

Permalink
minor changes in tutorials for docs
Browse files Browse the repository at this point in the history
  • Loading branch information
birnbaum committed Mar 13, 2024
1 parent a9b366d commit 112c742
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 59 deletions.
9 changes: 5 additions & 4 deletions docs/tutorials/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ Tutorials
=========

.. toctree::
:maxdepth: 1

signal_example
basic_example
controller_example
sil_example
signal_example
basic_example
controller_example
sil_example


.. note::
Expand Down
79 changes: 34 additions & 45 deletions examples/controller_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,31 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Controller Scenario\n",
"# Controllers\n",
"\n",
"In this scenario we want to continue our small datacenter from the basic\n",
"scenario by adding a Controller entity. This Controller will adjust the power\n",
"consumption of the computing system's nodes depending on the current power\n",
"delta. We can easily create a new Controller by subclassing the `Controller` ABC\n",
"from `vessim.controller`."
"To actively manipulate the computing or energy systems during experiments, we need to implement a custom `Controller`.\n",
"\n",
"In this example, our controller will adjust the power consumption of the compute nodes depending on the current power delta. "
]
},
{
"cell_type": "raw",
"metadata": {
"raw_mimetype": "text/restructuredtext"
},
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
".. automodule:: vessim.controller\n",
" :members: Controller\n",
" :noindex:"
"from __future__ import annotations\n",
"from vessim.actor import ComputingSystem, Generator\n",
"from vessim.controller import Controller, Monitor\n",
"from vessim.cosim import Environment, Microgrid\n",
"from vessim.power_meter import MockPowerMeter\n",
"from vessim.signal import HistoricalSignal\n",
"from vessim.storage import SimpleBattery\n",
"from vessim.util import Clock\n",
"\n",
"# Hotfix to execute asyncio in Jupyter\n",
"import nest_asyncio\n",
"nest_asyncio.apply()"
]
},
{
Expand All @@ -39,35 +46,17 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from __future__ import annotations\n",
"from vessim.actor import ComputingSystem, Generator\n",
"from vessim.controller import Controller, Monitor\n",
"from vessim.cosim import Environment, Microgrid\n",
"from vessim.power_meter import MockPowerMeter\n",
"from vessim.signal import HistoricalSignal\n",
"from vessim.storage import SimpleBattery\n",
"from vessim.util import Clock\n",
"\n",
"# Jupyter async bug fix\n",
"import nest_asyncio\n",
"nest_asyncio.apply()\n",
"\n",
"\n",
"class SimpleLoadBalancingController(Controller):\n",
" def __init__(self, max_load_adjustment: float, power_meters: list[MockPowerMeter]):\n",
" super().__init__()\n",
" self.max_load_adjustment = max_load_adjustment\n",
" self.power_meters = power_meters\n",
"\n",
" def start(\n",
" self,\n",
" microgrid: Microgrid,\n",
" clock: Clock,\n",
" ) -> None:\n",
" def start(self, microgrid, clock) -> None:\n",
" pass\n",
"\n",
" def step(self, time: int, p_delta: float, actor_infos: dict) -> None:\n",
Expand Down Expand Up @@ -96,21 +85,21 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[32m2024-02-17 16:56:23.507\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36mmosaik.scenario\u001b[0m:\u001b[36mstart\u001b[0m:\u001b[36m280\u001b[0m - \u001b[1mStarting \"Grid\" as \"Grid-0\" ...\u001b[0m\n",
"\u001b[32m2024-02-17 16:56:23.508\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36mmosaik.scenario\u001b[0m:\u001b[36mstart\u001b[0m:\u001b[36m280\u001b[0m - \u001b[1mStarting \"Actor\" as \"Actor-0\" ...\u001b[0m\n",
"\u001b[32m2024-02-17 16:56:23.508\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36mmosaik.scenario\u001b[0m:\u001b[36mstart\u001b[0m:\u001b[36m280\u001b[0m - \u001b[1mStarting \"Actor\" as \"Actor-1\" ...\u001b[0m\n",
"\u001b[32m2024-02-17 16:56:23.509\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36mmosaik.scenario\u001b[0m:\u001b[36mstart\u001b[0m:\u001b[36m280\u001b[0m - \u001b[1mStarting \"Controller\" as \"Controller-0\" ...\u001b[0m\n",
"\u001b[32m2024-02-17 16:56:23.509\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36mmosaik.scenario\u001b[0m:\u001b[36mstart\u001b[0m:\u001b[36m280\u001b[0m - \u001b[1mStarting \"Controller\" as \"Controller-1\" ...\u001b[0m\n",
"\u001b[32m2024-02-17 16:56:23.511\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36mmosaik.scenario\u001b[0m:\u001b[36mrun\u001b[0m:\u001b[36m598\u001b[0m - \u001b[1mStarting simulation.\u001b[0m\n",
"100%|\u001b[32m██████████\u001b[0m| 86400/86400 [00:00<00:00, 135641.36steps/s]\n",
"\u001b[32m2024-02-17 16:56:24.151\u001b[0m | \u001b[1mINFO \u001b[0m | \u001b[36mmosaik.scenario\u001b[0m:\u001b[36mrun\u001b[0m:\u001b[36m646\u001b[0m - \u001b[1mSimulation finished successfully.\u001b[0m\n"
"2024-03-13 16:39:11.892 | INFO | mosaik.scenario:start:280 - Starting \"Actor\" as \"Actor-0\" ...\n",
"2024-03-13 16:39:11.894 | INFO | mosaik.scenario:start:280 - Starting \"Actor\" as \"Actor-1\" ...\n",
"2024-03-13 16:39:11.895 | INFO | mosaik.scenario:start:280 - Starting \"Grid\" as \"Grid-0\" ...\n",
"2024-03-13 16:39:11.897 | INFO | mosaik.scenario:start:280 - Starting \"Controller\" as \"Controller-0\" ...\n",
"2024-03-13 16:39:11.898 | INFO | mosaik.scenario:start:280 - Starting \"Controller\" as \"Controller-1\" ...\n",
"2024-03-13 16:39:11.900 | INFO | mosaik.scenario:run:598 - Starting simulation.\n",
"100%|\u001b[32m███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████\u001b[0m| 86400/86400 [00:01<00:00, 86236.91steps/s]\u001b[0m\n",
"2024-03-13 16:39:12.904 | INFO | mosaik.scenario:run:646 - Simulation finished successfully.\n"
]
}
],
Expand Down Expand Up @@ -140,7 +129,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -154,9 +143,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.1"
"version": "3.8.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
19 changes: 9 additions & 10 deletions examples/sil_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"# Software-in-the-Loop (SiL) Example\n",
"# Software-in-the-Loop\n",
"\n",
"NOTE: Software-in-the-Loop interfaces as well as documentation are in alpha stage.\n",
"\n",
"Vessim supports the integration of non-simulated, real components. In this\n",
"example, we introduce a simple node that imitates workload and feeds its power\n",
"consumption to the Computing System Actor, while sitll running independently\n",
"from the simulation. \n",
"Vessim supports the integration of real applications running on hardware or virtualized environments.\n",
"\n",
"The use of Vessim's `SilController` is essential to facilitate communication\n",
"between Vessim and the Sil component:\n"
"In this example, we introduce a simple node that imitates workload and periodically communicates its power consumption to the `ComputingSystem` actor. \n",
"\n",
"For this, we can utilize Vessim's `SilController`:\n"
]
},
{
Expand Down Expand Up @@ -261,7 +260,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -275,9 +274,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.1"
"version": "3.8.12"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}

0 comments on commit 112c742

Please sign in to comment.