-
Notifications
You must be signed in to change notification settings - Fork 245
examples: Refresh several notebooks in examples/ #2542
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
Open
georgebisbas
wants to merge
12
commits into
main
Choose a base branch
from
refresh_snapshotting
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
504aa89
examples: Refresh 08_snapshotting
georgebisbas 4bc5610
examples: Better parametrization and error messages
georgebisbas f2cb28b
examples: Update /examples/seismic/tutorials/08_snapshotting.ipynb
georgebisbas 394994b
examples: Minor edits
georgebisbas b85b2e3
examples: Update 13/15/16
georgebisbas 08c02b8
examples: Update bs_ivbp
georgebisbas b7b3eb5
examples: Rename black-scholes tutorial
georgebisbas 000aa9f
Revert "examples: Rename black-scholes tutorial"
georgebisbas fc1a2c9
examples: Update by comments
georgebisbas 74a8cd7
examples: Relax tolerance
georgebisbas 1ff03de
examples: Further reviews and updates
georgebisbas 016b17c
examples: More updates and fixes
georgebisbas 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 hidden or 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 |
|---|---|---|
|
|
@@ -27,23 +27,22 @@ | |
| "name": "stdout", | ||
| "output_type": "stream", | ||
| "text": [ | ||
| "dt,tmax,nt; 0.0005 1.0 2001\n", | ||
| "shape; (81,)\n", | ||
| "origin; (60,)\n", | ||
| "spacing; (1.0,)\n", | ||
| "extent; 80\n" | ||
| "dt,tmax,nt: 0.0005, 1.0, 2001\n", | ||
| "shape: (81,)\n", | ||
| "origin: (60,)\n", | ||
| "spacing: (1.0,)\n", | ||
| "extent: 80\n" | ||
| ] | ||
| } | ||
| ], | ||
georgebisbas marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why?
georgebisbas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| "source": [ | ||
| "from devito import (Eq, Grid, TimeFunction, Operator, solve, Constant, \n", | ||
| " SpaceDimension, configuration, SubDomain, centered)\n", | ||
| " SpaceDimension, configuration, centered)\n", | ||
| "\n", | ||
| "from mpl_toolkits.mplot3d import Axes3D\n", | ||
| "from mpl_toolkits.mplot3d.axis3d import Axis\n", | ||
| "import matplotlib.pyplot as plt\n", | ||
| "import matplotlib as mpl\n", | ||
| "from matplotlib import cm\n", | ||
| "\n", | ||
| "from sympy.stats import Normal, cdf\n", | ||
| "import numpy as np\n", | ||
|
|
@@ -101,11 +100,11 @@ | |
| "spacing = (ds0, )\n", | ||
| "extent = int(ds0 * (ns - 1))\n", | ||
| "\n", | ||
| "print(\"dt,tmax,nt;\", dt0,tmax,nt)\n", | ||
| "print(\"shape; \", shape)\n", | ||
| "print(\"origin; \", origin)\n", | ||
| "print(\"spacing; \", spacing)\n", | ||
| "print(\"extent; \", extent)" | ||
| "print(f\"dt,tmax,nt: {dt0}, {tmax}, {nt}\")\n", | ||
| "print(f\"shape: {shape}\")\n", | ||
| "print(f\"origin: {origin}\")\n", | ||
| "print(f\"spacing: {spacing}\")\n", | ||
| "print(f\"extent: {extent}\")" | ||
| ] | ||
| }, | ||
| { | ||
|
|
@@ -242,8 +241,8 @@ | |
| "name": "stderr", | ||
| "output_type": "stream", | ||
| "text": [ | ||
| "Operator `Kernel` run in 0.01 s\n", | ||
| "Operator `Kernel` run in 0.01 s\n" | ||
| "Operator `Kernel` ran in 0.01 s\n", | ||
| "Operator `Kernel` ran in 0.01 s\n" | ||
| ] | ||
| }, | ||
| { | ||
|
|
@@ -263,7 +262,7 @@ | |
| "\n", | ||
| "# Run our operators\n", | ||
| "startDevito = timer.time()\n", | ||
| " \n", | ||
| "\n", | ||
| "# Apply operator\n", | ||
| "op.apply(dt=dt0)\n", | ||
| "\n", | ||
|
|
@@ -293,7 +292,7 @@ | |
| "#NBVAL_IGNORE_OUTPUT\n", | ||
| "\n", | ||
| "# Get an appropriate ylimit\n", | ||
| "slice_smax = v.data[:,int(smax-smin-padding)]\n", | ||
| "slice_smax = v.data[:, int(smax-smin-padding)]\n", | ||
| "ymax = max(slice_smax) + 2\n", | ||
| "\n", | ||
| "# Plot\n", | ||
|
|
@@ -477,8 +476,8 @@ | |
| "name": "stdout", | ||
| "output_type": "stream", | ||
| "text": [ | ||
| "devito pde timesteps: 2000, 0.205647s runtime\n", | ||
| "call_value_bs timesteps: 5, 3.813932s runtime\n" | ||
| "devito pde timesteps: 2000, 0.019737s runtime\n", | ||
| "call_value_bs timesteps: 5, 2.596800s runtime\n" | ||
| ] | ||
| }, | ||
| { | ||
|
|
@@ -501,10 +500,10 @@ | |
| "# https://aaronschlegel.me/black-scholes-formula-python.html\n", | ||
| "def call_value_bs(S, K, T, r, sigma):\n", | ||
| " N = Normal('x', 0.0, 1.0)\n", | ||
| " \n", | ||
| "\n", | ||
| " d1 = (np.log(S / K) + (r + 0.5 * sigma ** 2) * T) / (sigma * np.sqrt(T))\n", | ||
| " d2 = (np.log(S / K) + (r - 0.5 * sigma ** 2) * T) / (sigma * np.sqrt(T))\n", | ||
| " \n", | ||
| "\n", | ||
| " call = (S * cdf(N)(d1) - K * np.exp(-r * T) * cdf(N)(d2))\n", | ||
| " return call\n", | ||
| "\n", | ||
|
|
@@ -563,7 +562,7 @@ | |
| { | ||
| "data": { | ||
| "text/plain": [ | ||
| "[<matplotlib.lines.Line2D at 0x7f5495584640>]" | ||
| "[<matplotlib.lines.Line2D at 0x7fe2669fda50>]" | ||
| ] | ||
| }, | ||
| "execution_count": 9, | ||
|
|
@@ -587,8 +586,8 @@ | |
| "#NBVAL_IGNORE_OUTPUT\n", | ||
| "\n", | ||
| "# Plot the l2 norm of the formula and our solution over time\n", | ||
| "t_range = np.linspace(dt0,1.0,50)\n", | ||
| "x_range = range(padding, smax-smin-padding*2, 1)\n", | ||
| "t_range = np.linspace(dt0, 1.0, 50)\n", | ||
| "x_range = range(padding, smax-smin-padding*2, 1)\n", | ||
| "vals = []\n", | ||
| "\n", | ||
| "for t in t_range:\n", | ||
|
|
@@ -600,7 +599,7 @@ | |
| "\n", | ||
| " rms = np.sqrt(np.float64(l2 / len(x_range)))\n", | ||
| " vals.append(rms)\n", | ||
| " \n", | ||
| "\n", | ||
| "plt.figure(figsize=(12,10))\n", | ||
| "plt.plot(t_range, np.array(vals))" | ||
| ] | ||
|
|
@@ -609,22 +608,11 @@ | |
| "cell_type": "code", | ||
| "execution_count": 10, | ||
| "metadata": {}, | ||
| "outputs": [ | ||
| { | ||
| "data": { | ||
| "text/plain": [ | ||
| "0.00581731890853893" | ||
| ] | ||
| }, | ||
| "execution_count": 10, | ||
| "metadata": {}, | ||
| "output_type": "execute_result" | ||
| } | ||
| ], | ||
| "outputs": [], | ||
| "source": [ | ||
| "#NBVAL_IGNORE_OUTPUT\n", | ||
| "\n", | ||
| "np.mean(vals)" | ||
| "assert np.isclose(np.mean(vals), 0.005885, rtol=1e-2)\n" | ||
| ] | ||
| }, | ||
| { | ||
|
|
||
This file contains hidden or 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
This file contains hidden or 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
10,323 changes: 3,337 additions & 6,986 deletions
10,323
examples/seismic/tutorials/08_snapshotting.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Should this notebook be renamed "01_black_scholes" for consistency with other tutorials?
Reply via ReviewNB
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 would be happy with that