spyder is a Python GUI that works well with ipython, and therefore SoS if you configure it properly. Spyder should be readily available if you use Anaconda python, or you can install spyder using
$ conda install spyder
if you are using anaconda python distribution,
$ pip install spyder
for regular python, or according to instructions on the spyder website if you have a more complex Python environment.
Because spyder does not support third-party kernels and does not yet support .sos files, sos provides a script to monkey-patch Spyder to let it accept files with .sos extension, and accept kernel sos as its default kernel. Before using Spyder with sos, you should execute command
In [1]:
!sos patch-spyder
to patch spyder. After spyder is successfully patched, you can start spyder with a SoS kernel using command
$ spyder --kernel sos
Alternatively, you can connect spyder to an existing qtconsole with sos kernel by
jupyter qtconsole --kernel sos%connect_info from the console if you cannot find it.spyder, select consoles -> Connect an existing kernel. Put connection id and connect.It is certainly possible to set up a remote Jupyter server and connect to a remote SoS kernel but this usage is beyond the scope of this tutorial.
NOTE: Monkey-patching a rapid-evolving project such as Spyder is difficult. Please let us know if the script fails to patch certain version of spyder or if Spyder does not work well after the patch.
%edit magicYou can open and edit files using Spyder's menu system. However, it can be more convenient to open files from within the SoS console. The SoS kernel provides a magic called %edit to do this. It supports string interpolation so you can run
%edit ${sdir}/myscript.sos
if sdir is a variable pointing to your script directory. This magic also provides an option --cd that changes the current working directory to the script directory so
%edit --cd ${sdir}/myscript.sos
would be equivalent to
%edit ${sdir}/myscript.sos
%cd ${sdir}
Whereas in batch SoS scripts statements are divided into steps using section headers ([section: options]), it uses cell magic %cell to define cells corresponding to cells of Jupyter notebooks. Basically, whenever you would like to define a new cell or separate an existing cell into two cells, you simple insert
```
%cell
```
as the beginning of the new cell. Removing a cell or merging two existing cells can be easily achieved by removing a %cell line. Although a cell usually does not contain any step, it can contain multiple steps even multiple workflows. When you submit a line, a section (of multiple lines), or a cell to SoS, it execute the input as a complete workflow and returns the result of the last expression.
Spyder provides shortcuts for executing current line, selection, or cell. It is highly configurable so you can define your own shortcuts for
F9, which is awkward on my mac so I redefined it to Ctrl-Enter)Object inspector is useful for getting help message (e.g. definition of a function) of object. All you need to do is to navigate to the beginning of the work and press Cmd-i (Mac OSX).
Variable explorer lists all variables in the SoS namespace. This saves your effort of using magic %dict, or %preview vars because all variables are right in the window and can be viewed easily.
In [ ]: