sympy / scipy-2017-codegen-tutorial

SymPy code generation tutorial at SciPy 2017
http://www.sympy.org/scipy-2017-codegen-tutorial/
Other
61 stars 26 forks source link

General comments on notebooks #5

Closed moorepants closed 6 years ago

moorepants commented 7 years ago

general

25 chemical kinetics intro

32 chemical kinetics

int add(double first_array[10], double second_array[10], double result[10]){
    for (i = 0; i < n, i++) {
        result[i] = first_array[i] + second_array[i];
        }

or have this as an exercise, i.e. have them create their own vectorized function

~/miniconda3/envs/codegen17/lib/python3.6/site-packages/scipy2017codegen/chem.py in load_large_ode() 32 file_path = os.path.join(os.path.dirname(file), 'data', 33 'radiolysis_300_Gy_s.json') ---> 34 with open(file_path) as f: 35 ode_def_dict = json.load(f) 36 eqs, states = mk_exprs_symbs(ode_def_dict['reactions'],

FileNotFoundError: [Errno 2] No such file or directory: '/home/moorepants/miniconda3/envs/codegen17/lib/python3.6/site-packages/scipy2017codegen/data/radiolysis_300_Gy_s.json'


- show off the files that are generated so that people can see the translation,
  `!cat odes.c`
- maybe it is worth creating the cython pyx file and compiling the cython
  extension manually to show how that happen, then say "autowrap" does all this
  for you
- %time seems more appropriate than %timeit for the odeint calls since they
  take some time to run a lot of them
asmeurer commented 7 years ago

Heads up, my main focus right now is the release, so I may be slow in fixing the things for my notebooks.

is the llvm printer available to show?

The LLVM printer is a bit weird. It doesn't actually create a string. Rather, it creates an LLVM jit callable directly from llvmlite objects. The theanocode printer is similar actually.

it is unfortunate we don't really have a python printer

Agree. It wouldn't be hard to start doing a cleanup of lambdify moving the translations into the printers. Worth doing for the release?

a simple exercise would be to list a bunch of mathematical expressions in the mardown cell and ask them to try printing them with different languages

Good idea.

there are other interesting things to show here to like piecewise printing, indexed types that will print to loops, printing matrices, assignment, and different printer options

I'll add those. Also Piecewise is a good thing to show in the intro notebook.

custom functions

What do you mean here?

labmdify needs some explanation on the first use. the name is confusing and i don't think anyone will know what it is doing. it would be worth spend some time explaining what lambdify does with simple examples here, then you can let them try to use lambdify to convert the ODE rhs to a numerical function as an exercise. explain why it is called lambdify and show a simple lambda function.

Yes, I was just thinking this. It isn't even clear that lambdify is code generation. Honestly, I think it's worth explaining exactly how lambdify works. The better you understand exactly what it does, the better you can utilize it.

what about a vectorized operation for the example cython intro code. this would essentially show them what ufuncify does behind the scenes. this would be a function more like:

ufuncify is a bit more complicated than this (it specifically fits the ufunc API, which lets it get broadcasting).

i suggest we leave these out or have them as special extra topics, as they are outside the original scope of the proposal

100% agree on symengine, which is still early work anyway. But for numba, I think we should show that you can wrap lambdify in numba.jit to make it faster. It's literally just two extra cells, and it could just be a section at the bottom of an existing notebook. There's no need to have a whole separate notebook for it.

codegen and autowrap don't work with array inputs, would be nice if they did

Let's not use autowrap for anything ever. As far as I'm concerned, autowrap should be deprecated in favor of ufuncify. The only reason you might ever want to use it is if you know you never care about vectorization, you only care about Python's float (no numpy data types), and want to get rid of a little bit of Python overhead. Neither of those conditions are really worth it in my view, and they definitely don't make it worth showing in the tutorial.