Skip to content
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
4 changes: 2 additions & 2 deletions docs/literate/full_demo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ l′ = homomorphism(K′,L′; initial=(V=[1,2,3,1,2],));

"""Given a match L → G, compute what the typing map G → L' should be"""
function get_adherence(m::ACSetTransformation)
root, G, descendents = only(collect(m[:V])), codom(m), Set()
root, G, descendents = only(Base.collect(m[:V])), codom(m), Set()
queue = [root]
while !isempty(queue)
nxt = pop!(queue)
Expand Down Expand Up @@ -235,7 +235,7 @@ Here we'll do rewriting in graphs sliced over •⇆•, which is isomorphic to
```
function graph_slice(s::Slice)
h = s.slice
V, E = collect.([h[:V], h[:E]])
V, E = Base.collect.([h[:V], h[:E]])
g = dom(h)
(S, T), (I, O) = [[findall(==(i), X) for i in 1:2] for X in [V, E]]
nS, nT, nI, nO = length.([S, T, I, O])
Expand Down
2 changes: 1 addition & 1 deletion docs/literate/game_of_life.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ that's the case, we can visualize the game state using plaintext.
=#

function view_life(f::ACSetTransformation, pth=tempname())
v = collect(f[:V])
v = Base.collect(f[:V])
view_life(codom(f), pth; star=isempty(v) ? nothing : only(v))
end

Expand Down
1 change: 1 addition & 0 deletions src/analysis/Processes.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module Processes
import Base: collect
export find_deps

using Catlab
Expand Down
67 changes: 46 additions & 21 deletions src/categorical_algebra/CSets.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module CSets
import Base: collect
export extend_morphism, pushout_complement,
can_pushout_complement, dangling_condition, invert_hom, check_pb,
gluing_conditions, extend_morphisms, sub_vars,
Expand Down Expand Up @@ -61,7 +62,7 @@ function invert_iso(f::ACSetTransformation,
S = acset_schema(dom(f))
s_obs = isnothing(s) ? ob(S) : s
d = Dict(map(ob(S)) do o
o => o ∈ s_obs ? Base.invperm(collect(f[o])) : collect(f[o])
o => o ∈ s_obs ? Base.invperm(Base.collect(f[o])) : Base.collect(f[o])
end)
return only(homomorphisms(codom(f), dom(f); initial=d))
end
Expand Down Expand Up @@ -144,7 +145,7 @@ function fibers(f::FinFunction)
for v in dom(f)
push!(dic[f(v)], v)
end
filter(xs->length(xs)>1, collect(values(dic)))
filter(xs->length(xs)>1, Base.collect(values(dic)))
end

unions!(i::IntDisjointSets, xs::Vector{Int}) = if length(xs) > 1
Expand Down Expand Up @@ -182,7 +183,6 @@ use the function [`can_pushout_complement`](@ref).
} [model::ACSetCategory] begin
function pushout_complement(pair::ComposablePair)
l, m = pair
lm = compose[model](l,m)
I, G = dom(l), codom(m)
S = acset_schema(I)
𝒞 = entity_cat(model)
Expand All @@ -208,15 +208,15 @@ use the function [`can_pushout_complement`](@ref).
end
end
mapping_inv = Dict(o=>Dict(v=>k for (k,v) in mapping[o]) for o in keys(mapping))
g_components2 = Dict(map(collect(g_components)) do (o, comp)
g_components2 = Dict(map(Base.collect(g_components)) do (o, comp)
f = if haskey(mapping_inv, o)
FinFunction(Dict(k=>comp(v) for (k,v) in mapping_inv[o]), om(K,o), om(G,o))
else
nothing
end
o => f
end)
g_components2 = Dict(map(collect(g_components)) do (o, comp)
g_components2 = Dict(map(Base.collect(g_components)) do (o, comp)
f = if haskey(mapping_inv, o)
FinFunction(Dict(k=>comp(v) for (k,v) in mapping_inv[o]), om(K,o), om(G,o))
else
Expand All @@ -232,12 +232,36 @@ use the function [`can_pushout_complement`](@ref).
K[p, h] = c ∈ ob(S) ? only(preimage(g_c, res)) : res
end
end
k_components2 = Dict{Symbol,Any}(map(collect(k_components)) do (o, comp)
k_components2 = Dict{Symbol,Any}(map(Base.collect(k_components)) do (o, comp)
f = FinFunction(mapping[o], codom(comp), om(K,o))
o => postcompose(comp, f)
end)
for k in attrtypes(S)
k_components2[k] = lm[k]
T = attrtype_type(K, k)
vals = map(parts(I, k)) do i
hits = Any[]
for (f, c, _) in attrs(S; to=k), p in parts(I, c)
I[p, f] == AttrVar(i) || continue
push!(hits, K[k_components2[c](p), f])
end
if isempty(hits)
val = get(l[k])(i)
val = val isa Left ? get(m[k])(getvalue(val)) : val
val isa Left ? Left(getvalue(val)) : Right{T}(getvalue(val))
else
all(==(first(hits)), hits) || error("AttrVar $i in $k has inconsistent images in pushout complement")
val = first(hits)
val isa AttrVar ? Left(getvalue(val)) : Right{T}(val)
end
end
domk = dom(get(l[k]))
domk_parts = Base.collect(domk)
codk = domk_parts isa AbstractUnitRange{<:Integer} && first(domk_parts) == 1 ?
FinSet(nparts(K, k)) : FinSet(Set(parts(K, k)))
k_components2[k] = CopairedFinDomFunction(
FinDomFunction(Dict(zip(parts(I, k), vals)),
domk,
either(codk, SetOb(T))))
end

# need to reindex the components in light of the actual part IDs in K
Expand All @@ -261,6 +285,7 @@ use the function [`can_pushout_complement`](@ref).
function pushout_complement_violations(pair::ComposablePair)
viols = []
for k in keys(components(pair[1]))
applicable(id_condition, pair[1][k], pair[2][k]) || continue
a,b = id_condition(pair[1][k], pair[2][k])
append!(viols, [("Id: nondeleted ↦ deleted ", k, aa) for aa in a])
append!(viols,[("Id: nonmonic deleted", k, bb) for bb in b])
Expand Down Expand Up @@ -295,7 +320,7 @@ dangling_condition(pair::ComposablePair{<:DynamicACSet}) = let S = acset_schema(
L, G = codom(l), codom(m)
del_vector = Set{Int}[]
@ct_ctrl for o in obs
image = Set(collect(l[@ct o])) # SMALL
image = Set(Base.collect(l[@ct o])) # SMALL
dels = Set{Int}()
for pL in parts(L,@ct(o))
if pL ∉ image push!(dels, m[@ct o](pL)) end
Expand Down Expand Up @@ -335,7 +360,7 @@ function cascade_subobj(X::ACSet, sub)
end
end
end
return Dict([k => collect(v) for (k,v) in pairs(sub)])
return Dict([k => Base.collect(v) for (k,v) in pairs(sub)])
end


Expand Down Expand Up @@ -406,7 +431,7 @@ function var_pullback(c::Cospan{<:StructACSet{S,Ts}}) where {S,Ts}
attr_components = Dict(map(attrtypes(S)) do at
comp = Union{AttrVar,attrtype_instantiation(S,Ts,at)}[]
for (f, c, _) in attrs(S; to=at)
append!(comp, X[f][collect(compose[FinSetC()](A[c],p[c]))])
append!(comp, X[f][Base.collect(compose[FinSetC()](A[c],p[c]))])
end
return at => comp
end)
Expand Down Expand Up @@ -453,19 +478,19 @@ Migrate(cat, Dict(x => x for x in Symbol.(generators(s1, :Ob))),
s1, t1, s2, t2; delta)

Migrate(cat::ACSetCategory, o::Dict, h::Dict, s1::Presentation, t1::Type, s2=nothing, t2=nothing;
delta::Bool=true) = Migrate(cat, Dict(collect(pairs(o))),
Dict(collect(pairs(h))), s1, t1,
delta::Bool=true) = Migrate(cat, Dict(Base.collect(pairs(o))),
Dict(Base.collect(pairs(h))), s1, t1,
isnothing(s2) ? s1 : s2,
isnothing(t2) ? t1 : t2,
delta)


sparsify(d::Dict{V,<:ACSet}) where V = Dict([k=>sparsify(v) for (k,v) in collect(d)])
sparsify(d::Dict{<:ACSet,V}) where V = Dict([sparsify(k)=>v for (k,v) in collect(d)])
sparsify(d::Dict{V,<:ACSet}) where V = Dict([k=>sparsify(v) for (k,v) in Base.collect(d)])
sparsify(d::Dict{<:ACSet,V}) where V = Dict([sparsify(k)=>v for (k,v) in Base.collect(d)])
sparsify(::Nothing) = nothing

(F::Migrate)(d::Dict{V,<:ACSet}) where V = Dict([k=>F(v) for (k,v) in collect(d)])
(F::Migrate)(d::Dict{<:ACSet,V}) where V = Dict([F(k)=>v for (k,v) in collect(d)])
(F::Migrate)(d::Dict{V,<:ACSet}) where V = Dict([k=>F(v) for (k,v) in Base.collect(d)])
(F::Migrate)(d::Dict{<:ACSet,V}) where V = Dict([F(k)=>v for (k,v) in Base.collect(d)])
(m::Migrate)(::Nothing) = nothing
(m::Migrate)(s::Union{String,Symbol}) = s
function (m::Migrate)(Y::ACSet; cat=nothing)
Expand Down Expand Up @@ -494,9 +519,9 @@ function (m::Migrate)(Y::ACSet; cat=nothing)
end

function (F::Migrate)(f::ACSetTransformation)
d = Dict(map(collect(pairs(components(f)))) do (k,v)
d = Dict(map(Base.collect(pairs(components(f)))) do (k,v)
fun = v isa CopairedFinDomFunction ? get(v) : v
get(F.obs,k,k) => map(sort(collect(dom(fun)))) do i
get(F.obs,k,k) => map(sort(Base.collect(dom(fun)))) do i
e = fun(i)
if e isa Left
AttrVar(getvalue(e))
Expand All @@ -510,8 +535,8 @@ function (F::Migrate)(f::ACSetTransformation)
homomorphism(F(dom(f)), F(codom(f)); initial=d, cat=F.cat)
end

(F::Migrate)(s::Multispan) = Multispan(apex(s), F.(collect(s)))
(F::Migrate)(s::Multicospan) = Multicospan(apex(s), F.(collect(s)))
(F::Migrate)(d::AbstractDict) = Dict(get(F.obs,k, k)=>v for (k,v) in collect(d))
(F::Migrate)(s::Multispan) = Multispan(apex(s), F.(Base.collect(s)))
(F::Migrate)(s::Multicospan) = Multicospan(apex(s), F.(Base.collect(s)))
(F::Migrate)(d::AbstractDict) = Dict(get(F.obs,k, k)=>v for (k,v) in Base.collect(d))

end # module
1 change: 1 addition & 0 deletions src/categorical_algebra/FinSets.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module FinSets
import Base: collect
export pushout_complement,can_pushout_complement,id_condition

using Catlab.Theories
Expand Down
1 change: 1 addition & 0 deletions src/categorical_algebra/PartialMap.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module PartialMap
import Base: collect
export partial_map_classifier_universal_property, partial_map_functor_hom,
partial_map_classifier_eta
using DataStructures
Expand Down
4 changes: 3 additions & 1 deletion src/categorical_algebra/StructuredCospans.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module StructuredCospans

import Base: collect

export StructuredMultiCospanHom, StructuredMulticospan, openrule, can_open_pushout_complement, open_rewrite, open_rewrite_match, idH_, idV_, composeV_, composeH_, id2_, id2V_, id2H_

using Catlab, Catlab.CategoricalAlgebra, Catlab.Theories
Expand Down Expand Up @@ -328,4 +330,4 @@ function open_rewrite(rule::openrule, G::StructuredMulticospan;
end
end

end # module
end # module
2 changes: 2 additions & 0 deletions src/incremental/Algorithms.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Algorithms

import Base: collect

using DataStructures
using Catlab
using ...CategoricalAlgebra.CSets: invert_iso, var_reference
Expand Down
2 changes: 2 additions & 0 deletions src/incremental/IHSAccess.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module IHSAccess

import Base: collect

export rules, validate, state, states, matches, nmatches, qrules, decomp_dict,
get_cases, decomp_match, get_match, interaction_square

Expand Down
1 change: 1 addition & 0 deletions src/incremental/IHSData.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module IHSData
import Base: collect
export IHS

using DataStructures: DefaultDict, OrderedDict
Expand Down
2 changes: 2 additions & 0 deletions src/incremental/IHSModify.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module IHSModify

import Base: collect

using DataStructures
using Catlab

Expand Down
1 change: 1 addition & 0 deletions src/incremental/IHSRewrite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Maps into cokernels induce overlaps with R which hopefully are always
subobjects of the pullback of new matches with R->G2.
"""
module IHSRewrite
import Base: collect
export rewrite_matches!

using StructEquality, DataStructures, Combinatorics
Expand Down
3 changes: 2 additions & 1 deletion src/rewrite/CoNeg.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module CoNeg
import Base: collect
using Catlab.CategoricalAlgebra, GATlab

using ...CategoricalAlgebra.CSets
Expand Down Expand Up @@ -47,4 +48,4 @@ function rewrite_match_maps(r::Rule{:CoNeg}, m; cat, check::Bool=false)
Dict(:ik => ik, :kg => hom(K′), :rh => rh, :kh => kh)
end

end # module
end # module
1 change: 1 addition & 0 deletions src/rewrite/Constraints.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module Constraints
import Base: collect
export apply_constraint, Constraint, CGraph, arity,
∀, ∃, ∃!, True, False, Commutes,
AppCond, LiftCond, Trivial, PAC, NAC
Expand Down
1 change: 1 addition & 0 deletions src/rewrite/Inplace.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module Inplace
import Base: collect
export compile_rewrite, RewriteProgram, rewrite!, rewrite_match!

using MLStyle
Expand Down
1 change: 1 addition & 0 deletions src/rewrite/PBPO.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module PBPO
import Base: collect
export PBPORule

using Catlab, Catlab.CategoricalAlgebra
Expand Down
14 changes: 8 additions & 6 deletions src/rewrite/SPO.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module SPO

import Base: collect

using Catlab, Catlab.CategoricalAlgebra

using ...CategoricalAlgebra.CSets: var_pullback, cascade_subobj
Expand Down Expand Up @@ -42,7 +44,7 @@ function partial_pushout(f::Span, g::Span; cat)
# Step 1: compute Af ∩ Ag
glue = Dict{Symbol,Set{Int}}(map(types(S)) do o
funs = [o in ob(S) ? x : get(x) for x in [AfA[o], AgA[o]]]
o => κ(o)(intersect(Set.(collect.(funs))...))
o => κ(o)(intersect(Set.(Base.collect.(funs))...))
end)

# Step 2: add any elements which are mapped to the same elems by f or g
Expand All @@ -57,18 +59,18 @@ function partial_pushout(f::Span, g::Span; cat)
end
end
end
comps = NamedTuple(Dict([k=>collect(v) for (k,v) in collect(glue)]))
comps = NamedTuple(Dict([k=>Base.collect(v) for (k,v) in Base.collect(glue)]))
fg_A = Subobject(A, comps) |> hom # f ∇ g ↪ A
fg = dom(fg_A) # f ∇ g
# Construct scopes Bgf ⊆ B and Cfg ⊆ C
#---------------------------
Bgf_B, Cfg_C = map([f,g]) do (mono, ϕ)
sub = Dict{Symbol,Vector{Int}}(map(types(S)) do o
ϕfun = o ∈ ob(S) ? ϕ[o] : get(ϕ[o])
x1 = setdiff(parts(codom(ϕ),o),collect(ϕfun)) # e.g. C - g(A)
x1 = setdiff(parts(codom(ϕ),o),Base.collect(ϕfun)) # e.g. C - g(A)
pre = [preimage(mono[o], fg_A[o](i)) for i in parts(fg,o)]
x2 = Set(collect(ϕ[o].(vcat(pre...)))) # e.g. g(f ∇ g)
o => sort(collect(x1 ∪ x2))
x2 = Set(Base.collect(ϕ[o].(vcat(pre...)))) # e.g. g(f ∇ g)
o => sort(Base.collect(x1 ∪ x2))
end)

hom(Subobject(codom[cat](ϕ), NamedTuple(cascade_subobj(codom[cat](ϕ), sub))))
Expand All @@ -81,7 +83,7 @@ function partial_pushout(f::Span, g::Span; cat)
init = Dict(map(ob(S)) do o
o => map(parts(fg, o)) do i
c_index = ϕ[o](only(preimage(mono[o],fg_A[o](i))))
return findfirst(==(c_index), collect(cod[o]))
return findfirst(==(c_index), Base.collect(cod[o]))
end
end)
only(homomorphisms(fg, dom(cod); cat, initial=init))
Expand Down
Loading