Working Directly with PySSC

PySSC is a wrapper for the SAM Simulation Core (SSC) API PySSC is part of the SAM Software Development Kit (SDK). The PySAM package is built on PySSC.

Note

PySSC was the original method for running SSC from Python before PySAM was developed. Unless you are very familiar with SSC, we recommend using PySAM instead of PySSC because PySAM provides tools for creating models and accessing variables that are not available with PySSC.

The SSC Guide is a reference to SSC.

To use PySSC, import it with:

from PySAM.PySSC import PySSC

PySSC gives you more transparent and direct access to the SSC library than PySAM. It requires a good understanding of SSC. PySAM has supporting functions, such as those for accessing defaults and building configurations, that make it easier to build models without knowledge the underlying SSC library. Some situations where you would want to use PySSC instead of PySAM include:

  • To work with a custom SSC library (ssc.dll for Windows, ssc.dylib for Mac, or ssc.so for Linux) built from SSC with modified or different compute modules than an official NREL version of SSC.

  • To facilitate debugging of SSC through Python. For example, in Visual Studio, you can use “Attach to Process” to debug SSC from Python while SSC is running. See instructions below.

  • To work with different versions of the SSC library. In PySSC, you can easily change the SSC version by pointing to a different version of the SSC library.

Use SAM’s Code Generator for PySSC

To get started using PySSC directly, create a case in SAM for the model you want to build, and use the Python 3 (or Python 2) option in SAM’s code generator to generate Python code. You can then modify the code as needed for your model. See Importing Inputs from SAM for more about SAM’s code generator.

Debug SSC from Python using Visual Studio

  1. Build a Release or Debug version of SSC using Visual Studio Community (VS), which will create a release or debug version of the SSC library (ssc.dll or sscd.dll in Windows).

  2. Add a breakpoint in VS where you would like to start debugging the C++ code.

  3. In your Python code, change the DLL path to one of these newly built DLLs.

  4. Add a breakpoint in your Python code after the initialization of PySSC, and run your Python code up to this breakpoint.

  5. In VS, select Debug > Attach to Process and choose Native Code. Find the Python process and click Attach. There are multiple Python processes, so noting the ProcessID from the PySSC output and finding that ID is the best way.

  6. Continue executing the Python code and it will enter the VS code environment and stop at the set breakpoint.

PySSC description

class PySAM.PySSC.PySSC(pdll_path=None)
data_clear(p_data)
data_create()
data_deep_copy(data_source, data_dest)
data_first(p_data)
data_free(p_data)
data_get_array(p_data, name)
data_get_data_array(p_data, name, list_of_types)
data_get_data_matrix(p_data, name, matrix_of_types)
data_get_matrix(p_data, name)
data_get_number(p_data, name)
data_get_string(p_data, name)
data_get_table(p_data, name)
data_get_variable(data, ssc_var_name)
data_next(p_data)
data_query(p_data, name)
data_set_array(p_data, name, parr)
data_set_array_from_csv(p_data, name, fn)
data_set_data_array(p_data, name, data_arr)
data_set_data_matrix(p_data, name, data_mat)
data_set_matrix(p_data, name, mat)
data_set_matrix_from_csv(p_data, name, fn)
data_set_number(p_data, name, value)
data_set_string(p_data, name, value)
data_set_table(p_data, name, tab)
data_set_var(p_var, name, p_val)
data_set_variable(table, ssc_input_data_name, value)
data_unassign(p_data, name)
entry_description(p_entry)
entry_name(p_entry)
entry_version(p_entry)
get_var_value(p_var, var_type)
info_constraints(p_inf)
info_data_type(p_inf)
info_group(p_inf)
info_label(p_inf)
info_meta(p_inf)
info_name(p_inf)
info_required(p_inf)
info_uihint(p_inf)
info_units(p_inf)
info_var_type(p_inf)
module_create(name)
module_entry(index)
module_exec(p_mod, p_data)
module_exec_set_print(prn)
module_exec_simple_no_thread(modname, data)
module_free(p_mod)
module_log(p_mod, index)
module_var_info(p_mod, index)
var_create()
var_free(p_var)
var_get_array(p_var)
var_get_data_array(p_var, n, var_type)
var_get_data_matrix(p_var, r, c, var_type)
var_get_matrix(p_var)
var_get_number(p_var)
var_get_string(p_var)
var_set_array(p_var, parr)
var_set_data_array(p_var, p_arr, r)
var_set_data_matrix(p_var, p_mat, r, c)
var_set_matrix(p_var, mat)
var_set_number(p_var, value)
var_set_string(p_var, value)
var_set_table(p_var, p_tab)
var_set_value(var, value)
version()
ARRAY = 3
INOUT = 3
INPUT = 1
INVALID = 0
MATRIX = 4
NUMBER = 2
OUTPUT = 2
STRING = 1
TABLE = 5
PySAM.PySSC.dict_to_ssc_table(py_dict, cmod_name)
PySAM.PySSC.dict_to_ssc_table_dat(py_dict, cmod_name, dat)
PySAM.PySSC.ssc_cmod(dat, name)
PySAM.PySSC.ssc_sim(data_ssc, tech_model_name, financial_model_name)
PySAM.PySSC.ssc_sim_from_dict(data_pydict)

Run a technology compute module using parameters in a dict.

Parameters:

data_pydict (dict) –

Required keys are:
tech_model: str

name of the compute module to run.

financial_model: str or None

name of the financial model to apply. If None, no financial model is used.

Other keys are names of args for the selected tech_model or financial_model.

Returns:

(dict) – keys are outputs from the selected compute module.

Return type:

dict

PySAM.PySSC.ssc_table_to_dict(cmod, dat)