Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…rices.jl into rb/add_yft
  • Loading branch information
Roman Bolgaryn committed Jan 21, 2025
2 parents 1dbcb29 + 7069dca commit 9e774e3
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr_testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
matrix:
julia-version: ['1']
julia-arch: [x64]
os: [ubuntu-latest, windows-latest]
os: [ubuntu-latest, windows-latest, macOS-latest]

steps:
- uses: actions/checkout@v2
Expand Down
14 changes: 8 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
name = "PowerNetworkMatrices"
uuid = "bed98974-b02a-5e2f-9fe0-a103f5c450dd"
authors = ["Jose Daniel Lara", "Alessandro Francesco Castelli", "Sourabh Dalvi"]
version = "0.11.1"
version = "0.12.0"

[deps]
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
InfrastructureSystems = "2cd47ed4-ca9b-11e9-27f2-ab636a7671f1"
KLU = "ef3ab10e-7fda-4108-b977-705223b18434"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MKL = "33e6dc65-8f57-5167-99aa-e5a354878fb2"
Pardiso = "46dd5b70-b6fb-5a00-ae2d-e8fea33afaf2"
PowerSystems = "bcd98974-b02a-5e2f-9ee0-a103f5c450dd"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
AppleAccelerate = "13e28ba4-7ad8-5781-acae-3021b1ed3924"
MKL = "33e6dc65-8f57-5167-99aa-e5a354878fb2"
Pardiso = "46dd5b70-b6fb-5a00-ae2d-e8fea33afaf2"

[compat]
AppleAccelerate = "^0.4"
DocStringExtensions = "~0.8, ~0.9"
HDF5 = "0.17"
InfrastructureSystems = "2"
LinearAlgebra = "1"
MKL = "0.6"
KLU = "^0.6"
LinearAlgebra = "1"
MKL = "0.7"
Pardiso = "^0.5.5"
PowerSystems = "4"
PowerSystems = "^4.5"
SparseArrays = "1"
julia = "^1.6"
17 changes: 15 additions & 2 deletions src/PowerNetworkMatrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,28 @@ export VirtualPTDF
export Ybus

using DocStringExtensions
import MKL
import InfrastructureSystems
import PowerSystems
import PowerSystems: ACBusTypes

const IS = InfrastructureSystems
const PSY = PowerSystems

@static if (Sys.ARCH === :x86_64 || Sys.ARCH === :i686) && !Sys.isapple()
using MKL
using Pardiso
const USE_MKL = MKL.MKL_jll.is_available()
else
const USE_MKL = false
end

@static if Sys.isapple()
using AppleAccelerate
const USE_AA = true
else
const USE_AA = false
end

import SparseArrays
import SparseArrays: rowvals, nzrange
import HDF5
Expand All @@ -39,7 +53,6 @@ import LinearAlgebra
import LinearAlgebra: BLAS.gemm
import LinearAlgebra: ldiv!, mul!, I, dot
import LinearAlgebra: LAPACK.getrf!, LAPACK.getrs!
import Pardiso

@template DEFAULT = """
$(SIGNATURES)
Expand Down
7 changes: 6 additions & 1 deletion src/lodf_calculations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ function _buildlodf(
elseif linear_solver == "Dense"
lodf_t = _calculate_LODF_matrix_DENSE(a, ptdf)
elseif linear_solver == "MKLPardiso"
if !USE_MKL
error(
"The MKL library is not available. Check that your hardware and operating system support MKL.",
)
end
lodf_t = _calculate_LODF_matrix_MKLPardiso(a, ptdf)
end
return lodf_t
Expand All @@ -52,7 +57,7 @@ function _buildlodf(
if linear_solver == "KLU"
lodf_t = _calculate_LODF_matrix_KLU(a, k, ba, ref_bus_positions)
else
error("Other methods still to be implemented.")
error("Other linear solvers are not implemented.")
end
return lodf_t
end
Expand Down
5 changes: 5 additions & 0 deletions src/ptdf_calculations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ function _buildptdf(
dist_slack,
)
elseif linear_solver == "MKLPardiso"
if !USE_MKL
error(
"The MKL library is not available. Check that your hardware and operating system support MKL.",
)
end
PTDFm, A = calculate_PTDF_matrix_MKLPardiso(
branches,
buses,
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import Aqua
Aqua.test_unbound_args(PowerNetworkMatrices)
Aqua.test_undefined_exports(PowerNetworkMatrices)
Aqua.test_ambiguities(PowerNetworkMatrices)
Aqua.test_stale_deps(PowerNetworkMatrices)
Aqua.test_stale_deps(PowerNetworkMatrices; ignore = [:AppleAccelerate, :MKL, :Pardiso])
Aqua.test_deps_compat(PowerNetworkMatrices)

include("testing_data.jl")
Expand Down
11 changes: 7 additions & 4 deletions test/test_lodf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,19 @@
P5 = PTDF(sys5)
L5NS_from_ptdf = LODF(A, P5)
L5NS_from_ptdf2 = LODF(A, P5; linear_solver = "Dense")
L5NS_from_ptdf3 = LODF(A, P5; linear_solver = "MKLPardiso")
@test getindex(L5NS_from_ptdf, "5", "6") - -0.3071 <= 1e-4
@test getindex(L5NS_from_ptdf2, "5", "6") - -0.3071 <= 1e-4
@test getindex(L5NS_from_ptdf3, "5", "6") - -0.3071 <= 1e-4
total_error = abs.(L5NS_from_ptdf.data' .- Lodf_5)
total_error2 = abs.(L5NS_from_ptdf2.data' .- Lodf_5)
total_error3 = abs.(L5NS_from_ptdf3.data' .- Lodf_5)
@test isapprox(sum(total_error), 0.0, atol = 1e-3)
@test isapprox(sum(total_error2), 0.0, atol = 1e-3)
@test isapprox(sum(total_error3), 0.0, atol = 1e-3)

if !PowerNetworkMatrices.USE_AA
L5NS_from_ptdf3 = LODF(A, P5; linear_solver = "MKLPardiso")
@test getindex(L5NS_from_ptdf3, "5", "6") - -0.3071 <= 1e-4
total_error3 = abs.(L5NS_from_ptdf3.data' .- Lodf_5)
@test isapprox(sum(total_error3), 0.0, atol = 1e-3)
end

# A, ABA, and BA case
ABA = ABA_Matrix(sys5; factorize = true)
Expand Down
13 changes: 9 additions & 4 deletions test/test_ptdf.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
@testset "Test PTDF matrices, w/ and w/o tolerance" begin
sys5 = PSB.build_system(PSB.PSITestSystems, "c_sys5")
for solver in ["KLU", "Dense", "MKLPardiso"]
if PowerNetworkMatrices.USE_AA && solver == "MKLPardiso"
@info "Skipped MKLPardiso tests on Apple"
continue
end
for approach in ["standard", "separate_matrices"]
buses_5 = nodes5()
branches_5 = branches5(buses_5)
Expand Down Expand Up @@ -213,11 +217,12 @@ end

P5_1 = PTDF(sys5; dist_slack = slack_array, linear_solver = "KLU")
P5_2 = PTDF(sys5; dist_slack = slack_array, linear_solver = "Dense")
P5_3 = PTDF(sys5; dist_slack = slack_array, linear_solver = "MKLPardiso")

@test isapprox(P5_1.data, P5_2.data, atol = 1e-5)
@test isapprox(P5_1.data, P5_3.data, atol = 1e-5)
@test isapprox(P5_2.data, P5_3.data, atol = 1e-5)
if !PowerNetworkMatrices.USE_AA
P5_3 = PTDF(sys5; dist_slack = slack_array, linear_solver = "MKLPardiso")
@test isapprox(P5_2.data, P5_3.data, atol = 1e-5)
@test isapprox(P5_1.data, P5_3.data, atol = 1e-5)
end
end

@testset "Test PTDF matrix with distributed bus and with 2 reference buses" begin
Expand Down
12 changes: 2 additions & 10 deletions test/test_ybus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,14 @@

@test Ybus5[buses_5[1], buses_5[2]] == (-3.5234840209999647 + 35.234840209999646im)

c_sys5_re() = System(
100.0,
buses_5,
thermal_generators5(buses_5),
loads5(buses_5),
branches5(buses_5),
)

t_sys5_re = c_sys5_re()
t_sys5_re = PSB.build_system(PSB.PSITestSystems, "c_sys5")
# Make 2 islands. Island 1: 1 - 5. Island 2: 2, 3 ,4
remove_component!(Line, t_sys5_re, "1")
remove_component!(Line, t_sys5_re, "2")
remove_component!(Line, t_sys5_re, "6")
@test_throws IS.DataFormatError Ybus(t_sys5_re)

t2_sys5_re = c_sys5_re()
t2_sys5_re = PSB.build_system(PSB.PSITestSystems, "c_sys5")
# Remove lines. Don't cause islands
remove_component!(Line, t2_sys5_re, "3")
remove_component!(Line, t2_sys5_re, "5")
Expand Down

0 comments on commit 9e774e3

Please sign in to comment.