Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.0 Release #185

Open
wants to merge 328 commits into
base: master
Choose a base branch
from
Open

3.0 Release #185

wants to merge 328 commits into from

Conversation

0x0f0f0f
Copy link
Member

Release 3.0 when merged

@codecov-commenter
Copy link

codecov-commenter commented Jan 14, 2024

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

Attention: Patch coverage is 87.60469% with 148 lines in your changes missing coverage. Please review.

Project coverage is 81.12%. Comparing base (a8331d6) to head (6814104).
Report is 533 commits behind head on master.

Files with missing lines Patch % Lines
src/EGraphs/Schedulers.jl 43.47% 26 Missing ⚠️
src/utils.jl 7.69% 24 Missing ⚠️
src/EGraphs/egraph.jl 89.68% 23 Missing ⚠️
src/Syntax.jl 89.33% 16 Missing ⚠️
src/Patterns.jl 74.46% 12 Missing ⚠️
src/EGraphs/saturation.jl 95.20% 7 Missing ⚠️
src/Rules.jl 83.33% 7 Missing ⚠️
ext/Plotting.jl 0.00% 6 Missing ⚠️
src/Rewriters.jl 53.84% 6 Missing ⚠️
src/ematch_compiler.jl 95.83% 6 Missing ⚠️
... and 6 more

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff             @@
##           master     #185       +/-   ##
===========================================
+ Coverage   69.17%   81.12%   +11.94%     
===========================================
  Files          16       18        +2     
  Lines        1353     1499      +146     
===========================================
+ Hits          936     1216      +280     
+ Misses        417      283      -134     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Jan 14, 2024

Benchmark Results

egg-sym egg-cust MT@6814104fbe1... MT@ca867735988... egg-sym/MT@681... egg-cust/MT@68... MT@ca867735988...
egraph_addexpr 1.47 ms 5.11 ms 14.1 ms 0.288 2.75
basic_maths_simpl2 13.6 ms 4.9 ms 19.8 ms 841 ms 0.683 0.247 42.4
prop_logic_freges_theorem 2.5 ms 1.53 ms 1.05 ms 34.5 ms 2.39 1.46 33
calc_logic_demorgan 60.2 μs 35.7 μs 75.6 μs 495 μs 0.796 0.472 6.55
calc_logic_freges_theorem 21.8 ms 12.6 ms 43 ms 3.08e+03 ms 0.508 0.293 71.6
basic_maths_simpl1 6.33 ms 2.76 ms 4.58 ms 48.2 ms 1.38 0.602 10.5
egraph_constructor 0.0825 μs 0.0907 μs 0.102 μs 0.91 1.12
prop_logic_prove1 35 ms 13.7 ms 40.7 ms 8.55e+03 ms 0.861 0.336 210
prop_logic_demorgan 78.7 μs 44.6 μs 93.6 μs 734 μs 0.84 0.476 7.84
while_superinterpreter_while_10 18.1 ms 91.9 ms 5.06
prop_logic_rewrite 120 μs 124 μs 1.03
time_to_load 114 ms 140 ms 1.24

Benchmark Plots

A plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR.
Go to "Actions"->"Benchmark a pull request"->[the most recent run]->"Artifacts" (at the bottom).

@0x0f0f0f
Copy link
Member Author

0x0f0f0f commented Jan 14, 2024

This is 14.5 times faster than egg in rust!

Julia Code

using Metatheory, BenchmarkTools

t = @theory a b begin
  a + b --> b + a
  a * b --> b * a
  a + 0 --> a
  a * 0 --> 0
  a * 1 --> a
end

using BenchmarkTools

p = SaturationParams(; timer = false)

function simpl(ex)
  g = EGraph(ex)
  saturate!(g, t, p)
  extract!(g, astsize)
end

ex = :(0 + (1 * foo) * 0 + (a * 0) + a)

simpl(ex)

@btime simpl(ex)

94.462 μs (1412 allocations: 66.08 KiB)

Rust code

use egg::{rewrite as rw, *};
//use std::time::Duration;
fn main() {
    env_logger::init();
    use egg::*;

    define_language! {
        enum SimpleLanguage {
            Num(i32),
            "+" = Add([Id; 2]),
            "*" = Mul([Id; 2]),
            Symbol(Symbol),
        }
    }

    fn make_rules() -> Vec<Rewrite<SimpleLanguage, ()>> {
        vec![
            rewrite!("commute-add"; "(+ ?a ?b)" => "(+ ?b ?a)"),
            rewrite!("commute-mul"; "(* ?a ?b)" => "(* ?b ?a)"),
            rewrite!("add-0"; "(+ ?a 0)" => "?a"),
            rewrite!("mul-0"; "(* ?a 0)" => "0"),
            rewrite!("mul-1"; "(* ?a 1)" => "?a"),
        ]
    }

    /// parse an expression, simplify it using egg, and pretty print it back out
    fn simplify(s: &str) -> String {
        // parse the expression, the type annotation tells it which Language to use
        let expr: RecExpr<SimpleLanguage> = s.parse().unwrap();

        // simplify the expression using a Runner, which creates an e-graph with
        // the given expression and runs the given rules over it
        let runner = Runner::default().with_expr(&expr).run(&make_rules());

        // the Runner knows which e-class the expression given with `with_expr` is in
        let root = runner.roots[0];

        // use an Extractor to pick the best element of the root eclass
        let extractor = Extractor::new(&runner.egraph, AstSize);
        let (best_cost, best) = extractor.find_best(root);
        println!("Simplified {} to {} with cost {}", expr, best, best_cost);
        best.to_string()
    }

    // assert_eq!(simplify("(* 0 42)"), "0");
    let apply_time: std::time::Instant = instant::Instant::now();
    // assert_eq!(simplify("(+ 0 (* 1 foo))"), "foo");
    assert_eq!(simplify("(+ (+ (+ 0 (* (* 1 foo) 0)) (* a 0)) a)"), "a");
    let apply_time = apply_time.elapsed().as_secs_f64();
    println!("simplification time {}", apply_time);
}

simplification time 0.001375786 seconds which is 1375.786microseconds

1375.786 / 94.462 = 14.56x faster

well

@0x0f0f0f
Copy link
Member Author

0x0f0f0f commented Mar 1, 2024

@gkronber I have just updated this branch to include the latest release of https://github.com/JuliaSymbolics/TermInterface.jl - the interface for custom types has changed, please let me know if you encounter any issue

@gkronber
Copy link
Collaborator

gkronber commented Mar 2, 2024

@gkronber I have just updated this branch to include the latest release of https://github.com/JuliaSymbolics/TermInterface.jl - the interface for custom types has changed, please let me know if you encounter any issue

Thanks for the heads up. I only had to make minor changes because of the changed names for functions in VecExpr.

a and others added 2 commits March 2, 2024 16:31
@shashi
Copy link
Member

shashi commented Mar 12, 2024

@0x0f0f0f Can you summarize the changes in this PR? What's the huge number of deletions from? And what's the huge performance gain from? This is awesome.

@0x0f0f0f
Copy link
Member Author

@0x0f0f0f Can you summarize the changes in this PR? What's the huge number of deletions from? And what's the huge performance gain from? This is awesome.

@shashi I removed some unnecessary parts of the codebase, and basically changed the core types used for rewriting. The trick for performance was basically packing e-nodes in Vector{UInt64} such that loops (which happens hundreds of thousands of times) can be vectorized. Instead of having a struct with operation, hash, flags... fields, I just encode and pack everything into UInt64.

https://github.com/JuliaSymbolics/Metatheory.jl/blob/8f228fd0f8a5e1f97fd0ed986cb1c7e94cbce5c8/src/vecexpr.jl

Also some algorithms were updated, as the egg repo now has more efficient versions of parts of equality saturation (rebuilding) that were in the original paper

0x0f0f0f and others added 30 commits August 23, 2024 12:46
Fix hashing and memoization of enodes (VecExpr)
Fix MU-puzzle rules and add more tests from original source.
…vements

3.0 minor fixes and improvements
Mutable semantic analysis (data) for eclass
Fix power rules to fix some of the broken tests in CAS
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.

8 participants