Skip to content

Conversation

@sklam
Copy link

@sklam sklam commented Dec 16, 2025

This PR implements py-to-int and PyObject.to_int so that a Python int stored as PyObject can be converted into a i64.

Reason:

I am exploring (or maybe i'm abusing) the PyObject API to store Python objects into the EGraph and allowing them to generate equivalances in Python code back into EGraph. See example gist: https://gist.github.com/sklam/f141efe69bf86182ed185274b6648e93

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 16, 2025

CodSpeed Performance Report

Merging #393 will not alter performance

Comparing sklam:enh/py_to_int (17c7198) with main (6a892ec)

Summary

✅ 14 untouched

@saulshanabrook
Copy link
Member

Interesting timing, #394 was also just opened that added this after you. I just saw that one first and merged it.

In terms of storing py objects that have references to egglog values, this could be done but maybe would be better done by adding support for the container API? That way during rebuilding if you unioned two terms for example, it would know to rebuild that Python value that stored them so they could in turn be unioned. I have been meaning to add support for this for a while, so this could be a good use case for it. I just glanced at the example though, I wasn't sure if that was needed for it.

It seems like you are using it for an alternative list implementation?

@sklam
Copy link
Author

sklam commented Jan 5, 2026

The example is exploring the ability to write Python logic to expand eclasses by generating equivalent nodes. See the generate_alternatives method. The tensor expression transformation that I am trying is a lot more intuitive to reason about in terms of Python-side data-structure than as egglog declarative rewrites. If this can be done, I think it helps lowering the entry to use our compiler to create rewrite rules.

The other thing I wanted to try is have egglog see a simplified representation for MLIR node so that I can still use MLIR to run transformation. MLIR is creating a giant phase ordering problem for us. Maybe I can use egglog to find the best MLIR pass sequence as the default pipeline.

Btw, I notice that cloudpickle does not always make the same byte sequence for the same object if the object pickled by-value. This leads to duplicated egglog PyObject nodes even though the underlying py-object is the same. For example, any class in the __main__ module is not "importable" and will therefore pickled by-value (see https://github.com/cloudpipe/cloudpickle/blob/f5199fe2bc102a5ee070c743336699fc885ca966/cloudpickle/cloudpickle.py#L291-L303).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants