egglog 6.0.1__cp310-none-win_amd64.whl → 6.1.0__cp310-none-win_amd64.whl

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.

Potentially problematic release.


This version of egglog might be problematic. Click here for more details.

Binary file
egglog/bindings.pyi CHANGED
@@ -150,6 +150,20 @@ class Fact:
150
150
 
151
151
  _Fact: TypeAlias = Fact | Eq
152
152
 
153
+ ##
154
+ # Change
155
+ ##
156
+
157
+ @final
158
+ class Delete:
159
+ def __init__(self) -> None: ...
160
+
161
+ @final
162
+ class Subsume:
163
+ def __init__(self) -> None: ...
164
+
165
+ _Change: TypeAlias = Delete | Subsume
166
+
153
167
  ##
154
168
  # Actions
155
169
  ##
@@ -168,10 +182,11 @@ class Set:
168
182
  rhs: _Expr
169
183
 
170
184
  @final
171
- class Delete:
185
+ class Change:
186
+ change: _Change
172
187
  sym: str
173
188
  args: list[_Expr]
174
- def __init__(self, sym: str, args: list[_Expr]) -> None: ...
189
+ def __init__(self, change: _Change, sym: str, args: list[_Expr]) -> None: ...
175
190
 
176
191
  @final
177
192
  class Union:
@@ -195,7 +210,7 @@ class Extract:
195
210
  expr: _Expr
196
211
  variants: _Expr
197
212
 
198
- _Action: TypeAlias = Let | Set | Delete | Union | Panic | Expr_ | Extract
213
+ _Action: TypeAlias = Let | Set | Change | Union | Panic | Expr_ | Extract
199
214
 
200
215
  ##
201
216
  # Other Structs
@@ -210,6 +225,7 @@ class FunctionDecl:
210
225
  merge_action: list[_Action]
211
226
  cost: int | None
212
227
  unextractable: bool
228
+ ignore_viz: bool
213
229
 
214
230
  def __init__(
215
231
  self,
@@ -220,6 +236,7 @@ class FunctionDecl:
220
236
  merge_action: list[_Action] = [], # noqa: B006
221
237
  cost: int | None = None,
222
238
  unextractable: bool = False,
239
+ ignore_viz: bool = False,
223
240
  ) -> None: ...
224
241
 
225
242
  @final
@@ -374,7 +391,8 @@ class RewriteCommand:
374
391
  # TODO: Rename to ruleset
375
392
  name: str
376
393
  rewrite: Rewrite
377
- def __init__(self, name: str, rewrite: Rewrite) -> None: ...
394
+ subsume: bool
395
+ def __init__(self, name: str, rewrite: Rewrite, subsume: bool) -> None: ...
378
396
 
379
397
  @final
380
398
  class BiRewriteCommand:
egglog/egraph.py CHANGED
@@ -1465,6 +1465,7 @@ class Rewrite(Command):
1465
1465
  _lhs: RuntimeExpr
1466
1466
  _rhs: RuntimeExpr
1467
1467
  _conditions: tuple[Fact, ...]
1468
+ _subsume: bool
1468
1469
  _fn_name: ClassVar[str] = "rewrite"
1469
1470
 
1470
1471
  def __str__(self) -> str:
@@ -1473,7 +1474,7 @@ class Rewrite(Command):
1473
1474
 
1474
1475
  def _to_egg_command(self, default_ruleset_name: str) -> bindings._Command:
1475
1476
  return bindings.RewriteCommand(
1476
- self.ruleset.egg_name if self.ruleset else default_ruleset_name, self._to_egg_rewrite()
1477
+ self.ruleset.egg_name if self.ruleset else default_ruleset_name, self._to_egg_rewrite(), self._subsume
1477
1478
  )
1478
1479
 
1479
1480
  def _to_egg_rewrite(self) -> bindings.Rewrite:
@@ -1488,7 +1489,7 @@ class Rewrite(Command):
1488
1489
  return Declarations.create(self._lhs, self._rhs, *self._conditions)
1489
1490
 
