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

Codom error when using rule with attribute variables #66

Closed
slwu89 opened this issue May 28, 2024 · 5 comments
Closed

Codom error when using rule with attribute variables #66

slwu89 opened this issue May 28, 2024 · 5 comments

Comments

@slwu89
Copy link
Member

slwu89 commented May 28, 2024

If I have an acset and one of the attribute types is being modeled as Vector{String} and I make a rewrite rule which is mapped to another Vector{String} as follows, I get the following error ERROR: Codom error: Any[Any[["start"], "rule"]] Vector{String} FinSet(0)

example:

using Catlab, AlgebraicRewriting

@present TestSch(FreeSchema) begin
    X::Ob
    MyAttr::AttrType
    myattr::Attr(X,MyAttr)
end

@acset_type TestData(TestSch)

data = @acset TestData{Vector{String}} begin
    X=1
    myattr=[["start"]]
end

L = TestData{Vector{String}}()
add_part!(L, :MyAttr)
add_part!(L, :X, myattr=AttrVar(1))

I = TestData{Vector{String}}()

R = deepcopy(L)

l = only(homomorphisms(I, L, monic=true))
r = only(homomorphisms(I, R, monic=true))

rule = Rule(l, r, expr=(MyAttr=[t -> vcat(t, "rule")], ))

m = get_matches(rule, data)
rewrite_match(rule, only(m))
@kris-brown
Copy link
Collaborator

so the anonymous function that is used to assign values in $R$ is a function of the bound variables in $L$. So t is actually a list! A singleton list, since there is only one MyAttr value in $L$, but it's still a list, so your code would work if you did vcat(only(t), "rule")

@slwu89
Copy link
Member Author

slwu89 commented May 29, 2024

Ah ok, thanks! So the length of the list for each AttrType will be the number of bound variables in $L$ for that attribute?

@slwu89
Copy link
Member Author

slwu89 commented May 30, 2024

@kris-brown posting another question here which is related. When trying to do the following rewrite I get an error related to computing the pushout complement. The specific example here is contrived, but it comes up when wanting to do a rewrite that updates a hom, but leaves all the other attributes/homs of something unchanged.

Also, happy to contribute to the docs related to rewriting with attribute variables after all this!

@present TestSch(FreeSchema) begin
    X::Ob
    Label::AttrType
    x1::Attr(X,Label)
    x2::Attr(X,Label)
end

@acset_type TestData(TestSch)

L = @acset TestData{Symbol} begin
    X=1
    Label=2
    x1=[AttrVar(1)]
    x2=[AttrVar(2)]
end

I = TestData{Symbol}()

R = @acset TestData{Symbol} begin
    X=1
    Label=2
    x1=[AttrVar(1)]
    x2=[AttrVar(2)]
end

l = only(homomorphisms(I, L, monic=true))
r = only(homomorphisms(I, R, monic=true))

rule = Rule(l, r, expr=(Label=[x1 -> first(x1), x2 -> last(x2)], ))

test = @acset TestData{Symbol} begin
    X=1
    Label=2
    x1=[Symbol("a")]
    x2=[Symbol("b")]
end

m = get_matches(rule, test)
test1 = rewrite_match(rule, m[1])

@kris-brown
Copy link
Collaborator

Here the error is Cannot rewrite with AttrVars in G which means that, in the graph you were trying to rewrite, there were variables. I think by accident you forgot to delete the Label=2 in test?

@slwu89
Copy link
Member Author

slwu89 commented May 30, 2024

Ah, user error!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants