Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Fix python solver #1058

Merged
merged 37 commits into from
May 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
04f036e
Update solver_py.cpp
Sep 17, 2021
b60d7bc
Update solver_py.cpp
Sep 22, 2021
b451570
Added numpy array creation support
Sep 23, 2021
f209b9b
Implement MLE solver bus mapping
Sep 24, 2021
80c9358
Fix busdata mapping errors
Sep 24, 2021
47661d4
Change output to dataframe for improved readability
Sep 24, 2021
e746e22
Update test_IEEE_13_MLE.glm
Sep 24, 2021
2e863ac
Update setup-Linux-amzn-2.sh
Sep 24, 2021
297cf0a
Create setup-Linux-ubuntu-20.sh
Sep 24, 2021
7e8444c
Merge branch 'develop' into develop-fix-python-solver
dchassin Sep 25, 2021
6772353
Update setup-Linux-ubuntu-20.sh
Sep 27, 2021
12a56ee
Update setup-Linux-ubuntu-20.sh
Sep 27, 2021
526d215
Update setup-Darwin-20.sh
Sep 27, 2021
a4f4db9
Update setup-Linux-ubuntu-20.sh
Sep 27, 2021
6cb980a
Update version.sh
Sep 27, 2021
b2eca6e
Update setup-Linux-amzn-2.sh
Sep 27, 2021
3828c48
Update setup-Linux-ubuntu-20.sh
Sep 27, 2021
583922a
Update solver_py.cpp
Nov 3, 2021
3f11c54
Update test_IEEE_13_MLE.glm
Nov 5, 2021
1351612
Merge remote-tracking branch 'origin/develop' into develop-fix-python…
aivanova5 Nov 5, 2021
b022883
Merge branch 'develop' into develop-fix-python-solver
Nov 24, 2021
ebe5f38
Update solver_py.cpp
Nov 24, 2021
ca22f9c
Update solver_py.cpp
Nov 24, 2021
d67d609
Update solver_nr.cpp
Nov 24, 2021
e869b66
Merge branch 'develop-fix-python-solver' of https://github.com/slacgi…
aivanova5 Dec 7, 2021
5beb96b
Update solver_py.cpp
Jan 20, 2022
83d8f7a
Fix python solver copyback NR initialization error
Jan 24, 2022
2e8044b
Merge branch 'develop' into develop-fix-python-solver
Jan 24, 2022
e3e5607
Update solver_nr.cpp
Feb 3, 2022
8ab6b59
Update solver_nr.cpp
Feb 3, 2022
db23604
Fix NR profiler formatting
Feb 3, 2022
f10a6a2
Merge branch 'develop' into develop-fix-python-solver
Apr 12, 2022
60d4c9c
Merge branch 'develop' into develop-fix-python-solver
May 2, 2022
8445afe
Create Solver_profile_csv.md
May 6, 2022
66bf2b7
Merge branch 'develop' into develop-fix-python-solver
May 6, 2022
4a43e6e
Merge branch 'develop' into develop-fix-python-solver
aivanova5 May 10, 2022
7d1f680
Update solver_nr.cpp
May 11, 2022
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
23 changes: 23 additions & 0 deletions docs/Module/Powerflow/Global/Solver_profile_csv.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[[/Module/Powerflow/Global/Solver_profile_csv]] -- Enable CSV formatting of solver profile data

# Synopsis

Shell:

~~~
bash$ gridlabd -D|--define solver_profile_csv={TRUE,FALSE}
~~~

GLM:

~~~
#set solver_profile_csv={TRUE,FALSE}
~~~

# Description

This global enables formatting of solver output as CSV.

# See also

* [[/Module/Powerflow]]
2 changes: 2 additions & 0 deletions module/powerflow/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ EXPORT CLASS *init(CALLBACKS *fntable, MODULE *module, int argc, char *argv[])
gl_global_create("powerflow::solver_profile_headers_included", PT_bool, &solver_profile_headers_included,PT_DESCRIPTION, "Flag to include headers in NR solver profile file",NULL);
extern char1024 solver_headers;
gl_global_create("powerflow::solver_headers", PT_char1024, &solver_headers,PT_DESCRIPTION, "Headers in NR solver profile file",NULL);
extern bool solver_profile_csv;
gl_global_create("powerflow::solver_profile_csv", PT_bool, &solver_profile_csv,PT_DESCRIPTION, "Flag output solver profile in CSV format",NULL);

extern char1024 solver_py_config;
gl_global_create("powerflow::solver_py_config", PT_char1024, &solver_py_config, PT_DESCRIPTION, "PY solver configuration file location",NULL);
Expand Down
36 changes: 28 additions & 8 deletions module/powerflow/solver_nr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ using namespace std;
#include <stdio.h>
#include <string.h>

char1024 solver_profile_filename = "solver_nr_profile.csv";
char1024 solver_headers = "timestamp,duration[microsec],iteration,bus_count,branch_count,error";
char1024 solver_profile_filename = "solver_nr_profile.txt";
static FILE * nr_profile = NULL;
char1024 solver_headers = "timestamp,duration[microsec],iteration,bus_count,branch_count,error";
bool solver_profile_headers_included = true;
bool solver_profile_enable = false;
bool solver_dump_enable = false;
bool solver_profile_csv = false;

//SuperLU variable structure
//These are the working variables, but structured for island implementation
Expand All @@ -71,8 +72,8 @@ typedef struct {
//Initialize the sparse notation
void sparse_init(SPARSE* sm, int nels, int ncols)
{
if (solver_profile_enable)
{
if ( solver_profile_enable )
{
nr_profile = fopen(solver_profile_filename,"w");
if ( nr_profile == NULL )
{
Expand All @@ -83,7 +84,16 @@ void sparse_init(SPARSE* sm, int nels, int ncols)
}
else if ( solver_profile_headers_included )
{
fprintf(nr_profile,"%s\n",(const char*)solver_headers);
if ( solver_profile_csv )
{

fprintf(nr_profile,"%s\n",(const char*)solver_headers);
}
else
{
fprintf(nr_profile,"timestamp duration[microsec] iteration bus_count branch_count error\n");
fprintf(nr_profile,"----------------------- ------------------ --------- --------- ------------ -----\n");
}
}
}
int indexval;
Expand Down Expand Up @@ -335,10 +345,11 @@ int64 solver_nr(unsigned int bus_count,
if ( solver_python_init() == 0 )
{
Iteration = solver_python_solve(bus_count,bus,branch_count,branch,powerflow_values,powerflow_type,mesh_imped_vals,bad_computations,Iteration);
if ( Iteration >= 0 )
if ( Iteration == 0 )
{
return Iteration;
}
// else <0 proceed with NR solver
}
}
catch (const char *msg)
Expand Down Expand Up @@ -5027,7 +5038,7 @@ int64 solver_nr(unsigned int bus_count,
}
//Default else - it was a failure, just keep going
}
Iteration = return_value_for_solver_NR;
Iteration = return_value_for_solver_NR+1;

//Deflag the "island locker"
NR_solver_working = false;
Expand Down Expand Up @@ -5064,7 +5075,16 @@ int64 solver_nr(unsigned int bus_count,
double t = clock() - t_start;
char buffer[64];
if ( gl_printtime(gl_globalclock,buffer,sizeof(buffer)-1) > 0 )
fprintf(nr_profile, "%s,%.1f,%.1lld,%d,%d,%s\n", buffer, t, return_value_for_solver_NR == 0 ? 1 : return_value_for_solver_NR,bus_count,branch_count,bad_computations ? "false" : "true");
{
if ( solver_profile_csv )
{
fprintf(nr_profile, "%s,%.1f,%.1lld,%d,%d,%d\n", buffer, t, Iteration,bus_count,branch_count,bad_computations ? 0 : 1);
}
else
{
fprintf(nr_profile, "%s %18.1f %9lld %9d %12d %s\n", buffer, t, Iteration,bus_count,branch_count,bad_computations ? "no" : "yes");
}
}
}

//Return the maximum iteration count
Expand Down
15 changes: 11 additions & 4 deletions module/powerflow/solver_py.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -962,11 +962,11 @@ void sync_busdata_raw(PyObject *pModel,unsigned int &bus_count,BUSDATA *&bus,e_d
SET_BUS(n,17,bus[n].I[2].i);

SET_BUS(n,18,bus[n].V[0].Mag());
SET_BUS(n,19,bus[n].V[0].Ang());
SET_BUS(n,19,bus[n].V[0].Arg());
SET_BUS(n,20,bus[n].V[1].Mag());
SET_BUS(n,21,bus[n].V[1].Ang());
SET_BUS(n,21,bus[n].V[1].Arg());
SET_BUS(n,22,bus[n].V[2].Mag());
SET_BUS(n,23,bus[n].V[2].Ang());
SET_BUS(n,23,bus[n].V[2].Arg());
}
}
else if ( dir == ED_IN )
Expand Down Expand Up @@ -1165,6 +1165,13 @@ unsigned long long get_linkhash(unsigned int branch_count, BRANCHDATA *&branch,
return hashcode;
}

// Run python solver
//
// Returns:
// -1 call NR and initialize with guess
// 0 use guess and proceed without running NR
// <-1 error encountered, run NR and don't use the guess
//
int solver_python_solve (
unsigned int &bus_count,
BUSDATA *&bus,
Expand Down Expand Up @@ -1192,7 +1199,7 @@ int solver_python_solve (
else if ( pResult && PyLong_Check(pResult) )
{
result = PyLong_AsLong(pResult);
if ( result >= 0 )
if ( result == -1 || result == 0 ) // -1 means no solution but guess is ok, 0 means solution is ok
{
sync_model(bus_count,bus,branch_count,branch,ED_IN);
}
Expand Down
12 changes: 8 additions & 4 deletions source/cmdarg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,15 +378,15 @@ int GldCmdarg::profile(int argc, const char *argv[])
const char *opt = strchr(argv[0],'=');
if ( opt++ != NULL )
{
if ( strcmp(opt,"text") == 0 )
if ( stricmp(opt,"text") == 0 || stricmp(opt,"txt") == 0 )
{
global_profile_output_format = POF_TEXT;
}
else if ( strcmp(opt,"csv") == 0 )
else if ( stricmp(opt,"csv") == 0 )
{
global_profile_output_format = POF_CSV;
}
else if ( strcmp(opt,"json") == 0 )
else if ( stricmp(opt,"json") == 0 )
{
global_profile_output_format = POF_JSON;
}
Expand All @@ -395,8 +395,12 @@ int GldCmdarg::profile(int argc, const char *argv[])
output_error("profiler option '%s' is not valid",opt);
return CMDERR;
}
global_profiler = TRUE;
}
else
{
global_profiler = !global_profiler;
}
global_profiler = !global_profiler;
return 0;
}

Expand Down