Extraction Gym
A suite of benchmarks to test e-graph extraction algorithms.
Add your algorithm in src/extract
and then add a line in src/main.rs
. To run, type make
.
Data
Please add data! It's just a csv with the following schema:
eclass:str, cost:float, node_name:str, eclass_children:str*
There is a special ##
directive to specify the root(s) of the e-graph. You can have multiple of these on separate lines.
Make sure all ids (including roots) are canonical!
Example
Here's an e-graph with f(g(x)) = h(y, x)
, and everything has cost 1
except for h
which has cost 7.5
:
## root: 2
0, 1, x
1, 1, g, 0
2, 1, f, 1
# this is a comment, starting the second "term"
3, 1, y
2, 7.5, h, 3, 0
Snippet
Here's a snippet that you can base your csv printing code on if you want. Make sure to also print the ## root:
directive to specify the roots!
pub fn write_to_csv<L, A>(egraph: &EGraph<L, A>, w: &mut impl std::io::Write) -> std::io::Result<()>
where
L: Language + std::fmt::Display,
A: Analysis<L>,
{
writeln!(w, "# generated by egg {}", env!("CARGO_PKG_VERSION"))?;
let mut ids = egraph.classes().map(|c| c.id).collect::<Vec<_>>();
ids.sort();
for id in ids {
for node in &egraph[id].nodes {
let cost = 1;
write!(w, "{},{},{}", id, cost, node)?;
for child in node.children() {
write!(w, ",{}", child)?;
}
writeln!(w)?;
}
}
Ok(())
}