Avoiding array mutation with vector combinations for use in flux

Chris,

Tullio looks promising! Unfortunately, I tried implementing and ran into another with how I’m using Tullio, since there is no gradient definition for a Vector of a Vector. Is there a good way to get around this?

Another way I’m thinking of trying is trying to use Zygote.ignore() when using Combinatorics.jl functions.

My current function is now as follows and the error is attached below the code snippet:

# sol is the output of solve(ODEProblem)
function compute_objective(sol)
  # Slice matrix so each row (output) is a vector in a matrix
  M = sliceMatrix(sol)

  # Do all product permutations
  # Using Tullio, this does 3 combinations with repetition, hardcoded
  @tullio stats[i,j,k] := sum(M[i] .* M[j] .* M[k])
  println(stats)

  # Using combinatorics.jl, can you do this with pure Tullio? Error seems to occur with Zygote trying to pull gradient back through combinatorics library
  # counter = 0
  # for c in with_replacement_combinations(M,numComboElements) 
  #   counter += 1
  #   println("c", c)
  #   @tullio temp[i] := sum(c[i] .* c[j] .* c[k])
  #   println("temp #", counter, temp)
  #   # temp = ones(size(c[1]))
  #   # for i in c 
  #   #     temp = temp .* i
  #   # end 
  #   # temp = mean(temp)
  #   # stats = vcat(stats, temp)
  # end 

  # Return stats as 1d column vector
  return vec(stats)
end
ERROR: LoadError: no gradient definition here!
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:33
  [2] (::Tullio.var"#tullio_back#156"{Tullio.Eval{var"#ℳ𝒶𝓀ℯ#265"{var"#𝒜𝒸𝓉!#264"}, Nothing}, Tuple{Vector{Vector{Float64}}}, Array{Float64, 3}})(Δ::Array{Float64, 3})
    @ Tullio ~/.julia/packages/Tullio/u7Tk0/src/eval.jl:52
  [3] ZBack