egraph-serialize

Crates.ioegraph-serialize
lib.rsegraph-serialize
version0.2.0
sourcesrc
created_at2023-10-28 00:43:10.138906
updated_at2024-09-28 23:37:01.961705
descriptionA library to serialize e-graphs
homepage
repositoryhttps://github.com/egraphs-good/egraph-serialize
max_upload_size
id1016592
size20,908,295
Oliver Flatt (oflatt)

documentation

README

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.

Commit count: 20

cargo fmt