Skip to content

Commit

Permalink
remove unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
Kris Brown committed Oct 14, 2023
1 parent 909ba03 commit 60cce70
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 106 deletions.
103 changes: 2 additions & 101 deletions src/categorical_algebra/CSets.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module CSets
export extend_morphism, pushout_complement,
can_pushout_complement, dangling_condition, invert_hom, check_pb,
gluing_conditions, extend_morphisms, postcompose_partial, sub_vars,
Migrate, invert_iso, deattr, var_pullback, remove_freevars
gluing_conditions, extend_morphisms, sub_vars,
Migrate, invert_iso, deattr, var_pullback

using Catlab, Catlab.Theories
using Catlab.CategoricalAlgebra
Expand All @@ -23,48 +23,6 @@ using StructEquality

# Morphism search
#################

"""
Combine a user-specified initial dict with that generated by constraints
`Initial` could contain vectors or int-keyed dicts as its data for each object.
"""
function combine_dicts!(init, initial)
if isnothing(init) return nothing end
for (k,vs) in collect(initial)
for (i, v) in (vs isa AbstractVector ? enumerate : collect)(vs)
if haskey(init[k], i)
if init[k][i] != v return nothing end
else
init[k][i] = v
end
end
end
return NamedTuple(init)
end

# default behavior for types that don't explicitly implement `is_isomorphic`
is_isomorphic(x) = is_monic(x) && is_epic(x) # should be upstreamed
"""
Convert a morphism X->A to a morphism L->H using a partial morphism G->H,
if possible.
A ↩ C → B
↑ ↑
X ↩⌜Y
This is a more categorical way to compute `update_agent` but for now will
remain unused unless we want to generalize rewriting schedules beyond ACSet
rewriting.
"""
function postcompose_partial(ACB::Span, XA::ACSetTransformation)
S = acset_schema(dom(XA))
YX, YC = var_pullback(Cospan(XA, left(ACB)))
if all(o->is_isomorphic(YX[o]), ob(S))
return invert_iso(YX) YC right(ACB)
end
end


"""
Invert some (presumed iso) components of an ACSetTransformation (given by s)
Expand Down Expand Up @@ -296,23 +254,6 @@ end
# Subobjects
############

"""Recursively include anything, e.g. and edge includes its vertices """
function complete_subobj(X::ACSet, sub)
sub = Dict([k=>Set(v) for (k,v) in pairs(sub)])
S = acset_schema(X)
change = true
while change
change = false
for (f,c,d) in homs(S)
new_d = setdiff(Set(X[collect(sub[c]),f]), sub[d])
if !isempty(new_d)
change = true
union!(sub[d], new_d)
end
end
end
return Dict([k=>collect(v) for (k,v) in pairs(sub)])
end
"""Recursively delete anything, e.g. deleting a vertex deletes its edge"""
function cascade_subobj(X::ACSet, sub)
sub = Dict([k=>Set(v) for (k,v) in pairs(sub)])
Expand Down Expand Up @@ -411,46 +352,6 @@ function var_pullback(c::Cospan{<:StructACSet{S,Ts}}) where {S,Ts}
end


"""
We may replace some ...
"""
function remove_freevars(X::StructACSet{S}) where S
X = deepcopy(X)
d = Dict(map(attrtypes(S)) do at
vs = Set{Int}()
for f in attrs(S; to=at, just_names=true)
for v in filter(x->x isa AttrVar, X[f])
push!(vs, v.val)
end
end
# Get new variable IDs
svs = sort(collect(vs))
vdict = Dict(v=>k for (k,v) in enumerate(svs))
n_v = length(vdict)
rem_parts!(X,at, parts(X,at)[n_v+1:end])
for f in attrs(S; to=at, just_names=true)
for (v,fv) in filter(v_->v_[2] isa AttrVar,collect(enumerate(X[f])))
X[v,f] = AttrVar(vdict[fv.val])
end
end
return at => svs
end)
return X => d
end

function remove_freevars(f::ACSetTransformation; check::Bool=false)
S = acset_schema(dom(f))
!check || is_natural(f) || error("unnatural freevars input")
X, d = remove_freevars(dom(f))
comps = Dict{Symbol,Any}(o=>collect(f[o]) for o in ob(S))
for at in attrtypes(S)
comps[at] = collect(f[at])[d[at]]
end
res = ACSetTransformation(X, codom(f); comps...)
!check || is_natural(res) || error("unnatural freevars output")
return res
end

function deattr(X::StructACSet{S})::AnonACSet where S
P = Presentation(FreeSchema)
add_generators!(P, Ob(FreeSchema, objects(S)...))
Expand Down
5 changes: 1 addition & 4 deletions src/rewrite/PBPO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ import ..Utils:
rewrite_match_maps, get_matches, get_expr_binding_map, AbsRule, ruletype
using ..Constraints
using ...CategoricalAlgebra
using ...CategoricalAlgebra.CSets:
extend_morphism_constraints, var_pullback, remove_freevars,
combine_dicts!

using ...CategoricalAlgebra.CSets: extend_morphism_constraints, var_pullback

"""
l r
Expand Down
4 changes: 3 additions & 1 deletion test/schedules/Eval.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ end

z, g1, ar, loop = Graph(), Graph(1), path_graph(Graph, 2), apex(terminal(Graph))

N=Names(Dict("Z"=>z,""=>g1,"•→•"=>ar))
N=Names(Dict("Z"=>z,""=>g1))
@test length(N) == 2
N["•→•"] = ar
Dot, A = Symbol.([N[g1],N[ar]])

av = RuleApp(:add_vertex, Rule(id(z), create(g1)))
Expand Down

0 comments on commit 60cce70

Please sign in to comment.