Skip to content

Commit 9e7b13c

Browse files
Fix getting-started tutorial by removing @egraph.class_ decorator and updating API usage
Co-authored-by: saulshanabrook <[email protected]>
1 parent ffe894f commit 9e7b13c

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

docs/sg_execution_times.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
Computation times
88
=================
9-
**00:00.402** total execution time for 12 files **from all galleries**:
9+
**00:00.401** total execution time for 12 files **from all galleries**:
1010

1111
.. container::
1212

@@ -33,13 +33,13 @@ Computation times
3333
- Time
3434
- Mem (MB)
3535
* - :ref:`sphx_glr_auto_examples_lambda_.py` (``../python/egglog/examples/lambda_.py``)
36-
- 00:00.167
36+
- 00:00.168
3737
- 0.0
3838
* - :ref:`sphx_glr_auto_examples_fib.py` (``../python/egglog/examples/fib.py``)
39-
- 00:00.112
39+
- 00:00.110
4040
- 0.0
4141
* - :ref:`sphx_glr_auto_examples_ndarrays.py` (``../python/egglog/examples/ndarrays.py``)
42-
- 00:00.044
42+
- 00:00.043
4343
- 0.0
4444
* - :ref:`sphx_glr_auto_examples_matrix.py` (``../python/egglog/examples/matrix.py``)
4545
- 00:00.018
@@ -54,7 +54,7 @@ Computation times
5454
- 00:00.009
5555
- 0.0
5656
* - :ref:`sphx_glr_auto_examples_bool.py` (``../python/egglog/examples/bool.py``)
57-
- 00:00.008
57+
- 00:00.007
5858
- 0.0
5959
* - :ref:`sphx_glr_auto_examples_higher_order_functions.py` (``../python/egglog/examples/higher_order_functions.py``)
6060
- 00:00.006

docs/tutorials/getting-started.ipynb

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
"metadata": {},
8484
"outputs": [],
8585
"source": [
86-
"@egraph.class_\n",
8786
"class Dim(Expr):\n",
8887
" \"\"\"\n",
8988
" A dimension of a matix.\n",
@@ -108,16 +107,17 @@
108107
"tags": []
109108
},
110109
"source": [
111-
"As you can see, you must wrap any class with the `egraph.class_` to register\n",
112-
"it with the egraph and be able to use it like a Python class.\n",
110+
"As you can see, you can define a class that inherits from `Expr` to create\n",
111+
"a new type in the e-graph. The class will be automatically registered when you use it.\n",
113112
"\n",
114113
"### Testing in a notebook\n",
115114
"\n",
116115
"We can try out this by [creating a new notebook](https://code.visualstudio.com/docs/datascience/jupyter-notebooks#_create-or-open-a-jupyter-notebook) which imports this file:\n",
117116
"\n",
118117
"```python\n",
119118
"from matrix import *\n",
120-
"```\n"
119+
"```\n",
120+
""
121121
]
122122
},
123123
{
@@ -408,7 +408,8 @@
408408
}
409409
],
410410
"source": [
411-
"egraph.simplify(res, 10)"
411+
"egraph.run(10)\n",
412+
"egraph.extract(res)\n"
412413
]
413414
},
414415
{
@@ -429,7 +430,6 @@
429430
"metadata": {},
430431
"outputs": [],
431432
"source": [
432-
"@egraph.class_\n",
433433
"class Matrix(Expr):\n",
434434
" @classmethod\n",
435435
" def identity(cls, dim: Dim) -> Matrix:\n",
@@ -459,7 +459,7 @@
459459
" \"\"\"\n",
460460
"\n",
461461
"\n",
462-
"@egraph.function\n",
462+
"@function\n",
463463
"def kron(a: Matrix, b: Matrix) -> Matrix:\n",
464464
" \"\"\"\n",
465465
" Kronecker product of two matrices.\n",
@@ -530,8 +530,10 @@
530530
"x = Matrix.identity(Dim.named(\"x\"))\n",
531531
"y = Matrix.identity(Dim.named(\"y\"))\n",
532532
"x_mult_y = x @ y\n",
533-
"print(egraph.simplify(x_mult_y.ncols(), 10))\n",
534-
"print(egraph.simplify(x_mult_y.nrows(), 10))"
533+
"egraph.run(10)\n",
534+
"print(egraph.extract(x_mult_y.ncols()))\n",
535+
"egraph.run(10)\n",
536+
"print(egraph.extract(x_mult_y.nrows()))"
535537
]
536538
},
537539
{
@@ -1096,7 +1098,8 @@
10961098
")\n",
10971099
"# Create an example which should equal the kronecker product of A and B\n",
10981100
"ex1 = kron(Matrix.identity(n), B) @ kron(A, Matrix.identity(m))\n",
1099-
"egraph.simplify(ex1, 20)"
1101+
"egraph.run(20)\n",
1102+
"egraph.extract(ex1)\n"
11001103
]
11011104
},
11021105
{
@@ -1209,7 +1212,8 @@
12091212
],
12101213
"source": [
12111214
"ex2 = kron(Matrix.identity(p), C) @ kron(A, Matrix.identity(m))\n",
1212-
"egraph.simplify(ex2, 20)"
1215+
"egraph.run(20)\n",
1216+
"egraph.extract(ex2)\n"
12131217
]
12141218
},
12151219
{
@@ -1243,4 +1247,4 @@
12431247
},
12441248
"nbformat": 4,
12451249
"nbformat_minor": 5
1246-
}
1250+
}

0 commit comments

Comments
 (0)