2 unstable releases

0.2.0 Sep 28, 2024
0.1.0 Oct 28, 2023

#540 in Algorithms

Download history 21/week @ 2024-07-28 24/week @ 2024-08-04 26/week @ 2024-08-11 26/week @ 2024-08-18 59/week @ 2024-08-25 42/week @ 2024-09-01 46/week @ 2024-09-08 75/week @ 2024-09-15 115/week @ 2024-09-22 194/week @ 2024-09-29 73/week @ 2024-10-06 78/week @ 2024-10-13 98/week @ 2024-10-20 35/week @ 2024-10-27 43/week @ 2024-11-03 22/week @ 2024-11-10

207 downloads per month
Used in egglog

MIT license

3MB
487 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 from the root of this repo. Any tests that don't have SVG visualizations created yet will be generated. You'll need to have Graphviz installed.

Dependencies

~1–10MB
~125K SLoC