new Jupyter Notebook (feedback welcome)

5 views
Skip to first unread message

kirby urner

unread,
Jun 11, 2016, 3:21:47 PM6/11/16
to mathf...@googlegroups.com
(goes to nbviewer, a public renderer of Jupyter Notebooks saved elsewhere -- in this case at my Github account)

Kirby

@thekirbster


kirby urner

unread,
Jun 12, 2016, 1:57:50 AM6/12/16
to mathf...@googlegroups.com

I was "dogfooding" today, in practicing the skills mentioned below. [1]

http://mybizmo.blogspot.com/2016/06/success.html

* Got 3D graphics to show up in a Jupyter Notebook.

* Tested XYZ and IVM (i.e. q-ray) coordinates for inter-conversion and cube_volume vs. tetra_volume validation checks.

Kirby

PS:  I had a good meetup with Bradford here in Greater Portland on Friday

[1]  https://en.wikipedia.org/wiki/Eating_your_own_dog_food


Peter Farrell

unread,
Jun 12, 2016, 3:15:46 PM6/12/16
to MathFuture
Good work! Very powerful technology, Jupyter. Your examples are very clear. Is the __repr__ method what makes the class a decorator?

Joseph Austin

unread,
Jun 12, 2016, 3:42:43 PM6/12/16
to mathf...@googlegroups.com
Kirby,
I feel technology passing my by!
So suppose I want to create a blog with Jupyter notebooks.
How do I go about it?

I have a web host but I don't know if it knows about Jupyter.
I've been using WordPress for my blog.
I also have a github account, but I'm not sure how to blog with it.

Can I replace WordPress with Jupyter?
Would I be better off to use Google for my blog?

Of course we are communicating now with Google Groups.
Can we do Jupyter in Google Groups?
Where can I go for a tutorial, or a class?

Joe Austin


On Jun 12, 2016, at 1:57 AM, kirby


--
You received this message because you are subscribed to the Google Groups "MathFuture" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathfuture+...@googlegroups.com.
To post to this group, send email to mathf...@googlegroups.com.
Visit this group at https://groups.google.com/group/mathfuture.
For more options, visit https://groups.google.com/d/optout.

kirby urner

unread,
Jun 12, 2016, 5:33:03 PM6/12/16
to mathf...@googlegroups.com
On Sun, Jun 12, 2016 at 12:42 PM, Joseph Austin <drtec...@gmail.com> wrote:
Kirby,
I feel technology passing my by!
So suppose I want to create a blog with Jupyter notebooks.
How do I go about it?

I have a web host but I don't know if it knows about Jupyter.
I've been using WordPress for my blog.
I also have a github account, but I'm not sure how to blog with it.

Can I replace WordPress with Jupyter?
Would I be better off to use Google for my blog?

Of course we are communicating now with Google Groups.
Can we do Jupyter in Google Groups?
Where can I go for a tutorial, or a class?

Joe Austin


Greetings Joe.  

No need to take an either / or attitude, congratulations on
using WordPress and why fix what ain't broke.  I use
WordPress too and don't see giving it up for only Jupyter
Notebooks.

I'm showing students and their teachers a fast and free
way to serve web pages without even learning HTML,
providing they feel safe having a public GitHub account
in the clear.  Markdown is relatively easy, once one masters
a small vocabulary of symbols.

