Skip to content

Commit

Permalink
Merge pull request #108 from egraphs-good/change
Browse files Browse the repository at this point in the history
Internal changes to prepare for refactor
  • Loading branch information
saulshanabrook authored Jan 30, 2024
2 parents 135b4b2 + ad7a0e6 commit dea4390
Show file tree
Hide file tree
Showing 18 changed files with 1,064 additions and 759 deletions.
2 changes: 1 addition & 1 deletion .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ version: 2
build:
os: ubuntu-20.04
tools:
python: "3.11"
python: "3.12"
# # You can also specify other tool versions:
# # nodejs: "16"
rust: "1.70"
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@ _This project uses semantic versioning_

## UNRELEASED

### Auto Register Function and Class Definitions

_not yet implemented_

This is a large breaking change that moves the function and class decorators to the top level `egglog` module,
from the `EGraph` and `Module` classes. Rulesets are also moved to be defined globally instead of on the `EGraph` class.

The goal of this change is to remove the complexity of `Module`s and remove the need to think about what functions/classes
need to be registered for each `EGraph`. Instead, we will implicitly register and functions/classes that are used
in any rules or added in any commands.

- `egraph.class_` -> Simply subclass from `egglog.Expr`
- `egraph.method` -> `egglog.method`
- `egraph.function` -> `egglog.function`
- `egraph.relation` -> `egglog.relation`
- `egraph.ruleset` -> `egglog.Ruleset`

The `EGraph` class can take an optional `default_ruleset` argument to set the default ruleset for the `EGraph`. Otherwise,
there is a global default ruleset that is used, `egglog.Ruleset`.

This also adds support for classes with methods that are mutually recursive, by making type analysis more lazy.

## 5.0.0 (2024-01-16)

- Move egglog `!=` function to be called with `ne(x).to(y)` instead of `x != y` so that user defined expressions
Expand Down
10 changes: 8 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@
# Myst
##

myst_enable_extensions = ["attrs_inline", "smartquotes", "strikethrough", "html_image"]
myst_enable_extensions = [
# "attrs_inline",
"smartquotes",
"strikethrough",
"html_image",
"deflist",
]
myst_fence_as_directive = ["mermaid"]

##
Expand All @@ -38,7 +44,7 @@
output_dir = cwd / "presentations"

subprocess.run(
[ # noqa: S603,S607
[ # noqa: S607, S603
"jupyter",
"nbconvert",
str(presentation_file),
Expand Down
93 changes: 93 additions & 0 deletions docs/new_reference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Reference Documentation

```{module} egglog
```

_TODO: this isn't done yet_
This is a definitive reference of `egglog` module and the concepts in it.

## Terms

Ruleset
: A colleciton of rules

Rule
: Updates an EGraph by matching on a number of facts and then running a number of actions. Any variables in the facts can be used in the actions.

Fact
: A query on an EGraph, either by an expression or an equivalence between multiple expressions.

Action
: A change to an EGraph, either unioning multiple expressing, setting the value of a function call, deleting an expression, or panicking.
Union
: Merges two equivalence classes of two expressions.
Set
: Similar to union, except can be used on primitive expressions, whereas union can only be used on user defined expressions.
Delete
: Remove a function call from an EGraph.

Schedule
: A composition of some rulesets, either composing them sequentially, running them repeatedly, running them till saturation, or running until some facts are met

EGraph ([](egglog.EGraph))
: An equivalence relation over a set of expressions.
: A collection of expressions where each expression is part of a distinct equivalence class.
: Can run actions, check facts, run schedules, or extract minimal cost expressions.

Expression ([](egglog.Expr))
: Either a function called with some number of argument expressions or a literal integer, float, or string, with a particular type.

Function ([](egglog.function))
: Defined by a unique name and a typing relation that will specify the return type based on the types of the argument expressions.
: These can either be builtin functions, which are implemented in Rust, or user defined function which have types for each argument and the return type.
: Relations ([](egglog.relation)), constants ([](egglog.constant)), methods ([](egglog.method)), classmethods, and class variables are all syntactic sugar for defining functions.

Type (called a "sort" in the rust bindings)
: A uniquely named entity, that is used to constraint the composition of functions.
: Can be either a primitive type if it is defined in Rust or a user defined type.

## Classes

```{class} EGraph
```

https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#module-sphinx.ext.autodoc
https://www.sphinx-doc.org/en/master/usage/domains/python.html#signatures
https://myst-parser.readthedocs.io/en/latest/syntax/roles-and-directives.html

```{class} Expr
Subclass `Expr` to create a new type. Only direct subclasses are supported, subclasses of subclasses are not for now.
```

```{decorator} function
```

```{decorator} method
Any method can be decorated with this to customize it's behavior. This is only supported in classes which subclass [](egglog.Expr).
```

```{function} relation
Creates a function whose return type is [](egglog.Unit) and whose default value is `[](egglog.Unit)`.
```

```{function} constant
A "constant" is implemented as the instantiation of a value that takes no args.
This creates a function with `name` and return type `tp` and returns a value of it being called.
```

```{class} Unit
Primitive type with only one possible value.
```
1 change: 1 addition & 0 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ reference/high-level
reference/egglog-translation
reference/python-integration
reference/bindings
new_reference
```
4 changes: 2 additions & 2 deletions docs/reference/python-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ assert egraph.eval(evalled) == 3

### Simpler Eval

Instead of using the above low level primitive for evaluating, there is a higher level wrapper function, `eval_fn`.
Instead of using the above low level primitive for evaluating, there is a higher level wrapper function, `py_eval_fn`.

It takes in a Python function and converts it to a function of PyObjects, by using `py_eval` under the hood.

Expand All @@ -115,7 +115,7 @@ The above code code be re-written like this:
def my_add(a, b):
return a + b
evalled = eval_fn(lambda a: my_add(a, 2))(1)
evalled = py_eval_fn(lambda a: my_add(a, 2))(1)
assert egraph.eval(evalled) == 3
```

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ dependencies = ["typing-extensions", "black", "graphviz"]

[project.optional-dependencies]

array = ["scikit-learn", "array_api_compat", 'numba; python_version<"3.12"']
array = ["scikit-learn", "array_api_compat", "numba==0.59.0rc1", "llvmlite==0.42.0rc1"]
dev = ["pre-commit", "ruff", "mypy", "anywidget[dev]", "egglog[docs,test]"]

test = ["pytest", "mypy", "syrupy", "egglog[array]"]
Expand Down
Loading

0 comments on commit dea4390

Please sign in to comment.