You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+21Lines changed: 21 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,27 @@ Please see the [documentation](https://egglog-python.readthedocs.io/) for more i
9
9
10
10
Come say hello [on the e-graphs Zulip](https://egraphs.zulipchat.com/#narrow/stream/375765-egglog/) or [open an issue](https://github.com/egraphs-good/egglog-python/issues/new/choose)!
11
11
12
+
## Install
13
+
14
+
With pip:
15
+
16
+
```shell
17
+
python -m pip install egglog
18
+
```
19
+
20
+
With uv in a project:
21
+
22
+
```shell
23
+
uv add egglog
24
+
```
25
+
26
+
For array examples, install the optional array dependencies:
27
+
28
+
```shell
29
+
python -m pip install "egglog[array]"
30
+
uv add "egglog[array]"
31
+
```
32
+
12
33
## How to cite
13
34
14
35
If you use **egglog-python** in academic work, please cite the paper:
Custom backoff scheduler from egglog-experimental is supported. Create a custom backoff scheduler with `bo = BackOff(match_limit: None | int=None, ban_length: None | int=None)`, then run using `run(ruleset, *facts, scheduler=bo)`:
501
+
The custom backoff scheduler can delay rules that produce too many matches in a
502
+
single scheduler iteration. Create one with
503
+
`bo = back_off(match_limit=None, ban_length=None)`, then pass it to
504
+
`run(ruleset, *facts, scheduler=bo)`.
476
505
477
506
-`match_limit`: per-rule threshold of matches allowed in a single scheduler iteration. If a rule produces more matches than the threshold, that rule is temporarily banned.
478
507
-`ban_length`: initial ban duration (in scheduler iterations). While banned, that rule is skipped.
479
-
- Exponential backoff: each time a rule is banned, both the threshold and ban length double for that rule (threshold = match_limit << times_banned; ban = ban_length << times_banned).
508
+
- Exponential backoff: each time a rule is banned, both the threshold and ban length double for that rule. After `times_banned` bans, the effective threshold is `match_limit << times_banned` and the ban duration is `ban_length << times_banned`.
480
509
- Fast-forwarding: when any rule is banned, the scheduler fast-forwards by the minimum remaining ban to unban at least one rule before checking for termination again.
481
510
- Defaults: match_limit defaults to 1000; ban_length defaults to 5.
511
+
-`:until` support: custom scheduler runs can use at most one non-equality fact as the stop condition. Equality stop facts and multiple stop facts raise `ValueError`.
482
512
483
513
For example, this egglog code:
484
514
@@ -497,7 +527,7 @@ step_egraph.run(
497
527
```
498
528
499
529
By default the scheduler will be created before any other schedules are run.
500
-
To control where is instantiated explicitly, use `bo.scope(<schedule>)`, where it will be created before everything in `<schedule>`.
530
+
To control where it is instantiated explicitly, use `bo.scope(<schedule>)`, where it will be created before everything in `<schedule>`.
501
531
502
532
So the previous is equivalent to:
503
533
@@ -526,6 +556,11 @@ This would be equivalent to this egglog:
526
556
(run-with bo step_right)))
527
557
```
528
558
559
+
That distinction matters because a scheduler carries state. Hoisting one
560
+
scheduler outside `* 10` lets its `times_banned` counters accumulate across all
561
+
ten runs. Placing `bo.scope(...)` inside `* 10` creates a fresh scheduler each
562
+
time, so every iteration starts with the initial `match_limit` and `ban_length`.
563
+
529
564
## Check
530
565
531
566
The `(check ...)` command to verify that some facts are true, can be translated to Python with the `egraph.check` function:
Copy file name to clipboardExpand all lines: docs/tutorials/getting-started.ipynb
+27-10Lines changed: 27 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -18,30 +18,47 @@
18
18
"\n",
19
19
"## Install egglog Python\n",
20
20
"\n",
21
-
"First, you will need to have a working Python interpreter. In this tutorial, we will [use `miniconda`](https://docs.conda.io/en/latest/miniconda.html) to create a new Python environment and activate it:\n",
21
+
"First, you will need a working Python 3.11 or newer interpreter. The safest setup is to create a new environment before installing `egglog`.\n",
22
+
"\n",
23
+
"With `pip`:\n",
22
24
"\n",
23
25
"```bash\n",
24
-
"$ brew install miniconda\n",
25
-
"$ conda create -n egglog-python python=3.11\n",
26
-
"$ conda activate egglog-python\n",
26
+
"$ python3.13 -m venv .venv # or any supported Python 3.11+\n",
27
+
"$ source .venv/bin/activate\n",
28
+
"$ python -m pip install --upgrade pip\n",
29
+
"$ python -m pip install egglog\n",
27
30
"```\n",
28
31
"\n",
29
-
"Then we want to install `egglog` Python. `egglog` Python can run on any recent Python version, and is tested on 3.8 - 3.11. To install it, run:\n",
32
+
"With `uv`:\n",
30
33
"\n",
31
34
"```bash\n",
32
-
"$ pip install egglog\n",
35
+
"$ uv init egglog-python-start\n",
36
+
"$ cd egglog-python-start\n",
37
+
"$ uv add egglog\n",
33
38
"```\n",
34
39
"\n",
35
40
"To test you have installed it correctly, run:\n",
"We also want to install `mypy` for static type checking. This is not required, but it will help us write correct representations. With pip, run:\n",
53
+
"\n",
54
+
"```bash\n",
55
+
"$ python -m pip install mypy\n",
39
56
"```\n",
40
57
"\n",
41
-
"We also want to install `mypy` for static type checking. This is not required, but it will help us write correct representations. To install it, run:\n",
Copy file name to clipboardExpand all lines: python/egglog/egraph.py
+16-3Lines changed: 16 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1560,7 +1560,11 @@ def ruleset(
1560
1560
@dataclass
1561
1561
classSchedule(DelayedDeclarations):
1562
1562
"""
1563
-
A composition of some rulesets, either composing them sequentially, running them repeatedly, running them till saturation, or running until some facts are met
1563
+
A composable e-graph schedule.
1564
+
1565
+
Use ``left + right`` to run schedules in sequence, ``schedule * n`` to
1566
+
repeat a schedule a fixed number of times, and ``schedule.saturate()`` to
1567
+
repeat until the schedule stops changing the e-graph.
1564
1568
"""
1565
1569
1566
1570
# Defer declerations so that we can have rule generators that used not yet defined yet
0 commit comments