Hi, I would like to use Enzyme.jl to get gradients for a max-flow result. Enzyme gives me an illegal type analysis
error in this MWE:
using Enzyme
using Graphs, GraphsFlows
# Graph from GraphsFlows.jl demo
flow_graph = Graphs.DiGraph(8) # Create a flow graph
flow_edges = [
(1,2,10),(1,3,5),(1,4,15),(2,3,4),(2,5,9),
(2,6,15),(3,4,4),(3,6,8),(4,7,16),(5,6,15),
(5,8,10),(6,7,15),(6,8,10),(7,3,6),(7,8,10)
]
capacity_matrix = zeros(8, 8) # Create a capacity matrix
for e in flow_edges
u, v, f = e
Graphs.add_edge!(flow_graph, u, v)
capacity_matrix[u,v] = f
end
# Some arbitrary function which depends on the max-flow results
foo(capacity_matrix) = maximum_flow(flow_graph, 1, 8, capacity_matrix, algorithm=DinicAlgorithm())[2][1, 2] # Run Dinic's algorithm
foo(capacity_matrix) # 10.0
gradient(Forward, foo, capacity_matrix)
Is this a lost cause because of the numerous type instabilities (JET.jl gives me 136 possible errors…)?