Skip to content
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

Initial commit for the Black Scholes devito example #1288

Merged
merged 9 commits into from May 26, 2020

Conversation

rawsh
Copy link
Contributor

@rawsh rawsh commented May 15, 2020

I've got a small notebook demonstrating using Devito to solve a PDE with nonzero boundary conditions, please take a look and let me know what you think. Thanks

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

Review Jupyter notebook visual diffs & provide feedback on notebooks.


Powered by ReviewNB

@codecov
Copy link

codecov bot commented May 15, 2020

Codecov Report

Merging #1288 into master will decrease coverage by 25.79%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff             @@
##           master    #1288       +/-   ##
===========================================
- Coverage   86.64%   60.85%   -25.80%     
===========================================
  Files         182      147       -35     
  Lines       26153    17140     -9013     
  Branches     3598     3054      -544     
===========================================
- Hits        22661    10431    -12230     
- Misses       3064     6167     +3103     
- Partials      428      542      +114     
Impacted Files Coverage Δ
benchmarks/user/tools/__init__.py 0.00% <0.00%> (-100.00%) ⬇️
benchmarks/user/tools/executor.py 0.00% <0.00%> (-83.79%) ⬇️
devito/core/autotuning.py 12.77% <0.00%> (-77.98%) ⬇️
devito/data/utils.py 18.34% <0.00%> (-74.24%) ⬇️
devito/mpi/routines.py 22.61% <0.00%> (-72.52%) ⬇️
devito/finite_differences/coefficients.py 18.34% <0.00%> (-70.45%) ⬇️
benchmarks/user/tools/driver.py 0.00% <0.00%> (-65.34%) ⬇️
examples/checkpointing/checkpoint.py 38.63% <0.00%> (-61.37%) ⬇️
devito/builtins.py 29.16% <0.00%> (-60.65%) ⬇️
benchmarks/user/benchmark.py 0.00% <0.00%> (-56.16%) ⬇️
... and 122 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e7e358e...1f1a02b. Read the comment docs.

@rhodrin
Copy link
Contributor

rhodrin commented May 15, 2020

@rawsh Thanks for this work and contribution. I'll take a good look through everything early next week.

@FabioLuporini
Copy link
Contributor

from a quick glance this looks awesome.
I've just registered the reviewers for this PR (including myself). I will take a proper look soon.

Thanks a lot for this!

examples/finance/bs_ivbp.ipynb Show resolved Hide resolved
examples/finance/bs_ivbp.ipynb Show resolved Hide resolved
examples/finance/bs_ivbp.ipynb Show resolved Hide resolved
examples/finance/bs_ivbp.ipynb Show resolved Hide resolved
@mloubout
Copy link
Contributor

This looks super cool overall, thanks a lot for contributing it to the examples. I left a few minor comments but great work.

examples/finance/bs_ivbp.ipynb Show resolved Hide resolved
examples/finance/bs_ivbp.ipynb Show resolved Hide resolved
examples/finance/bs_ivbp.ipynb Show resolved Hide resolved
@@ -0,0 +1,550 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for i in range(shape[0]):
   v.data[0, i] = max((smin + ds0 * i) - K, 0)

This can be done in one line right?


Reply via ReviewNB

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added another operator for the example without a boundary condition which added a line to the for loop so I left it how it was

Copy link
Contributor

@georgebisbas georgebisbas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for this contribution Robert. I think the notebook is in a very good shape already. A few minor fixes may be needed, but overall great work. Congrats!

Copy link
Collaborator

@jkwashbourne jkwashbourne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

I still think you need a little more exposition for the boundary conditions, as that is the heart of the success here. I also think you might consider adding an example of what happens when there is no boundary condition. so my suggestions:

  • set up two operators, one without the BC and one with
  • run both ops and contrast the results
  • add more exposition for the BC, maybe some ASCII art as below, with comments like "x in the interior (s < smax) and determed by the PDE", "o in the boundary (s >= smax) and determined by the BC using a Eq" ...
ASCII ART

                      |  o  v(t,smax+1)  
                      | /
                      |/
                      o  v(t,smax)  
                     /|
                    / |
      v(t,smax-1)  X  |
                  /   | BC: constant slope for v when s >= smax
                 /    | for 4th order derivative, need 2 points 
   v(t,smax-2)  X     |   slope = v(t,smax-1) - v(t,smax-2)
               /      |   v(t,smax)   = v(t,smax-1) + slope
              /       |   v(t,smax+1) = v(t,smax)   + slope
v(t,smax-2)  X        |
                      |
     interior         |        boundary 
    (s < smax)      smax      (s >= smax)

@jkwashbourne
Copy link
Collaborator

jkwashbourne commented May 18, 2020

Maybe you should also highlight how devito is stupid fast (your words) compared to the other solution. also ... needs units.

devito pde    timesteps:         2000,     0.029431 runtime
call_value_bs timesteps:            5,     3.802610 runtime

@jkwashbourne
Copy link
Collaborator

need to wrap the ASCII in three single quotes on blank lines both ends, per markdown code segment.

@jkwashbourne
Copy link
Collaborator

love the second example. suggest instead of "plateau", "fall incorrectly towards zero".

@FabioLuporini
Copy link
Contributor

you may also wanna update the README here: https://github.com/devitocodes/devito/tree/master/examples#how-to-navigate-this-directory

with info about this new "finance" subdirectory

"smin = 70\n",
"smax = 130\n",
"\n",
"# If you want to try some different problems, uncomment these lines\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to add a short description/explanation re. the various choices of constants?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robert you might add a link to the various papers we looked at to reproduce results.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an explanation. I added the papers I looked at that weren't behind paywalls (the 3 point approximation one I showed you is on research gate and I think the UNL math one is a better example anyway)

@rhodrin
Copy link
Contributor

rhodrin commented May 19, 2020

Very nice notebook, thanks for the contribution. Some nitpicking above.

@rawsh
Copy link
Contributor Author

rawsh commented May 20, 2020

Thank you for the comments! It was a fun notebook to work on.
@FabioLuporini I wasn't sure how to describe the finance directory but I added this for now:

finance: Jupyter notebooks with examples of applying Devito to partial differential equations with financial applications.

@FabioLuporini
Copy link
Contributor

OK, I think this is ready, but we need to add it to our Continuous Integration framework. This means two small things:

  • Add an entry here, along the lines of what we do for the other tutorials: https://github.com/devitocodes/devito/blob/master/.github/workflows/tutorials.yml#L104
  • Add the #NBVAL_IGNORE_OUTPUT comment at the top of each cell producing potentially non-determininstic output (e.g., an Operator that runs and produces the string "Operator run in 0.01 sec" (the next time could be 0.02); a cell producing a plot). Take a look here -- several cells start with NBVAL_IGNORE_OUTPUT

@jkwashbourne I think you're already familiar with this

@mloubout mloubout merged commit 5d80838 into devitocodes:master May 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants