-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from cuihantao/migrate-PythonCall
Migrate to use PythonCall.jl
- Loading branch information
Showing
11 changed files
with
71 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
channels = ["conda-forge"] | ||
|
||
[deps] | ||
andes = "" | ||
kvxopt = ">1.3.0.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using CondaPkg | ||
using SparseArrays: AbstractSparseMatrixCSC, SparseMatrixCSC | ||
using PythonCall: pyconvert_add_rule | ||
|
||
""" | ||
Convert KVXOPT.spmatrix to SparseMatrixCSC | ||
""" | ||
function spmatrix_to_julia(S::Type{T}, x::Py) where {T<:AbstractSparseMatrixCSC} | ||
# Ensure x is a KVXOPT spmatrix | ||
if Bool(pytype(x) != pyimport("kvxopt").spmatrix) | ||
throw(ArgumentError("x must be a KVXOPT spmatrix")) | ||
end | ||
|
||
# Extract the size, I, J, and V arrays from the spmatrix and explicitly convert them | ||
m, n = pyconvert(Tuple{Int64,Int64}, x.size) | ||
I = pyconvert(Vector{Int64}, x.CCS[0]) .+ 1 | ||
J = pyconvert(Vector{Int64}, x.CCS[1]) .+ 1 | ||
V = pyconvert(Vector{Float64}, x.CCS[2]) | ||
|
||
# Create and return the SparseMatrixCSC | ||
return PythonCall.pyconvert_return(SparseMatrixCSC(m, n, I, J, V)) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
using Test | ||
|
||
include("test_andes_py.jl") | ||
include("test_andes_pythoncall.jl") |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using Test | ||
using Andes | ||
using PythonCall | ||
using SparseArrays | ||
|
||
@testset "Test Andes functionalities" begin | ||
@testset "SparseMatrixCSC conversion from Andes system example" begin | ||
ss = Andes.py.system.example() | ||
converted_matrix = pyconvert(SparseMatrixCSC, ss.dae.gy) | ||
@test converted_matrix isa SparseMatrixCSC | ||
@test size(converted_matrix) == (34, 34) | ||
end | ||
|
||
@testset "Power flow run" begin | ||
Andes.py.config_logger(40) | ||
kundur = Andes.py.utils.paths.get_case("kundur/kundur_full.xlsx") | ||
system = Andes.py.run(kundur, no_output=true) | ||
|
||
@test Bool(system.PFlow.converged == true) | ||
end | ||
end |
c6f942d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
c6f942d
There was a problem hiding this comment.
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/100251
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.
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:
c6f942d
There was a problem hiding this comment.
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
c6f942d
There was a problem hiding this comment.
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/100251
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: