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

Specialize Base.isequal #254

Merged
merged 2 commits into from
Mar 30, 2021
Merged

Specialize Base.isequal #254

merged 2 commits into from
Mar 30, 2021

Conversation

YingboMa
Copy link
Member

@YingboMa YingboMa commented Mar 28, 2021

Fix JuliaSymbolics/Symbolics.jl#129

using MeshCat
using ModelingToolkit
using TORA
using RigidBodyDynamics
using Symbolics
import SymPy

function setup(vis, n_dof, sympy=false)
    robot = create_robot_kuka_iiwa_14(vis)
    x = MechanismState{sympy ? SymPy.Sym : Num}(robot.mechanism)
    q = configuration(x)
    if sympy
        for i in 1:n_dof
            q[i] = SymPy.symbols("q_$i", real = true)
        end
    else
        for i in 1:n_dof
            q[i] = Num(Sym{Real}(Symbol("q$i")))
        end
    end
    return x
end
vis = Visualizer()

Symbolics:

julia> x = setup(vis, 3); @time M = mass_matrix(x);
  3.721925 seconds (7.73 M allocations: 462.482 MiB, 2.41% gc time, 99.20% compilation time)

julia> for n in 3:7; x = setup(vis, n); @time M = mass_matrix(x); end
  0.006976 seconds (79.61 k allocations: 3.028 MiB)
  0.007024 seconds (80.71 k allocations: 3.072 MiB)
  0.007367 seconds (81.56 k allocations: 3.106 MiB)
  0.007341 seconds (82.07 k allocations: 3.131 MiB)
  0.007315 seconds (82.66 k allocations: 3.157 MiB)

SymPy:

julia> x = setup(vis, 3, true); @time M = mass_matrix(x);
 16.333147 seconds (31.71 M allocations: 1.870 GiB, 2.18% gc time)

julia> for n in 3:7; x = setup(vis, n, true); @time M = mass_matrix(x); end
  2.899745 seconds (78.61 k allocations: 2.414 MiB)
  4.737822 seconds (78.61 k allocations: 2.414 MiB)
  9.462235 seconds (78.61 k allocations: 2.414 MiB)
 16.858959 seconds (78.61 k allocations: 2.414 MiB)
 17.311054 seconds (78.61 k allocations: 2.414 MiB)

@YingboMa YingboMa changed the title Specialize Base.isequal(a::Mul, b::Add) Specialize Base.isequal Mar 28, 2021
@codecov-io
Copy link

Codecov Report

Merging #254 (525d38e) into master (142ea18) will increase coverage by 0.10%.
The diff coverage is 93.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #254      +/-   ##
==========================================
+ Coverage   86.28%   86.38%   +0.10%     
==========================================
  Files          11       11              
  Lines        1108     1124      +16     
==========================================
+ Hits          956      971      +15     
- Misses        152      153       +1     
Impacted Files Coverage Δ
src/types.jl 88.91% <93.75%> (+0.19%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 142ea18...525d38e. Read the comment docs.

@YingboMa YingboMa requested a review from shashi March 29, 2021 01:14
src/types.jl Outdated Show resolved Hide resolved
src/types.jl Outdated Show resolved Hide resolved
@YingboMa
Copy link
Member Author

YingboMa commented Mar 30, 2021

Test failures are due to some functions break the invariance of the canonical form.

julia> SymbolicUtils.arguments(f(x1 + 2.0))[1] |> typeof
SymbolicUtils.Add{Real, Float64, Dict{Any, Number}, Nothing}

julia> SymbolicUtils.arguments(polynormalize(f(x1 + 2.0)))[1] |> typeof

Term{Real, Nothing}

@baggepinnen
Copy link
Contributor

Cool!
A further benchmark could be @time simplify(M[1,1])

Co-authored-by: "Shashi Gowda" <[email protected]>
Co-authored-by: "Shashi Gowda" <[email protected]>
@shashi shashi merged commit 9d1a99b into master Mar 30, 2021
@YingboMa YingboMa deleted the myb/perf branch March 30, 2021 20:11
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.

Slower than SymPy bug, robotics benchmark
4 participants