The nbviewer website (Jupyter's) eats public GitHub-saved
notebooks, giving read-only non-interactive content -- which
may be enough (besides, embedded Youtubes have their
own controls).  Save your Notebooks anywhere public, and
nbviewer will freely render them.

Indeed, GitHub itself will render a saved Jupyter Notebook.

Also check out nbconvert!

Jupyter Notebooks fill the same niches as spreadsheets
and Mathematica and MathCAD:  they give people a way to
share working code snippets embedded in intra-office memos. 

The memos include instructions and example use cases. 
Recipients are then free to alter the input values and re-run
the affected cells.  I know of cases where such notebooks are
vital to the office workflow.

However, all talk of office workflows aside, I'm advertising
a quick on-ramp to world readable even if you have no source c
ode you want to share. 

My Getting Started page has not a lick of code anywhere, only
links to other sites that do.  I have only pictures and text,
(you can see from the URL again how this is actually coming
from my public Github account).

For some students, that's enough information to start
serving web pages in under 10 minutes.  No HTML needed.

However I'm starting the clock only after a local install of
Anaconda, the free engine I'm using to build my Jupyter
Notebooks in the first place.  That also takes time and
bandwidth, not to mention access to a capable computer.

Kirby

 

kirby urner

unread,
Jun 12, 2016, 5:44:24 PM6/12/16
to mathf...@googlegroups.com
On Sun, Jun 12, 2016 at 12:15 PM, Peter Farrell <peterfa...@gmail.com> wrote:
Good work! Very powerful technology, Jupyter. Your examples are very clear. Is the __repr__ method what makes the class a decorator?


Thanks Peter.  Your positive feedback is encouraging.  You're not like a troll under the bridge.

__repr__ controls how an object represents itself to the console, when named, though __str__ will take over (is checked first) where print( ) is concerned.

>>> obj = Obj()
>>> obj
any ol' object, who wants to know?

(Obj's __repr__ could have made it say that).

I like the collections.namedtuple type because it enhances how tuples represent themselves with a more elaborate built-in __repr__ (source code under the hood somewhere).

From qrays.py @ my Github:

from collections import namedtuple

XYZ = namedtuple("xyz_vector", "x y z")
IVM = namedtuple("ivm_vector", "a b c d")

(I stick these inside of Vectors and Qvectors respectively, so students can experiment with the two coordinate systems).

What makes a class a decorator is its willingness to both eat a callable and return a callable, where a callable is any object that "eats" (takes arguments, or may be called without one using parens e.g. compose()).

"Eating" a callable function with a decorator class involves ingesting it through __init__ and returning and instance that implements __call__ (the special method for objects that need to eat arguments).

The pattern:

class Compose:
    def __init__(self, callable):
        self.callable = callable  # <--- store incoming function
    def __call__(self, var):
        return self.callable(var)  # <-- the returned instance eats vars

@Compose
def G(x):
    return x + 2  # random function, behavior will seem unaffected in this case

I could always add a __repr__ to Compose above.

Kirby

 

On Saturday, June 11, 2016 at 12:21:47 PM UTC-7, kirby urner wrote:
(goes to nbviewer, a public renderer of Jupyter Notebooks saved elsewhere -- in this case at my Github account)

Kirby

@thekirbster


kirby urner

unread,
Jun 13, 2016, 12:52:51 AM6/13/16
to mathf...@googlegroups.com
On Sun, Jun 12, 2016 at 2:44 PM, kirby urner <kirby...@gmail.com> wrote:

 


What makes a class a decorator is its willingness to both eat a callable and return a callable, where a callable is any object that "eats" (takes arguments, or may be called without one using parens e.g. compose()).

"Eating" a callable function with a decorator class involves ingesting it through __init__ and returning and instance that implements __call__ (the special method for objects that need to eat arguments).

The pattern:

class Compose:
    def __init__(self, callable):
        self.callable = callable  # <--- store incoming function
    def __call__(self, var):
        return self.callable(var)  # <-- the returned instance eats vars

@Compose
def G(x):
    return x + 2  # random function, behavior will seem unaffected in this case

I could always add a __repr__ to Compose above.

Kirby


Here's a script with its output.  Note below that in addition to my using callable as a name for an __init__ parameter, and as an attribute of the Compose self (means "any instance of"), 'callable' natively names a built-in function, to which object you may feed objects to ask if they "eat" (may be "called"):

class Compose:
    def __init__(self, callable):
        self.callable = callable  # <--- store incoming function
    def __call__(self, var):
        return self.callable(var)  # <-- the returned instance eats vars
    def __repr__(self):
        return "Compose instance containing a callable"


@Compose
def G(x):
    return x + 2  # random function, behavior will seem unaffected in this case

print("Test:", G(10))
print(G)
print(callable(G))
  #  showing the built-in function in action


Output:

Test: 12
Compose instance containing a callable
True


 
 

I added a __repr__ and that shows in the printout.

Remember this simple algebra when it comes to decorator syntax (@):

@F
def G(x):
   """whatever G does"""
  

is equivalent to:

G = F(G)

i.e. we're sending G "through the wringer" (F) and naming the transformed thing we get back the same thing.

In my classrooms I sometimes use the "abucted" storyline:

@UFO
def innocent_bystander():
    pass

where:

def UFO(abductee):
    abductee.abducted = True
    return abductee

meaning UFO really needs to be defined above where it does the act of decoration (i.e. abduction).

Scripts get run top down, with no "hoisting" as in JavaScript, so UFO better by identifiable by the time the interpreter gets to it for converting to bytecode.

Kirby

Reply all
Reply to author
Forward
0 new messages