1 unstable release

0.1.0 Oct 28, 2023

#2023 in Encoding

Download history 1/week @ 2024-01-01 20/week @ 2024-01-08 16/week @ 2024-01-15 27/week @ 2024-01-22 8/week @ 2024-01-29 10/week @ 2024-02-05 25/week @ 2024-02-12 63/week @ 2024-02-19 27/week @ 2024-02-26 24/week @ 2024-03-04 23/week @ 2024-03-11 16/week @ 2024-03-18 17/week @ 2024-03-25 74/week @ 2024-04-01 20/week @ 2024-04-08 18/week @ 2024-04-15

130 downloads per month
Used in egglog

MIT license

2.5MB
389 lines

serialize ur egraphs

mostly for use in extraction gym rn

snippet for egg

One day egg will natively export to this format, but for now you can use this:

pub fn egg_to_serialized_egraph<L, A>(egraph: &EGraph<L, A>) -> egraph_serialize::EGraph
where
    L: Language + Display,
    A: Analysis<L>,
{
    use egraph_serialize::*;
    let mut out = EGraph::default();
    for class in egraph.classes() {
        for (i, node) in class.nodes.iter().enumerate() {
            out.add_node(
                format!("{}.{}", class.id, i),
                Node {
                    op: node.to_string(),
                    children: node
                        .children()
                        .iter()
                        .map(|id| NodeId::from(format!("{}.0", id)))
                        .collect(),
                    eclass: ClassId::from(format!("{}", class.id)),
                    cost: Cost::new(1.0).unwrap(),
                },
            )
        }
    }
    out
}

Don't forget to add something to root_eclasses on the resulting serialized egraph!

Visualization

Check out the ./tests-viz directory to view visualizations of all the test cases with Graphviz.

To remake them, run make tests-viz from the root of this repo. You'll need to have Graphviz installed.

Dependencies

~1–12MB
~129K SLoC