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
Conversation
* 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.
Things I am still working on:
|
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? |
Cool!.. I will try it out as soon as possible. Hopefully, I can help to provide some useful example. |
@ellisonbg |
Hmm, no I wasn't aware of the tab-indentation. Don't know why it did On Thu, May 3, 2012 at 4:52 PM, Min RK
Brian E. Granger |
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? |
@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. |
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) { |
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 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.
VERY nice! Woohoo, IPython has interacts! This is a really big deal. |
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. |
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) { |
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.
This still suggests some coupling of kernels and notebooks. Kernels do not need to be associated with a notebook, do they?
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.
Currently kernels do need to associated with a notebook. We could relax that assumption, but I think it is a separate issue.
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 don't understand, isn't this coupling precisely the issue this PR is meant to resolve?
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 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.
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.
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
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.
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.
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.
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.
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.
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
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.
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
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 understand Brian's position better now, consider my question resolved.
I've got this as first message in the console
When trying @minrk's example. It does not prevent it from working.... |
This is now superseded by #1711, yes? |
Notebook into the Kernel.
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.