Skip to content

Commit

Permalink
Merge pull request #97 from NREL-Sienna/jd/bump_psy_version
Browse files Browse the repository at this point in the history
Jd/bump psy version
  • Loading branch information
jd-lara authored Jan 20, 2025
2 parents 0239dfc + e0a460d commit 7069dca
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

4 comments on commit 7069dca

@jd-lara
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/123307

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.12.0 -m "<description of version>" 7069dcaab94c96d0a83457ee098cc01e83d0f094
git push origin v0.12.0

@jd-lara
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

Breaking changes

  • Change in the use of MKL and added AppleAccelerate dependency

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/123307

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.12.0 -m "<description of version>" 7069dcaab94c96d0a83457ee098cc01e83d0f094
git push origin v0.12.0

Please sign in to comment.