1490
1491
  def with_ruleset(self, ruleset: Ruleset) -> Rewrite:
1491
- return Rewrite(ruleset, self._lhs, self._rhs, self._conditions)
1492
+ return Rewrite(ruleset, self._lhs, self._rhs, self._conditions, self._subsume)
1492
1493
 
1493
1494
 
1494
1495
  @dataclass
@@ -1652,21 +1653,23 @@ class ExprAction(Action):
1652
1653
 
1653
1654
 
1654
1655
  @dataclass
1655
- class Delete(Action):
1656
+ class Change(Action):
1656
1657
  """
1657
- Remove a function call from an EGraph.
1658
+ Change a function call in an EGraph.
1658
1659
  """
1659
1660
 
1661
+ change: Literal["delete", "subsume"]
1660
1662
  _call: RuntimeExpr
1661
1663
 
1662
1664
  def __str__(self) -> str:
1663
- return f"delete({self._call})"
1665
+ return f"{self.change}({self._call})"
1664
1666
 
1665
- def _to_egg_action(self) -> bindings.Delete:
1667
+ def _to_egg_action(self) -> bindings.Change:
1666
1668
  egg_call = self._call.__egg__
1667
1669
  if not isinstance(egg_call, bindings.Call):
1668
1670
  raise ValueError(f"Can only create a call with a call for the lhs, got {self._call}") # noqa: TRY004
1669
- return bindings.Delete(egg_call.name, egg_call.args)
1671
+ change: bindings._Change = bindings.Delete() if self.change == "delete" else bindings.Subsume()
1672
+ return bindings.Change(change, egg_call.name, egg_call.args)
1670
1673
 
1671
1674
  @property
1672
1675
  def __egg_decls__(self) -> Declarations:
@@ -1800,16 +1803,16 @@ class Sequence(Schedule):
1800
1803
 
1801
1804
  @deprecated("Use <ruleset>.register(<rewrite>) instead of passing rulesets as arguments to rewrites.")
1802
1805
  @overload
1803
- def rewrite(lhs: EXPR, ruleset: Ruleset) -> _RewriteBuilder[EXPR]: ...
1806
+ def rewrite(lhs: EXPR, ruleset: Ruleset, *, subsume: bool = False) -> _RewriteBuilder[EXPR]: ...
1804
1807
 
1805
1808
 
1806
1809
  @overload
1807
- def rewrite(lhs: EXPR, ruleset: None = None) -> _RewriteBuilder[EXPR]: ...
1810
+ def rewrite(lhs: EXPR, ruleset: None = None, *, subsume: bool = False) -> _RewriteBuilder[EXPR]: ...
1808
1811
 
1809
1812
 
1810
- def rewrite(lhs: EXPR, ruleset: Ruleset | None = None) -> _RewriteBuilder[EXPR]:
1813
+ def rewrite(lhs: EXPR, ruleset: Ruleset | None = None, *, subsume: bool = False) -> _RewriteBuilder[EXPR]:
1811
1814
  """Rewrite the given expression to a new expression."""
1812
- return _RewriteBuilder(lhs, ruleset)
1815
+ return _RewriteBuilder(lhs, ruleset, subsume)
1813
1816
 
1814
1817
 
1815
1818
  @deprecated("Use <ruleset>.register(<birewrite>) instead of passing rulesets as arguments to birewrites.")
@@ -1852,7 +1855,12 @@ def expr_action(expr: Expr) -> Action:
1852
1855
 
1853
1856
  def delete(expr: Expr) -> Action:
1854
1857
  """Create a delete expression."""
1855
- return Delete(to_runtime_expr(expr))
1858
+ return Change("delete", to_runtime_expr(expr))
1859
+
1860
+
1861
+ def subsume(expr: Expr) -> Action:
1862
+ """Subsume an expression."""
1863
+ return Change("subsume", to_runtime_expr(expr))
1856
1864
 
1857
1865
 
1858
1866
  def expr_fact(expr: Expr) -> Fact:
@@ -1905,10 +1913,11 @@ def vars_(names: str, bound: type[EXPR]) -> Iterable[EXPR]:
1905
1913
  class _RewriteBuilder(Generic[EXPR]):
1906
1914
  lhs: EXPR
1907
1915
  ruleset: Ruleset | None
1916
+ subsume: bool
1908
1917
 
1909
1918
  def to(self, rhs: EXPR, *conditions: FactLike) -> Rewrite:
1910
1919
  lhs = to_runtime_expr(self.lhs)
1911
- rule = Rewrite(self.ruleset, lhs, convert_to_same_type(rhs, lhs), _fact_likes(conditions))
1920
+ rule = Rewrite(self.ruleset, lhs, convert_to_same_type(rhs, lhs), _fact_likes(conditions), self.subsume)
1912
1921
  if self.ruleset:
1913
1922
  self.ruleset.append(rule)
1914
1923
  return rule
@@ -1924,7 +1933,7 @@ class _BirewriteBuilder(Generic[EXPR]):
1924
1933
 
1925
1934
  def to(self, rhs: EXPR, *conditions: FactLike) -> Command:
1926
1935
  lhs = to_runtime_expr(self.lhs)
1927
- rule = BiRewrite(self.ruleset, lhs, convert_to_same_type(rhs, lhs), _fact_likes(conditions))
1936
+ rule = BiRewrite(self.ruleset, lhs, convert_to_same_type(rhs, lhs), _fact_likes(conditions), False)
1928
1937
  if self.ruleset:
1929
1938
  self.ruleset.append(rule)
1930
1939
  return rule
egglog/exp/array_api.py CHANGED
@@ -977,7 +977,7 @@ def _astype(x: NDArray, dtype: DType, i: i64):
977
977
  ]
978
978
 
979
979
 
980
- @function(cost=500)
980
+ @function
981
981
  def unique_counts(x: NDArray) -> TupleNDArray: ...
982
982
 
983
983
 
@@ -1016,7 +1016,7 @@ def _abs(f: Float):
1016
1016
  ]
1017
1017
 
1018
1018
 
1019
- @function(cost=100)
1019
+ @function
1020
1020
  def unique_inverse(x: NDArray) -> TupleNDArray: ...
1021
1021
 
1022
1022
 
@@ -1039,7 +1039,7 @@ def zeros(
1039
1039
  def expand_dims(x: NDArray, axis: Int = Int(0)) -> NDArray: ...
1040
1040
 
1041
1041
 
1042
- @function(cost=100000)
1042
+ @function
1043
1043
  def mean(x: NDArray, axis: OptionalIntOrTuple = OptionalIntOrTuple.none, keepdims: Boolean = FALSE) -> NDArray: ...
1044
1044
 
1045
1045
 
@@ -1048,7 +1048,7 @@ def mean(x: NDArray, axis: OptionalIntOrTuple = OptionalIntOrTuple.none, keepdim
1048
1048
  def sqrt(x: NDArray) -> NDArray: ...
1049
1049
 
1050
1050
 
1051
- @function(cost=100000)
1051
+ @function
1052
1052
  def std(x: NDArray, axis: OptionalIntOrTuple = OptionalIntOrTuple.none) -> NDArray: ...
1053
1053
 
1054
1054
 
@@ -10,12 +10,9 @@ from egglog.exp.array_api import *
10
10
 
11
11
  array_api_numba_ruleset = ruleset()
12
12
  array_api_numba_schedule = (array_api_ruleset + array_api_numba_ruleset).saturate()
13
- # For these rules, we not only wanna rewrite, we also want to delete the original expression,
13
+ # For these rules, we not only wanna rewrite, we also want to subsume the original expression,
14
14
  # so that the rewritten one is used, even if the original one is simpler.
15
15
 
16
- # TODO: Try deleting instead if we support that in the future, and remove high cost
17
- # https://egraphs.zulipchat.com/#narrow/stream/375765-egglog/topic/replacing.20an.20expression.20with.20delete
18
-
19
16
 
20
17
  # Rewrite mean(x, <int>, <expand dims>) to use sum b/c numba cant do mean with axis
21
18
  # https://github.com/numba/numba/issues/1269
@@ -24,8 +21,8 @@ def _mean(y: NDArray, x: NDArray, i: Int):
24
21
  axis = OptionalIntOrTuple.some(IntOrTuple.int(i))
25
22
  res = sum(x, axis) / NDArray.scalar(Value.int(x.shape[i]))
26
23
 
27
- yield rewrite(mean(x, axis, FALSE)).to(res)
28
- yield rewrite(mean(x, axis, TRUE)).to(expand_dims(res, i))
24
+ yield rewrite(mean(x, axis, FALSE), subsume=True).to(res)
25
+ yield rewrite(mean(x, axis, TRUE), subsume=True).to(expand_dims(res, i))
29
26
 
30
27
 
31
28
  # Rewrite std(x, <int>) to use mean and sum b/c numba cant do std with axis
@@ -34,7 +31,7 @@ def _std(y: NDArray, x: NDArray, i: Int):
34
31
  axis = OptionalIntOrTuple.some(IntOrTuple.int(i))
35
32
  # https://numpy.org/doc/stable/reference/generated/numpy.std.html
36
33
  # "std = sqrt(mean(x)), where x = abs(a - a.mean())**2."
37
- yield rewrite(std(x, axis)).to(sqrt(mean(square(x - mean(x, axis, keepdims=TRUE)), axis)))
34
+ yield rewrite(std(x, axis), subsume=True).to(sqrt(mean(square(x - mean(x, axis, keepdims=TRUE)), axis)))
38
35
 
39
36
 
40
37
  # rewrite unique_counts to count each value one by one, since numba doesn't support np.unique(..., return_counts=True)
@@ -49,11 +46,11 @@ def count_values(x: NDArray, values: NDArray) -> TupleValue:
49
46
  def _unique_counts(x: NDArray, c: NDArray, tv: TupleValue, v: Value):
50
47
  return [
51
48
  # The unique counts are the count of all the unique values
52
- rewrite(unique_counts(x)[Int(1)]).to(NDArray.vector(count_values(x, unique_values(x)))),
53
- rewrite(count_values(x, NDArray.vector(TupleValue(v) + tv))).to(
49
+ rewrite(unique_counts(x)[Int(1)], subsume=True).to(NDArray.vector(count_values(x, unique_values(x)))),
50
+ rewrite(count_values(x, NDArray.vector(TupleValue(v) + tv)), subsume=True).to(
54
51
  TupleValue(sum(x == NDArray.scalar(v)).to_value()) + count_values(x, NDArray.vector(tv))
55
52
  ),
56
- rewrite(count_values(x, NDArray.vector(TupleValue(v)))).to(
53
+ rewrite(count_values(x, NDArray.vector(TupleValue(v))), subsume=True).to(
57
54
  TupleValue(sum(x == NDArray.scalar(v)).to_value()),
58
55
  ),
59
56
  ]
@@ -64,7 +61,7 @@ def _unique_counts(x: NDArray, c: NDArray, tv: TupleValue, v: Value):
64
61
  def _unique_inverse(x: NDArray, i: Int):
65
62
  return [
66
63
  # Creating a mask array of when the unique inverse is a value is the same as a mask array for when the value is that index of the unique values
67
- rewrite(unique_inverse(x)[Int(1)] == NDArray.scalar(Value.int(i))).to(
64
+ rewrite(unique_inverse(x)[Int(1)] == NDArray.scalar(Value.int(i)), subsume=True).to(
68
65
  x == NDArray.scalar(unique_values(x).index(TupleInt(i)))
69
66
  ),
70
67
  ]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: egglog
3
- Version: 6.0.1
3
+ Version: 6.1.0
4
4
  Classifier: Environment :: MacOS X
5
5
  Classifier: Environment :: Win32 (MS Windows)
6
6
  Classifier: Intended Audience :: Developers
@@ -24,6 +24,10 @@ Requires-Dist: ruff; extra == 'dev'
24
24
  Requires-Dist: mypy; extra == 'dev'
25
25
  Requires-Dist: anywidget[dev]; extra == 'dev'
26
26
  Requires-Dist: egglog[docs,test]; extra == 'dev'
27
+ Requires-Dist: scikit-learn; extra == 'array'
28
+ Requires-Dist: array_api_compat; extra == 'array'
29
+ Requires-Dist: numba==0.59.0rc1; extra == 'array'
30
+ Requires-Dist: llvmlite==0.42.0rc1; extra == 'array'
27
31
  Requires-Dist: pytest; extra == 'test'
28
32
  Requires-Dist: mypy; extra == 'test'
29
33
  Requires-Dist: syrupy; extra == 'test'
@@ -31,10 +35,6 @@ Requires-Dist: egglog[array]; extra == 'test'
31
35
  Requires-Dist: pytest-codspeed; extra == 'test'
32
36
  Requires-Dist: pytest-benchmark; extra == 'test'
33
37
  Requires-Dist: pytest-xdist; extra == 'test'
34
- Requires-Dist: scikit-learn; extra == 'array'
35
- Requires-Dist: array_api_compat; extra == 'array'
36
- Requires-Dist: numba==0.59.0rc1; extra == 'array'
37
- Requires-Dist: llvmlite==0.42.0rc1; extra == 'array'
38
38
  Requires-Dist: pydata-sphinx-theme; extra == 'docs'
39
39
  Requires-Dist: myst-nb; extra == 'docs'
40
40
  Requires-Dist: sphinx-autodoc-typehints; extra == 'docs'
@@ -48,8 +48,8 @@ Requires-Dist: line-profiler; extra == 'docs'
48
48
  Requires-Dist: sphinxcontrib-mermaid; extra == 'docs'
49
49
  Requires-Dist: ablog; extra == 'docs'
50
50
  Provides-Extra: dev
51
- Provides-Extra: test
52
51
  Provides-Extra: array
52
+ Provides-Extra: test
53
53
  Provides-Extra: docs
54
54
  License-File: LICENSE
55
55
  Summary: e-graphs in Python built around the the egglog rust library
@@ -1,11 +1,11 @@
1
- egglog-6.0.1.dist-info/METADATA,sha256=_0zzByEDW1HDQDSLUWZ35_k9psax38q85ZOf88XWeLM,3838
2
- egglog-6.0.1.dist-info/WHEEL,sha256=keLBtIOE7ZgLyd8Cijw37iqv72a2jhfxMdDu8Unr7zo,96
3
- egglog-6.0.1.dist-info/license_files/LICENSE,sha256=TfaboMVZ81Q6OUaKjU7z6uVjSlcGKclLYcOpgDbm9_s,1091
4
- egglog/bindings.pyi,sha256=bOaXFUKse5yCUrwbGY_TujRsTZfVUNYMNw8z-fgMyGk,11199
1
+ egglog-6.1.0.dist-info/METADATA,sha256=1MhEh2rFwsmv5yqI6TZ2hoHfGwxUBSzFk1Z_slTV0HU,3838
2
+ egglog-6.1.0.dist-info/WHEEL,sha256=keLBtIOE7ZgLyd8Cijw37iqv72a2jhfxMdDu8Unr7zo,96
3
+ egglog-6.1.0.dist-info/license_files/LICENSE,sha256=TfaboMVZ81Q6OUaKjU7z6uVjSlcGKclLYcOpgDbm9_s,1091
4
+ egglog/bindings.pyi,sha256=YPGerQlOpSO6kHyIYTUh1hnOopy4cyAKMPtljr3a1rg,11514
5
5
  egglog/builtins.py,sha256=lc7jWEjf5hUXzPRvo8pJrkGFIUBC0oLXV4U6WYXDrEw,11959
6
6
  egglog/config.py,sha256=mALVaxh7zmGrbuyzaVKVmYKcu1lF703QsKJw8AF7gSM,176
7
7
  egglog/declarations.py,sha256=JMivLe8Cwna3BsLgls9X_LU-ZQuFapyD-KkZpkf4Eq0,39062
8
- egglog/egraph.py,sha256=EtcXWeTg74QXSe4uK9dFmFIGfGmcfZWl53nj_FULMcI,69203
8
+ egglog/egraph.py,sha256=y-vPuD0U1h8ajNrjy3V5q-r61j6yDtQbeOyDFaZy9eE,69677
9
9
  egglog/examples/bool.py,sha256=pWZTjfXR1cFy3KcihLBU5AF5rn83ImORlhUUJ1YiAXc,733
10
10
  egglog/examples/eqsat_basic.py,sha256=ORXFYYEDsEZK2IPhHtoFsd-LdjMiQi1nn7kix4Nam0s,1011
11
11
  egglog/examples/fib.py,sha256=wAn-PjazxgHDkXAU4o2xTk_GtM_iGL0biV66vWM1st4,520
@@ -16,9 +16,9 @@ egglog/examples/README.rst,sha256=QrbfmivODBvUvmY3-dHarcbC6bEvwoqAfTDhiI-aJxU,23
16
16
  egglog/examples/resolution.py,sha256=sKkbRI_v9XkQM0DriacKLINqKKDqYGFhvMCAS9tZbTA,2203
17
17
  egglog/examples/schedule_demo.py,sha256=iJtIbcLaZ7zK8UalY0z7KAKMqYjQx0MKTsNF24lKtik,652
18
18
  egglog/examples/__init__.py,sha256=KuhaJFOyz_rpUvEqZubsgLnv6rhQNE_AVFXA6bUnpdY,34
19
- egglog/exp/array_api.py,sha256=SlClQ4aqXL3rwWG7j-mfjbLjduA83qginlm0p7c01zM,40947
19
+ egglog/exp/array_api.py,sha256=ozOPzHzWBT6-5TFX4Flc9Em4I_WBywZZsekmadi06wg,40901
20
20
  egglog/exp/array_api_jit.py,sha256=HIZzd0G17u-u_F4vfRdhoYvRo-ETx5HFO3RBcOfLcco,1287
21
- egglog/exp/array_api_numba.py,sha256=oAO9o5LfBlASDXqovdBUX0CT8GCCk8B4P9TIlBQPSps,2981
21
+ egglog/exp/array_api_numba.py,sha256=b7pA3Mk0s0H5s0N5ZWofcWUXb4EVmnUZMEJk0EXyukw,2881
22
22
  egglog/exp/array_api_program_gen.py,sha256=crgUYXXNhQdfTq31FSIpWLIfzNsgQD8ngg3OosCtIgg,19680
23
23
  egglog/exp/program_gen.py,sha256=2qlfc-dVSNbPFQVl0eIzUzf-yw28AeaARa4PUC1xtRA,12257
24
24
  egglog/exp/__init__.py,sha256=G9zeKUcPBgIhgUg1meC86OfZVFETYIugyHWseTcCe_0,52
@@ -30,5 +30,5 @@ egglog/type_constraint_solver.py,sha256=u-b2SZxptCxjYNcht_TQSAebIVEcf3P_-2-TJk8u
30
30
  egglog/widget.css,sha256=WJS2M1wQdujhSTCakMa_ZXuoTPre1Uy1lPcvBE1LZQU,102
31
31
  egglog/widget.js,sha256=UNOER3sYZ-bS7Qhw9S6qtpR81FuHa5DzXQaWWtQq334,2021
32
32
  egglog/__init__.py,sha256=AGM-7H_Vx1Xb0Z-tc0C9Y8JbQxpa6hdYfhSU_dnT3Mw,244
33
- egglog/bindings.cp310-win_amd64.pyd,sha256=rqr6-ruHokEX0FshXaGf6dN4-GLH3l6KFcSbVP0Kp70,4878336
34
- egglog-6.0.1.dist-info/RECORD,,
33
+ egglog/bindings.cp310-win_amd64.pyd,sha256=M6YHB0Ef-G-xSpFHmIFtPa-sL8yQ2t_C_DfDoPjCJ0s,4991488
34
+ egglog-6.1.0.dist-info/RECORD,,
File without changes