Skip to content

Commit 811c955

Browse files
Merge pull request #17 from JuliaComputing/dg/readme
Add README
2 parents e4f1c6a + f1f77de commit 811c955

1 file changed

Lines changed: 94 additions & 0 deletions

File tree

README.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# SymbolicCompilerPasses.jl
2+
3+
[![Join the chat at https://julialang.zulipchat.com #sciml-bridged](https://img.shields.io/static/v1?label=Zulip&message=chat&color=9558b2&labelColor=389826)](https://julialang.zulipchat.com/#narrow/stream/279055-sciml-bridged)
4+
5+
6+
[![Build Status](https://github.com/JuliaComputing/SymbolicCompilerPasses.jl/actions/workflows/ci.yml/badge.svg)](https://github.com/JuliaComputing/SymbolicCompilerPasses.jl/actions/workflows/ci.yml)
7+
8+
9+
[![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor%27s%20Guide-blueviolet)](https://github.com/SciML/ColPrac)
10+
[![SciML Code Style](https://img.shields.io/static/v1?label=code%20style&message=SciML&color=9558b2&labelColor=389826)](https://github.com/SciML/SciMLStyle)
11+
12+
Compiler Pass Plugins for Symbolic Expressions. Designed to work with array heavy code.
13+
14+
## ModelingToolkit Integration
15+
16+
```julia
17+
using Multibody
18+
import ModelingToolkit as MTK
19+
20+
t = Multibody.t
21+
world = Multibody.world
22+
23+
@named joint = Revolute(n = Float64[0, 0, 1], isroot = true);
24+
@named body = Body(; m = 1, isroot = false, r_cm = [0.5, 0, 0])
25+
26+
connections = [
27+
connect(world.frame_b, joint.frame_a)
28+
connect(joint.frame_b, body.frame_a)
29+
]
30+
31+
@named model = System(connections, t, systems=[world, joint, body])
32+
ssys = multibody(model)
33+
34+
D = Differential(t)
35+
36+
prob = ODEProblem(ssys, defs, (0, 3.35),
37+
optimize = MTK.SCP_BASIC
38+
)
39+
```
40+
41+
42+
A list of passes can be passed as well.
43+
44+
```julia
45+
import SymbolicCompilerPasses as SC
46+
47+
prob = ODEProblem(ssys, defs, (0, 3.35),
48+
optimize = [SC.LDIV_RULE,
49+
SC.HVNCAT_STATIC_RULE,
50+
SC.MB_VIEW_RULE,
51+
SC.MATMUL_ADD_RULE]
52+
)
53+
```
54+
55+
Lower level API gives more granular control over applying passes to standard symbolic expressions.
56+
57+
```julia
58+
julia> using SymbolicUtils
59+
60+
julia> using SymbolicUtils.Code
61+
62+
julia> import SymbolicUtils as SU
63+
64+
julia> import SymbolicCompilerPasses as SC
65+
66+
julia> @syms A[1:3, 1:3] B[1:3, 1:3] C[1:3, 1:3] D[1:3, 1:3] E[1:3, 1:3]
67+
(A, B, C, D, E)
68+
69+
julia> expr = A * B + C
70+
C + A*B
71+
72+
julia> current = Code.cse(expr)
73+
Let(Union{Assignment, DestructuredArgs}[Assignment(var"##cse#1", A*B), Assignment(var"##cse#2", var"##cse#1" + C)], var"##cse#2", false)
74+
75+
julia> toexpr(current)
76+
quote
77+
var"##cse#1" = (*)(A, B)
78+
var"##cse#2" = (+)(var"##cse#1", C)
79+
var"##cse#2"
80+
end
81+
82+
julia> state = Code.CSEState();
83+
84+
julia> optimized = Code.apply_optimization_rule(current, state, SC.MATMUL_ADD_RULE)
85+
Let(Union{Assignment, DestructuredArgs}[Assignment(var"##mul5_temp#1", SymbolicCompilerPasses.get_from_cache(C)), Assignment(var"##mul5_temp#1", LinearAlgebra.mul!(var"##mul5_temp#1", A, B, 1, 1)), Assignment(var"##mul5_temp#1", var"##mul5_temp#1")], var"##mul5_temp#1", false)
86+
87+
julia> toexpr(optimized)
88+
quote
89+
var"##mul5_temp#1" = (SymbolicCompilerPasses.get_from_cache)(C)
90+
var"##mul5_temp#1" = (LinearAlgebra.mul!)(var"##mul5_temp#1", A, B, 1, 1)
91+
var"##mul5_temp#1" = var"##mul5_temp#1"
92+
var"##mul5_temp#1"
93+
end
94+
```

0 commit comments

Comments
 (0)