Overflow error in `mtkcompile` for friction model with 32 nodes

Đang mở
#172 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
52/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
julia
Lĩnh vực
backend

Hướng nghiên cứu

The reproducer calls mtkcompile on a generated friction model network and reports an OverflowError at 32 or more nodes; start by running the script with the listed ModelingToolkit version to confirm the threshold. The issue points to ModelingToolkit PR #2089 as possibly related, so inspect that change and the state selection code reached during compilation. Done means identifying and fixing the overflow so the reproducer compiles at the reported node counts.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

A network of friction model fails to compile with node counts 32 or larger, it seems to be an integer that overflows. With 31 it works fine.

copilot-authored script to reproduce and monkeypatch to use BigInt below.

ModelingToolkit version 11.45.5, Julia 1.13.2.

Maybe ModelingToolkit #2089: Fix Barreiss algorithm is related in some way?

using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D

@connector function ContactPort(; name)
    variables = @variables begin
        velocity(t)
        force(t), [connect = Flow]
    end
    return System(Equation[], t, variables, []; name)
end

function contact_model(; name)
    parameters = @parameters stiffness = 1.0 rate_coefficient = 1.0
    variables = @variables begin
        deformation(t) = 0.0
        plastic_slip(t) = 0.0
        accumulated_slip(t) = 0.0
        resistance(t)
        capacity(t)
        positive_rate(t)
        negative_rate(t)
        slip_rate(t)
    end
    @named port = ContactPort()
    equations = [
        resistance ~ stiffness * deformation,
        capacity ~ 1 + exp(-accumulated_slip),
        positive_rate ~ (resistance - capacity + abs(resistance - capacity)) /
                         (2rate_coefficient),
        negative_rate ~ (-resistance - capacity + abs(-resistance - capacity)) /
                         (2rate_coefficient),
        slip_rate ~ positive_rate - negative_rate,
        D(deformation) ~ port.velocity - slip_rate,
        D(plastic_slip) ~ slip_rate,
        D(accumulated_slip) ~ positive_rate + negative_rate,
        port.force ~ resistance,
    ]
    return compose(System(equations, t, variables, parameters; name), port)
end

function velocity_source(; name)
    @named port = ContactPort()
    return compose(System([port.velocity ~ -1.0], t; name), port)
end

function contact_network(contact_count)
    @named source = velocity_source()
    contacts = [contact_model(; name = Symbol(:contact, index)) for index in 1:contact_count]
    equations = [connect(source.port, [contact.port for contact in contacts]...)]
    return compose(System(equations, t; name = :contact_network), source, contacts...)
end

function reproduce_main()
    for contact_count in (1, 30, 31, 32, 45, 60)
        try
            elapsed = @elapsed mtkcompile(contact_network(contact_count))
            println("PASS contacts=", contact_count, " compile_s=", elapsed)
        catch exception
            println("FAIL contacts=", contact_count, " ", sprint(showerror, exception))
            exception isa OverflowError || rethrow()
        end
    end
end

function enable_bigint_probe!()
    @eval ModelingToolkit.StateSelection begin
        function aag_bareiss!(structure, original::CLIL.SparseMatrixCLIL{Int, Int})
            pristine = copy(original)
            try
                return invoke(aag_bareiss!, Tuple{Any, CLIL.SparseMatrixCLIL},
                              structure, original)
            catch exception
                exception isa OverflowError || rethrow()
            end
            reduced, solvable, ranks = aag_bareiss!(structure,
                convert(CLIL.SparseMatrixCLIL{BigInt, Int}, pristine))
            maximum_coefficient = maximum(
                (maximum(abs, row; init = big(0)) for row in reduced.row_vals);
                init = big(0))
            println("BIGINT_RETRY_OK rows=", size(pristine, 1),
                    " max_reduced_coefficient=", maximum_coefficient)
            return convert(CLIL.SparseMatrixCLIL{Int, Int}, reduced), solvable, ranks
        end
    end
end

if "--bigint-probe" in ARGS
    enable_bigint_probe!()
end

if abspath(PROGRAM_FILE) == @__FILE__
    reproduce_main()
end
Ngôn ngữ chính
Julia
Star
8
Fork
14
Merge trung bình
8 ngày 8 giờ
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của JuliaComputing/StateSelection.jl

Tất cả issue của JuliaComputing/StateSelection.jl

Issue tương tự

Thêm issue về Julia

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.