AlgebraicJulia / DataMigrations.jl

https://algebraicjulia.github.io/DataMigrations.jl/
MIT License
2 stars 0 forks source link

Error converting types with TowersOfHanoi schema #155

Closed aaguinal closed 5 months ago

aaguinal commented 6 months ago

I am getting the following error message:

MethodError: Cannot `convert` an object of type Catlab.CategoricalAlgebra.Sets.IdentityFunction{Catlab.CategoricalAlgebra.FinSets.FinSetInt} to an object of type Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{Int64, Vector{Int64}, Catlab.CategoricalAlgebra.FinSets.FinSetInt}

Closest candidates are:
  convert(::Type{T}, ::T) where T
   @ Base Base.jl:84
  (::Type{Catlab.CategoricalAlgebra.FinSets.FinDomFunctionVector{T, V, Codom}} where {T, V<:AbstractVector{T}, Codom<:SetOb{T}})(::Any, ::Any)
   @ Catlab ~/.julia/packages/Catlab/bgTXj/src/categorical_algebra/FinSets.jl:266

Stacktrace:
  [1] convert(::Type{…}, x::Catlab.CategoricalAlgebra.Sets.IdentityFunction{…})
    @ ACSets.ColumnImplementations ~/.julia/packages/ACSets/b3rhT/src/ColumnImplementations.jl:23
  [2] setindex!(A::Vector{…}, x::Catlab.CategoricalAlgebra.Sets.IdentityFunction{…}, i1::Int64)
    @ Base ./array.jl:1021
  [3] setindex!
    @ ~/.julia/packages/ACSets/b3rhT/src/Mappings.jl:115 [inlined]
  [4] setindex!(c::ACSets.ColumnImplementations.DenseColumn{…}, y::Catlab.CategoricalAlgebra.Sets.IdentityFunction{…}, x::Int64)
    @ ACSets.Columns ~/.julia/packages/ACSets/b3rhT/src/Columns.jl:55
  [5] macro expansion
    @ ~/.julia/packages/ACSets/b3rhT/src/DenseACSets.jl:548 [inlined]
  [6] macro expansion
    @ ~/.julia/packages/CompTime/Ppb3B/src/CompTime.jl:137 [inlined]
  [7] comptime(::typeof(ACSets.DenseACSets._set_subpart!), acs::Catlab.CategoricalAlgebra.FreeDiagrams.FreeDiagramAsBipartite{…}, 318::Type{…}, 319::Type{…}, part::Int64, 320::Type{…}, subpart::Catlab.CategoricalAlgebra.Sets.IdentityFunction{…})
    @ ACSets.DenseACSets ~/.julia/packages/CompTime/Ppb3B/src/CompTime.jl:137
  [8] _set_subpart!(acs::Catlab.CategoricalAlgebra.FreeDiagrams.FreeDiagramAsBipartite{…}, 318::Type{…}, 319::Type{…}, part::Int64, 320::Type{…}, subpart::Catlab.CategoricalAlgebra.Sets.IdentityFunction{…})
    @ ACSets.DenseACSets ./none:0
  [9] set_subpart!
    @ ~/.julia/packages/ACSets/b3rhT/src/DenseACSets.jl:535 [inlined]
 [10] macro expansion
    @ ./none:0 [inlined]
 [11] set_subparts!
    @ ./none:0 [inlined]
 [12] add_part!
    @ ~/.julia/packages/ACSets/b3rhT/src/ACSetInterface.jl:218 [inlined]
 [13] add_part!
    @ ~/.julia/packages/ACSets/b3rhT/src/ACSetInterface.jl:207 [inlined]
 [14] add_edge!(g::Catlab.CategoricalAlgebra.FreeDiagrams.FreeDiagramAsBipartite{…}, src::Int64, tgt::Int64; kw::@Kwargs{…})
    @ Catlab.Graphs.BipartiteGraphs ~/.julia/packages/Catlab/bgTXj/src/graphs/BipartiteGraphs.jl:141
 [15] (BipartiteFreeDiagram{…})(F::Catlab.CategoricalAlgebra.FinCats.FinDomFunctorMap{…}; colimit::Bool)
    @ Catlab.CategoricalAlgebra.FreeDiagrams ~/.julia/packages/Catlab/bgTXj/src/categorical_algebra/FreeDiagrams.jl:455
 [16] _BipartiteFreeDiagram
    @ ~/.julia/packages/Catlab/bgTXj/src/categorical_algebra/FreeDiagrams.jl:440 [inlined]
 [17] _BipartiteFreeDiagram
    @ ~/.julia/packages/Catlab/bgTXj/src/categorical_algebra/FreeDiagrams.jl:465 [inlined]
 [18] limit(F::Catlab.CategoricalAlgebra.FinCats.FinDomFunctorMap{…}, ::ToBipartiteLimit)
    @ Catlab.CategoricalAlgebra.Limits ~/.julia/packages/Catlab/bgTXj/src/categorical_algebra/Limits.jl:573
 [19] limit(F::Catlab.CategoricalAlgebra.FinCats.FinDomFunctorMap{…}, alg::SpecializeLimit)
    @ Catlab.CategoricalAlgebra.Limits ~/.julia/packages/Catlab/bgTXj/src/categorical_algebra/Limits.jl:416
 [20] (::DataMigrations.Migrations.var"#19#23"{…})(c::Catlab.Theories.FreePointedSetSchema.Ob{…})
    @ DataMigrations.Migrations ~/.julia/packages/DataMigrations/O0QOg/src/Migrations.jl:398
 [21] (::Catlab.CategoricalAlgebra.FinCats.var"#94#95"{…})(x::Catlab.Theories.FreePointedSetSchema.Ob{…})
    @ Catlab.CategoricalAlgebra.FinCats ./none:0
 [22] iterate
    @ ./generator.jl:47 [inlined]
 [23] grow_to!(dest::Dict{…}, itr::Base.Generator{…}, st::Int64)
    @ Base ./dict.jl:131
 [24] grow_to!(dest::Dict{Any, Any}, itr::Base.Generator{Vector{…}, Catlab.CategoricalAlgebra.FinCats.var"#94#95"{…}})
    @ Base ./dict.jl:125
 [25] dict_with_eltype(DT_apply::F, kv::Base.Generator, t::Any) where F
    @ Base ./abstractdict.jl:590 [inlined]
 [26] Dict(kv::Base.Generator{Vector{…}, Catlab.CategoricalAlgebra.FinCats.var"#94#95"{…}})
    @ Base ./dict.jl:109
 [27] make_map(f::DataMigrations.Migrations.var"#19#23"{…}, xs::Vector{…}, ::Type{…})
    @ Catlab.CategoricalAlgebra.FinCats ~/.julia/packages/Catlab/bgTXj/src/categorical_algebra/FinCats.jl:816
 [28] make_map
    @ ~/.julia/packages/Catlab/bgTXj/src/categorical_algebra/FinCats.jl:794 [inlined]
 [29] migrate(X::Catlab.CategoricalAlgebra.CSets.ACSetFunctor{…}, M::DataMigration{…}; return_limits::Bool, tabular::Bool)
    @ DataMigrations.Migrations ~/.julia/packages/DataMigrations/O0QOg/src/Migrations.jl:375
 [30] migrate
    @ ~/.julia/packages/DataMigrations/O0QOg/src/Migrations.jl:367 [inlined]
 [31] #migrate#2
    @ ~/.julia/packages/Catlab/bgTXj/src/categorical_algebra/FunctorialDataMigrations.jl:74 [inlined]
 [32] migrate
    @ ~/.julia/packages/Catlab/bgTXj/src/categorical_algebra/FunctorialDataMigrations.jl:73 [inlined]
 [33] migrate(::Type{…}, X::TowersOfHanoi{…}, M::DataMigration{…}; kw::@Kwargs{})
    @ Catlab.CategoricalAlgebra.FunctorialDataMigrations ~/.julia/packages/Catlab/bgTXj/src/categorical_algebra/FunctorialDataMigrations.jl:71
 [34] migrate(::Type{…}, X::TowersOfHanoi{…}, M::DataMigration{…})
    @ Catlab.CategoricalAlgebra.FunctorialDataMigrations ~/.julia/packages/Catlab/bgTXj/src/categorical_algebra/FunctorialDataMigrations.jl:70
 [35] top-level scope
    @ ~/Documents/Git/ieee-tase24-skilltransfer/PlanningDomainMigrations/src/ExampleMigrations.jl:322
Some type information was truncated. Use `show(err)` to see complete types.

This may be a strict typing bug within either DataMigrations.jl or Catlab.jl.

Here is the code that is producing the error:

@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)
KevinDCarlson commented 6 months ago

yTowersOfHanoi isn't declared here. Is it yoneda(TowersOfHanoi{Bool,Bool,Sring})?

aaguinal commented 6 months ago

yTowersOfHanoi isn't declared here. Is it yoneda(TowersOfHanoi{Bool,Bool,Sring})?

Whoops! Forgot to include that. Yes it is. I modified the code block above.

epost commented 6 months ago

@aaguinal FWIW, I happened upon this slide just last week. The yoneda(...) computation was missing there too, and as a bit of an (Algebraic)Julia noob, it took me a while to figure out. Cool slides and paper though! They inspired me to be the lesser noob that I am this week. 🙏

aaguinal commented 6 months ago

@aaguinal FWIW, I happened upon this slide just last week. The yoneda(...) computation was missing there too, and as a bit of an (Algebraic)Julia noob, it took me a while to figure out. Cool slides and paper though! They inspired me to be the lesser noob that I am this week. 🙏

Hi @epost Thanks for the comment!! I'm glad you found the slide interesting. There were a few lines of code that were intentionally hidden because it would require too much overhead to explain during the talk. You can take a look at the source for the presentation here and find the blocks of Julia code (marked by ```julia) to see all the code blocks.

epost commented 6 months ago

Oh cool, thanks for that! This whole ecosystem just seems to be brimming with exciting stuff. :D