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

Major refactoring of the Notebook, Kernel and CodeCell JavaScript. #1697

Closed
wants to merge 1 commit into from

Conversation

ellisonbg
Copy link
Member

  • Kernel doesn't depend on Notebook or CodeCell.
  • CodeCell doesn't depend on Notebook, only Kernel.
  • All of the kernel management logic has been moved out of the
    Notebook into the Kernel.
  • Public methods of the Kernel (execute, complete, etc) take
    a callbacks object that registers the callbacks for that msg.

With this change, it should be easy for JavaScript widgets to make further calls to the kernel.

* Kernel doesn't depend on Notebook or CodeCell.
* CodeCell doesn't depend on Notebook, only Kernel.
* All of the kernel management logic has been moved out of the
  Notebook into the Kernel.
* Public methods of the Kernel (execute, complete, etc) take
  a callbacks object that registers the callbacks for that msg.
@ellisonbg
Copy link
Member Author

Things I am still working on:

  • I need to create some simple examples to test this.
  • I need to do an audit of how Notebook.dirty is set.

@minrk
Copy link
Member

minrk commented May 3, 2012

Great! Very exciting to see what will be done with this.

Small question: Are you aware that some of your new js is tab-indented?

@cschin
Copy link

cschin commented May 4, 2012

Cool!.. I will try it out as soon as possible. Hopefully, I can help to provide some useful example.

@Carreau
Copy link
Member

Carreau commented May 4, 2012

@ellisonbg
#1509 and #1417 are not that difficult to merge ...
(https://github.com/Carreau/ipython/tree/testmerge) where I cherry-picked, fixed conflict and modified some part of my code to works ( with a quick test)

@ellisonbg
Copy link
Member Author

Hmm, no I wasn't aware of the tab-indentation. Don't know why it did
that as I have been using TextMate as I normally do. I will fix that
though.

On Thu, May 3, 2012 at 4:52 PM, Min RK
reply@reply.github.com
wrote:

Great!  Very exciting to see what will be done with this.

Small question: Are you aware that some of your new js is tab-indented?


Reply to this email directly or view it on GitHub:
#1697 (comment)

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

@jasongrout
Copy link
Member

I'm really interested in seeing your example of JavaScript widgets making further calls to the kernel. Do you mean that we could easily have a javascript slider which changes a variable value? Or we could have a click on a graph relay coordinates of the point back to a python variable?

@minrk
Copy link
Member

minrk commented May 5, 2012

@jasongrout yes, that's exactly the idea. With execution decoupled from cells, any javascript can run code on the kernel, and process the output via callbacks.

@minrk
Copy link
Member

minrk commented May 5, 2012

Here's a notebook with a flot plot, and sliders that allow updating the data in the kernel, and redrawing the plot. There is one Python code cell that defines the function that generates the plot data, though this could obviously be submitted via the javascript as well.

return msg.header.msg_id;
}
return;
}

Kernel.prototype.execute = function (code) {
Copy link
Member

Choose a reason for hiding this comment

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

I think this should expose at least the silent arg, and probably also the user_expressions/variables keys.

In my example, I have sliders that trigger execute, so my prompt count quickly rises into the hundreds while I am fiddling around. And I really don't care about keeping track of any of those near-identical calls in my history.

Also, the default value for silent should be True, just like the default value for store_history in InteractiveShell.run_cell is False.

@jasongrout
Copy link
Member

VERY nice! Woohoo, IPython has interacts! This is a really big deal.

@minrk
Copy link
Member

minrk commented May 5, 2012

I would say a bit more precisely that IPython allows interacts, because we don't really help you do this at all, but my morning exercise, which was my first look at the refactored code, and my first ever use of flot suggests it's pretty easy.

@jasongrout
Copy link
Member

Yes, true. We have a framework for making things easier to define a gui. This is coming at the right time, because we are deciding right now how to revamp things this summer. It's looking more and more like we should use a lot of the javascript and other code already written in IPython for our Sage Cell Server. Here is the equivalent of your notebook using interacts and Sage plotting (which isn't javascript---it uses matplotlib to generate the image): Bessel Functions

