-
Notifications
You must be signed in to change notification settings - Fork 84
Debug SSC in Windows using Python VS 2017 and SAM SDK
The SAM software development kit is a library which allows users of other languages to interface with the underlying functionality in SAM. A common use case is to use Python (or MATLAB, Java, C#, or PHP) to set up the inputs to SAM, call SAM through the SDK, and then generate custom plots or analysis using the tools available in the calling language.
More information about the software development kit can be found here.
When using the SDK, it's possible that you will want more information about the underlying operation of the code. Since SAM is open-source it is possible to do this by following the processes outlined here.
The process, using the Python SDK and PyCharm IDE as example, is:
- Download Visual Studio Community 2017
- Clone the SSC repo:
git clone https://github.com/NREL/ssc.git
. - Checkout the
master
branch, which contains the latest released code. - Within Visual Studio, open the
build_vs2017.sln
solution file from your downloaded SSC project source - Start a project in Python containing sscd.dll from your SAM installation (i.e,
C:\SAM\2018.11.11\deploy\x64\sscd.dll
) in Debug mode and set a break point. It is important that the DLL aligns with the source code that you've downloaded. In this case, thesscd.dll
within the SAM download should align with the code from themaster
branch of SSC. Alternatively, you can build your own custom version of SSC by following this process.
-
Within the
build_vs2017
folder. Go to the Debug menu and click "Attach to process" -
Find the
python.exe
process and attach to it. Ensure that 'Native' code is selected above that. -
There may be exceptions which pop up, click to ignore all
-
Set a breakpoint in the Visual Studio code for the model you are running. At a high level, the compute module you are running through the SDK can be accessed within the
ssc
folder, and is within thecmod_
file. For instance, the battery compute module resides incmod_battery.cpp
. -
Go back to Pycharm and continue the run.
-
Eventually, the breakpoint in Visual Studio should be hit, at which point you can step through and examine local variables, the call stack, and other information