Skip to content

Debug SSC in Windows using Python VS 2017 and SAM SDK

Paul Gilman edited this page Jan 15, 2021 · 1 revision

Software Development Kit

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.

Debugging with the SDK on Windows

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, the sscd.dll within the SAM download should align with the code from the master branch of SSC. Alternatively, you can build your own custom version of SSC by following this process.

PyCharm

  • Within the build_vs2017 folder. Go to the Debug menu and click "Attach to process" Attach to process

  • Find the python.exe process and attach to it. Ensure that 'Native' code is selected above that. Python process

  • 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 the cmod_ file. For instance, the battery compute module resides in cmod_battery.cpp. Visual Studio Breakpoint

  • 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 Debug information