@@ -46,46 +49,45 @@ var IPython = (function (IPython) {
return msg;
};

Kernel.prototype.start = function (notebook_id, callback) {
Kernel.prototype.start = function (notebook_id) {
Copy link
Member

Choose a reason for hiding this comment

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

This still suggests some coupling of kernels and notebooks. Kernels do not need to be associated with a notebook, do they?

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently kernels do need to associated with a notebook. We could relax that assumption, but I think it is a separate issue.

Copy link
Member

Choose a reason for hiding this comment

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

I don't understand, isn't this coupling precisely the issue this PR is meant to resolve?

Copy link
Member

Choose a reason for hiding this comment

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

I thought this PR was resolving the issue of cells being coupled with execution requests. Now, you don't need a cell to execute some code and get a result.

Copy link
Member Author

Choose a reason for hiding this comment

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

This PR is meant to decouple the code cell, kernel, and notebook objects in JavaScript. It doesn't change the weak notebook/kernel coupling in the notebook server though. That is a separate issue.

Sent from my iPad

On May 8, 2012, at 1:42 PM, Min RKreply@reply.github.com wrote:

@@ -46,46 +49,45 @@ var IPython = (function (IPython) {
return msg;
};

  • Kernel.prototype.start = function (notebook_id, callback) {
  • Kernel.prototype.start = function (notebook_id) {

I don't understand, isn't this coupling precisely the issue this PR is meant to resolve?


Reply to this email directly or view it on GitHub:
https://github.com/ipython/ipython/pull/1697/files#r791160

Copy link
Member

Choose a reason for hiding this comment

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

The general goal is to resolve the unnecessary coupling of kernels, notebooks, and cells. Part of that is using the Kernel alone (no notebook, no cells) as a javascript library for remote execution.

I should note that I did a test, and it does seem to work if you call Kernel.start()without specifying the notebook-id.

Copy link
Member

Choose a reason for hiding this comment

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

If I understand things correctly, decoupling the notebook and kernel is effectively what we did with the Sage Cell server (any webpage can embed a single cell and execute code as part of that single cell, and in fact, any webpage can just call the aleph.sagemath.org/service/ URL to do arbitrary computations without even embedding any cells into the webpage). It would be great if IPython had that sort of thing.

Copy link
Member Author

Choose a reason for hiding this comment

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

On Tue, May 8, 2012 at 2:05 PM, Min RK
reply@reply.github.com
wrote:

@@ -46,46 +49,45 @@ var IPython = (function (IPython) {
         return msg;
     };

  •    Kernel.prototype.start = function (notebook_id, callback) {
  •    Kernel.prototype.start = function (notebook_id) {

The general goal is to resolve the unnecessary coupling of kernels, notebooks, and cells.  Part of that is using the Kernel alone (no notebook, no cells) as a javascript library for remote execution.

I should note that I did a test, and it does seem to work if you call Kernel.start()without specifying the notebook-id.

I have a vague recollection that I made sure the web service/handlers
behaved properly when no notebook_id was passed. It should create the
kernel fine, but not associate it with a notebook.


Reply to this email directly or view it on GitHub:
https://github.com/ipython/ipython/pull/1697/files#r791389

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

Copy link
Member Author

Choose a reason for hiding this comment

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

On Tue, May 8, 2012 at 2:07 PM, Jason Grout
reply@reply.github.com
wrote:

@@ -46,46 +49,45 @@ var IPython = (function (IPython) {
         return msg;
     };

  •    Kernel.prototype.start = function (notebook_id, callback) {
  •    Kernel.prototype.start = function (notebook_id) {

If I understand things correctly, decoupling the notebook and kernel is effectively what we did with the Sage Cell server (any webpage can embed a single cell and execute code as part of that single cell, and in fact, any webpage can just call the aleph.sagemath.org/service/ URL to do arbitrary computations without even embedding any cells into the webpage).  It would be great if IPython had that sort of thing.

With the recent pull request, I think anyone can simply grab our
kernel.js file (and a few other basic JS dependencies) and start to
talk to a kernel on an IPython notebook server.


Reply to this email directly or view it on GitHub:
https://github.com/ipython/ipython/pull/1697/files#r791411

Brian E. Granger
Cal Poly State University, San Luis Obispo
bgranger@calpoly.edu and ellisonbg@gmail.com

Copy link
Member

Choose a reason for hiding this comment

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

I understand Brian's position better now, consider my question resolved.

@Carreau
Copy link
Member

Carreau commented May 6, 2012

I've got this as first message in the console

Uncaught TypeError: Cannot call method 'send' of null  --  kernel.js:236

When trying @minrk's example. It does not prevent it from working....

@minrk
Copy link
Member

minrk commented May 8, 2012

This is now superseded by #1711, yes?

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

5 participants