We start by sepecifying that %%isolate will police inputs and outputs.

In strict mode, if post or pre clause is specified and their content does not match what the cell actually does, an exception is raised.

In [1]:
%isolatemode strict echo

setting up user_ns to <class '__main__.ProtectedNamespace'>

We can ask isolate-magic to automatically detect the pre/post conditions by omitting the clauses. In this case no exception would ever be raised

In [2]:
%%isolate name(InitializeAuto)
a = 10
b = 10

%%isolate nodename(InitializeAuto)  post(a,b)

If a post clause is give, it must match the cell's side effects on the user namespace

In [3]:
%%isolate name(Initialize) post(a, b)
a = 10
b = 20

%%isolate nodename(Initialize)  post(a,b)

Now observe the PostConditionException, if 'a' is not propertly declared

In [4]:
%%isolate name(BadInitialize) post(b)
a = 10
b = 20

%%isolate nodename(BadInitialize)  post(a,b)
Post execution variables not defined in clause: a

Cells without a %%isolate magic are ignored. Even if they modify a variable declared in another cell.

In [5]:

%%isolate nodename(5) pre(b) 

If it wasn't obvious, libraries can be handled in the same way.

In [6]:
%%isolate name(ImportModules) post(os)
import os
import os.path

%%isolate nodename(ImportModules)  post(os)

We see a run a cell that access a variable (b) that not declared in pre; The cell has run in full. But we still see the PreConditionError

In [7]:
%%isolate name(Diagonistics) post(b) pre()
except NameError:
    print 'A NameError is caught'
    b = 20

A NameError is caught
%%isolate nodename(Diagonistics)  post(b)

If we don't export, the value in the top-level namespace is left as-is

In [8]:
%%isolate name(SetB)
b = 10

%%isolate nodename(SetB)  post(b)

In [9]:
%%isolate name(TestUntaintedNameSpace) post()
b = 5

%%isolate nodename(TestUntaintedNameSpace)  post(b)
Post execution variables not defined in clause: b

In [10]:
%%isolate name(GetB)

%%isolate nodename(GetB) pre(b) 

In [11]:
%%isolate name(Iterative) pre(a) post(a)
a = a + 1

%%isolate nodename(Iterative) pre(a) post(a)

This produces a list of the cells, with inputs and outputs. The layout here sucks, but it shows the basis for something that could be improved.

In [12]:
g = %dag


This is the beginnings of a debugging helper that I found useful.

In [13]:
im = %iso_debug

In [14]:


In [15]:

ERROR: No traceback has been produced, nothing to debug.

In [15]: