AlgebraicJulia / AlgebraicJulia/AlgebraicRewriting.jl

Rewriting with attributes produces mysterious traceback

Open
#92 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Julia
Stars
41
Forks
9
PR merge metrics
No merged PRs in 30d

Description

Here is a schema:

```julia
@present SchHuman(FreeSchema) begin
Human::Ob
Sex::AttrType
sex::Attr(Human, Sex)
Birth::Ob
(mother, father, child)::Hom(Birth, Human)
end

@enum BiologicalSex begin
male_sex
female_sex
end

@acset_type AbstractHuman(SchHuman)
const CompiledHuman = AbstractHuman{BiologicalSex}
```

Here is a rule:

```julia
reproductive_pair = @acset_colim_names yHuman begin
(male_parent, female_parent)::Human
sex(female_parent) == $(female_sex)
sex(male_parent) == $(male_sex)
end

boy_birth = @acset_colim_names yHuman begin
(male_parent, female_parent, baby)::Human
birth::Birth
mother(birth) == female_parent
father(birth) == male_parent
child(birth) == baby
sex(male_parent) == $(male_sex)
sex(female_parent) == $(female_sex)
sex(baby) == $(male_sex)
end

r = @xrule yHuman begin
inv => reproductive_pair
lhs => reproductive_pair
rhs => boy_birth
end
```

We can verify that the rule and initial conditions are reasonable:

```julia-repl
julia> r.L.codom
CompiledHuman {Human:2, Birth:0, Sex:0}
┌───────┬────────────┐
│ Human │ sex │
├───────┼────────────┤
│ 1 │ male_sex │
│ 2 │ female_sex │
└───────┴────────────┘

julia> r.R.codom
CompiledHuman {Human:3, Birth:1, Sex:0}
┌───────┬────────────┐
│ Human │ sex │
├───────┼────────────┤
│ 1 │ female_sex │
│ 2 │ male_sex │
│ 3 │ male_sex │
└───────┴────────────┘
┌───────┬────────┬────────┬───────┐
│ Birth │ mother │ father │ child │
├───────┼────────┼────────┼───────┤
│ 1 │ 1 │ 2 │ 3 │
└───────┴────────┴────────┴───────┘

julia> reproductive_pair[2]
CompiledHuman {Human:2, Birth:0, Sex:0}
┌───────┬────────────┐
│ Human │ sex │
├───────┼────────────┤
│ 1 │ male_sex │
│ 2 │ female_sex │
└───────┴────────────┘
```

Applying this rule with `rewrite(r, reproductive_pair[2])` produces this difficult to debug traceback that I think has to do with the presence of attributes.

```
ERROR: MethodError: no method matching id_condition(::Nothing, ::Nothing)
The function `id_condition` exists, but no method is defined for this combination of argument types.

Closest candidates are:
id_condition(::FinDomFunction, ::FinDomFunction)
@ AlgebraicRewriting ~/src/synthema/AlgebraicRewriting.jl/src/categorical_algebra/FinSets.jl:158
id_condition(::FinFunction, ::FinFunction)
@ AlgebraicRewriting ~/src/synthema/AlgebraicRewriting.jl/src/categorical_algebra/FinSets.jl:147
id_condition(::CopairedFinDomFunction, ::CopairedFinDomFunction)
@ AlgebraicRewriting ~/src/synthema/AlgebraicRewriting.jl/src/categorical_algebra/FinSets.jl:173

Stacktrace:
[1] #pushout_complement_violations#41
@ ~/src/synthema/AlgebraicRewriting.jl/src/categorical_algebra/CSets.jl:264 [inlined]
[2] pushout_complement_violations(m#256::WithModel{…}, pair::ComposablePair{…}; context::Nothing)
@ AlgebraicRewriting.CategoricalAlgebra.CSets ./none:0
[3] pushout_complement_violations
@ ./none:0 [inlined]
[4] ##pushout_complement_violations#234#27#33
@ ~/.julia/packages/GATlab/g7SpO/src/syntax/TheoryInterface.jl:254 [inlined]
[5] (::AlgebraicRewriting.CategoricalAlgebra.Theories.var"##pushout_complement_violations#234#32"{…})(args::ComposablePair{…})
@ AlgebraicRewriting.CategoricalAlgebra.Theories ~/.julia/packages/GATlab/g7SpO/src/syntax/TheoryInterface.jl:253
[6] can_match(r::Rule{…}, m::StructACSetTransformation{…}; cat::ACSetCategory, homsearch::Bool, initial::Dict{…})
@ AlgebraicRewriting.Rewrite.Utils ~/src/synthema/AlgebraicRewriting.jl/src/rewrite/Utils.jl:177
[7] can_match
@ ~/src/synthema/AlgebraicRewriting.jl/src/rewrite/Utils.jl:159 [inlined]
[8] (::AlgebraicRewriting.Rewrite.Utils.var"#19#20"{…})(m::StructACSetTransformation{…})
@ AlgebraicRewriting.Rewrite.Utils ~/src/synthema/AlgebraicRewriting.jl/src/rewrite/Utils.jl:211
[9] (::Catlab.CategoricalAlgebra.Pointwise.HomSearch.var"#5#6"{…})(αs::Base.Generator{…})
@ Catlab.CategoricalAlgebra.Pointwise.HomSearch ~/src/synthema/Catlab.jl/src/categorical_algebra/pointwise/homsearch/HomSearch.jl:131
[10] backtracking_search(f::Catlab.CategoricalAlgebra.Pointwise.HomSearch.var"#5#6"{…}, state::Catlab.CategoricalAlgebra.Pointwise.HomSearch.BacktrackingState{…}, depth::Int64; random::Bool)
@ Catlab.CategoricalAlgebra.Pointwise.HomSearch ~/src/synthema/Catlab.jl/src/categorical_algebra/pointwise/homsearch/HomSearch.jl:349
[11] backtracking_search(f::Function, state::Catlab.CategoricalAlgebra.Pointwise.HomSearch.BacktrackingState{…}, depth::Int64)
@ Catlab.CategoricalAlgebra.Pointwise.HomSearch ~/src/synthema/Catlab.jl/src/categorical_algebra/pointwise/homsearch/HomSearch.jl:337
[12] backtracking_search(f::Catlab.CategoricalAlgebra.Pointwise.HomSearch.var"#5#6"{…}, state::Catlab.CategoricalAlgebra.Pointwise.HomSearch.BacktrackingState{…}, depth::Int64; random::Bool)
@ Catlab.CategoricalAlgebra.Pointwise.HomSearch ~/src/synthema/Catlab.jl/src/categorical_algebra/pointwise/homsearch/HomSearch.jl:360
[13] backtracking_search(f::Function, state::Catlab.CategoricalAlgebra.Pointwise.HomSearch.BacktrackingState{…}, depth::Int64)
@ Catlab.CategoricalAlgebra.Pointwise.HomSearch ~/src/synthema/Catlab.jl/src/categorical_algebra/pointwise/homsearch/HomSearch.jl:337
[14] backtracking_search(f::Catlab.CategoricalAlgebra.Pointwise.HomSearch.var"#5#6"{…}, state::Catlab.CategoricalAlgebra.Pointwise.HomSearch.BacktrackingState{…}, depth::Int64; random::Bool)
@ Catlab.CategoricalAlgebra.Pointwise.HomSearch ~/src/synthema/Catlab.jl/src/categorical_algebra/pointwise/homsearch/HomSearch.jl:360
[15] backtracking_search(f::Catlab.CategoricalAlgebra.Pointwise.HomSearch.var"#5#6"{…}, X::CompiledHuman, Y::CompiledHuman; monic::Vector{…}, epic::Bool, iso::Bool, random::Bool, predicates::@NamedTuple{}, type_components::@NamedTuple{}, initial::@NamedTuple{}, error_failures::Bool, no_bind::Bool, cat::ACSetCategory)
@ Catlab.CategoricalAlgebra.Pointwise.HomSearch ~/src/synthema/Catlab.jl/src/categorical_algebra/pointwise/homsearch/HomSearch.jl:330
[16] backtracking_search
@ ~/src/synthema/Catlab.jl/src/categorical_algebra/pointwise/homsearch/HomSearch.jl:219 [inlined]
[17] #homomorphisms#4
@ ~/src/synthema/Catlab.jl/src/categorical_algebra/pointwise/homsearch/HomSearch.jl:129 [inlined]
[18] homomorphisms
@ ~/src/synthema/Catlab.jl/src/categorical_algebra/pointwise/homsearch/HomSearch.jl:121 [inlined]
[19] #homomorphisms#3
@ ~/src/synthema/Catlab.jl/src/categorical_algebra/pointwise/homsearch/HomSearch.jl:107 [inlined]
[20] get_matches(r::Rule{…}, G::CompiledHuman; cat::ACSetCategory, kw::@Kwargs{…})
@ AlgebraicRewriting.Rewrite.Utils ~/src/synthema/AlgebraicRewriting.jl/src/rewrite/Utils.jl:210
[21] get_matches
@ ~/src/synthema/AlgebraicRewriting.jl/src/rewrite/Utils.jl:208 [inlined]
[22] get_match
@ ~/src/synthema/AlgebraicRewriting.jl/src/rewrite/Utils.jl:198 [inlined]
[23] rewrite(r::Rule{:DPO}, G::CompiledHuman; cat::Nothing, initial::@NamedTuple{}, random::Bool, kw::@Kwargs{})
@ AlgebraicRewriting.Rewrite.Utils ~/src/synthema/AlgebraicRewriting.jl/src/rewrite/Utils.jl:279
[24] rewrite(r::Rule{:DPO}, G::CompiledHuman)
@ AlgebraicRewriting.Rewrite.Utils ~/src/synthema/AlgebraicRewriting.jl/src/rewrite/Utils.jl:277
[25] top-level scope
@ REPL[2]:1
Some type information was truncated. Use `show(err)` to see complete types.

```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.