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

ACset map MethodError running convert #735

Closed
mehalter opened this issue Jan 30, 2023 · 3 comments
Closed

ACset map MethodError running convert #735

mehalter opened this issue Jan 30, 2023 · 3 comments

Comments

@mehalter
Copy link
Member

I'm running into an issue with map in AlgebraicPetri even though the types align correctly. Here is an example to replicate the bug (this example does require the AlgebraicPetri package):

using AlgebraicPetri

# Create a labelled reaction net with integer concentrations and rates
# and tuples of symbols
tuple_rxn = AlgebraicPetri.LabelledReactionNetUntyped{Int,Int,Tuple{Symbol,Symbol}}()
add_species!(tuple_rxn, 3, sname=((:U, :S), (:U, :I), (:U, :R)), concentration=(1, 1, 1))
add_transitions!(tuple_rxn, 2, tname=((:Q, :inf), (:Q, :rec)), rate=(1, 1))

# Create a simple function to convert nested tuples of symbols to a single Symbol
flat_symbol(sym::Symbol)::Symbol = sym
flat_symbol(sym::Tuple)::Symbol = mapreduce(x -> isa(x, Tuple) ? flat_symbol(x) : x, (x, y) -> Symbol(x, "_", y), sym)

# Map this `flat_symbol` function to all Name types
# (`tname` and `sname` parts)
map(tuple_rxn, Name=flat_symbol)

Also to note I get the same behavior even if I specify the parts in particular with

map(tuple_rxn, tname=flat_symbol, sname=flat_symbol)

This results in the following error:

ERROR: MethodError: Cannot `convert` an object of type Int64 to an object of type Tuple{Int64, Int64, Tuple{Symbol, Symbol}}
Closest candidates are:
  convert(::Type{T}, ::T) where T<:Tuple at essentials.jl:331
  convert(::Type{T}, ::Tuple{Vararg{Any, N}}) where {N, T<:Tuple} at essentials.jl:332
  convert(::Type{T}, ::CartesianIndex) where T<:Tuple at multidimensional.jl:131
  ...
Stacktrace:
  [1] setindex!(A::Vector{Tuple{Int64, Int64, Tuple{Symbol, Symbol}}}, x::Int64, i1::Int64)
    @ Base ./array.jl:966
  [2] getindex(#unused#::Type{Tuple{Int64, Int64, Tuple{Symbol, Symbol}}}, vals::Int64)
    @ Base ./array.jl:407
  [3] (::Catlab.DenseACSets.var"#118#132"{DataType, Dict{Symbol, Vector{Symbol}}, Vector{Symbol}, Catlab.DenseACSets.var"#q#123"})(::Tuple{I
nt64, Symbol})
    @ Catlab.DenseACSets ~/.local/share/julia/depot/packages/Catlab/NT7Hr/src/acsets/DenseACSets.jl:771
  [4] iterate
    @ ./generator.jl:47 [inlined]
  [5] collect(itr::Base.Generator{Base.Iterators.Enumerate{Vector{Symbol}}, Catlab.DenseACSets.var"#118#132"{DataType, Dict{Symbol, Vector{S
ymbol}}, Vector{Symbol}, Catlab.DenseACSets.var"#q#123"}})
    @ Base ./array.jl:787
  [6] map(f::Function, A::Base.Iterators.Enumerate{Vector{Symbol}})
    @ Base ./abstractarray.jl:2961
  [7] #s92#109
    @ ~/.local/share/julia/depot/packages/Catlab/NT7Hr/src/acsets/DenseACSets.jl:766 [inlined]
  [8] var"#s92#109"(S::Any, Ts::Any, AT::Any, map_over::Any, ::Any, acs::Any, fns::Any)
    @ Catlab.DenseACSets ./none:0
  [9] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any})
    @ Core ./boot.jl:582
 [10] #map#108
    @ ~/.local/share/julia/depot/packages/Catlab/NT7Hr/src/acsets/DenseACSets.jl:712 [inlined]
 [11] top-level scope
    @ REPL[78]:1
@epatters
Copy link
Member

Found while implementing AlgebraicJulia/AlgebraicPetri.jl#94

@mehalter
Copy link
Member Author

Thanks for this! I'll test out the simplified flatten_labels in AlgebraicPetri

@epatters
Copy link
Member

Thanks Micah, but I already did, so don't worry about that! I'll make a PR to AlgebraicPetri.

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

No branches or pull requests

2 participants