API Reference¶
block¶
Attribute
¶
Represents an attribute in an SMS++ model.
Attributes store metadata and configuration parameters for blocks in the SMS++ hierarchical structure. They can hold string, integer, or floating-point values.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the attribute. |
value |
str | int | float
|
The value of the attribute. |
Examples:
>>> attr = Attribute("block_type", "UCBlock")
>>> attr = Attribute("TimeHorizon", 24)
>>> attr = Attribute("LinearTerm", 0.3)
Source code in pysmspp/block.py
__eq__(other)
¶
Compare attribute with another value or Attribute object.
__init__(name, value)
¶
Initialize an Attribute object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the attribute. |
required |
value
|
str | int | float
|
The value of the attribute. |
required |
Source code in pysmspp/block.py
__repr__()
¶
Block
¶
Hierarchical container for SMS++ model components.
A Block is the fundamental building component of SMS++ models, providing a hierarchical structure to organize attributes, dimensions, variables, and sub-blocks. Blocks can be nested to create complex optimization models with multiple layers of structure.
The Block class supports: - Reading from and writing to NetCDF4 files - Dynamic construction from attributes, dimensions, variables, and sub-blocks - Hierarchical nesting of blocks - Type-based component management
Attributes:
| Name | Type | Description |
|---|---|---|
attributes |
Dict
|
Dictionary of Attribute objects containing metadata and parameters. |
dimensions |
Dict
|
Dictionary of Dimension objects defining array sizes. |
variables |
Dict
|
Dictionary of Variable objects containing data arrays. |
blocks |
Dict
|
Dictionary of nested Block objects forming the hierarchy. |
components |
Dict
|
Configuration dictionary for component types. |
Examples:
Create an empty block:
Create a block from a NetCDF file:
Create a block with attributes:
Create a block with variables using kwargs:
See Also
SMSNetwork : Network-level block for complete SMS++ models Attribute : Metadata storage Dimension : Array dimension definition Variable : Data array storage
Source code in pysmspp/block.py
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 | |
attributes
property
¶
Return the attributes of the block.
block_type
property
writable
¶
Return the type of the block.
blocks
property
¶
Return the blocks of the block.
dimensions
property
¶
Return the dimensions of the block.
variables
property
¶
Return the variables of the block.
__init__(fp='', attributes=None, dimensions=None, variables=None, blocks=None, **kwargs)
¶
Initialize a Block object. A block object can be created from a NetCDF file, or, alternatively, from the given attributes, dimensions, variables, and blocks. Moreover, optional additional arguments can be passed to the Block constructor to override the values loaded from files or from the arguments (attributes, dimensions, variables and blocks).
Example of possible usage:
Block() Block(fp="file.nc") Block(attributes={"block_type": "UCBlock"}) Block(dimensions={"n": 10}) Block(variables={"var1": Variable("var1", "float", None, 0.0)}) Block(blocks={"Block_0": Block()}) Block(fp="file.nc", attributes={"block_type": "UCBlock"}) Block(MinPower=Variable("MinPower", "float", None, 0.0))
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fp
|
Path | str (default: "")
|
The path to the NetCDF file to read. |
''
|
attributes
|
Dict (default: None)
|
The attributes of the block. |
None
|
dimensions
|
Dict (default: None)
|
The dimensions of the block. |
None
|
variables
|
Dict (default: None)
|
The variables of the block. |
None
|
blocks
|
Dict (default: None)
|
The blocks of the block. |
None
|
kwargs
|
dict
|
The arguments to pass to the Block constructor. |
{}
|
Source code in pysmspp/block.py
__repr__()
¶
Return a string representation of the Block object.
Returns:
| Type | Description |
|---|---|
str
|
A formatted string showing the counts and names of attributes, dimensions, variables, and sub-blocks. |
Source code in pysmspp/block.py
add(component_name, name, *args, **kwargs)
¶
Add a component to the block.
Dispatches to the appropriate add method based on component type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component_name
|
str
|
The SMS++ component class name (e.g., 'Attribute', 'Dimension', 'Variable', or a Block type). |
required |
name
|
str
|
The name of the component to add. |
required |
*args
|
tuple
|
Positional arguments passed to the specific add method. |
()
|
**kwargs
|
dict
|
Keyword arguments passed to the specific add method. |
{}
|
Returns:
| Type | Description |
|---|---|
Attribute, Dimension, Variable, or Block
|
The created component object. |
Source code in pysmspp/block.py
add_attribute(name, value, force=False)
¶
Add an attribute to the block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the attribute |
required |
value
|
any
|
The value of the attribute. Can be provided as a plain value or as an Attribute object. |
required |
force
|
bool (default: False)
|
If True, overwrite the attribute if it exists. |
False
|
Returns:
| Type | Description |
|---|---|
Attribute
|
Returns the Attribute object being created. |
Source code in pysmspp/block.py
add_block(name, *args, **kwargs)
¶
Add a block.
add_block("Block_0", block=Block()) add_block("Block_0", Block()) add_block("Block_0", **kwargs})
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the block |
required |
args
|
list
|
The arguments to pass to the Block constructor. If a Block argument is passed, it is used as the block. |
()
|
kwargs
|
dict
|
The attributes of the block. If the argument "block" is present, the block is set to that value. Otherwise, arguments are passed to the Block constructor. |
{}
|
Returns:
| Type | Description |
|---|---|
Returns the block being created.
|
|
Source code in pysmspp/block.py
add_dimension(name, value, force=False)
¶
Add a dimension to the block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the dimension |
required |
value
|
int
|
The value of the dimension. Can be provided as a plain value or as a Dimension object. |
required |
force
|
bool (default: False)
|
If True, overwrite the dimension if it exists. |
False
|
Returns:
| Type | Description |
|---|---|
Dimension
|
Returns the Dimension object being created. |
Source code in pysmspp/block.py
add_variable(name, *args, force=False, **kwargs)
¶
Add a variable to the block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the variable |
required |
var_type
|
str
|
The type of the variable |
required |
dimensions
|
tuple
|
The dimensions of the variable |
required |
data
|
float | list | ndarray
|
The data of the variable |
required |
force
|
bool (default: False)
|
If True, overwrite the variable if it exists. |
False
|
Returns:
| Type | Description |
|---|---|
Returns the variable being created.
|
|
Source code in pysmspp/block.py
from_kwargs(**kwargs)
¶
Populate the Block from keyword arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
dict
|
Keyword arguments representing block components. If 'block_type' is provided, it sets the block type and other arguments are added as components based on the block type configuration. |
{}
|
Returns:
| Type | Description |
|---|---|
Block
|
Returns self for method chaining. |
Source code in pysmspp/block.py
from_netcdf(filename)
classmethod
¶
Deserialize a NetCDF file to create a Block instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
str or Path
|
Path to the NetCDF file to read. |
required |
Returns:
| Type | Description |
|---|---|
Block
|
A new Block instance with nested sub-blocks from the file. |
Source code in pysmspp/block.py
plot(variables=None, figsize=None, **kwargs)
¶
Plot variables of the block.
Each variable is rendered in its own subplot using :meth:Variable.plot.
Only variables whose data array has at least 1 dimension are plotted by
default; scalar variables are included when they are explicitly listed in
variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variables
|
list of str
|
Names of the variables to plot. If None, all variables whose data is a 1-D or 2-D array are included. |
None
|
figsize
|
tuple of (float, float)
|
Figure size |
None
|
**kwargs
|
dict
|
Additional keyword arguments forwarded to :meth: |
{}
|
Returns:
| Type | Description |
|---|---|
Figure
|
The figure containing the subplots. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no plottable variables are found. |
Examples:
Source code in pysmspp/block.py
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 | |
print_tree(name=None, show_dimensions=False, show_variables=False, show_attributes=False, _indent='', _is_last=True, _is_root=True)
¶
Print a tree representation of the block structure.
This method displays the hierarchical structure of blocks in a tree format, with optional display of dimensions, variables, and attributes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the block. If not provided, uses the block_type if available, otherwise defaults to "Block". |
None
|
show_dimensions
|
bool
|
Whether to display dimensions (default: False). |
False
|
show_variables
|
bool
|
Whether to display variables (default: False). |
False
|
show_attributes
|
bool
|
Whether to display attributes (default: False). |
False
|
_indent
|
str
|
Internal parameter for indentation (default: ""). |
''
|
_is_last
|
bool
|
Internal parameter to track if this is the last child (default: True). |
True
|
_is_root
|
bool
|
Internal parameter to track if this is the root node (default: True). |
True
|
Examples:
>>> from pysmspp import Block
>>> block = Block(fp="network.nc4")
>>> block.print_tree() # Uses block_type as name
UCBlock [UCBlock]
└── Block_0 [UCBlock]
├── UnitBlock_0 [ThermalUnitBlock]
└── UnitBlock_1 [BatteryUnitBlock]
>>> block.print_tree("MyNetwork") # Uses custom name
MyNetwork [UCBlock]
└── Block_0 [UCBlock]
...
>>> block.print_tree(show_dimensions=True, show_variables=True)
UCBlock [UCBlock]
Dimensions (2): n=10, m=5
Variables (3): var1, var2, var3
└── Block_0 [UCBlock]
...
Source code in pysmspp/block.py
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 | |
remove(component_name, name)
¶
Remove a component from the block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component_name
|
str
|
The SMS++ component class name. |
required |
name
|
str
|
The name of the component to remove. |
required |
Returns:
| Type | Description |
|---|---|
Attribute, Dimension, Variable, or Block
|
The removed component object. |
Source code in pysmspp/block.py
static(component_name)
¶
Return the Dictionary of static components for component_name. For example, for component_name = "attribute", the Dictionary of attributes is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
component_name
|
string
|
|
required |
Returns:
| Type | Description |
|---|---|
Dict
|
|
Source code in pysmspp/block.py
to_netcdf(fp, force=False)
¶
Write the SMSNetwork object to a netCDF4 file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fp
|
Path | str
|
The path to the file to write. |
required |
force
|
bool (default: False)
|
If True, overwrite the file if it exists. |
False
|
Source code in pysmspp/block.py
Dimension
¶
Represents a dimension in an SMS++ model.
Dimensions define the size of arrays and variables in the SMS++ model structure. They are used to specify the shape of multi-dimensional variables and data arrays.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the dimension. |
value |
int
|
The size of the dimension (number of elements). |
Examples:
Source code in pysmspp/block.py
SMSConfig
¶
Configuration manager for SMS++ solver settings.
SMSConfig manages solver configuration files for SMS++ optimization. It can load configurations from file paths or use predefined templates stored in the package data directory.
Configuration files specify solver parameters such as tolerances, iteration limits, decomposition strategies, and other optimization settings required by SMS++ solvers.
Attributes:
| Name | Type | Description |
|---|---|---|
config |
str
|
The absolute path to the configuration file. |
Examples:
Load from a template:
Load from a file path:
Get available templates:
See Also
SMSNetwork.optimize : Uses SMSConfig for optimization
Source code in pysmspp/block.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
config
property
¶
Return the configuration path.
__init__(fp=None, template=None)
¶
Initialize a SMSConfig object. If an existing fp is provided, it is used as the configuration file; an error is thrown if the file does not exist. If a template is provided, the configuration file is set to the template file in the data/configs directory. fp and template cannot be both None.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fp
|
Path | str (default: None)
|
The path to the configuration file. |
None
|
template
|
str (default: None)
|
The template name of the configuration file. |
None
|
Source code in pysmspp/block.py
__repr__()
¶
__str__()
¶
get_templates()
staticmethod
¶
Return the list of available configuration templates.
Returns:
| Type | Description |
|---|---|
list of str
|
List of template names available in the data/configs directory. |
Source code in pysmspp/block.py
SMSFileType
¶
Bases: IntEnum
Enumeration of SMS++ file types.
Defines the different types of files that can be created and managed in SMS++ systems. Each file type serves a specific purpose in the modeling and optimization workflow.
Attributes:
| Name | Type | Description |
|---|---|---|
eProbFile |
int
|
Problem file (value 0): Contains both the model block structure and solver configuration. This is the complete specification needed to run an optimization. |
eBlockFile |
int
|
Block file (value 1): Contains only the model structure with blocks, variables, dimensions, and attributes. No solver configuration included. |
eConfigFile |
int
|
Configuration file (value 2): Contains only solver settings and parameters. No model structure included. |
eSolutionFile |
int
|
Solution file (value 3): Contains the optimization results including objective values, variable values, and solver status. |
Examples:
>>> network = SMSNetwork(file_type=SMSFileType.eBlockFile)
>>> print(SMSFileType.eProbFile) # Output: 0
>>> file_type = SMSFileType(1) # eBlockFile
See Also
SMSNetwork : Uses SMSFileType to specify file format
Source code in pysmspp/block.py
SMSNetwork
¶
Bases: Block
Top-level network container for SMS++ optimization models.
SMSNetwork is the main entry point for creating and managing complete SMS++ models. It extends Block with network-specific functionality including file type management and optimization execution.
An SMSNetwork can contain multiple blocks organized hierarchically to represent complex optimization problems such as unit commitment, investment planning, or multi-stage stochastic problems.
Attributes:
| Name | Type | Description |
|---|---|---|
file_type |
SMSFileType
|
The type of SMS++ file (eProbFile, eBlockFile, eConfigFile, or eSolutionFile). |
attributes |
Dict
|
Inherited from Block. Network-level attributes. |
dimensions |
Dict
|
Inherited from Block. Network-level dimensions. |
variables |
Dict
|
Inherited from Block. Network-level variables. |
blocks |
Dict
|
Inherited from Block. Nested blocks forming the model structure. |
Examples:
Create an empty network:
Create a network with block file type:
Load a network from file:
Create and optimize a network:
>>> network = SMSNetwork(file_type=SMSFileType.eBlockFile)
>>> network.add("UCBlock", "Block_0", TimeHorizon=24, NumberUnits=1)
>>> result = network.optimize(config, temp_file, output_file)
See Also
Block : Base class for hierarchical components SMSConfig : Configuration manager for SMS++ solvers SMSFileType : Enumeration of file types
Source code in pysmspp/block.py
1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 | |
file_type
property
writable
¶
Return the file type of the SMS file.
__init__(fp='', file_type=SMSFileType.eProbFile, **kwargs)
¶
Initialize an SMSNetwork object.
Creates a new SMS++ network, either empty, from a file, or with specified components. The file_type determines how the network will be stored and used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fp
|
Path | str
|
Path to a NetCDF file to load the network from. If provided, the network is loaded from the file. Default is empty string (create empty network). |
''
|
file_type
|
SMSFileType | int
|
The type of SMS++ file to create. Options: - eProbFile (0): Problem file with block and configuration - eBlockFile (1): Block file only (no configuration) - eConfigFile (2): Configuration file only - eSolutionFile (3): Solution file Default is eProbFile. |
eProbFile
|
**kwargs
|
dict
|
Additional keyword arguments to pass to the Block constructor for dynamic component creation. |
{}
|
Examples:
>>> network = SMSNetwork()
>>> network = SMSNetwork(file_type=SMSFileType.eBlockFile)
>>> network = SMSNetwork(fp="existing_model.nc")
Source code in pysmspp/block.py
__repr__()
¶
Return a string representation of the SMSNetwork object.
Returns:
| Type | Description |
|---|---|
str
|
A formatted string identifying this as an SMSNetwork with its components. |
Source code in pysmspp/block.py
optimize(configfile, fp_temp='temp.nc', fp_log=None, fp_solution=None, smspp_solver='auto', inner_block_name='Block_0', logging=True, tracking_period=0.1, **kwargs)
¶
Optimize the SMSNetwork object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
configfile
|
SMSConfig | Path | str
|
The configuration file. If a path is provided, it is first parsed into a SMSConfig object. |
required |
fp_temp
|
Path | str (default: "temp.nc")
|
The path to the temporary file. |
'temp.nc'
|
fp_log
|
Path | str (default: None)
|
The path to the log file. |
None
|
fp_solution
|
Path | str (default: None)
|
The path to the solution file. |
None
|
smspp_tool
|
SMSPPSolverTool | str (default: "auto")
|
The optimization mode. It supports a SMSPPSolverTool or string-based values. If string value is passed, the supported values are:
|
required |
inner_block_name
|
str (default: "Block_0")
|
The name of the inner block, to decide on the automatic solver to use. |
'Block_0'
|
logging
|
bool (default: True)
|
Whether to enable logging during optimization. |
True
|
tracking_period
|
float (default: 0.1)
|
The period (in seconds) to track optimization progress when logging is enabled. |
0.1
|
kwargs
|
dict
|
Optional arguments to pass to the solver constructor. These can include any additional parameters required by specific solvers. |
{}
|
Source code in pysmspp/block.py
1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 | |
print_tree(name=None, show_dimensions=False, show_variables=False, show_attributes=False, show_all=False, _indent='', _is_last=True, _is_root=True)
¶
Print a tree representation of the SMSNetwork structure.
This method overrides Block.print_tree() to use "SMSNetwork" as the default name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the network. If not provided, defaults to "SMSNetwork". |
None
|
show_dimensions
|
bool
|
Whether to display dimensions (default: False). |
False
|
show_variables
|
bool
|
Whether to display variables (default: False). |
False
|
show_attributes
|
bool
|
Whether to display attributes (default: False). |
False
|
show_all
|
bool
|
If True, show dimensions, variables, and attributes (default: False). Overrides individual show_* flags. |
False
|
_indent
|
str
|
Internal parameter for indentation (default: ""). |
''
|
_is_last
|
bool
|
Internal parameter to track if this is the last child (default: True). |
True
|
_is_root
|
bool
|
Internal parameter to track if this is the root node (default: True). |
True
|
Examples:
>>> from pysmspp import SMSNetwork
>>> net = SMSNetwork(fp="network.nc4")
>>> net.print_tree() # Uses "SMSNetwork" as default name
SMSNetwork
└── Block_0 [UCBlock]
...
Source code in pysmspp/block.py
1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 | |
Variable
¶
Represents a variable in an SMS++ model.
Variables hold the data arrays and parameters used in SMS++ optimization models. They have a specific type, dimensional structure, and associated data values.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The name of the variable. |
var_type |
str
|
The data type of the variable (e.g., "float", "int", "double"). |
dimensions |
tuple
|
The dimensions of the variable as a tuple of dimension names. |
data |
float | list | ndarray
|
The data values of the variable. |
Examples:
>>> var = Variable("MinPower", "float", (), 0.0)
>>> var = Variable("ActivePowerDemand", "float", ("NumberNodes", "TimeHorizon"), np.full((2, 24), 50.0))
Source code in pysmspp/block.py
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | |
__init__(name, var_type, dimensions, data)
¶
Initialize a Variable object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the variable. |
required |
var_type
|
str
|
The data type of the variable (e.g., "float", "int", "double"). |
required |
dimensions
|
tuple
|
The dimensions of the variable. Use empty tuple () for scalar values. |
required |
data
|
float | list | ndarray
|
The data values of the variable. |
required |
Source code in pysmspp/block.py
__repr__()
¶
Return detailed representation of the variable.
Source code in pysmspp/block.py
plot(ax=None, kind='auto', **kwargs)
¶
Plot the variable data.
The plot type depends on the variable dimensionality and kind:
- Scalar (0-D): bar chart.
- 1-D array: line plot with the dimension name on the x-axis.
- 2-D array: heatmap (
imshow) with a colorbar whenkind="heatmap", or a line plot where each row is a separate line with a legend whenkind="line".kind="auto"defaults to"heatmap".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Axes
|
Axes to draw on. If None a new figure and axes are created. |
None
|
kind
|
str
|
Plot style for 2-D variables. Accepted values are |
'auto'
|
**kwargs
|
dict
|
Additional keyword arguments forwarded to the underlying
matplotlib function ( |
{}
|
Returns:
| Type | Description |
|---|---|
Axes
|
The axes containing the plot. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the variable has more than 2 dimensions, or an unsupported kind is given. |
Examples:
>>> var = Variable("ActivePowerDemand", "float", ("NumberNodes", "TimeHorizon"), data)
>>> ax = var.plot()
>>> ax = var.plot(kind="line")
Source code in pysmspp/block.py
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 | |
get_attr_field(block_type, attr_name, attr_value=None, col_name=None)
¶
Return the entry or the entire attribute row (pandas.Series) from block configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block_type
|
str
|
The type of the block. |
required |
attr_name
|
str
|
The name of the attribute. |
required |
attr_value
|
any
|
The value used to infer the smspp_object type when |
None
|
col_name
|
str
|
The specific entry to retrieve. If None, returns the entire row. |
None
|
Returns:
| Type | Description |
|---|---|
str or Series
|
The requested entry or entire attribute row (pandas.Series). |
Source code in pysmspp/block.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
smspp_tools¶
InvestmentBlockSolver
¶
Bases: SMSPPSolverTool
Class to interact with the InvestmentBlockSolver tool from SMS++, with executable file "investmentblock_solver".
Source code in pysmspp/smspp_tools.py
__init__(solver_path='investmentblock_solver', fp_network=None, configfile=None, fp_log=None, fp_solution=None, configsolution=None, help_option='-h', **kwargs)
¶
The arguments of the constructor coincide with the options of SMSPPSolverTool; see the base class for details.
Source code in pysmspp/smspp_tools.py
parse_solver_log()
¶
Check the output of the InvestmentBlockSolver. It will extract the status, upper bound, lower bound, and objective value from the log.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log
|
str
|
The path to the solution file. |
required |
Source code in pysmspp/smspp_tools.py
InvestmentBlockTestSolver
¶
Bases: SMSPPSolverTool
Class to interact with the InvestmentBlockTestSolver tool from SMS++, with executable file "InvestmentBlock_test".
Source code in pysmspp/smspp_tools.py
__init__(solver_path='InvestmentBlock_test', fp_network=None, configfile=None, fp_log=None, fp_solution=None, configsolution=None, help_option='-h', **kwargs)
¶
The arguments of the constructor coincide with the options of SMSPPSolverTool; see the base class for details.
Source code in pysmspp/smspp_tools.py
parse_solver_log()
¶
Check the output of the InvestmentBlockTestSolver. It will extract the status, upper bound, lower bound, and objective value from the log.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log
|
str
|
The path to the solution file. |
required |
Source code in pysmspp/smspp_tools.py
InvestmentSolver
¶
Bases: SMSPPSolverTool
Class to interact with the InvestmentSolver tool from SMS++, with name "investment_solver".
Source code in pysmspp/smspp_tools.py
__init__(solver_path='investment_solver', fp_network=None, configfile=None, fp_log=None, fp_solution=None, configsolution=None, help_option='-h', **kwargs)
¶
The arguments of the constructor coincide with the options of SMSPPSolverTool; see the base class for details.
Source code in pysmspp/smspp_tools.py
SDDPSolver
¶
Bases: SMSPPSolverTool
Class to interact with the SDDPSolver tool from SMS++, with name "sddp_solver".
Source code in pysmspp/smspp_tools.py
__init__(solver_path='sddp_solver', fp_network=None, configfile=None, fp_log=None, fp_solution=None, configsolution=None, help_option='-h', **kwargs)
¶
The arguments of the constructor coincide with the options of SMSPPSolverTool; see the base class for details.
Source code in pysmspp/smspp_tools.py
parse_solver_log()
¶
Check the output of the SDDPSolver. It will extract the status, upper bound, lower bound, and objective value from the log.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log
|
str
|
The path to the solution file. |
required |
Source code in pysmspp/smspp_tools.py
SMSPPSolverTool
¶
Base class for the SMS++ solver tools.
Source code in pysmspp/smspp_tools.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | |
computational_time
property
¶
Returns the total computational time of the optimization in seconds. This is a placeholder method and should be implemented in derived classes if applicable.
solution
property
¶
Returns the solution of the optimization problem. This is a placeholder method and should be implemented in derived classes if applicable.
solution_time
property
¶
Returns the time taken to parse the solution in seconds. This is a placeholder method and should be implemented in derived classes if applicable.
subprocess_time
property
¶
Returns the time taken to run the subprocess in seconds. This is a placeholder method and should be implemented in derived classes if applicable.
__init__(solver_path, fp_network=None, configfile=None, fp_log=None, fp_solution=None, configsolution=None, help_option='-h', shell=False, **kwargs)
¶
Constructor for an abstract SMSPPSolverTool. Option arguments coincide with the options of the SMS++ solver tools. Additional options can be passed through kwargs. Option "-o" is automatically added to kwargs with value None if not provided, to allow logging the solution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solver_path
|
str
|
The name or path of the executable file. |
required |
fp_network
|
Path | str
|
Path to the SMSpp network to solve, by default None. When provided, automatically the option "-p" is added to the executable call to specify the folder of the network file. |
None
|
configfile
|
Path | str
|
Path to the configuration file, by default None. This option specifies the solver configuration with option "-S" when provided. The folder of the configuration file is also specified automatically with option "-c" when provided. |
None
|
fp_log
|
Path | str
|
When provided, the solver log is saved to the specified log file, by default None. |
None
|
fp_solution
|
Path | str
|
Path to the solution file, by default None. When provided, option "-O" is added to the executable call to specify the output solution file. |
None
|
configsolution
|
Path | str
|
Path to the configuration solution file, by default None. When provided, option "-C" is added to the executable call to specify the configuration solution file. |
None
|
help_option
|
str
|
The option to display the help message, by default "-h". |
'-h'
|
shell
|
bool
|
Whether to execute the command through the shell. Defaults to False. |
False
|
**kwargs
|
Additional keyword arguments to pass as options to the function. The keys of the kwargs should be the option name, and the value should be the option value. For example, if the function has an option "-x" that takes a value, the kwargs should include {"x": value}. |
{}
|
Source code in pysmspp/smspp_tools.py
__repr__()
¶
Return a string representation of the solver tool.
Returns:
| Type | Description |
|---|---|
str
|
A formatted string showing key solver properties. |
Source code in pysmspp/smspp_tools.py
calculate_executable_call()
¶
Generate the standard command-line call for SMS++ solvers and can be customized by subclasses.
Returns:
| Type | Description |
|---|---|
list[str]
|
The command array to execute the solver. |
Source code in pysmspp/smspp_tools.py
help(print_message=True)
¶
Print the help message of the SMS++ solver tool.
solver.help()
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
print_message
|
bool
|
Whether to print the message, by default True. |
True
|
Returns:
| Type | Description |
|---|---|
The help message.
|
|
Source code in pysmspp/smspp_tools.py
is_available()
¶
Check if the SMS++ tool is available in the PATH.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shell
|
bool
|
Whether to execute the command through the shell. Defaults to False. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the tool is available, False otherwise. |
Source code in pysmspp/smspp_tools.py
optimize(logging=True, tracking_period=0.1)
¶
Run the SMSPP Solver tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logging
|
bool
|
When true, logging is provided, including the executable call. |
True
|
tracking_period
|
float
|
Delay in seconds between resource usage tracking samples. |
0.1
|
Source code in pysmspp/smspp_tools.py
206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 | |
parse_solver_log()
¶
Check the output of the Solver. It will extract the status, upper bound, lower bound, and objective value from the log.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
log
|
str
|
The path to the solution file. |
required |
Source code in pysmspp/smspp_tools.py
TSSBSolver
¶
Bases: SMSPPSolverTool
Class to interact with the TSSBSolver tool from SMS++, with name "tssb_solver".
Source code in pysmspp/smspp_tools.py
__init__(solver_path='tssb_solver', fp_network=None, configfile=None, fp_log=None, fp_solution=None, configsolution=None, help_option='-h', **kwargs)
¶
The arguments of the constructor coincide with the options of SMSPPSolverTool; see the base class for details.
Source code in pysmspp/smspp_tools.py
UCBlockSolver
¶
Bases: SMSPPSolverTool
Class to interact with the UCBlockSolver tool from SMS++.
Source code in pysmspp/smspp_tools.py
__init__(solver_path='ucblock_solver', fp_network=None, configfile=None, fp_log=None, fp_solution=None, configsolution=None, help_option='-h', **kwargs)
¶
The arguments of the constructor coincide with the options of SMSPPSolverTool; see the base class for details.
Source code in pysmspp/smspp_tools.py
is_smspp_installed(solvers=[UCBlockSolver()])
¶
Check if SMS++ is installed by verifying that the specified solver executables can be found in the PATH.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
solvers
|
list[type[SMSPPSolverTool]]
|
List of solver classes to check. Defaults to [UCBlockSolver]. Available solvers: UCBlockSolver, InvestmentBlockTestSolver, InvestmentBlockSolver, SDDPSolver. |
[UCBlockSolver()]
|
Returns:
| Type | Description |
|---|---|
bool
|
True if all specified SMS++ solvers are installed, False otherwise. |
Examples:
>>> import pysmspp
>>> if pysmspp.is_smspp_installed():
... print("SMS++ is installed and available")
... else:
... print("SMS++ is not available")
>>> # Check multiple solvers
>>> if pysmspp.is_smspp_installed([pysmspp.UCBlockSolver, pysmspp.InvestmentBlockTestSolver]):
... print("Both solvers are available")
Source code in pysmspp/smspp_tools.py
components¶
Dict
¶
Bases: dict
Dict is a subclass of dict, which allows you to get AND SET items in the dict using the attribute syntax!
Imported from https://github.com/PyPSA/pypsa, derived from addict https://github.com/mewwts/addict/ .
Source code in pysmspp/components.py
__delattr__(name)
¶
__dir__()
¶
Return a list of object attributes.
This includes key names of any dict entries, filtered to the subset of valid attribute names (e.g. alphanumeric strings beginning with a letter or underscore). Also includes attributes of parent dict class.
Source code in pysmspp/components.py
__getattr__(item)
¶
Get an item using attribute syntax (e.g., dict.key).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
str
|
The key name to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The value associated with the key. |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the key does not exist. |
Source code in pysmspp/components.py
__setattr__(name, value)
¶
Setattr is called when the syntax a.b = 2 is used to set a value.