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

Another collection typing bug #157

Merged
merged 3 commits into from
Feb 26, 2024
Merged
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: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
ACSets = "0.2.5"
Documenter = "1"
GATlab = "0.0.7,0.1"
Catlab = "0.16.2"
Catlab = "0.16.8"
Literate = "2"
MLStyle = "0.4"
Reexport = "1"
Expand Down
19 changes: 3 additions & 16 deletions src/Migrations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -374,22 +374,9 @@ function migrate(X::FinDomFunctor, M::ConjSchemaMigration;
limits = make_map(ob_generators(tgt_schema)) do c
Fc = ob_map(F, c)
J = shape(Fc)
# Must supply object/morphism types to handle case of empty diagram.
#=
diagram_types = if c isa AttrTypeExpr #Note this won't work if M constructed its own target schema!!!
(TypeSet, SetFunction)
elseif isempty(J)
(FinSet{Int}, FinFunction{Int})
else
(SetOb, FinDomFunction{Int})
end
=#
diagram_types = isempty(J) ? (FinSet{Int}, FinFunction{Int}) : (Any,Any)
# Make sure the diagram to be limited is a FinCat{<:Int}.
# Disable domain check because acsets don't store schema equations.
k = dom_to_graph(diagram(force(compose(Fc, X), diagram_types...)))
#cover for the annoying fact that FinDomFunctions containing a lambda are SetFunctionCallables but FinDomFunctionMaps are not.
if valtype(k.hom_map) <: SetFunctionCallable k = FinDomFunctorMap(k.ob_map,FinDomFunction{Int}[a for a in k.hom_map],k.dom,TypeCat(SetOb,FinDomFunction{Int})) end
# Make sure the diagram to be limited has loose enough types
diagram_types = isempty(J) ? (FinSet{Int}, FinFunction{Int}) : (SetOb,FinDomFunction{Int})
k = dom_to_graph(diagram(force(compose(Fc, X))), diagram_types...)
lim = limit(k, SpecializeLimit(fallback=ToBipartiteLimit()))
if tabular
names = (ob_generator_name(J, j) for j in ob_generators(J))
Expand Down
89 changes: 89 additions & 0 deletions test/Migrations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -550,4 +550,93 @@ S = migrate(AttrSet2{Bool, String}, T, M)
@test subpart(S,:f) == [false]
@test subpart(S,:g) == ["unknown"]



#Handle identity morphisms when building diagram to limit

@present OntBlocksworld(FreeSchema) begin
Block::Ob # rename Thing --> Block

# Gripper::Ob
# isHolding::Hom(Gripper, Block) # add attribute

InOn::Ob
inOn_l::Hom(InOn, Block) # rename Thing --> Block
inOn_r::Hom(InOn, Block) # rename Thing --> Block

Clear::AttrType
isClear::Attr(Block, Clear) # add attribute
onTable::AttrType
isOnTable::Attr(Block, onTable) # add attribute

# AttrTypes for datatypes (placeholder until Kevin can get this to work)
MyBool::AttrType
MyString::AttrType
end
@acset_type Blocksworld(OntBlocksworld)


@present OntTowersOfHanoi(FreeSchema) begin
Disk::Ob
Peg::Ob

diskIsOnPeg::Hom(Disk, Peg)

Smaller::Ob # add relation
isSmaller_l::Hom(Smaller, Disk)
isSmaller_r::Hom(Smaller, Disk)

Clear::AttrType
isClear::Attr(Disk, Clear)

# AttrTypes for datatypes (placeholder until Kevin can get this to work)
MyBool::AttrType
MyString::AttrType
end
@acset_type TowersOfHanoi(OntTowersOfHanoi)
yTowersOfHanoi = yoneda(TowersOfHanoi{Bool,Bool,String})

F = @migration OntBlocksworld OntTowersOfHanoi begin
Block => Disk
InOn => @join begin
disk1::Disk
disk2::Disk
peg::Peg
diskIsOnPeg(disk1) == peg
diskIsOnPeg(disk2) == peg
smaller::Smaller
isSmaller_l(smaller) == disk1 # disk1 < disk2
isSmaller_r(smaller) == disk2
end # a block is on another if it is smaller and on the same peg
inOn_l => disk1
inOn_r => disk2
Clear => Clear
isClear => isClear
onTable => MyBool
isOnTable => (x -> false) # it is on the table if it is the largest disk on a peg.
MyBool => MyBool
MyString => MyString
end

data = @acset_colim yTowersOfHanoi begin
(disk1, disk2, disk3)::Disk
(peg1, peg2)::Peg
(smaller1, smaller2, smaller3)::Smaller
isSmaller_l(smaller1) == disk1 # disk1 < disk2
isSmaller_r(smaller1) == disk2
isSmaller_l(smaller2) == disk2 # disk2 < disk3
isSmaller_r(smaller2) == disk3
isSmaller_l(smaller3) == disk1 # disk1 < disk3
isSmaller_r(smaller3) == disk3
diskIsOnPeg(disk1) == peg1
diskIsOnPeg(disk2) == peg1
diskIsOnPeg(disk3) == peg2
isClear(disk1) == true
isClear(disk2) == false
isClear(disk3) == true
end

new_data = migrate(Blocksworld, data, F)
@test length(parts(new_data,:Block)) == 3
@test subpart(new_data,:isOnTable) == [false, false, false]
end#module
Loading