gap-packages / JupyterKernel

Native Jupyter kernel for GAP
https://gap-packages.github.io/JupyterKernel/
BSD 3-Clause "New" or "Revised" License
19 stars 12 forks source link

Start notebook from within GAP. #93

Open stevelinton opened 5 years ago

stevelinton commented 5 years ago

As SAGEMath does, it would be nice to be able to start a notebook from within a terminal GAP session. Something like

gap> Notebook();
#I Notebook at localhost:8888 should be open in your web browser

or

gap> Notebook( "MyNoteBook.ipynb");
#I Notebook MyNoteBook.ipynb at localhost:8888 should be open in your web browser

or something of the kind. As far as I can see this should be easy. Notebook essentially just needs to copy a template .ipynb file into a scratch directory and call jupyter notebook foo.ipynb

Maybe it should also be possible to invoke a GAP notebook directly from the shell

$ gap --notebook
Notebook at localhost:8888 should be open in your web browser

and

$gap --notebook MyNoteBook.ipynb
stevelinton commented 5 years ago

I have a prototype implementation of this which seems to work at least sometimes:

templateNotebook := "/Users/sal/gap_jupyter_template.ipynb";

Notebook := function(arg...)
    local  name, dir;
    if Length(arg) >= 1 then
        name := arg[1];
    else
        name := "GAP";
    fi;
    Append(name,".ipynb");    
    dir := DirectoryTemporary();
    name := Filename(dir,name);    
    Exec(Concatenation( "cp ",templateNotebook, " ", name));
    Exec(Concatenation("cd ",Filename(dir,"."),"; jupyter notebook ",name));
end;
markuspf commented 5 years ago

calling jupyter notebook foo.ipynb will start a new GAP session inside Jupyter. If that is intended, fine.

Connecting the current gap session to a jupyter notebook will require more doing (you have to start the jupyter part of the notebook, get the ports and encryption keys, and then fire up the jupyter kernel, which will then fork gap, etc...)

stevelinton commented 5 years ago

@markuspf I realise it starts a new session. This is the same as SageMath, I think. It's still quite useful. Ideally I'd save a workspace from the current session and get the session inside JuPyter to load that. One could even provide a way to close down the notebook save a workspace and load that into the terminal-based session, so you could basically return with the global-variable state from the notebook intact.