memory-graph 0.3.62__tar.gz → 0.3.63__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {memory_graph-0.3.62/memory_graph.egg-info → memory_graph-0.3.63}/PKG-INFO +60 -55
- {memory_graph-0.3.62 → memory_graph-0.3.63}/README.md +59 -54
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/__init__.py +1 -1
- {memory_graph-0.3.62 → memory_graph-0.3.63/memory_graph.egg-info}/PKG-INFO +60 -55
- memory_graph-0.3.63/memory_graph.egg-info/SOURCES.txt +39 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/pyproject.toml +1 -1
- memory_graph-0.3.62/MANIFEST.in +0 -1
- memory_graph-0.3.62/images/add_one.png +0 -0
- memory_graph-0.3.62/images/add_one.py +0 -18
- memory_graph-0.3.62/images/avltree.py +0 -42
- memory_graph-0.3.62/images/avltree_dir.png +0 -0
- memory_graph-0.3.62/images/avltree_fail.png +0 -0
- memory_graph-0.3.62/images/avltree_key_value.png +0 -0
- memory_graph-0.3.62/images/avltree_leaf.png +0 -0
- memory_graph-0.3.62/images/avltree_linear.png +0 -0
- memory_graph-0.3.62/images/avltree_table.png +0 -0
- memory_graph-0.3.62/images/bin_search.png +0 -0
- memory_graph-0.3.62/images/bin_search.py +0 -40
- memory_graph-0.3.62/images/bin_search_linear.png +0 -0
- memory_graph-0.3.62/images/bin_tree.gif +0 -0
- memory_graph-0.3.62/images/bin_tree.png +0 -0
- memory_graph-0.3.62/images/bin_tree.py +0 -38
- memory_graph-0.3.62/images/binary.gif +0 -0
- memory_graph-0.3.62/images/binary.py +0 -14
- memory_graph-0.3.62/images/bitwise_operators.png +0 -0
- memory_graph-0.3.62/images/bitwise_operators.py +0 -39
- memory_graph-0.3.62/images/colab_example.png +0 -0
- memory_graph-0.3.62/images/copy_immutable.png +0 -0
- memory_graph-0.3.62/images/copy_immutable.py +0 -15
- memory_graph-0.3.62/images/copy_method.png +0 -0
- memory_graph-0.3.62/images/copy_method.py +0 -23
- memory_graph-0.3.62/images/copy_mix.png +0 -0
- memory_graph-0.3.62/images/copy_mix.py +0 -15
- memory_graph-0.3.62/images/copy_mutable.png +0 -0
- memory_graph-0.3.62/images/copy_mutable.py +0 -15
- memory_graph-0.3.62/images/create_gif.sh +0 -27
- memory_graph-0.3.62/images/create_images.sh +0 -47
- memory_graph-0.3.62/images/debug_vscode.png +0 -0
- memory_graph-0.3.62/images/debugging.gif +0 -0
- memory_graph-0.3.62/images/debugging.py +0 -13
- memory_graph-0.3.62/images/embedded1.png +0 -0
- memory_graph-0.3.62/images/embedded2.png +0 -0
- memory_graph-0.3.62/images/extension_numpy.png +0 -0
- memory_graph-0.3.62/images/extension_numpy.py +0 -15
- memory_graph-0.3.62/images/extension_pandas.png +0 -0
- memory_graph-0.3.62/images/extension_pandas.py +0 -17
- memory_graph-0.3.62/images/extension_torch.png +0 -0
- memory_graph-0.3.62/images/extension_torch.py +0 -10
- memory_graph-0.3.62/images/factorial.gif +0 -0
- memory_graph-0.3.62/images/factorial.py +0 -16
- memory_graph-0.3.62/images/hash_set.gif +0 -0
- memory_graph-0.3.62/images/hash_set.png +0 -0
- memory_graph-0.3.62/images/hash_set.py +0 -39
- memory_graph-0.3.62/images/hidden_edges.png +0 -0
- memory_graph-0.3.62/images/hidden_edges.py +0 -8
- memory_graph-0.3.62/images/immutable.py +0 -11
- memory_graph-0.3.62/images/immutable1.png +0 -0
- memory_graph-0.3.62/images/immutable2.png +0 -0
- memory_graph-0.3.62/images/introspect_depth.png +0 -0
- memory_graph-0.3.62/images/introspect_depth.py +0 -43
- memory_graph-0.3.62/images/ipython.png +0 -0
- memory_graph-0.3.62/images/jupyter_example.png +0 -0
- memory_graph-0.3.62/images/linked_list.gif +0 -0
- memory_graph-0.3.62/images/linked_list.png +0 -0
- memory_graph-0.3.62/images/linked_list.py +0 -35
- memory_graph-0.3.62/images/many_types.png +0 -0
- memory_graph-0.3.62/images/many_types.py +0 -13
- memory_graph-0.3.62/images/marimo_example.png +0 -0
- memory_graph-0.3.62/images/memory_graph_web_debugger.png +0 -0
- memory_graph-0.3.62/images/mutable.py +0 -11
- memory_graph-0.3.62/images/mutable1.png +0 -0
- memory_graph-0.3.62/images/mutable2.png +0 -0
- memory_graph-0.3.62/images/name_rebinding.py +0 -9
- memory_graph-0.3.62/images/not_node_types.py +0 -9
- memory_graph-0.3.62/images/power_set.gif +0 -0
- memory_graph-0.3.62/images/power_set.py +0 -26
- memory_graph-0.3.62/images/rebinding1.png +0 -0
- memory_graph-0.3.62/images/rebinding2.png +0 -0
- memory_graph-0.3.62/images/selection_sort.gif +0 -0
- memory_graph-0.3.62/images/sliding_puzzle.png +0 -0
- memory_graph-0.3.62/images/uva.png +0 -0
- memory_graph-0.3.62/images/vscode_copying.gif +0 -0
- memory_graph-0.3.62/images/wrap_int.png +0 -0
- memory_graph-0.3.62/images/wrap_int.py +0 -16
- memory_graph-0.3.62/memory_graph.egg-info/SOURCES.txt +0 -117
- {memory_graph-0.3.62 → memory_graph-0.3.63}/LICENSE.txt +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/call_stack.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/config.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/config_default.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/config_helpers.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/extension_numpy.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/extension_pandas.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/extension_torch.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/html_table.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/list_view.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/memory_to_nodes.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/node_base.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/node_key_value.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/node_leaf.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/node_linear.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/node_table.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/sequence.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/slicer.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/slices.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/slices_iterator.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/slices_table_iterator.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/test.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/test_max_graph_depth.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/test_memory_graph.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/test_memory_to_nodes.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/test_sequence.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/test_slicer.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/test_slices.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/test_slices_iterator.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph/utils.py +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph.egg-info/dependency_links.txt +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph.egg-info/requires.txt +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/memory_graph.egg-info/top_level.txt +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/setup.cfg +0 -0
- {memory_graph-0.3.62 → memory_graph-0.3.63}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: memory_graph
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.63
|
|
4
4
|
Summary: Teaching tool and debugging aid in context of references, mutable data types, and shallow and deep copy.
|
|
5
5
|
Author-email: Bas Terwijn <bterwijn@gmail.com>
|
|
6
6
|
License-Expression: BSD-2-Clause
|
|
@@ -26,7 +26,7 @@ pip install --upgrade memory_graph
|
|
|
26
26
|
Additionally [Graphviz](https://graphviz.org/download/) needs to be installed.
|
|
27
27
|
|
|
28
28
|
# Highlights #
|
|
29
|
-

|
|
30
30
|
Run a live demo in the 👉 [**Memory Graph Web Debugger**](https://memory-graph.com/#breakpoints=8&continues=1×tep=1.0&play) 👈 now, no installation required!
|
|
31
31
|
|
|
32
32
|
- learn the right **mental model** to think about Python data (references, mutability, shallow vs deep copy)
|
|
@@ -34,7 +34,7 @@ Run a live demo in the 👉 [**Memory Graph Web Debugger**](https://memory-graph
|
|
|
34
34
|
- understand function calls, variable scope, and the **complete program state** through call stack visualization
|
|
35
35
|
|
|
36
36
|
An example Binary Tree data structure:
|
|
37
|
-

|
|
38
38
|
Or see it in the [Memory Grah Web Debugger](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/bin_tree.py×tep=0.2&play).
|
|
39
39
|
|
|
40
40
|
# Videos #
|
|
@@ -57,7 +57,7 @@ class My_Class:
|
|
|
57
57
|
data = [ range(1, 2), (3, 4), {5, 6}, {7:'seven', 8:'eight'}, My_Class(9, 10) ]
|
|
58
58
|
mg.show(data)
|
|
59
59
|
```
|
|
60
|
-

|
|
61
61
|
|
|
62
62
|
Instead of showing the graph on screen you can also render it to an output file (see [Graphviz Output Formats](https://graphviz.org/docs/outputs/)) using for example:
|
|
63
63
|
|
|
@@ -96,7 +96,7 @@ mg.show( locals() )
|
|
|
96
96
|
|
|
97
97
|
</td><td>
|
|
98
98
|
|
|
99
|
-

|
|
100
100
|
|
|
101
101
|
a graph showing `a` and `b` share values
|
|
102
102
|
|
|
@@ -117,6 +117,10 @@ A better way to understand what values are shared is to draw a graph using [memo
|
|
|
117
117
|
|
|
118
118
|
[Call Stack](#call-stack)
|
|
119
119
|
|
|
120
|
+
[Data Model Exercises](#data-model-exercises)
|
|
121
|
+
|
|
122
|
+
[Block](#block)
|
|
123
|
+
|
|
120
124
|
[Debugging](#debugging)
|
|
121
125
|
|
|
122
126
|
[Data Structure Examples](#data-structure-examples)
|
|
@@ -164,7 +168,7 @@ The main difference are that running memory_graph locally is a key design choice
|
|
|
164
168
|
* [Reddit](https://www.reddit.com/r/Python_memory_graph/)
|
|
165
169
|
|
|
166
170
|
## Supported by ##
|
|
167
|
-
<img src="https://raw.githubusercontent.com/bterwijn/
|
|
171
|
+
<img src="https://raw.githubusercontent.com/bterwijn/memory_graph_images/main/images/uva.png" alt="University of Amsterdam" width="600">
|
|
168
172
|
|
|
169
173
|
___
|
|
170
174
|
___
|
|
@@ -189,7 +193,7 @@ mg.render(locals(), 'immutable1.png')
|
|
|
189
193
|
b += (1,)
|
|
190
194
|
mg.render(locals(), 'immutable2.png')
|
|
191
195
|
```
|
|
192
|
-
|  |  |
|
|
193
197
|
|:-----------------------------------------------------------:|:-------------------------------------------------------------:|
|
|
194
198
|
| immutable1.png | immutable2.png |
|
|
195
199
|
|
|
@@ -207,7 +211,7 @@ mg.render(locals(), 'mutable1.png')
|
|
|
207
211
|
b += [1] # equivalent to: b.append(1)
|
|
208
212
|
mg.render(locals(), 'mutable2.png')
|
|
209
213
|
```
|
|
210
|
-
|  |  |
|
|
211
215
|
|:-----------------------------------------------------------:|:-------------------------------------------------------------:|
|
|
212
216
|
| mutable1.png | mutable2.png |
|
|
213
217
|
|
|
@@ -234,7 +238,7 @@ mg.show(locals())
|
|
|
234
238
|
* `c2` is a **shallow copy**, only the first value is copied, all the underlying values are shared
|
|
235
239
|
* `c3` is a **deep copy**, all the values are copied, nothing is shared
|
|
236
240
|
|
|
237
|
-

|
|
238
242
|
|
|
239
243
|
Or see it in the [Memory Grah Web Debugger](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/copies.py&play).
|
|
240
244
|
|
|
@@ -262,7 +266,7 @@ b = a.custom_copy()
|
|
|
262
266
|
|
|
263
267
|
mg.show(locals())
|
|
264
268
|
```
|
|
265
|
-

|
|
266
270
|
|
|
267
271
|
Or see it in the [Memory Grah Web Debugger](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/custom_copy.py&breakpoints=15&continues=1&play).
|
|
268
272
|
|
|
@@ -280,7 +284,7 @@ b += [1] # changes the value of 'b' and 'a'
|
|
|
280
284
|
b = [100, 200] # rebinds 'b' to another value, 'a' is unaffected
|
|
281
285
|
mg.render(locals(), 'rebinding2.png')
|
|
282
286
|
```
|
|
283
|
-
|  |  |
|
|
284
288
|
|:-----------------------------------------------------------:|:-------------------------------------------------------------:|
|
|
285
289
|
| rebinding1.png | rebinding2.png |
|
|
286
290
|
|
|
@@ -302,7 +306,7 @@ c3 = copy.deepcopy(a)
|
|
|
302
306
|
|
|
303
307
|
mg.show(locals())
|
|
304
308
|
```
|
|
305
|
-

|
|
306
310
|
|
|
307
311
|
## Copying a Mix of Mutable and Immutable Values ##
|
|
308
312
|
When copying a mix of values of mutable and immutable type, to save on time and space, a deep copy will try to copy as few values of immutable type as possible in order to copy each value of mutable type.
|
|
@@ -319,7 +323,7 @@ c3 = copy.deepcopy(a)
|
|
|
319
323
|
|
|
320
324
|
mg.show(locals())
|
|
321
325
|
```
|
|
322
|
-

|
|
323
327
|
|
|
324
328
|
# Call Stack #
|
|
325
329
|
The `mg.stack()` function retrieves the entire call stack, including the local variables for each function on the stack. This enables us to understand function calls, variable scope, and the **complete program state** through call stack visualization. By examining the graph, we can see whether local variables from different function calls share data. For instance, consider the function `add_one()` which adds the value `1` to each of its parameters `a`, `b`, and `c`.
|
|
@@ -340,7 +344,7 @@ add_one(a, b, c.copy())
|
|
|
340
344
|
|
|
341
345
|
print(f"a:{a} b:{b} c:{c}")
|
|
342
346
|
```
|
|
343
|
-

|
|
344
348
|
|
|
345
349
|
Or see it in the [Memory Grah Web Debugger](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/function_call.py&play).
|
|
346
350
|
|
|
@@ -367,7 +371,7 @@ add_one(a, b)
|
|
|
367
371
|
|
|
368
372
|
print(f"a:{a} b:{b[0]}")
|
|
369
373
|
```
|
|
370
|
-

|
|
371
375
|
```
|
|
372
376
|
a:10 b:11
|
|
373
377
|
```
|
|
@@ -375,11 +379,11 @@ Or see it in the [Memory Grah Web Debugger](https://memory-graph.com/#codeurl=ht
|
|
|
375
379
|
|
|
376
380
|
The effect of calling `add_one()` is that `b[0]` increases by 1, while `a` is unaffected.
|
|
377
381
|
|
|
378
|
-
|
|
382
|
+
# Data Model Exercises #
|
|
379
383
|
|
|
380
384
|
Now is a good time to practice with Python Data Model concepts. Here are [some exercises](https://github.com/bterwijn/memory_graph_videos/blob/main/exercises/exercises.md) on references, mutability, copies, and function calls.
|
|
381
385
|
|
|
382
|
-
|
|
386
|
+
# Block #
|
|
383
387
|
It is often helpful to temporarily block program execution to inspect the graph. For this we can use the `mg.block()` function:
|
|
384
388
|
|
|
385
389
|
```python
|
|
@@ -408,7 +412,7 @@ def factorial(n):
|
|
|
408
412
|
|
|
409
413
|
print( factorial(4) )
|
|
410
414
|
```
|
|
411
|
-

|
|
412
416
|
|
|
413
417
|
and the result is: 1 x 2 x 3 x 4 = 24
|
|
414
418
|
|
|
@@ -431,7 +435,7 @@ def binary(value: int) -> list[int]:
|
|
|
431
435
|
|
|
432
436
|
print( binary(100) )
|
|
433
437
|
```
|
|
434
|
-

|
|
435
439
|
```
|
|
436
440
|
[1, 1, 0, 0, 1, 0, 0]
|
|
437
441
|
```
|
|
@@ -463,7 +467,7 @@ def power_set(data):
|
|
|
463
467
|
print( power_set(['a', 'b', 'c']) )
|
|
464
468
|
```
|
|
465
469
|
|
|
466
|
-

|
|
467
471
|
```
|
|
468
472
|
[['a', 'b', 'c'], ['a', 'b'], ['a', 'c'], ['a'], ['b', 'c'], ['b'], ['c'], []]
|
|
469
473
|
```
|
|
@@ -494,7 +498,7 @@ The ```mg.stack()``` doesn't work well in **watch** context in most debuggers be
|
|
|
494
498
|
| [PyCharm](https://www.jetbrains.com/pycharm/) | `mg.stack_pycharm()` |
|
|
495
499
|
| [Wing](https://wingware.com/) | `mg.stack_wing()` |
|
|
496
500
|
|
|
497
|
-

|
|
498
502
|
See the [Quick Intro (3:49)](https://www.youtube.com/watch?v=23_bHcr7hqo) video for the setup.
|
|
499
503
|
|
|
500
504
|
## Other Debuggers ##
|
|
@@ -544,7 +548,7 @@ for i in range(1, 6):
|
|
|
544
548
|
```
|
|
545
549
|
and pressing <Enter> a number of times, results in:
|
|
546
550
|
|
|
547
|
-

|
|
548
552
|
|
|
549
553
|
# Data Structure Examples #
|
|
550
554
|
Package memory_graph can **visualize the structure of your data** to easily understand and debug data structures, some examples:
|
|
@@ -581,11 +585,11 @@ for i in range(n):
|
|
|
581
585
|
linked_list.add_back(value)
|
|
582
586
|
mg.block(mg.show, locals()) # <--- draw locals
|
|
583
587
|
```
|
|
584
|
-

|
|
585
589
|
|
|
586
590
|
### Linked List in Cursor AI ###
|
|
587
591
|
Here we show values being added to a Linked List in Cursor AI. When adding the last value '5' we "Step Into" the code to show more of the details.
|
|
588
|
-

|
|
589
593
|
|
|
590
594
|
Or see it in the [Memory Grah Web Debugger](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/linked_list.py×tep=0.2&play).
|
|
591
595
|
|
|
@@ -623,13 +627,13 @@ for i in range(n):
|
|
|
623
627
|
value = random.randrange(n)
|
|
624
628
|
tree.add(value)
|
|
625
629
|
```
|
|
626
|
-

|
|
627
631
|
|
|
628
632
|
### Binary Tree in Visual Studio Code ###
|
|
629
633
|
Here we show values being inserted in a Binary Tree in Visual Studio Code. When inserting the last value '29' we "Step Into" the code to show the recursive implementation.
|
|
630
|
-

|
|
631
635
|
|
|
632
|
-
|
|
636
|
+
See it in the [Memory Grah Web Debugger](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/bin_tree.py×tep=0.2&play) or see the more advanced [Multiway Tree](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/multiway_tree.py&breakpoints=19,33&continues=1×tep=0.2&play) with more than two children per node, making the tree less deep and more efficient.
|
|
633
637
|
|
|
634
638
|
## Hash Set ##
|
|
635
639
|
```python
|
|
@@ -667,11 +671,11 @@ for i in range(n):
|
|
|
667
671
|
new_value = random.randrange(n)
|
|
668
672
|
hash_set.add(new_value)
|
|
669
673
|
```
|
|
670
|
-

|
|
671
675
|
|
|
672
676
|
### Hash Set in PyCharm ###
|
|
673
677
|
Here we show values being inserted in a HashSet in PyCharm. When inserting the last value '44' we "Step Into" the code to show more of the details.
|
|
674
|
-

|
|
675
679
|
|
|
676
680
|
Or see it in the [Memory Grah Web Debugger](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/hash_set.py&breakpoints=32&continues=1×tep=0.5&play).
|
|
677
681
|
|
|
@@ -679,7 +683,7 @@ Or see it in the [Memory Grah Web Debugger](https://memory-graph.com/#codeurl=ht
|
|
|
679
683
|
# Sorting Algorithms #
|
|
680
684
|
|
|
681
685
|
Visualization of different sorting algorithms in Memory Graph Web Debugger.
|
|
682
|
-

|
|
683
687
|
|
|
684
688
|
- [selection sort](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/selection_sort.py&breakpoints=13,27&continues=1×tep=0.2&play)
|
|
685
689
|
- [insertion sort](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/insertion_sort.py&breakpoints=13,29&continues=1×tep=0.2&play)
|
|
@@ -692,7 +696,7 @@ In this configuration example we show the decimal, binary and [two's complement
|
|
|
692
696
|
|
|
693
697
|
- [bitwise operators](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/bitwise_operators.py&breakpoints=22&continues=1&play)
|
|
694
698
|
|
|
695
|
-

|
|
696
700
|
|
|
697
701
|
|
|
698
702
|
# Sliding Puzzle Solver #
|
|
@@ -701,7 +705,7 @@ A sliding puzzle solver as a challenging example showing how memory_graph deals
|
|
|
701
705
|
|
|
702
706
|
- [sliding puzzle solver](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/sliding_puzzle.py&breakpoints=17,27,29,40&continues=1)
|
|
703
707
|
|
|
704
|
-

|
|
705
709
|
|
|
706
710
|
|
|
707
711
|
# Configuration #
|
|
@@ -783,7 +787,7 @@ mg.config.embedded_types.remove(int) # now show separate nodes for int values
|
|
|
783
787
|
|
|
784
788
|
mg.render(locals(), 'embedded2.png')
|
|
785
789
|
```
|
|
786
|
-
|  |  |
|
|
787
791
|
|:-----------------------------------------------------------:|:-------------------------------------------------------------:|
|
|
788
792
|
| embedded1.png — simplified | embedded2.png — technically correct |
|
|
789
793
|
|
|
@@ -805,7 +809,7 @@ tree.insert(15, "fifteen")
|
|
|
805
809
|
|
|
806
810
|
mg.show(locals())
|
|
807
811
|
```
|
|
808
|
-

|
|
809
813
|
|
|
810
814
|
## All attributes using dir() ##
|
|
811
815
|
A useful start is to give it some color, show the list of all its attributes using `dir()`, and setting an empty Slicer to see the attribute list in full.
|
|
@@ -828,7 +832,7 @@ mg.config.type_to_slicer[bintrees.avltree.Node] = mg.Slicer()
|
|
|
828
832
|
|
|
829
833
|
mg.show(locals())
|
|
830
834
|
```
|
|
831
|
-

|
|
832
836
|
|
|
833
837
|
Next figure out what the attributes are you want to graph and choose a Node type, there are four options:
|
|
834
838
|
|
|
@@ -851,7 +855,7 @@ mg.config.type_to_node[bintrees.avltree.Node] = lambda data: mg.Node_Leaf(data,
|
|
|
851
855
|
|
|
852
856
|
mg.show(locals())
|
|
853
857
|
```
|
|
854
|
-

|
|
855
859
|
|
|
856
860
|
## 2) Node_Linear ##
|
|
857
861
|
Node_Linear shows multiple values in a line like a list.
|
|
@@ -875,7 +879,7 @@ mg.config.type_to_node[bintrees.avltree.Node] = lambda data: mg.Node_Linear(data
|
|
|
875
879
|
|
|
876
880
|
mg.show(locals())
|
|
877
881
|
```
|
|
878
|
-

|
|
879
883
|
|
|
880
884
|
## 3) Node_Key_Value ##
|
|
881
885
|
Node_Key_Value shows key-value pairs like a dictionary. Note the required `items()` call at the end.
|
|
@@ -899,7 +903,7 @@ mg.config.type_to_node[bintrees.avltree.Node] = lambda data: mg.Node_Key_Value(d
|
|
|
899
903
|
|
|
900
904
|
mg.show(locals())
|
|
901
905
|
```
|
|
902
|
-

|
|
903
907
|
|
|
904
908
|
## 4) Node_Table ##
|
|
905
909
|
Node_Table shows all the values as a table.
|
|
@@ -921,7 +925,7 @@ mg.config.type_to_node[bintrees.avltree.Node] = lambda data: mg.Node_Table(data,
|
|
|
921
925
|
|
|
922
926
|
mg.show(locals())
|
|
923
927
|
```
|
|
924
|
-

|
|
925
929
|
|
|
926
930
|
## Binary Search ##
|
|
927
931
|
For binary search we can use a List_View class to represent a particular sublist without making a list copy.
|
|
@@ -964,16 +968,17 @@ value = data[random.randrange(n)]
|
|
|
964
968
|
index = bin_search(List_View(data, 0, len(data)), value)
|
|
965
969
|
print('index:', index, 'data[index]:', data[index])
|
|
966
970
|
```
|
|
967
|
-

|
|
968
972
|
|
|
969
973
|
Arguably the visualization is then more clear when we show a List_View object as an actual sublist using a Node_linear node:
|
|
970
974
|
|
|
971
975
|
```python
|
|
972
|
-
mg.config.
|
|
973
|
-
|
|
974
|
-
|
|
976
|
+
mg.config.type_to_node[List_View] = (lambda l: mg.Node_Linear(l,
|
|
977
|
+
[v if l.begin <= i < l.end else '' for i, v in enumerate(l.lst)]
|
|
978
|
+
if hasattr(l, 'end') else [])
|
|
979
|
+
)
|
|
975
980
|
```
|
|
976
|
-

|
|
977
982
|
|
|
978
983
|
# Graph Depth #
|
|
979
984
|
To limit the size of the graph the maximum depth of the graph is set by `mg.config.max_graph_depth`. Additionally for each type a depth can be set to further limit the graph, as is done for type `B` in the example below. Scissors indicate where the graph is cut short. Alternatively the `id()` of a data elements can be used to limit the graph for that specific element, as is done for the value referenced by variable `c`.
|
|
@@ -1025,7 +1030,7 @@ mg.config.type_to_depth[B] = 3
|
|
|
1025
1030
|
mg.config.type_to_depth[id(c)] = 2
|
|
1026
1031
|
mg.show(locals())
|
|
1027
1032
|
```
|
|
1028
|
-

|
|
1029
1034
|
|
|
1030
1035
|
## Hidden Edges ##
|
|
1031
1036
|
|
|
@@ -1041,7 +1046,7 @@ for i in range(20):
|
|
|
1041
1046
|
|
|
1042
1047
|
mg.show(locals())
|
|
1043
1048
|
```
|
|
1044
|
-

|
|
1045
1050
|
|
|
1046
1051
|
# Extensions #
|
|
1047
1052
|
Different extensions are available for types from other Python packages.
|
|
@@ -1062,7 +1067,7 @@ ndarray_3d = np.random.rand(2,2,2)
|
|
|
1062
1067
|
|
|
1063
1068
|
mg.show(locals())
|
|
1064
1069
|
```
|
|
1065
|
-

|
|
1066
1071
|
|
|
1067
1072
|
Or see it in the [Memory Grah Web Debugger](https://memory-graph.com/#micropip=numpy&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/mg_numpy.py&continues=1).
|
|
1068
1073
|
|
|
@@ -1083,7 +1088,7 @@ dataframe2 = pd.DataFrame({ 'Name' : [ 'Tom', 'Anna', 'Steve', 'Lisa'],
|
|
|
1083
1088
|
index=['one', 'two', 'three', 'four']) # with row names
|
|
1084
1089
|
mg.show(locals())
|
|
1085
1090
|
```
|
|
1086
|
-

|
|
1087
1092
|
|
|
1088
1093
|
Or see it in the [Memory Grah Web Debugger](https://memory-graph.com/#micropip=pandas&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/mg_pandas.py&continues=1).
|
|
1089
1094
|
|
|
@@ -1102,11 +1107,11 @@ tensor_3d = torch.rand(2, 2, 2)
|
|
|
1102
1107
|
|
|
1103
1108
|
mg.show(locals())
|
|
1104
1109
|
```
|
|
1105
|
-

|
|
1106
1111
|
|
|
1107
1112
|
# Memory Graph Web Debugger #
|
|
1108
1113
|
The <a href="https://memory-graph.com/#play" target="_blank">Memory Graph Web Debugger</a> lets us use memory_graph without any installation.
|
|
1109
|
-

|
|
1110
1115
|
|
|
1111
1116
|
# Jupyter Notebook #
|
|
1112
1117
|
In Jupyter Notebook `locals()` has additional variables that cause problems in the graph, use `mg.locals_jupyter()` to get the local variables with these problematic variables filtered out. Use `mg.stack_jupyter()` to get the whole call stack with these variables filtered out.
|
|
@@ -1119,7 +1124,7 @@ mg.block(display, mg.create_graph(mg.locals_jupyter()) ) # the same but blocked
|
|
|
1119
1124
|
```
|
|
1120
1125
|
|
|
1121
1126
|
See for example [jupyter_example.ipynb](https://raw.githubusercontent.com/bterwijn/memory_graph/main/src/jupyter_example.ipynb).
|
|
1122
|
-

|
|
1123
1128
|
|
|
1124
1129
|
# ipython #
|
|
1125
1130
|
In ipython `locals()` has additional variables that cause problems in the graph, use `mg.locals_ipython()` to get the local variables with these problematic variables filtered out. Use `mg.stack_ipython()` to get the whole call stack with these variables filtered out.
|
|
@@ -1129,19 +1134,19 @@ Additionally install file [auto_memory_graph.py](https://raw.githubusercontent.c
|
|
|
1129
1134
|
* Windows: `%USERPROFILE%\.ipython\profile_default\startup\`
|
|
1130
1135
|
|
|
1131
1136
|
Then after starting 'ipython' call function `mg_switch()` to turn on/off the automatic visualization of local variables after each command.
|
|
1132
|
-

|
|
1133
1138
|
|
|
1134
1139
|
# Google Colab #
|
|
1135
1140
|
In Google Colab `locals()` has additional variables that cause problems in the graph, use `mg.locals_colab()` to get the local variables with these problematic variables filtered out. Use `mg.stack_colab()` to get the whole call stack with these variables filtered out.
|
|
1136
1141
|
|
|
1137
1142
|
See for example [colab_example.ipynb](https://raw.githubusercontent.com/bterwijn/memory_graph/main/src/colab_example.ipynb).
|
|
1138
|
-

|
|
1139
1144
|
|
|
1140
1145
|
# Marimo #
|
|
1141
1146
|
In Marimo `locals()` has additional variables that cause problems in the graph, use `mg.locals_marimo()` to get the local variables with these problematic variables filtered out. Use `mg.stack_marimo()` to get the whole call stack with these variables filtered out. Memory_graph only works when running Marimo locally, not in the playground.
|
|
1142
1147
|
|
|
1143
1148
|
See for example [marimo_example.py](https://raw.githubusercontent.com/bterwijn/memory_graph/main/src/marimo_example.py).
|
|
1144
|
-

|
|
1145
1150
|
|
|
1146
1151
|
|
|
1147
1152
|
# Animated GIF #
|
|
@@ -1154,7 +1159,7 @@ in your source or better as a *watch* in a debugger so that stepping through the
|
|
|
1154
1159
|
|
|
1155
1160
|
animated0.png, animated1.png, animated2.png, ...
|
|
1156
1161
|
|
|
1157
|
-
Then use these images to make an animated GIF, for example using this Bash script [create_gif.sh](https://raw.githubusercontent.com/bterwijn/
|
|
1162
|
+
Then use these images to make an animated GIF, for example using this Bash script [create_gif.sh](https://raw.githubusercontent.com/bterwijn/memory_graph_images/main/images/create_gif.sh):
|
|
1158
1163
|
|
|
1159
1164
|
```bash
|
|
1160
1165
|
$ bash create_gif.sh animated
|