Skip to content

AssertionError: roots_activep (DFT_CONSTANT) != activep (DFT_DUP_ARG) #3241

Description

@kshyatt

On

Enzyme v0.13.169
EnzymeTestUtils v0.2.8
Enzyme_jll v0.0.275+0
Julia 1.12.6

Full stack trace:

  AssertionError: roots_activep (DFT_CONSTANT) != activep (DFT_DUP_ARG) arg.typ=TensorKit.Tensor{Float64, TensorKit.GradedSpace{TensorKitSectors.U1Irrep, TensorKit.SortedVectorDict{TensorKitSectors.U1Irrep, Int64}}, 2, Vector{Float64}} equivalent_rooted_type=@NamedTuple{var"1"::Vector{Float64}, var"2"::Vector{TensorKitSectors.U1Irrep}, var"3"::Vector{Int64}, var"4"::Vector{TensorKitSectors.U1Irrep}, var"5"::Vector{Int64}} non_rooted_types=Type[TensorKit.ProductSpace{TensorKit.GradedSpace{TensorKitSectors.U1Irrep, TensorKit.SortedVectorDict{TensorKitSectors.U1Irrep, Int64}}, 0}, Bool, Bool]
  Stacktrace:
    [1] enzyme_custom_setup_args(B::Union{Nothing, LLVM.IRBuilder}, orig::LLVM.CallInst, gutils::Enzyme.Compiler.GradientUtils, mi::Core.MethodInstance, RT::Type, reverse::Bool, isKWCall::Bool, tape::Union{Nothing, LLVM.Value})
      @ Enzyme.Compiler ~/.julia/packages/Enzyme/TPTfM/src/rules/customrules.jl:441
    [2] fwd_mi
      @ ~/.julia/packages/Enzyme/TPTfM/src/rules/customrules.jl:1436 [inlined]
    [3] enzyme_custom_fwd
      @ ~/.julia/packages/Enzyme/TPTfM/src/rules/customrules.jl:1043 [inlined]
    [4] enzyme_custom_fwd_cfunc(B::Ptr{LLVM.API.LLVMOpaqueBuilder}, OrigCI::Ptr{LLVM.API.LLVMOpaqueValue}, gutils::Ptr{Nothing}, normalR::Ptr{Ptr{LLVM.API.LLVMOpaqueValue}}, shadowR::Ptr{Ptr{LLVM.API.LLVMOpaqueValue}}) 
      @ Enzyme.Compiler ~/.julia/packages/Enzyme/TPTfM/src/rules/llvmrules.jl:75
    [5] EnzymeCreateForwardDiff(logic::Enzyme.Logic, todiff::LLVM.Function, retType::Enzyme.API.CDIFFE_TYPE, constant_args::Vector{Enzyme.API.CDIFFE_TYPE}, TA::Enzyme.TypeAnalysis, returnValue::Bool, mode::Enzyme.API.CDerivativeMode, runtimeActivity::Bool, strongZero::Bool, width::Int64, additionalArg::Ptr{Nothing}, typeInfo::Enzyme.FnTypeInfo, uncacheable_args::Vector{Bool})
      @ Enzyme.API ~/.julia/packages/Enzyme/TPTfM/src/api.jl:342
    [6] macro expansion
      @ ~/.julia/packages/Enzyme/TPTfM/src/compiler.jl:2878 [inlined]
    [7] macro expansion
      @ ~/.julia/packages/LLVM/aXQtR/src/base.jl:113 [inlined]
    [8] enzyme!(enzyme_context::Enzyme.EnzymeContext, job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget{GPUCompiler.NativeCompilerTarget}, Enzyme.Compiler.EnzymeCompilerParams{Enzyme.Compiler.PrimalCompilerParams}}, interp::Enzyme.Compiler.Interpreter.EnzymeInterpreter{Nothing}, mod::LLVM.Module, primalf::LLVM.Function, TT::Type, mode::Enzyme.API.CDerivativeMode, width::Int64, parallel::Bool, actualRetType::Type, wrap::Bool, modifiedBetween::NTuple{N, Bool} where N, returnPrimal::Bool, expectedTapeType::Type, loweredArgs::Set{Int64}, boxedArgs::Set{Int64}, removedRoots::Set{Int64})
      @ Enzyme.Compiler ~/.julia/packages/Enzyme/TPTfM/src/compiler.jl:2700
    [9] compile_unhooked(output::Symbol, job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget{GPUCompiler.NativeCompilerTarget}, Enzyme.Compiler.EnzymeCompilerParams{Enzyme.Compiler.PrimalCompilerParams}})
      @ Enzyme.Compiler ~/.julia/packages/Enzyme/TPTfM/src/compiler.jl:6016
   [10] #compile#118
      @ ~/.julia/packages/GPUCompiler/QgckP/src/driver.jl:67 [inlined]
   [11] compile
      @ ~/.julia/packages/GPUCompiler/QgckP/src/driver.jl:55 [inlined]
   [12] _thunk(job::GPUCompiler.CompilerJob{Enzyme.Compiler.EnzymeTarget{GPUCompiler.NativeCompilerTarget}, Enzyme.Compiler.EnzymeCompilerParams{Enzyme.Compiler.PrimalCompilerParams}}, postopt::Bool)
      @ Enzyme.Compiler ~/.julia/packages/Enzyme/TPTfM/src/compiler.jl:6959
   [13] _thunk
      @ ~/.julia/packages/Enzyme/TPTfM/src/compiler.jl:6957 [inlined]
   [14] cached_compilation
      @ ~/.julia/packages/Enzyme/TPTfM/src/compiler.jl:7027 [inlined]
   [15] thunkbase(mi::Core.MethodInstance, World::UInt64, FA::Type{<:EnzymeCore.Annotation}, A::Type{<:EnzymeCore.Annotation}, TT::Type, Mode::Enzyme.API.CDerivativeMode, width::Int64, ModifiedBetween::NTuple{N, Bool} where N, ReturnPrimal::Bool, ShadowInit::Bool, ABI::Type, ErrIfFuncWritten::Bool, RuntimeActivity::Bool, StrongZero::Bool, edges::Vector{Any})
      @ Enzyme.Compiler ~/.julia/packages/Enzyme/TPTfM/src/compiler.jl:7143
   [16] thunk_generator(world::UInt64, source::Union{LineNumberNode, Method}, FA::Type, A::Type, TT::Type, Mode::Enzyme.API.CDerivativeMode, Width::Int64, ModifiedBetween::NTuple{N, Bool} where N, ReturnPrimal::Bool, ShadowInit::Bool, ABI::Type, ErrIfFuncWritten::Bool, RuntimeActivity::Bool, StrongZero::Bool, self::Any, fakeworld::Any, fa::Type, a::Type, tt::Type, mode::Type, width::Type, modifiedbetween::Type, returnprimal::Type, shadowinit::Type, abi::Type, erriffuncwritten::Type, runtimeactivity::Type, strongzero::Type)
      @ Enzyme.Compiler ~/.julia/packages/Enzyme/TPTfM/src/compiler.jl:7287
   [17] autodiff
      @ ~/.julia/packages/Enzyme/TPTfM/src/Enzyme.jl:673 [inlined]
   [18] autodiff(::EnzymeCore.ForwardMode{false, EnzymeCore.FFIABI, false, false, false}, ::EnzymeTestUtils.CallWithKWargs{@NamedTuple{}}, ::Type{EnzymeCore.Const}, ::EnzymeCore.Const{typeof(TensorKit.trace_permute!)}, ::EnzymeCore.Const{TensorKit.Tensor{Float64, TensorKit.GradedSpace{TensorKitSectors.U1Irrep, TensorKit.SortedVectorDict{TensorKitSectors.U1Irrep, Int64}}, 0, Vector{Float64}}}, ::EnzymeCore.Const{TensorKit.Tensor{Float64, TensorKit.GradedSpace{TensorKitSectors.U1Irrep, TensorKit.SortedVectorDict{TensorKitSectors.U1Irrep, Int64}}, 2, Vector{Float64}}}, ::EnzymeCore.Const{Tuple{Tuple{}, Tuple{}}}, ::EnzymeCore.Const{Tuple{Tuple{Int64}, Tuple{Int64}}}, ::EnzymeCore.Const{Float64}, ::EnzymeCore.Duplicated{Float64}, ::EnzymeCore.Const{TensorOperations.DefaultBackend})
      @ Enzyme ~/.julia/packages/Enzyme/TPTfM/src/Enzyme.jl:557
   [19] macro expansion
      @ ~/.julia/packages/EnzymeTestUtils/fNmYk/src/test_forward.jl:96 [inlined]

