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

Compute graphs #160

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*.jl]
indent_size = 2
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ docs/site/
# committed for packages, but should be committed for applications that require a static
# environment.
Manifest.toml
/coverage/
31 changes: 31 additions & 0 deletions DEC/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name = "DEC"
uuid = "e670b126-1168-4583-bd0f-29deacb39f6a"
authors = ["Owen Lynch <[email protected]>"]
version = "0.1.0"

[deps]
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
CombinatorialSpaces = "b1c52339-7909-45ad-8b6a-6e388f7c67f2"
Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
Decapodes = "679ab3ea-c928-4fe6-8d59-fd451142d391"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
Metatheory = "e9d8d322-4543-424a-9be4-0cc815abe26c"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
StructEquality = "6ec83bb0-ed9f-11e9-3b4c-2b04cb4e219c"

[compat]
CairoMakie = "0.12.5"
Colors = "0.12.11"
CombinatorialSpaces = "0.6.7"
Crayons = "4.1.1"
Decapodes = "0.5.5"
GeometryBasics = "0.4.11"
MLStyle = "0.4.17"
OrdinaryDiffEq = "6.86.0"
Random = "1.11.0"
Reexport = "1.2.2"
StructEquality = "2.1.0"
20 changes: 20 additions & 0 deletions DEC/src/DEC.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module DEC
using MLStyle
using Reexport
using StructEquality
import Metatheory
using Metatheory: EGraph, EGraphs, Id, VECEXPR_FLAG_ISCALL, VECEXPR_FLAG_ISTREE, VECEXPR_META_LENGTH
import Metatheory: extract!

import Base: +, -
import Base: *

include("HashColor.jl")
include("Signature.jl")
include("Roe.jl")
include("SSAExtract.jl")
include("Luke.jl")

@reexport using .SSAExtract

end # module DEC
32 changes: 32 additions & 0 deletions DEC/src/HashColor.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module HashColor
export hashcolor, hashcrayon

using Colors
using Random
using Crayons

randunif(rng, range) = rand(rng) * (range[2] - range[1]) + range[1]

"""
Returns a Color generated randomly by hashing `x`.

This uses the LCHuv space to sample uniformly across the human visual spectrum.
"""
function hashcolor(x; lightnessrange=(0.,100.), chromarange=(0.,100.), huerange=(0.,360.))
h = hash(x)
rng = MersenneTwister(h)
l = randunif(rng, lightnessrange)
c = randunif(rng, chromarange)
h = randunif(rng, huerange)
LCHuv{Float64}(l, c, h)
end

"""
Returns a Crayon with foreground color given by `hashcolor`
"""
function hashcrayon(x; lightnessrange=(0.,100.), chromarange=(0.,100.), huerange=(0.,360.))
c = hashcolor(x; lightnessrange, chromarange, huerange)
Crayon(foreground=RGB24(RGB{Float64}(c)).color)
end

end
75 changes: 75 additions & 0 deletions DEC/src/Luke.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import Decapodes
using StructEquality

@struct_hash_equal struct TypedApplication
fn::Function
sorts::Vector{Sort}
end

const TA = TypedApplication

function Base.show(io::IOBuffer, ta::TA)
print(io, Expr(:call, ta.fn, ta.sorts...))
end

function precompute_matrices(sd, hodge)::Dict{TypedApplication, Any}
Dict{TypedApplication, Any}(
# Regular Hodge Stars
TA(★, Sort[PrimalForm(0)]) => Decapodes.dec_mat_hodge(0, sd, hodge),
TA(★, Sort[PrimalForm(1)]) => Decapodes.dec_mat_hodge(1, sd, hodge),
TA(★, Sort[PrimalForm(2)]) => Decapodes.dec_mat_hodge(2, sd, hodge),

# Inverse Hodge Stars
TA(★, Sort[DualForm(0)]) => Decapodes.dec_mat_inverse_hodge(1, sd, hodge), # why is this 1???
TA(★, Sort[DualForm(1)]) => Decapodes.dec_pair_inv_hodge(Val{1}, sd, hodge), # Special since Geo is a solver
TA(★, Sort[DualForm(2)]) => Decapodes.dec_mat_inverse_hodge(0, sd, hodge),

# Differentials
TA(d, Sort[PrimalForm(0)]) => Decapodes.dec_mat_differential(0, sd),
TA(d, Sort[PrimalForm(1)]) => Decapodes.dec_mat_differential(1, sd),

# Dual Differentials
TA(d, Sort[DualForm(0)]) => Decapodes.dec_mat_dual_differential(0, sd),
TA(d, Sort[DualForm(1)]) => Decapodes.dec_mat_dual_differential(1, sd),

# Wedge Products
TA(∧, Sort[PrimalForm(0), PrimalForm(1)]) => Decapodes.dec_pair_wedge_product(Tuple{0,1}, sd),
TA(∧, Sort[PrimalForm(1), PrimalForm(0)]) => Decapodes.dec_pair_wedge_product(Tuple{1,0}, sd),
TA(∧, Sort[PrimalForm(0), PrimalForm(2)]) => Decapodes.dec_pair_wedge_product(Tuple{0,2}, sd),
TA(∧, Sort[PrimalForm(2), PrimalForm(0)]) => Decapodes.dec_pair_wedge_product(Tuple{2,0}, sd),
TA(∧, Sort[PrimalForm(1), PrimalForm(1)]) => Decapodes.dec_pair_wedge_product(Tuple{1,1}, sd),

# Primal-Dual Wedge Products
TA(∧, Sort[PrimalForm(1), DualForm(1)]) => Decapodes.dec_wedge_product_pd(Tuple{1,1}, sd),
TA(∧, Sort[PrimalForm(0), DualForm(1)]) => Decapodes.dec_wedge_product_pd(Tuple{0,1}, sd),
TA(∧, Sort[PrimalForm(1), DualForm(1)]) => Decapodes.dec_wedge_product_dp(Tuple{1,1}, sd),
TA(∧, Sort[PrimalForm(1), DualForm(0)]) => Decapodes.dec_wedge_product_dp(Tuple{1,0}, sd),

# Dual-Dual Wedge Products
# TA(∧, Sort[DualForm(1), DualForm(1)]) => Decapodes.dec_wedge_product_dd(Tuple{1,1}, sd),
TA(∧, Sort[DualForm(1), DualForm(0)]) => Decapodes.dec_wedge_product_dd(Tuple{1,0}, sd),
TA(∧, Sort[DualForm(0), DualForm(1)]) => Decapodes.dec_wedge_product_dd(Tuple{0,1}, sd),

# # Dual-Dual Interior Products
# :ι₁₁ => interior_product_dd(Tuple{1,1}, sd)
# :ι₁₂ => interior_product_dd(Tuple{1,2}, sd)

# # Dual-Dual Lie Derivatives
# :ℒ₁ => ℒ_dd(Tuple{1,1}, sd)

# # Dual Laplacians
# :Δᵈ₀ => Δᵈ(Val{0},sd)
# :Δᵈ₁ => Δᵈ(Val{1},sd)

# # Musical Isomorphisms
# :♯ => Decapodes.dec_♯_p(sd)
# :♯ᵈ => Decapodes.dec_♯_d(sd)

# :♭ => Decapodes.dec_♭(sd)

# # Averaging Operator
# :avg₀₁ => Decapodes.dec_avg₀₁(sd)

# :neg => x -> -1 .* x
)
end
4 changes: 4 additions & 0 deletions DEC/src/OperatorStorage.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
struct OperatorStorage
hodge::Tuple{}
end

Loading
Loading