Skip to content

Commit 6aa2d11

Browse files
Switch to new backend branch
* Changes PyObjectSort to use new interface * Removes Rational since experimental not updated yet
1 parent d38a8b0 commit 6aa2d11

File tree

8 files changed

+796
-774
lines changed

8 files changed

+796
-774
lines changed

Cargo.lock

Lines changed: 521 additions & 294 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ crate-type = ["cdylib"]
1212
[dependencies]
1313
pyo3 = { version = "0.23.0", features = ["extension-module"] }
1414

15-
egglog = { git = "https://github.com/egraphs-good/egglog", rev = "6f494282442803201b512e9d0828007b52a0b29c" }
16-
egglog-experimental = { git = "https://github.com/egraphs-good/egglog-experimental", rev = "8a1b3d6ad2723a8438f51f05027161e51f37917c" }
15+
# egglog = { git = "https://github.com/egraphs-good/egglog", rev = "dd8e8cfa1f8851d32c8b7a0d1f4165e2164a7313" }
16+
egglog = { git = "https://github.com/saulshanabrook/egg-smol", rev = "8cd7c0e77a27c271cbaef09ab23514675d646937" }
17+
egglog-bridge = { git = "https://github.com/egraphs-good/egglog-backend.git", rev = "e8fb003" }
18+
core-relations = { git = "https://github.com/egraphs-good/egglog-backend.git", rev = "e8fb003" }
19+
# egglog-experimental = { git = "https://github.com/egraphs-good/egglog-experimental", rev = "8a1b3d6ad2723a8438f51f05027161e51f37917c" }
1720
egraph-serialize = { version = "0.2.0", features = ["serde", "graphviz"] }
1821
serde_json = "1.0.140"
1922
pyo3-log = "0.12.3"
@@ -23,9 +26,9 @@ ordered-float = "3.7.0"
2326
uuid = { version = "1.16.0", features = ["v4"] }
2427

2528
# Use unreleased version of egglog in experimental
26-
[patch.'https://github.com/egraphs-good/egglog']
29+
# [patch.'https://github.com/egraphs-good/egglog']
2730
# https://github.com/rust-lang/cargo/issues/5478#issuecomment-522719793
28-
egglog = { git = "https://github.com/egraphs-good//egglog.git", rev = "6f494282442803201b512e9d0828007b52a0b29c" }
31+
# egglog = { git = "https://github.com/egraphs-good//egglog.git", rev = "6f494282442803201b512e9d0828007b52a0b29c" }
2932

3033
# [replace]
3134
# 'https://github.com/egraphs-good/egglog.git#[email protected]' = { git = "https://github.com/egraphs-good/egglog.git", rev = "215714e1cbb13ae9e21bed2f2e1bf95804571512" }

docs/changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ _This project uses semantic versioning_
44

55
## UNRELEASED
66

7+
- Upgrade egglog which includes new backend. Removes support for egglog experimental including `Rational` since it
8+
is not compatible with new backend yet.
9+
710
## 10.0.1 (2025-04-06)
811

