Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v2
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
env:
Expand Down
4 changes: 2 additions & 2 deletions src/library/format/qubin/parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ function _parse_model_form(fp::P, ::QUBin) where {P<:Union{HDF5.File,HDF5.Group}
li = read(fp["model"]["form"]["linear"]["i"])
lv = read(fp["model"]["form"]["linear"]["v"])

L = SparseLinearForm(sparsevec(li, lv))
L = SparseLinearForm(sparsevec(li, lv, n))

qi = read(fp["model"]["form"]["quadratic"]["i"])
qj = read(fp["model"]["form"]["quadratic"]["j"])
qv = read(fp["model"]["form"]["quadratic"]["v"])

Q = SparseQuadraticForm(sparse(qi, qj, qv))
Q = SparseQuadraticForm(sparse(qi, qj, qv, n, n))

α = read(fp["model"]["form"]["scale"])
β = read(fp["model"]["form"]["offset"])
Expand Down
24 changes: 24 additions & 0 deletions test/unit/library/formats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,30 @@ function test_qubin_format()
@test _compare_models(src_model, dst_model)
end
end

# Test sparse array dimensions are preserved when some variables have no terms
@testset "sparse dimensions" begin
# Create a model where variable 3 has no linear or quadratic terms
# This tests that sparse(I, J, V, n, n) correctly sets dimensions
src_model = QUBOTools.Model{Int,Float64,Int}(
Set{Int}([1, 2, 3]), # Explicitly include all 3 variables
Dict{Int,Float64}(1 => 1.0), # Only variable 1 has linear term
Dict{Tuple{Int,Int},Float64}((1, 2) => 2.0); # Only (1,2) quadratic term
sense = :min,
domain = :bool,
)

temp_path = "$(tempname()).sparse_dim.qb"

QUBOTools.write_model(temp_path, src_model)

dst_model = QUBOTools.read_model(temp_path)

@test dst_model isa QUBOTools.Model
@test QUBOTools.dimension(dst_model) == 3 # Must preserve dimension n=3
@test QUBOTools.dimension(dst_model) == QUBOTools.dimension(src_model)
@test _compare_models(src_model, dst_model)
end
end

return nothing
Expand Down