Global Views in PhasorDynamics SystemModel using new Vector#452
Global Views in PhasorDynamics SystemModel using new Vector#452lukelowry wants to merge 11 commits into
Conversation
|
I like the
That is, virtual std::vector<ScalarT>& y() = 0;
virtual const std::vector<ScalarT>& y() const = 0;
becomes virtual VectorView<ScalarT> y() = 0; // no `&` needed
virtual VectorView<const ScalarT> y() const = 0;
This means that the
|
e7e6b07 to
5d4f6ff
Compare
|
I suggest removing |
2955062 to
b70b473
Compare
|
@pelesh @PhilipFackler thank you both for your suggestions. I tried my hardest to take the best of both solutions to get the best of both. Please let me know what you think. |
0231d24 to
de9a228
Compare
|
Rebased, but the speedup is not as significant because the scatter of the jacobian is is now much larger from recent changes in develop :( |
3efa5b9 to
57e09d3
Compare
There was a problem hiding this comment.
For some reason I cannot build this branch. When building from scratch, I get following compile error:
Details
``` [ 5%] Built target phasor_dynamics_signal_dependency_tracking Undefined symbols for architecture arm64: "GridKit::LinearAlgebra::Vector::getData(GridKit::LinearAlgebra::memory::MemorySpace)", referenced from: AnalysisManager::Sundials::Kinsol::Residual(_generic_N_Vector*, _generic_N_Vector*, void*) in Kinsol.cpp.o AnalysisManager::Sundials::Kinsol::copyVec(_generic_N_Vector*, GridKit::LinearAlgebra::Vector&) in Kinsol.cpp.o "GridKit::LinearAlgebra::Vector::getData(GridKit::LinearAlgebra::memory::MemorySpace)", referenced from: AnalysisManager::Sundials::Kinsol::Residual(_generic_N_Vector*, _generic_N_Vector*, void*) in Kinsol.cpp.o AnalysisManager::Sundials::Kinsol::copyVec(_generic_N_Vector*, GridKit::LinearAlgebra::Vector&) in Kinsol.cpp.o "GridKit::LinearAlgebra::Vector::getData(GridKit::LinearAlgebra::memory::MemorySpace)", referenced from: AnalysisManager::Sundials::Kinsol::Residual(_generic_N_Vector*, _generic_N_Vector*, void*) in Kinsol.cpp.o AnalysisManager::Sundials::Kinsol::copyVec(_generic_N_Vector*, GridKit::LinearAlgebra::Vector&) in Kinsol.cpp.o "GridKit::LinearAlgebra::Vector::getData(GridKit::LinearAlgebra::memory::MemorySpace) const", referenced from: AnalysisManager::Sundials::Kinsol::Residual(_generic_N_Vector*, _generic_N_Vector*, void*) in Kinsol.cpp.o AnalysisManager::Sundials::Kinsol::getDefaultInitialCondition() in Kinsol.cpp.o AnalysisManager::Sundials::Kinsol::copyVec(GridKit::LinearAlgebra::Vector const&, _generic_N_Vector*) in Kinsol.cpp.o "GridKit::LinearAlgebra::Vector::getSize() const", referenced from: AnalysisManager::Sundials::Kinsol::Residual(_generic_N_Vector*, _generic_N_Vector*, void*) in Kinsol.cpp.o AnalysisManager::Sundials::Kinsol::Residual(_generic_N_Vector*, _generic_N_Vector*, void*) in Kinsol.cpp.o AnalysisManager::Sundials::Kinsol::getDefaultInitialCondition() in Kinsol.cpp.o AnalysisManager::Sundials::Kinsol::copyVec(GridKit::LinearAlgebra::Vector const&, _generic_N_Vector*) in Kinsol.cpp.o AnalysisManager::Sundials::Kinsol::copyVec(_generic_N_Vector*, GridKit::LinearAlgebra::Vector&) in Kinsol.cpp.o "GridKit::LinearAlgebra::Vector::getData(GridKit::LinearAlgebra::memory::MemorySpace) const", referenced from: AnalysisManager::Sundials::Kinsol::Residual(_generic_N_Vector*, _generic_N_Vector*, void*) in Kinsol.cpp.o AnalysisManager::Sundials::Kinsol::getDefaultInitialCondition() in Kinsol.cpp.o AnalysisManager::Sundials::Kinsol::copyVec(GridKit::LinearAlgebra::Vector const&, _generic_N_Vector*) in Kinsol.cpp.o "GridKit::LinearAlgebra::Vector::getSize() const", referenced from: AnalysisManager::Sundials::Kinsol::Residual(_generic_N_Vector*, _generic_N_Vector*, void*) in Kinsol.cpp.o AnalysisManager::Sundials::Kinsol::Residual(_generic_N_Vector*, _generic_N_Vector*, void*) in Kinsol.cpp.o AnalysisManager::Sundials::Kinsol::getDefaultInitialCondition() in Kinsol.cpp.o AnalysisManager::Sundials::Kinsol::copyVec(GridKit::LinearAlgebra::Vector const&, _generic_N_Vector*) in Kinsol.cpp.o AnalysisManager::Sundials::Kinsol::copyVec(_generic_N_Vector*, GridKit::LinearAlgebra::Vector&) in Kinsol.cpp.o "GridKit::LinearAlgebra::Vector::getData(GridKit::LinearAlgebra::memory::MemorySpace) const", referenced from: AnalysisManager::Sundials::Kinsol::Residual(_generic_N_Vector*, _generic_N_Vector*, void*) in Kinsol.cpp.o AnalysisManager::Sundials::Kinsol::getDefaultInitialCondition() in Kinsol.cpp.o AnalysisManager::Sundials::Kinsol::copyVec(GridKit::LinearAlgebra::Vector const&, _generic_N_Vector*) in Kinsol.cpp.o "GridKit::LinearAlgebra::Vector::getSize() const", referenced from: AnalysisManager::Sundials::Kinsol::Residual(_generic_N_Vector*, _generic_N_Vector*, void*) in Kinsol.cpp.o AnalysisManager::Sundials::Kinsol::Residual(_generic_N_Vector*, _generic_N_Vector*, void*) in Kinsol.cpp.o AnalysisManager::Sundials::Kinsol::getDefaultInitialCondition() in Kinsol.cpp.o AnalysisManager::Sundials::Kinsol::copyVec(GridKit::LinearAlgebra::Vector const&, _generic_N_Vector*) in Kinsol.cpp.o AnalysisManager::Sundials::Kinsol::copyVec(_generic_N_Vector*, GridKit::LinearAlgebra::Vector&) in Kinsol.cpp.o ld: symbol(s) not found for architecture arm64 [ 5%] Built target utilities_logger clang++: error: linker command failed with exit code 1 (use -v to see invocation) make[2]: *** [GridKit/Solver/SteadyState/libgridkit_solvers_steady.0.1.0.dylib] Error 1 make[1]: *** [GridKit/Solver/SteadyState/CMakeFiles/solvers_steady.dir/all] Error 2 make[1]: *** Waiting for unfinished jobs.... ```|
@pelesh i think it was a linker issue, fixed in recent commit. Could you try again? |
That fixed it. Thanks! |
pelesh
left a comment
There was a problem hiding this comment.
This is great work and I suggest we make it top priority for merging.
I suggest we complete all necessary Vector class and other infrastructure changes in #477 and have this PR address redundant copies. That way we avoid scope creep here.
|
I will rebase as soon as I get a chance, high priority |
3e44075 to
d2636cc
Compare
|
@pelesh I am marking this ready for review, this is one of the last big things before I can get the new models ready for final review |
e668c7d to
1827b6a
Compare
1827b6a to
93a6fc5
Compare
nkoukpaizan
left a comment
There was a problem hiding this comment.
Mostly looks good to me. A few relatively minor comments.
|
|
||
| result += test.constructor(); | ||
| result += test.composer(); | ||
| result += test.elementStateAliasesSystemState(); |
There was a problem hiding this comment.
| result += test.elementStateAliasesSystemState(); | |
| result += test.componentStateAliasesSystemState(); |
| auto residual_y = load.getResidual(); | ||
| load.evaluateResidual(); ///< Computes the residual and the Jacobian values by tracking | ||
| ///< the dependencies | ||
| auto& residual_y_view = load.getResidual(); |
There was a problem hiding this comment.
I'm not sure I understand the _view in the variable name in the context of the current version of the PR.
| ///< the dependencies | ||
| std::vector<DependencyTracking::Variable> residual_yp = exciter.getResidual(); | ||
| auto& residual_yp_view = exciter.getResidual(); | ||
| std::vector<DependencyTracking::Variable> residual_yp(residual_yp_view.getData(), residual_yp_view.getData() + residual_yp_view.getSize()); |
There was a problem hiding this comment.
Probably out of scope for this PR, but we'll need to remove the std::vector<DependencyTracking::Variable>. I'll give that some thought.
| // static void copyMat(Model::Evaluator::Mat& J, SlsMat Jida); | ||
| static void copyVec(const N_Vector x, std::vector<ScalarT>& y); | ||
| static void copyVec(const std::vector<ScalarT>& x, N_Vector y); | ||
| static void copyVec(const std::vector<bool>& x, N_Vector y); |
There was a problem hiding this comment.
If VectorT is GridKit::LinearAlgebra::Vector<ScalarT, IdxT>, what's the behavior for the tag (bool)? An implicit conversion seems dangerous to me, but looks like IDA is expecting a floating point value anyway. cc @Steven-Roberts
| } | ||
|
|
||
| private: | ||
| static ScalarT* dataOrNull(VectorT& vector) |
There was a problem hiding this comment.
This is not as elegant as what is being done in PhasorDynamics to explicitly check the size.
Trying to access the nullptr is undefined behavior. We'd have to check if the return value is nullptr before using.
| * @return true if the write was successful, false otherwise | ||
| */ | ||
| template <typename VectorT> | ||
| void writeVectorToMatrixMarket(const VectorT& vec, const std::string& filename, const std::string& header) |
| int evaluateJacobian() override; | ||
|
|
||
| void updateVariables(); | ||
| CsrMatrixT* getCsrJacobian() const override |
There was a problem hiding this comment.
I believe I moved this to the Component base class and it should not need an override here.
| { | ||
| y[i] = dg->y()[i]; | ||
| res[i] = dg->getResidual()[i]; | ||
| y[i] = dg->y().getData()[i]; |
There was a problem hiding this comment.
The pattern auto* y_data = dg->y().getData(); y_data[i]... (used elsewhere) looks cleaner to me. .getData()[1] looks cleaner if we are only accessing a specific index.
| assert(child_offset == size_); | ||
|
|
||
| // Default variable and residual index mapping to local index | ||
| variable_indices_.resize(size); |
There was a problem hiding this comment.
It may be a good idea to make these GridKit::LinearAlgebra::Vector<IdxT, IdxT> right away and allocate them with the others.
| } | ||
|
|
||
| [[noreturn]] std::vector<ScalarT>& yB() override | ||
| [[noreturn]] VectorT& yB() override |
There was a problem hiding this comment.
The member variables should also be updated, though they are not used. Please add a TODO around those member variables, so we know to pay attention to them later.
Description
This PR updates PhasorDynamics so buses and components use their slices of the
SystemModelstate vectors directly. This removes the local state copy path and keeps component accessors consistent with the integrator-updated system state.Partially addresses #96. Related to #145.
Proposed changes
StateVectorsupport soGridElementcan own standalone state or aliasSystemModelstate.SystemModelallocation to bind each bus/component to global state and verify element sizes remain fixed.yData()accessor for live state pointers.Performance was measured with
application/PhasorDynamics/PDSimusing the app-reportedComplete intime. Each row reports the median of 3 trials after rebuildingPDSimon the corresponding branch.develop(s)Checklist
-Wall -Wpedantic -Wconversion -Wextra.Further comments
This work was motivated by the addition of IEEEST stabilizers: adding 333 stabilizers to the Texas case dramatically reduced performance, and this change removes avoidable state-copy overhead in PhasorDynamics system evaluation.
NOTE: I had to make a new PR but this is revival of #411