912
- Fix bug on resolving types if not all imported to your module [#286](https://github.com/egraphs-good/egglog-python/pull/286)

docs/reference/egglog-translation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ i64(10) + i64(2)
2929
```
3030

3131
```{code-cell} python
32-
# egg: (+ (rational 1 2) (rational 2 1))
33-
Rational(i64(1), i64(2)) / Rational(i64(2), i64(1))
32+
# egg: (+ (bigrat (bigint 1) (bigint 2)) (big-rat (bigint 2) (bigint 1)))
33+
BigRat(1, 2) / BigRat(2, 1)
3434
```
3535

3636
These types are also all checked statically with MyPy, so for example, if you try to add a `String` and a `i64`, you will get a type error.
@@ -44,7 +44,7 @@ i64(10) + 2
4444
```
4545

4646
```{code-cell} python
47-
Rational(1, 2) / Rational(2, 1)
47+
BigRat(1, 2) / BigRat(2, 1)
4848
```
4949

5050
### `!=` Operator

python/egglog/builtins.py

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
"MapLike",
3737
"MultiSet",
3838
"PyObject",
39-
"Rational",
4039
"Set",
4140
"SetLike",
4241
"String",
@@ -527,91 +526,92 @@ def __add__(self, other: MultiSet[T]) -> MultiSet[T]: ...
527526
def map(self, f: Callable[[T], T]) -> MultiSet[T]: ...
528527

529528

530-
class Rational(BuiltinExpr):
531-
@method(preserve=True)
532-
def eval(self) -> Fraction:
533-
call = _extract_call(self)
534-
if call.callable != InitRef("Rational"):
535-
msg = "Rational can only be initialized with the Rational constructor."
536-
raise BuiltinEvalError(msg)
529+
# Removed until egglog experimental supports new backend
530+
# class Rational(BuiltinExpr):
531+
# @method(preserve=True)
532+
# def eval(self) -> Fraction:
533+
# call = _extract_call(self)
534+
# if call.callable != InitRef("Rational"):
535+
# msg = "Rational can only be initialized with the Rational constructor."
536+
# raise BuiltinEvalError(msg)
537537

538-
def _to_int(e: TypedExprDecl) -> int:
539-
expr = e.expr
540-
if not isinstance(expr, LitDecl):
541-
msg = "Rational can only be initialized with literals"
542-
raise BuiltinEvalError(msg)
543-
assert isinstance(expr.value, int)
544-
return expr.value
538+
# def _to_int(e: TypedExprDecl) -> int:
539+
# expr = e.expr
540+
# if not isinstance(expr, LitDecl):
541+
# msg = "Rational can only be initialized with literals"
542+
# raise BuiltinEvalError(msg)
543+
# assert isinstance(expr.value, int)
544+
# return expr.value
545545

546-
num, den = call.args
547-
return Fraction(_to_int(num), _to_int(den))
546+
# num, den = call.args
547+
# return Fraction(_to_int(num), _to_int(den))
548548

549-
@method(preserve=True)
550-
def __float__(self) -> float:
551-
return float(self.eval())
549+
# @method(preserve=True)
550+
# def __float__(self) -> float:
551+
# return float(self.eval())
552552

553-
@method(preserve=True)
554-
def __int__(self) -> int:
555-
return int(self.eval())
553+
# @method(preserve=True)
554+
# def __int__(self) -> int:
555+
# return int(self.eval())
556556

557-
@method(egg_fn="rational")
558-
def __init__(self, num: i64Like, den: i64Like) -> None: ...
557+
# @method(egg_fn="rational")
558+
# def __init__(self, num: i64Like, den: i64Like) -> None: ...
559559

560-
@method(egg_fn="to-f64")
561-
def to_f64(self) -> f64: ...
560+
# @method(egg_fn="to-f64")
561+
# def to_f64(self) -> f64: ...
562562

563-
@method(egg_fn="+")
564-
def __add__(self, other: Rational) -> Rational: ...
563+
# @method(egg_fn="+")
564+
# def __add__(self, other: Rational) -> Rational: ...
565565

566-
@method(egg_fn="-")
567-
def __sub__(self, other: Rational) -> Rational: ...
566+
# @method(egg_fn="-")
567+
# def __sub__(self, other: Rational) -> Rational: ...
568568

569-
@method(egg_fn="*")
570-
def __mul__(self, other: Rational) -> Rational: ...
569+
# @method(egg_fn="*")
570+
# def __mul__(self, other: Rational) -> Rational: ...
571571

572-
@method(egg_fn="/")
573-
def __truediv__(self, other: Rational) -> Rational: ...
572+
# @method(egg_fn="/")
573+
# def __truediv__(self, other: Rational) -> Rational: ...
574574

575-
@method(egg_fn="min")
576-
def min(self, other: Rational) -> Rational: ...
575+
# @method(egg_fn="min")
576+
# def min(self, other: Rational) -> Rational: ...
577577

578-
@method(egg_fn="max")
579-
def max(self, other: Rational) -> Rational: ...
578+
# @method(egg_fn="max")
579+
# def max(self, other: Rational) -> Rational: ...
580580

581-
@method(egg_fn="neg")
582-
def __neg__(self) -> Rational: ...
581+
# @method(egg_fn="neg")
582+
# def __neg__(self) -> Rational: ...
583583

584-
@method(egg_fn="abs")
585-
def __abs__(self) -> Rational: ...
584+
# @method(egg_fn="abs")
585+
# def __abs__(self) -> Rational: ...
586586

587-
@method(egg_fn="floor")
588-
def floor(self) -> Rational: ...
587+
# @method(egg_fn="floor")
588+
# def floor(self) -> Rational: ...
589589

590-
@method(egg_fn="ceil")
591-
def ceil(self) -> Rational: ...
590+
# @method(egg_fn="ceil")
591+
# def ceil(self) -> Rational: ...
592592

593-
@method(egg_fn="round")
594-
def round(self) -> Rational: ...
593+
# @method(egg_fn="round")
594+
# def round(self) -> Rational: ...
595595

596-
@method(egg_fn="pow")
597-
def __pow__(self, other: Rational) -> Rational: ...
596+
# @method(egg_fn="pow")
597+
# def __pow__(self, other: Rational) -> Rational: ...
598598

599-
@method(egg_fn="log")
600-
def log(self) -> Rational: ...
599+
# @method(egg_fn="log")
600+
# def log(self) -> Rational: ...
601601

602-
@method(egg_fn="sqrt")
603-
def sqrt(self) -> Rational: ...
602+
# @method(egg_fn="sqrt")
603+
# def sqrt(self) -> Rational: ...
604604

605-
@method(egg_fn="cbrt")
606-
def cbrt(self) -> Rational: ...
605+
# @method(egg_fn="cbrt")
606+
# def cbrt(self) -> Rational: ...
607607

608-
@method(egg_fn="numer") # type: ignore[misc]
609-
@property
610-
def numer(self) -> i64: ...
608+
# @method(egg_fn="numer") # type: ignore[misc]
609+
# @property
610+
# def numer(self) -> i64: ...
611611

612-
@method(egg_fn="denom") # type: ignore[misc]
613-
@property
614-
def denom(self) -> i64: ...
612+
# @method(egg_fn="denom") # type: ignore[misc]
613+
# @property
614+
# def denom(self) -> i64: ...
615615

616616

617617
class BigInt(BuiltinExpr):

python/tests/test_high_level.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,10 @@ def test_set(self):
511511
assert i64(1) in s
512512
assert i64(3) not in s
513513

514-
def test_rational(self):
515-
assert Rational(1, 2).eval() == Fraction(1, 2)
516-
assert float(Rational(1, 2)) == 0.5
517-
assert int(Rational(1, 1)) == 1
514+
# def test_rational(self):
515+
# assert Rational(1, 2).eval() == Fraction(1, 2)
516+
# assert float(Rational(1, 2)) == 0.5
517+
# assert int(Rational(1, 1)) == 1
518518

519519
def test_vec(self):
520520
assert Vec[i64].empty().eval() == ()

src/egraph.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::error::{EggResult, WrappedError};
55
use crate::py_object_sort::ArcPyObjectSort;
66
use crate::serialize::SerializedEGraph;
77

8-
use egglog::{span, SerializeConfig};
8+
use egglog::{span, EGraph as EgglogEGraph, SerializeConfig};
99
use log::info;
1010
use pyo3::prelude::*;
1111
use std::path::PathBuf;
@@ -33,7 +33,7 @@ impl EGraph {
3333
seminaive: bool,
3434
record: bool,
3535
) -> Self {
36-
let mut egraph = egglog_experimental::new_experimental_egraph();
36+
let mut egraph = EgglogEGraph::default();
3737
egraph.fact_directory = fact_directory;
3838
egraph.seminaive = seminaive;
3939
if let Some(py_object_sort) = py_object_sort {

0 commit comments

Comments
 (0)