Skip to content

Commit

Permalink
Merge pull request #718 from epatters/query-hom-promotion
Browse files Browse the repository at this point in the history
Missing case in query promotion for `@migration` macro
  • Loading branch information
epatters authored Dec 1, 2022
2 parents c279616 + b6012e3 commit d0a9a16
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/categorical_algebra/DataMigrations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function migrate(X::FinDomFunctor, F::GlucSchemaMigration)
colimits_of_limits = make_map(ob_generators(tgt_schema)) do c
Fc = ob_map(F, c)
Fc_set, limits = migrate(X, diagram(Fc), return_limits=true)
(colimit(Fc_set), Fc_set, limits)
(colimit(Fc_set, SpecializeColimit()), Fc_set, limits)
end
funcs = make_map(hom_generators(tgt_schema)) do f
Ff, c, d = hom_map(F, f), dom(tgt_schema, f), codom(tgt_schema, f)
Expand Down
29 changes: 20 additions & 9 deletions src/programs/DiagrammaticPrograms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ function make_query(C::FinCat{Ob}, data::DiagramData{T}) where {T, Ob}
@assert query_type != Any
F_ob = mapvals(x -> convert_query(C, query_type, x), F_ob)
F_hom = mapvals(F_hom, keys=true) do h, f
make_query_hom(f, F_ob[dom(J,h)], F_ob[codom(J,h)])
make_query_hom(C, f, F_ob[dom(J,h)], F_ob[codom(J,h)])
end
if query_type <: Ob
Diagram(DiagramData{T}(F_ob, F_hom, J, data.params), C)
Expand All @@ -720,44 +720,55 @@ end

make_query(C::FinCat{Ob}, x::Ob) where Ob = x

function make_query_hom(f::DiagramHomData{op}, d::Diagram{op}, d′::Diagram{op})
function make_query_hom(C::FinCat, f::DiagramHomData{op},
d::Diagram{op}, d′::Diagram{op})
f_ob = mapvals(f.ob_map, keys=true) do j′, x
x = @match x begin
::Missing => only_ob(shape(d))
(::Missing, g) => (only_ob(shape(d)), g)
_ => x
end
@match x begin
(j, g) => Pair(j, make_query_hom(g, ob_map(d, j), ob_map(d′, j′)))
(j, g) => Pair(j, make_query_hom(C, g, ob_map(d, j), ob_map(d′, j′)))
j => j
end
end
f_hom = mapvals(h -> ismissing(h) ? only_hom(shape(d)) : h, f.hom_map)
DiagramHom{op}(f_ob, f_hom, d, d′)
end

function make_query_hom(f::DiagramHomData{id}, d::Diagram{id}, d′::Diagram{id})
function make_query_hom(C::FinCat, f::DiagramHomData{id},
d::Diagram{id}, d′::Diagram{id})
f_ob = mapvals(f.ob_map, keys=true) do j, x
x = @match x begin
::Missing => only_ob(shape(d′))
(::Missing, g) => (only_ob(shape(d′)), g)
_ => x
end
@match x begin
(j′, g) => Pair(j′, make_query_hom(g, ob_map(d, j), ob_map(d′, j′)))
(j′, g) => Pair(j′, make_query_hom(C, g, ob_map(d, j), ob_map(d′, j′)))
j′ => j′
end
end
f_hom = mapvals(h -> ismissing(h) ? only_hom(shape(d′)) : h, f.hom_map)
DiagramHom{id}(f_ob, f_hom, d, d′)
end

function make_query_hom(f::Hom, d::Diagram{T,C}, d′::Diagram{T,C}) where
function make_query_hom(::C, f::Hom, d::Diagram{T,C}, d′::Diagram{T,C}) where
{T, Ob, Hom, C<:FinCat{Ob,Hom}}
cat = codom(diagram(d))
munit(DiagramHom{T}, cat, f, dom_shape=shape(d), codom_shape=shape(d′))
munit(DiagramHom{T}, codom(diagram(d)), f,
dom_shape=shape(d), codom_shape=shape(d′))
end
make_query_hom(f, x, y) = f

function make_query_hom(cat::C, f::Union{Hom,DiagramHomData{op}},
d::Diagram{id}, d′::Diagram{id}) where
{Ob, Hom, C<:FinCat{Ob,Hom}}
f = make_query_hom(cat, f, only(collect_ob(d)), only(collect_ob(d′)))
munit(DiagramHom{id}, codom(diagram(d)), f,
dom_shape=shape(d), codom_shape=shape(d′))
end

make_query_hom(C::FinCat{Ob,Hom}, f::Hom, x::Ob, y::Ob) where {Ob,Hom} = f

only_ob(C::FinCat) = only(ob_generators(C))
only_hom(C::FinCat) = (@assert is_discrete(C); id(C, only_ob(C)))
Expand Down
6 changes: 4 additions & 2 deletions test/programs/DiagrammaticPrograms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,8 @@ F_C = diagram(ob_map(F, :Component))
# Gluc migration
#---------------

# Graph with edges that are paths of length <= 2.
F = @migration SchGraph SchGraph begin
# Labeled graph with edges that are paths of length <= 2.
F = @migration SchLabeledGraph SchLabeledGraph begin
V => V
E => @cases begin
v => V
Expand All @@ -476,6 +476,8 @@ F = @migration SchGraph SchGraph begin
e => tgt
path => e₂tgt
end
Label => Label
label => label
end
@test ob_map(F, :V) isa DataMigrations.GlucQuery
@test F isa DataMigrations.GlucSchemaMigration
Expand Down

0 comments on commit d0a9a16

Please sign in to comment.