Here's a reproducer:

  1. Check out https://github.com/QuantumKitHub/TensorKit.jl/tree/ksh/enz_to
  2. Pkg.add(["Enzyme", "EnzymeTestUtils"])
  3. Run the trace_mwe.jl below:
using TensorKit, TensorOperations, Enzyme, EnzymeTestUtils, Random

function randindextuple(N::Int, k::Int = rand(0:N))
    @assert 0  k  N
    _p = randperm(N)
    return (tuple(_p[1:k]...), tuple(_p[(k + 1):end]...))
end

V = (
    Vect[U1Irrep](0 => 2, 1 => 2, -1 => 2),
    Vect[U1Irrep](0 => 1, 1 => 1, -1 => 1)',
    Vect[U1Irrep](0 => 3, 1 => 1, -1 => 1),
    Vect[U1Irrep](0 => 1, 1 => 2, -1 => 1)',
    Vect[U1Irrep](0 => 1, 1 => 1, -1 => 2),
)

k1 = rand(0:2)
k2 = rand(1:2)
V1 = map(v -> rand(Bool) ? v' : v, rand(V, k1))
V2 = map(v -> rand(Bool) ? v' : v, rand(V, k2))

(_p, _q) = randindextuple(k1 + 2 * k2, k1)
p = TensorOperations.repartition(_p, rand(0:k1))
q = TensorOperations.repartition(_q, k2)
ip = TensorOperations.repartition(invperm(linearize((_p, _q))), rand(0:(k1 + 2 * k2)))
eltypes = (Float64,)
for T in eltypes
    A = randn(T, permute(prod(V1)  prod(V2)  prod(V2), ip))

    α = randn(T)
    β = randn(T)
    C = randn!(TensorOperations.tensoralloc_add(T, A, p, false, Val(false)))

    EnzymeTestUtils.test_forward(
        TensorKit.trace_permute!, Duplicated,
        (copy(C), Duplicated), (A, Const), (p, Const), (q, Const),
        (α, Duplicated), (β, Duplicated), (TensorOperations.DefaultBackend(), Const);
    )
end

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions