ModelingToolkit: How to interpret "ERROR: Cyclic guesses detected in the system" during initialization?

I’ve got a simple RC circuit with two series resistors:

using ModelingToolkit, DifferentialEquations
using ModelingToolkitStandardLibrary.Electrical
using ModelingToolkitStandardLibrary.Blocks

@mtkmodel Circuit begin
    @components begin
        # Battery Model
        v_source = Constant(k=1)
        voltage = Voltage()
        resistor1 = Resistor(R=1)
        resistor2 = Resistor(R=1)
        capacitor = Capacitor(C=1)
        ground = Ground()
    end
    @equations begin
        # Input to voltage source
        connect(v_source.output, voltage.V)
        # Circuit connections
        connect(voltage.p, resistor1.p)
        connect(resistor1.n, resistor2.p)
        connect(resistor2.n, capacitor.p)
        connect(capacitor.n, ground.g, voltage.n)
    end
end

@mtkcompile sys = Circuit()

I can initialize the system by specifying the initial capacitor current as follows:

prob = ODEProblem(sys, [sys.capacitor.i=>0], (0,5))

But if I try to initialize the system by specifying the capacitor voltage instead,

prob = ODEProblem(sys, [sys.capacitor.v=>0], (0,5))

I get an ERROR; Cyclic guesses detected in the system... with the following full traceback

┌ Warning: Did not converge after `maxiters = 100` substitutions. Either there is a cycle in the rules or `maxiters` needs to be higher.
└ @ Symbolics C:\Users\nhemenway\.julia\packages\Symbolics\xD5Pj\src\variable.jl:646
ERROR: Cyclic guesses detected in the system. Symbolic values were found for the following variables/parameters in the map: 
resistor1₊v(t)  => -capacitor₊i(t)
In order to resolve this, please provide additional numeric guesses so that the chain can be resolved to assign numeric values to each variable.

Stacktrace:
  [1] varmap_to_vars(varmap::Dict{…}, vars::Vector{…}; tofloat::Bool, use_union::Bool, container_type::Type, buffer_eltype::Type, toterm::Function, check::Bool, allow_symbolic::Bool, is_initializeprob::Bool, substitution_limit::Int64)
    @ ModelingToolkit C:\Users\nhemenway\.julia\packages\ModelingToolkit\KTR1R\src\systems\problem_utils.jl:408
  [2] process_SciMLProblem(constructor::Type, sys::System, op::Dict{…}; build_initializeprob::Bool, implicit_dae::Bool, t::Nothing, guesses::Dict{…}, warn_initialize_determined::Bool, initialization_eqs::Vector{…}, eval_expression::Bool, eval_module::Module, fully_determined::Nothing, check_initialization_units::Bool, u0_eltype::Nothing, tofloat::Bool, u0_constructor::typeof(identity), p_constructor::typeof(identity), check_length::Bool, symbolic_u0::Bool, warn_cyclic_dependency::Bool, circular_dependency_max_cycle_length::Int64, circular_dependency_max_cycles::Int64, substitution_limit::Int64, use_scc::Bool, time_dependent_init::Bool, algebraic_only::Bool, allow_incomplete::Bool, is_initializeprob::Bool, kwargs::@Kwargs{…})
    @ ModelingToolkit C:\Users\nhemenway\.julia\packages\ModelingToolkit\KTR1R\src\systems\problem_utils.jl:1443
  [3] (NonlinearProblem{…})(sys::System, op::Dict{…}; expression::Type, check_length::Bool, check_compatibility::Bool, kwargs::@Kwargs{…})
    @ ModelingToolkit C:\Users\nhemenway\.julia\packages\ModelingToolkit\KTR1R\src\problems\nonlinearproblem.jl:66
  [4] NonlinearProblem
    @ C:\Users\nhemenway\.julia\packages\ModelingToolkit\KTR1R\src\problems\nonlinearproblem.jl:57 [inlined]
  [5] NonlinearProblem
    @ .\none:-1 [inlined]
  [6] (SCCNonlinearProblem{…} where iip)(sys::System, op::Dict{…}; eval_expression::Bool, eval_module::Module, cse::Bool, u0_constructor::Function, kwargs::@Kwargs{…})
    @ ModelingToolkit C:\Users\nhemenway\.julia\packages\ModelingToolkit\KTR1R\src\problems\sccnonlinearproblem.jl:110
  [7] InitializationProblem{…}(sys::System, t::Int64, op::Dict{…}; guesses::Dict{…}, check_length::Bool, warn_initialize_determined::Bool, initialization_eqs::Vector{…}, fully_determined::Nothing, check_units::Bool, use_scc::Bool, allow_incomplete::Bool, algebraic_only::Bool, time_dependent_init::Bool, kwargs::@Kwargs{…})
    @ ModelingToolkit C:\Users\nhemenway\.julia\packages\ModelingToolkit\KTR1R\src\problems\initializationproblem.jl:138
  [8] InitializationProblem
    @ C:\Users\nhemenway\.julia\packages\ModelingToolkit\KTR1R\src\problems\initializationproblem.jl:20 [inlined]
  [9] #_#1180
    @ .\none:-1 [inlined]
 [10] maybe_build_initialization_problem(sys::System, iip::Bool, op::Dict{…}, t::Int64, defs::Dict{…}, guesses::Dict{…}, missing_unknowns::Set{…}; implicit_dae::Bool, time_dependent_init::Bool, u0_constructor::Function, p_constructor::Function, floatT::Type, initialization_eqs::Vector{…}, use_scc::Bool, eval_expression::Bool, eval_module::Module, kwargs::@Kwargs{…})
    @ ModelingToolkit C:\Users\nhemenway\.julia\packages\ModelingToolkit\KTR1R\src\systems\problem_utils.jl:1135
 [11] process_SciMLProblem(constructor::Type, sys::System, op::Vector{…}; build_initializeprob::Bool, implicit_dae::Bool, t::Int64, guesses::Dict{…}, warn_initialize_determined::Bool, initialization_eqs::Vector{…}, eval_expression::Bool, eval_module::Module, fully_determined::Nothing, check_initialization_units::Bool, u0_eltype::Nothing, tofloat::Bool, u0_constructor::typeof(identity), p_constructor::typeof(identity), check_length::Bool, symbolic_u0::Bool, warn_cyclic_dependency::Bool, circular_dependency_max_cycle_length::Int64, circular_dependency_max_cycles::Int64, substitution_limit::Int64, use_scc::Bool, time_dependent_init::Bool, algebraic_only::Bool, allow_incomplete::Bool, is_initializeprob::Bool, kwargs::@Kwargs{…})
    @ ModelingToolkit C:\Users\nhemenway\.julia\packages\ModelingToolkit\KTR1R\src\systems\problem_utils.jl:1409
 [12] (ODEProblem{…})(sys::System, op::Vector{…}, tspan::Tuple{…}; callback::Nothing, check_length::Bool, eval_expression::Bool, expression::Type, eval_module::Module, check_compatibility::Bool, kwargs::@Kwargs{})
    @ ModelingToolkit C:\Users\nhemenway\.julia\packages\ModelingToolkit\KTR1R\src\problems\odeproblem.jl:81
 [13] ODEProblem
    @ C:\Users\nhemenway\.julia\packages\ModelingToolkit\KTR1R\src\problems\odeproblem.jl:73 [inlined]
 [14] ODEProblem
    @ .\none:-1 [inlined]
 [15] ODEProblem(sys::System, op::Vector{Pair{Num, Int64}}, tspan::Tuple{Int64, Int64})
    @ ModelingToolkit .\none:-1
 [16] top-level scope
    @ c:\Users\nhemenway\OneDrive - Brunswick Corporation\Documents\01_Projects\Snapper\TRs\TR2024-0506-005_snapper_battery_cable_sizing\julia\example.jl:27
Some type information was truncated. Use `show(err)` to see complete types.

I’ve read the documentation on initialization and believe I’m doing everything correct. I’m confused by why it’s failing, and more importantly, how to interpret the error message to be able to debug this in the future.

After playing with it a bit more, the system will initialize if I provide a guess for the capacitor current as:

prob = ODEProblem(sys, [sys.capacitor.v=>0], (0,5),  guesses=[sys.capacitor.i=>0])

But then if I specify the resistor current in resistor1 (which is the same as the capacitor current), I get the same “Cyclic guesses” error.

prob = ODEProblem(sys, [sys.capacitor.v=>0], (0,5),  guesses=[sys.resistor1.i=>0])

However, supplying a guess for the current in resistor2 works fine:

prob = ODEProblem(sys, [sys.capacitor.v=>0], (0,5),  guesses=[sys.resistor2.i=>0])

I’m puzzled.