-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ipynb benchmarking #2
Merged
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
576c91a
First draft
teubert 7730e61
Apply suggestions from code review
aqitya 8cdccb5
Update benchmarking.ipynb
aqitya 9682f08
Update benchmarking.ipynb
aqitya 130441e
Apply suggestions from code review
aqitya a210bf9
Apply suggestions from code review
aqitya 5309a9b
Apply suggestions from code review
aqitya 677ac7a
Update benchmarking.ipynb
aqitya bbe3e5b
Merge branch 'ipynb-benchmarking' of https://github.com/nasa/progpy i…
aqitya 51304e3
Merge branch 'dev' into ipynb-benchmarking
teubert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%matplotlib inline" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Welcome to ProgPy's Benchmarking Example" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"The goal of this notebook is to demonstrate the Benchmarking feature offered for Prognostic Models. Specifically, we will demonstrate how to benchmark the computational efficiency of models with a simple example." | ||
aqitya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"First, we need to import the necessary modules." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from prog_models.models import BatteryCircuit\n", | ||
aqitya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"from timeit import timeit" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"The first import is importing ProgPy's BatteryCircuit Model, and the second import will be used to benchmark our model!" | ||
aqitya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Next, let's initialize our Battery Circuit by creating a model object." | ||
aqitya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Step 1: Create a model object\n", | ||
"batt = BatteryCircuit()" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Then, for our model, we will need to define a future loading function. More information on what a future loading function is and how to use it can be found here: https://nasa.github.io/progpy/prog_models_guide.html#future-loading" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Since this is a simple example, we are going to have a constant loading!" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Step 2: Define future loading function \n", | ||
"loading = batt.InputContainer({'i': 2}) # Constant loading\n", | ||
"def future_loading(t, x=None):\n", | ||
" # Constant Loading\n", | ||
" return loading" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Finally, we are ready to benchmark the simulation.\n", | ||
"\n", | ||
"We can do this by using the `timeit()` function and pass in our `simulate_to()` or `simulate_to_threshold()` function for the `stmt` argument. For more information regarding the `timeit()` function, please read its documentation located here: https://docs.python.org/3/library/timeit.html" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Step 3: Benchmark simulation of 600 seconds\n", | ||
"def sim(): \n", | ||
" batt.simulate_to(600, future_loading)\n", | ||
"time = timeit(sim, number=500)" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"In this example, we are benchmarking the simulation for the BatteryCircuit model up to 600 seconds. Furthermore, we define our `number` argument to be 500 for sake of runtime." | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Let's print out the results of the benchmark test!" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Print results\n", | ||
"print('Simulation Time: {} ms/sim'.format(time))" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"In this example, we benchmarked the simulation of the BatteryCircuit model up to 600 seconds by utilizing the `time` package!" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.8" | ||
}, | ||
"orig_nbformat": 4 | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this supposed to show up at the top? (the answer might be yes, I'm not very familiar enough with jupyter notebooks)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically, no, but I think with how we are formatting the Jupyter Notebooks, we want that cell there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember us talking about it at one point in the past, but I can't remember why it's here. Can you explain it for me?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We mentioned how the automated notebooks had this at the top. But from what I can tell, this does not serve a purpose for us, so I'll remove this cell.