Skip to content

Commit 0bd0686

Browse files
committed
fixed first three tutorials and improved plotting facilities
1 parent 04d1062 commit 0bd0686

File tree

12 files changed

+4188
-225
lines changed

12 files changed

+4188
-225
lines changed

docs/conf.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,16 @@ def get_latest_git_tag():
6767
# The master toctree document.
6868
master_doc = "index"
6969

70-
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
70+
exclude_patterns = ["_build", "experimental_tutorials", "Thumbs.db", ".DS_Store"]
7171

7272
pygments_style = "default"
7373
pygments_dark_style = "gruvbox-dark"
7474

7575
# -- Options for HTML output ------
7676
html_theme = "furo"
77+
78+
# Configure JavaScript files for Plotly support
79+
html_js_files = [
80+
"require.min.js",
81+
"custom.js",
82+
]

docs/datasets.rst

Lines changed: 0 additions & 95 deletions
This file was deleted.
File renamed without changes.

docs/tutorials/1_first_steps.ipynb

Lines changed: 4005 additions & 12 deletions
Large diffs are not rendered by default.

docs/tutorials/2_signals_and_datasets.ipynb

Lines changed: 18 additions & 47 deletions
Large diffs are not rendered by default.

docs/tutorials/3_controller.ipynb

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,14 @@
7474
"metadata": {},
7575
"outputs": [
7676
{
77-
"name": "stderr",
78-
"output_type": "stream",
79-
"text": [
80-
"2024-06-21 11:43:37.514 | INFO | mosaik.scenario:start:311 - Starting \"Actor\" as \"ComputingSystem-0\" ...\n",
81-
"2024-06-21 11:43:37.515 | INFO | mosaik.scenario:start:311 - Starting \"Actor\" as \"solar\" ...\n",
82-
"2024-06-21 11:43:37.516 | INFO | mosaik.scenario:start:311 - Starting \"Grid\" as \"Grid-0\" ...\n",
83-
"2024-06-21 11:43:37.516 | INFO | mosaik.scenario:start:311 - Starting \"Controller\" as \"Monitor-0\" ...\n",
84-
"2024-06-21 11:43:37.517 | INFO | mosaik.scenario:start:311 - Starting \"Controller\" as \"SimpleLoadBalancingController-0\" ...\n",
85-
"2024-06-21 11:43:37.518 | INFO | mosaik.scenario:start:311 - Starting \"Storage\" as \"Storage-0\" ...\n",
86-
"2024-06-21 11:43:37.519 | INFO | mosaik.scenario:run:651 - Starting simulation.\n",
87-
"100%|\u001b[32m██████████\u001b[0m| 86400/86400 [00:01<00:00, 51383.86steps/s]\n",
88-
"2024-06-21 11:43:39.203 | INFO | mosaik.scenario:run:708 - Simulation finished successfully.\n"
77+
"ename": "AttributeError",
78+
"evalue": "module 'vessim' has no attribute 'ComputingSystem'",
79+
"output_type": "error",
80+
"traceback": [
81+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
82+
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
83+
"Cell \u001b[0;32mIn[3], line 11\u001b[0m\n\u001b[1;32m 7\u001b[0m monitor \u001b[38;5;241m=\u001b[39m vs\u001b[38;5;241m.\u001b[39mMonitor() \u001b[38;5;66;03m# Stores simulation result on each step\u001b[39;00m\n\u001b[1;32m 8\u001b[0m load_balancer \u001b[38;5;241m=\u001b[39m SimpleLoadBalancingController(nodes\u001b[38;5;241m=\u001b[39mnodes)\n\u001b[1;32m 9\u001b[0m environment\u001b[38;5;241m.\u001b[39madd_microgrid(\n\u001b[1;32m 10\u001b[0m actors\u001b[38;5;241m=\u001b[39m[\n\u001b[0;32m---> 11\u001b[0m \u001b[43mvs\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mComputingSystem\u001b[49m(nodes\u001b[38;5;241m=\u001b[39mnodes, pue\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1.6\u001b[39m),\n\u001b[1;32m 12\u001b[0m vs\u001b[38;5;241m.\u001b[39mActor(\n\u001b[1;32m 13\u001b[0m name\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124msolar\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 14\u001b[0m signal\u001b[38;5;241m=\u001b[39mvs\u001b[38;5;241m.\u001b[39mTrace\u001b[38;5;241m.\u001b[39mload(\n\u001b[1;32m 15\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124msolcast2022_global\u001b[39m\u001b[38;5;124m\"\u001b[39m, column\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mBerlin\u001b[39m\u001b[38;5;124m\"\u001b[39m, params\u001b[38;5;241m=\u001b[39m{\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mscale\u001b[39m\u001b[38;5;124m\"\u001b[39m: \u001b[38;5;241m5000\u001b[39m}\n\u001b[1;32m 16\u001b[0m ),\n\u001b[1;32m 17\u001b[0m ),\n\u001b[1;32m 18\u001b[0m ],\n\u001b[1;32m 19\u001b[0m storage\u001b[38;5;241m=\u001b[39mvs\u001b[38;5;241m.\u001b[39mSimpleBattery(capacity\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m500\u001b[39m, initial_soc\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m0.8\u001b[39m),\n\u001b[1;32m 20\u001b[0m controllers\u001b[38;5;241m=\u001b[39m[monitor, load_balancer],\n\u001b[1;32m 21\u001b[0m step_size\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m60\u001b[39m, \u001b[38;5;66;03m# Global step size (can be overridden by actors or controllers)\u001b[39;00m\n\u001b[1;32m 22\u001b[0m )\n\u001b[1;32m 24\u001b[0m environment\u001b[38;5;241m.\u001b[39mrun(until\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m24\u001b[39m \u001b[38;5;241m*\u001b[39m \u001b[38;5;241m3600\u001b[39m) \u001b[38;5;66;03m# 24h\u001b[39;00m\n\u001b[1;32m 25\u001b[0m monitor\u001b[38;5;241m.\u001b[39mto_csv(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mresult.csv\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n",
84+
"\u001b[0;31mAttributeError\u001b[0m: module 'vessim' has no attribute 'ComputingSystem'"
8985
]
9086
}
9187
],
@@ -126,9 +122,53 @@
126122
},
127123
{
128124
"cell_type": "code",
125+
"execution_count": null,
129126
"metadata": {},
130127
"outputs": [],
131-
"source": "import pandas as pd\nimport plotly.graph_objects as go\n\ndf = pd.read_csv(\"result.csv\", parse_dates=[0], index_col=0)\n# divide e_delta by step size because e_delta is energy\ndf[\"grid_power\"] = df[\"e_delta\"] / 60\n\n# Create the plot\nfig = go.Figure()\n\n# Add grid power trace\nfig.add_trace(go.Scatter(\n x=df.index, \n y=df[\"grid_power\"], \n mode='lines',\n name=\"Grid Power\",\n line=dict(color=\"blue\")\n))\n\n# Add solar power trace\nfig.add_trace(go.Scatter(\n x=df.index, \n y=df[\"solar.p\"], \n mode='lines',\n name=\"Solar\",\n line=dict(color=\"orange\")\n))\n\n# Update layout\nfig.update_layout(\n title=\"Load Balancing Controller - Grid and Solar Power Over Time\",\n xaxis_title=\"Time\",\n yaxis_title=\"Power (W)\",\n hovermode='x unified',\n showlegend=True,\n margin=dict(l=0, t=40, b=0, r=0)\n)\n\n# Update x-axis to show hours\nfig.update_xaxes(tickformat=\"%H\")\n\nfig.show()"
128+
"source": [
129+
"import pandas as pd\n",
130+
"import plotly.graph_objects as go\n",
131+
"\n",
132+
"df = pd.read_csv(\"result.csv\", parse_dates=[0], index_col=0)\n",
133+
"# divide e_delta by step size because e_delta is energy\n",
134+
"df[\"grid_power\"] = df[\"e_delta\"] / 60\n",
135+
"\n",
136+
"# Create the plot\n",
137+
"fig = go.Figure()\n",
138+
"\n",
139+
"# Add grid power trace\n",
140+
"fig.add_trace(go.Scatter(\n",
141+
" x=df.index, \n",
142+
" y=df[\"grid_power\"], \n",
143+
" mode='lines',\n",
144+
" name=\"Grid Power\",\n",
145+
" line=dict(color=\"blue\")\n",
146+
"))\n",
147+
"\n",
148+
"# Add solar power trace\n",
149+
"fig.add_trace(go.Scatter(\n",
150+
" x=df.index, \n",
151+
" y=df[\"solar.p\"], \n",
152+
" mode='lines',\n",
153+
" name=\"Solar\",\n",
154+
" line=dict(color=\"orange\")\n",
155+
"))\n",
156+
"\n",
157+
"# Update layout\n",
158+
"fig.update_layout(\n",
159+
" title=\"Load Balancing Controller - Grid and Solar Power Over Time\",\n",
160+
" xaxis_title=\"Time\",\n",
161+
" yaxis_title=\"Power (W)\",\n",
162+
" hovermode='x unified',\n",
163+
" showlegend=True,\n",
164+
" margin=dict(l=0, t=40, b=0, r=0)\n",
165+
")\n",
166+
"\n",
167+
"# Update x-axis to show hours\n",
168+
"fig.update_xaxes(tickformat=\"%H\")\n",
169+
"\n",
170+
"fig.show()"
171+
]
132172
}
133173
],
134174
"metadata": {
@@ -147,9 +187,9 @@
147187
"name": "python",
148188
"nbconvert_exporter": "python",
149189
"pygments_lexer": "ipython3",
150-
"version": "3.8.19"
190+
"version": "3.10.4"
151191
}
152192
},
153193
"nbformat": 4,
154194
"nbformat_minor": 4
155-
}
195+
}

pyproject.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,12 @@ docs = [
6060
"nbsphinx",
6161
"pandoc",
6262
"ipython",
63-
"matplotlib",
64-
"windpowerlib"
63+
"plotly",
6564
]
6665
examples = [
6766
"jupyter",
6867
"nbconvert",
69-
"matplotlib",
70-
"windpowerlib"
68+
"plotly",
7169
]
7270

7371

vessim/__init__.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,3 @@
3131
__all__.extend(["Broker", "SilController", "WatttimeSignal", "get_latest_event"])
3232
except ImportError:
3333
pass
34-
35-
try:
36-
from vessim import plot # noqa: F401
37-
38-
__all__.extend(["plot"])
39-
except ImportError:
40-
pass

0 commit comments

Comments
 (0)