Skip to content

Commit

Permalink
Merge pull request pybamm-team#3046 from pybamm-team/issue-1839-time-…
Browse files Browse the repository at this point in the history
…based-experiments

Fix failing notebook
  • Loading branch information
brosaplanella authored Jun 17, 2023
2 parents c2ca937 + 1996a11 commit abc53f5
Showing 1 changed file with 39 additions and 8 deletions.
47 changes: 39 additions & 8 deletions examples/notebooks/experiments-start-time.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
],
"source": [
"%pip install pybamm -q # install PyBaMM if it is not installed\n",
"import pybamm"
"import pybamm\n",
"from datetime import datetime"
]
},
{
Expand Down Expand Up @@ -77,7 +78,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5516f708a0264190a51d1811064afd82",
"model_id": "86a9137722254204893ad9cf3402c6df",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -91,7 +92,7 @@
{
"data": {
"text/plain": [
"<pybamm.plotting.quick_plot.QuickPlot at 0x7f3194e00eb0>"
"<pybamm.plotting.quick_plot.QuickPlot at 0x7f8910adb4f0>"
]
},
"execution_count": 3,
Expand Down Expand Up @@ -124,7 +125,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4832134ba802437e957ccdd5072d6d93",
"model_id": "a22e45e9e8ff46b194efe28b21f7a9a6",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -138,7 +139,7 @@
{
"data": {
"text/plain": [
"<pybamm.plotting.quick_plot.QuickPlot at 0x7f31943d3760>"
"<pybamm.plotting.quick_plot.QuickPlot at 0x7f8910b8e250>"
]
},
"execution_count": 4,
Expand All @@ -151,9 +152,9 @@
"\n",
"experiment = pybamm.Experiment(\n",
" [\n",
" s(\"Discharge at 1C for 1 hour\", start_time=\"Day 1 08:00:00\"),\n",
" s(\"Charge at C/3 for 10 minutes\", start_time=\"Day 1 08:30:00\"),\n",
" s(\"Discharge at C/2 for 30 minutes\", start_time=\"Day 1 09:00:00\"),\n",
" s(\"Discharge at 1C for 1 hour\", start_time=datetime(1, 1, 1, 8, 0, 0)),\n",
" s(\"Charge at C/3 for 10 minutes\", start_time=datetime(1, 1, 1, 8, 30, 0)),\n",
" s(\"Discharge at C/2 for 30 minutes\", start_time=datetime(1, 1, 1, 9, 0, 0)),\n",
" s(\"Rest for 1 hour\"),\n",
" ]\n",
")\n",
Expand All @@ -171,9 +172,39 @@
"In the example above, we note that the first step (1C discharge) is cut short as the second step (C/3 charge) start time occurs before the end of the first step. On the other hand, an additional resting period is added after the second step as the third step (C/2 discharge) start time is 20 minutes later than the end of the second step. The final step does not have a start time so it is triggered immediately after the previous step. Note that if the argument `start_time` is used in an experiment, the first step should always have a `start_time`, otherwise the solver will throw an error."
]
},
{
"attachments": {},
"cell_type": "markdown",
"id": "fff78a14",
"metadata": {},
"source": [
"Note that you can use the `datetime.strptime` (see [the docs](https://docs.python.org/3/library/datetime.html#datetime.datetime.strptime) for more info) function to convert a string to a datetime object. For example, to start the experiment at 8:30 on the 2nd of January 2023, you can use"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "bb616043",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"datetime.datetime(2023, 1, 2, 8, 30)"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"datetime.strptime(\"2023-01-02 8:30:00\", \"%Y-%m-%d %H:%M:%S\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "driven-sensitivity",
"metadata": {},
"outputs": [
Expand Down

0 comments on commit abc53f5

Please sign in to comment.