Newer
Older
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"# Constraint Satisfaction Problems (CSPs)\n",
"\n",
"This IPy notebook acts as supporting material for topics covered in **Chapter 6 Constraint Satisfaction Problems** of the book* Artificial Intelligence: A Modern Approach*. We make use of the implementations in **csp.py** module. Even though this notebook includes a brief summary of the main topics familiarity with the material present in the book is expected. We will look at some visualizations and solve some of the CSP problems described in the book. Let us import everything from the csp module to get started."
]
},
{
"cell_type": "code",
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from csp import *"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Review\n",
"\n",
"CSPs are a special kind of search problems. Here we don't treat the space as a black box but the state has a particular form and we use that to our advantage to tweak our algorithms to be more suited to the problems. A CSP State is defined by a set of variables which can take values from corresponding domains. These variables can take only certain values in their domains to satisfy the constraints. A set of assignments which satisfies all constraints passes the goal test. Let us start by exploring the CSP class which we will use to model our CSPs. You can keep the popup open and read the main page to get a better idea of the code.\n"
]
},
{
"cell_type": "code",
Tarun Kumar Vangani
a validé
"collapsed": false
},
"outputs": [],
"source": [
"%psource CSP"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The __ _ _init_ _ __ method parameters specify the CSP. Variable can be passed as a list of strings or integers. Domains are passed as dict where key specify the variables and value specify the domains. The variables are passed as an empty list. Variables are extracted from the keys of the domain dictionary. Neighbor is a dict of variables that essentially describes the constraint graph. Here each variable key has a list its value which are the variables that are constraint along with it. The constraint parameter should be a function **f(A, a, B, b**) that **returns true** if neighbors A, B **satisfy the constraint** when they have values **A=a, B=b**. We have additional parameters like nassings which is incremented each time an assignment is made when calling the assign method. You can read more about the methods and parameters in the class doc string. We will talk more about them as we encounter their use. Let us jump to an example."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Graph Coloring\n",
"\n",
"We use the graph coloring problem as our running example for demonstrating the different algorithms in the **csp module**. The idea of map coloring problem is that the adjacent nodes (those connected by edges) should not have the same color throughout the graph. The graph can be colored using a fixed number of colors. Here each node is a variable and the values are the colors that can be assigned to them. Given that the domain will be the same for all our nodes we use a custom dict defined by the **UniversalDict** class. The **UniversalDict** Class takes in a parameter which it returns as value for all the keys of the dict. It is very similar to **defaultdict** in Python except that it does not support item assignment."
]
},
{
"cell_type": "code",
"metadata": {
"collapsed": false
},
"source": [
"s = UniversalDict(['R','G','B'])\n",
"s[5]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For our CSP we also need to define a constraint function **f(A, a, B, b)**. In this what we need is that the neighbors must not have the same color. This is defined in the function **different_values_constraint** of the module."
]
},
{
"cell_type": "code",
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%psource different_values_constraint"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The CSP class takes neighbors in the form of a Dict. The module specifies a simple helper function named **parse_neighbors** which allows to take input in the form of strings and return a Dict of the form compatible with the **CSP Class**."
]
},
{
"cell_type": "code",
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The **MapColoringCSP** function creates and returns a CSP with the above constraint function and states. The variables our the keys of the neighbors dict and the constraint is the one specified by the **different_values_constratint** function. **australia**, **usa** and **france** are three CSPs that have been created using **MapColoringCSP**. **australia** corresponds to ** Figure 6.1 ** in the book."
]
},
{
"cell_type": "code",
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%psource MapColoringCSP"
]
},
{
"cell_type": "code",
"metadata": {
"collapsed": false
},
"source": [
"australia, usa, france"
]
},
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## NQueens\n",
"\n",
"The N-queens puzzle is the problem of placing N chess queens on a N×N chessboard so that no two queens threaten each other. Here N is a natural number. Like the graph coloring, problem NQueens is also implemented in the csp module. The **NQueensCSP** class inherits from the **CSP** class. It makes some modifications in the methods to suit the particular problem. The queens are assumed to be placed one per column, from left to right. That means position (x, y) represents (var, val) in the CSP. The constraint that needs to be passed on the CSP is defined in the **queen_constraint** function. The constraint is satisfied (true) if A, B are really the same variable, or if they are not in the same row, down diagonal, or up diagonal. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%psource queen_constraint"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The **NQueensCSP** method implements methods that support solving the problem via **min_conflicts** which is one of the techniques for solving CSPs. Because **min_conflicts** hill climbs the number of conflicts to solve the CSP **assign** and **unassign** are modified to record conflicts. More details about the structures **rows**, **downs**, **ups** which help in recording conflicts are explained in the docstring."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%psource NQueensCSP"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The _ ___init___ _ method takes only one parameter **n** the size of the problem. To create an instance we just pass the required n into the constructor."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"eight_queens = NQueensCSP(8)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Helper Functions\n",
"\n",
"We will now implement few helper functions that will help us visualize the Coloring Problem. We will make some modifications to the existing Classes and Functions for additional book keeping. To begin with we modify the **assign** and **unassign** methods in the **CSP** to add a copy of the assignment to the **assingment_history**. We call this new class **InstruCSP**. This would allow us to see how the assignment evolves over time."
]
},
{
"cell_type": "code",
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import copy\n",
"class InstruCSP(CSP):\n",
" \n",
" def __init__(self, variables, domains, neighbors, constraints):\n",
" super().__init__(variables, domains, neighbors, constraints)\n",
" self.assingment_history = []\n",
" \n",
" def assign(self, var, val, assignment):\n",
" super().assign(var,val, assignment)\n",
" self.assingment_history.append(copy.deepcopy(assignment))\n",
" \n",
" def unassign(self, var, assignment):\n",
" super().unassign(var,assignment)\n",
" self.assingment_history.append(copy.deepcopy(assignment)) "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
Tarun Kumar Vangani
a validé
"Next, we define **make_instru** which takes an instance of **CSP** and returns a **InstruCSP** instance. "
]
},
{
"cell_type": "code",
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
Tarun Kumar Vangani
a validé
"def make_instru(csp):\n",
" return InstruCSP(csp.variables, csp.domains, csp.neighbors,\n",
" csp.constraints)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
Tarun Kumar Vangani
a validé
"We will now use a graph defined as a dictonary for plotting purposes in our Graph Coloring Problem. The keys are the nodes and their corresponding values are the nodes are they are connected to."
{
"cell_type": "code",
"metadata": {
"collapsed": true
},
"outputs": [],
Tarun Kumar Vangani
a validé
"neighbors = {\n",
" 0: [6, 11, 15, 18, 4, 11, 6, 15, 18, 4], \n",
" 1: [12, 12, 14, 14], \n",
" 2: [17, 6, 11, 6, 11, 10, 17, 14, 10, 14], \n",
" 3: [20, 8, 19, 12, 20, 19, 8, 12], \n",
" 4: [11, 0, 18, 5, 18, 5, 11, 0], \n",
" 5: [4, 4], \n",
" 6: [8, 15, 0, 11, 2, 14, 8, 11, 15, 2, 0, 14], \n",
" 7: [13, 16, 13, 16], \n",
" 8: [19, 15, 6, 14, 12, 3, 6, 15, 19, 12, 3, 14], \n",
" 9: [20, 15, 19, 16, 15, 19, 20, 16], \n",
" 10: [17, 11, 2, 11, 17, 2], \n",
" 11: [6, 0, 4, 10, 2, 6, 2, 0, 10, 4], \n",
" 12: [8, 3, 8, 14, 1, 3, 1, 14], \n",
" 13: [7, 15, 18, 15, 16, 7, 18, 16], \n",
" 14: [8, 6, 2, 12, 1, 8, 6, 2, 1, 12], \n",
" 15: [8, 6, 16, 13, 18, 0, 6, 8, 19, 9, 0, 19, 13, 18, 9, 16], \n",
" 16: [7, 15, 13, 9, 7, 13, 15, 9], \n",
" 17: [10, 2, 2, 10], \n",
" 18: [15, 0, 13, 4, 0, 15, 13, 4], \n",
" 19: [20, 8, 15, 9, 15, 8, 3, 20, 3, 9], \n",
" 20: [3, 19, 9, 19, 3, 9]\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
Tarun Kumar Vangani
a validé
"Now we are ready to create an InstruCSP instance for our problem. We are doing this for an instance of **MapColoringProblem** class which inherits from the **CSP** Class. This means that our **make_instru** function will work perfectly for it."
]
},
{
"cell_type": "code",
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
Tarun Kumar Vangani
a validé
"coloring_problem = MapColoringCSP('RGBY', neighbors)"
]
},
{
"cell_type": "code",
Tarun Kumar Vangani
a validé
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"coloring_problem1 = make_instru(coloring_problem)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Backtracking Search\n",
"\n",
"For solving a CSP the main issue with Naive search algorithms is that they can continue expanding obviously wrong paths. In backtracking search, we check constraints as we go. Backtracking is just the above idea combined with the fact that we are dealing with one variable at a time. Backtracking Search is implemented in the repository as the function **backtracking_search**. This is the same as **Figure 6.5** in the book. The function takes as input a CSP and few other optional parameters which can be used to further speed it up. The function returns the correct assignment if it satisfies the goal. We will discuss these later. Let us solve our **coloring_problem1** with **backtracking_search**.\n"
]
},
{
"cell_type": "code",
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"result = backtracking_search(coloring_problem1)"
]
},
{
"cell_type": "code",
"metadata": {
"collapsed": false
},
"source": [
"result # A dictonary of assingments."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let us also check the number of assingments made."
]
},
{
"cell_type": "code",
"metadata": {
"collapsed": false
},
"source": [
"coloring_problem1.nassigns"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now let us check the total number of assingments and unassingments which is the lentgh ofour assingment history."
]
},
{
"cell_type": "code",
"metadata": {
"collapsed": false
},
"source": [
"len(coloring_problem1.assingment_history)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Visualization\n",
"\n",
"Next, we define some functions to create the visualisation from the assingment_history of **coloring_problem1**. The reader need not concern himself with the code that immediately follows as it is the usage of Matplotib with IPython Widgets. If you are interested in reading more about these visit [ipywidgets.readthedocs.io](http://ipywidgets.readthedocs.io). We will be using the **networkx** library to generate graphs. These graphs can be treated as the graph that needs to be colored or as a constraint graph for this problem. If interested you can read a dead simple tutorial [here](https://www.udacity.com/wiki/creating-network-graphs-with-python). We start by importing the necessary libraries and initializing matplotlib inline.\n"
]
},
{
"cell_type": "code",
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import networkx as nx\n",
"import matplotlib.pyplot as plt\n",
"import matplotlib\n",
"import time"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The ipython widgets we will be using require the plots in the form of a step function such that there is a graph corresponding to each value. We define the **make_update_step_function** which return such a function. It takes in as inputs the neighbors/graph along with an instance of the **InstruCSP**. This will be more clear with the example below. If this sounds confusing do not worry this is not the part of the core material and our only goal is to help you visualize how the process works."
]
},
{
"cell_type": "code",
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def make_update_step_function(graph, instru_csp):\n",
" \n",
" def draw_graph(graph):\n",
" # create networkx graph\n",
" G=nx.Graph(graph)\n",
" # draw graph\n",
" pos = nx.spring_layout(G,k=0.15)\n",
" return (G, pos)\n",
" \n",
" G, pos = draw_graph(graph)\n",
" \n",
" def update_step(iteration):\n",
" # here iteration is the index of the assingment_history we want to visualize.\n",
" current = instru_csp.assingment_history[iteration]\n",
" # We convert the particular assingment to a default dict so that the color for nodes which \n",
" # have not been assigned defaults to black.\n",
" current = defaultdict(lambda: 'Black', current)\n",
"\n",
" # Now we use colors in the list and default to black otherwise.\n",
" colors = [current[node] for node in G.node.keys()]\n",
" # Finally drawing the nodes.\n",
" nx.draw(G, pos, node_color=colors, node_size=500)\n",
"\n",
" labels = {label:label for label in G.node}\n",
" # Labels shifted by offset so as to not overlap nodes.\n",
" label_pos = {key:[value[0], value[1]+0.03] for key, value in pos.items()}\n",
" nx.draw_networkx_labels(G, label_pos, labels, font_size=20)\n",
"\n",
" # show graph\n",
" plt.show()\n",
"\n",
" return update_step # <-- this is a function\n",
"\n",
"def make_visualize(slider):\n",
" ''' Takes an input a slider and returns \n",
" callback function for timer and animation\n",
" '''\n",
" \n",
" def visualize_callback(Visualize, time_step):\n",
" if Visualize is True:\n",
" for i in range(slider.min, slider.max + 1):\n",
" slider.value = i\n",
" time.sleep(float(time_step))\n",
" \n",
" return visualize_callback\n",
" "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Finally let us plot our problem. We first use the function above to obtain a step function."
]
},
{
"cell_type": "code",
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"step_func = make_update_step_function(neighbors, coloring_problem1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next we set the canvas size."
]
},
{
"cell_type": "code",
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"matplotlib.rcParams['figure.figsize'] = (18.0, 18.0)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Finally our plot using ipywidget slider and matplotib. You can move the slider to experiment and see the coloring change. It is also possible to move the slider using arrow keys or to jump to the value by directly editing the number with a double click. The **Visualize Button** will automatically animate the slider for you. The **Extra Delay Box** allows you to set time delay in seconds upto one second for each time step."
]
},
{
"cell_type": "code",
"metadata": {
"collapsed": false
},
"source": [
"import ipywidgets as widgets\n",
"from IPython.display import display\n",
"\n",
"iteration_slider = widgets.IntSlider(min=0, max=len(coloring_problem1.assingment_history)-1, step=1, value=0)\n",
"w=widgets.interactive(step_func,iteration=iteration_slider)\n",
"display(w)\n",
"\n",
"visualize_callback = make_visualize(iteration_slider)\n",
"\n",
"visualize_button = widgets.ToggleButton(desctiption = \"Visualize\", value = False)\n",
"time_select = widgets.ToggleButtons(description='Extra Delay:',options=['0', '0.1', '0.2', '0.5', '0.7', '1.0'])\n",
"\n",
"a = widgets.interactive(visualize_callback, Visualize = visualize_button, time_step=time_select)\n",
"display(a)"
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## NQueens Visualization\n",
"\n",
"Just like the Graph Coloring Problem we will start with defining a few helper functions to help us visualize the assignments as they evolve over time. The **make_plot_board_step_function** behaves similar to the **make_update_step_function** introduced earlier. It initializes a chess board in the form of a 2D grid with alternating 0s and 1s. This is used by **plot_board_step** function which draws the board using matplotlib and adds queens to it. This function also calls the **label_queen_conflicts** which modifies the grid placing 3 in positions in a position where there is a conflict."
]
},
{
"cell_type": "code",
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def label_queen_conflicts(assingment,grid):\n",
" ''' Mark grid with queens that are under conflict. '''\n",
" for col, row in assingment.items(): # check each queen for conflict\n",
" row_conflicts = {temp_col:temp_row for temp_col,temp_row in assingment.items() \n",
" if temp_row == row and temp_col != col}\n",
" up_conflicts = {temp_col:temp_row for temp_col,temp_row in assingment.items() \n",
" if temp_row+temp_col == row+col and temp_col != col}\n",
" down_conflicts = {temp_col:temp_row for temp_col,temp_row in assingment.items() \n",
" if temp_row-temp_col == row-col and temp_col != col}\n",
" \n",
" # Now marking the grid.\n",
" for col, row in row_conflicts.items():\n",
" grid[col][row] = 3\n",
" for col, row in up_conflicts.items():\n",
" grid[col][row] = 3\n",
" for col, row in down_conflicts.items():\n",
" grid[col][row] = 3\n",
"\n",
" return grid\n",
"\n",
"def make_plot_board_step_function(instru_csp):\n",
" '''ipywidgets interactive function supports\n",
" single parameter as input. This function\n",
" creates and return such a function by taking\n",
" in input other parameters.\n",
" '''\n",
" n = len(instru_csp.variables)\n",
" \n",
" \n",
" def plot_board_step(iteration):\n",
" ''' Add Queens to the Board.'''\n",
" data = instru_csp.assingment_history[iteration]\n",
" \n",
" grid = [[(col+row+1)%2 for col in range(n)] for row in range(n)]\n",
" grid = label_queen_conflicts(data, grid) # Update grid with conflict labels.\n",
" \n",
" # color map of fixed colors\n",
" cmap = matplotlib.colors.ListedColormap(['white','lightsteelblue','red'])\n",
" bounds=[0,1,2,3] # 0 for white 1 for black 2 onwards for conflict labels (red).\n",
" norm = matplotlib.colors.BoundaryNorm(bounds, cmap.N)\n",
" \n",
" fig = plt.imshow(grid, interpolation='nearest', cmap = cmap,norm=norm)\n",
"\n",
" plt.axis('off')\n",
" fig.axes.get_xaxis().set_visible(False)\n",
" fig.axes.get_yaxis().set_visible(False)\n",
"\n",
" # Place the Queens Unicode Symbol\n",
" for col, row in data.items():\n",
" fig.axes.text(row, col, u\"\\u265B\", va='center', ha='center', family='Dejavu Sans', fontsize=32)\n",
" plt.show()\n",
" \n",
" return plot_board_step"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now let us visualize a solution obtained via backtracking. We use of the previosuly defined **make_instru** function for keeping a history of steps."
]
},
{
"cell_type": "code",
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"twelve_queens_csp = NQueensCSP(12)\n",
"backtracking_instru_queen = make_instru(twelve_queens_csp)\n",
"result = backtracking_search(backtracking_instru_queen)"
]
},
{
"cell_type": "code",
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"backtrack_queen_step = make_plot_board_step_function(backtracking_instru_queen) # Step Function for Widgets"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now finally we set some matplotlib parameters to adjust how our plot will look. The font is necessary because the Black Queen Unicode character is not a part of all fonts. You can move the slider to experiment and observe the how queens are assigned. It is also possible to move the slider using arrow keys or to jump to the value by directly editing the number with a double click.The **Visualize Button** will automatically animate the slider for you. The **Extra Delay Box** allows you to set time delay in seconds upto one second for each time step.\n"
"source": [
"matplotlib.rcParams['figure.figsize'] = (8.0, 8.0)\n",
"matplotlib.rcParams['font.family'].append(u'Dejavu Sans')\n",
"\n",
"iteration_slider = widgets.IntSlider(min=0, max=len(backtracking_instru_queen.assingment_history)-1, step=0, value=0)\n",
"w=widgets.interactive(backtrack_queen_step,iteration=iteration_slider)\n",
"display(w)\n",
"\n",
"visualize_callback = make_visualize(iteration_slider)\n",
"\n",
"visualize_button = widgets.ToggleButton(desctiption = \"Visualize\", value = False)\n",
"time_select = widgets.ToggleButtons(description='Extra Delay:',options=['0', '0.1', '0.2', '0.5', '0.7', '1.0'])\n",
"\n",
"a = widgets.interactive(visualize_callback, Visualize = visualize_button, time_step=time_select)\n",
"display(a)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now let us finally repeat the above steps for **min_conflicts** solution."
]
},
{
"cell_type": "code",
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"conflicts_instru_queen = make_instru(twelve_queens_csp)\n",
"result = min_conflicts(conflicts_instru_queen)"
]
},
{
"cell_type": "code",
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"conflicts_step = make_plot_board_step_function(conflicts_instru_queen)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The visualization has same features as the above. But here it also highlights the conflicts by labeling the conflicted queens with a red background."
]
},
{
"cell_type": "code",
"source": [
"iteration_slider = widgets.IntSlider(min=0, max=len(conflicts_instru_queen.assingment_history)-1, step=0, value=0)\n",
"w=widgets.interactive(conflicts_step,iteration=iteration_slider)\n",
"display(w)\n",
"\n",
"visualize_callback = make_visualize(iteration_slider)\n",
"\n",
"visualize_button = widgets.ToggleButton(desctiption = \"Visualize\", value = False)\n",
"time_select = widgets.ToggleButtons(description='Extra Delay:',options=['0', '0.1', '0.2', '0.5', '0.7', '1.0'])\n",
"\n",
"a = widgets.interactive(visualize_callback, Visualize = visualize_button, time_step=time_select)\n",
"display(a)"
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",