openswmm 5.3.0.dev0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. openswmm-5.3.0.dev0/LICENSE +12 -0
  2. openswmm-5.3.0.dev0/MANIFEST.in +32 -0
  3. openswmm-5.3.0.dev0/PKG-INFO +228 -0
  4. openswmm-5.3.0.dev0/README.md +176 -0
  5. openswmm-5.3.0.dev0/openswmm/CMakeLists.txt +31 -0
  6. openswmm-5.3.0.dev0/openswmm/__init__.py +42 -0
  7. openswmm-5.3.0.dev0/openswmm/_openswmm.pyx +12 -0
  8. openswmm-5.3.0.dev0/openswmm/data/__init__.py +0 -0
  9. openswmm-5.3.0.dev0/openswmm/gym/__init__.py +0 -0
  10. openswmm-5.3.0.dev0/openswmm/openswmm.pxd +10 -0
  11. openswmm-5.3.0.dev0/openswmm/output/CMakeLists.txt +45 -0
  12. openswmm-5.3.0.dev0/openswmm/output/__init__.pxd +1 -0
  13. openswmm-5.3.0.dev0/openswmm/output/__init__.py +13 -0
  14. openswmm-5.3.0.dev0/openswmm/output/_output.pyi +732 -0
  15. openswmm-5.3.0.dev0/openswmm/output/_output.pyx +1557 -0
  16. openswmm-5.3.0.dev0/openswmm/output/output.pxd +368 -0
  17. openswmm-5.3.0.dev0/openswmm/solver/CMakeLists.txt +50 -0
  18. openswmm-5.3.0.dev0/openswmm/solver/__init__.pxd +1 -0
  19. openswmm-5.3.0.dev0/openswmm/solver/__init__.py +22 -0
  20. openswmm-5.3.0.dev0/openswmm/solver/_solver.pyi +1012 -0
  21. openswmm-5.3.0.dev0/openswmm/solver/_solver.pyx +1646 -0
  22. openswmm-5.3.0.dev0/openswmm/solver/solver.pxd +356 -0
  23. openswmm-5.3.0.dev0/openswmm.egg-info/SOURCES.txt +36 -0
  24. openswmm-5.3.0.dev0/pyproject.toml +79 -0
  25. openswmm-5.3.0.dev0/setup.cfg +4 -0
  26. openswmm-5.3.0.dev0/setup.py +97 -0
  27. openswmm-5.3.0.dev0/tests/.DS_Store +0 -0
  28. openswmm-5.3.0.dev0/tests/__init__.py +3 -0
  29. openswmm-5.3.0.dev0/tests/data/.DS_Store +0 -0
  30. openswmm-5.3.0.dev0/tests/data/__init__.py +3 -0
  31. openswmm-5.3.0.dev0/tests/data/output/__init__.py +22 -0
  32. openswmm-5.3.0.dev0/tests/data/output/example_output_1.out +0 -0
  33. openswmm-5.3.0.dev0/tests/data/output/json_time_series.pickle +0 -0
  34. openswmm-5.3.0.dev0/tests/data/solver/__init__.py +17 -0
  35. openswmm-5.3.0.dev0/tests/data/solver/non_existent_input_file.rpt +2387 -0
  36. openswmm-5.3.0.dev0/tests/data/solver/site_drainage_example.inp +499 -0
  37. openswmm-5.3.0.dev0/tests/data/solver/site_drainage_example.rpt +354 -0
  38. openswmm-5.3.0.dev0/tests/test_swmm_solver.py +716 -0
  39. openswmm-5.3.0.dev0/tests/test_swwm_output.py +1048 -0
@@ -0,0 +1,12 @@
1
+ Copyright 2026 HydroCouple
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
+
9
+ This project contains original material has been released as part of various USEPA SWMM software over the years. These reside in the
10
+ public domain and cannot be claimed. This project also contains new material prepared by the United States
11
+ Government for which domestic copyright protection is not available under 17
12
+ USC § 105.
@@ -0,0 +1,32 @@
1
+ include LICENSE
2
+ include README.md
3
+ prune **/.git
4
+ prune **/.git
5
+ prune **/.github
6
+ prune **/.vscode
7
+ prune **/.pytest_cache
8
+ prune **/__pycache__
9
+ prune **/build
10
+ prune **/dist
11
+ prune **/openswmm.egg-info
12
+ prune **/venvopenswmm
13
+ prune **/venvtest
14
+ prune **/output_build
15
+ prune **/_skbuild
16
+ prune **/wheelhouse
17
+ recursive-include openswmm *.py
18
+ recursive-include tests *.py
19
+ recursive-include openswmm *.txt
20
+ recursive-include openswmm *.md
21
+ recursive-include openswmm *.pyi
22
+ recursive-include openswmm *.pyx
23
+ recursive-include openswmm *.pxd
24
+ recursive-include tests *.inp
25
+ recursive-include docs *.*
26
+ recursive-include tests *.*
27
+ global-exclude *.pyd
28
+ global-exclude *.so
29
+ global-exclude *.pyc
30
+ global-exclude *_drainage_example.out
31
+ global-exclude *__pycache__*
32
+ global-exclude __pycache__
@@ -0,0 +1,228 @@
1
+ Metadata-Version: 2.4
2
+ Name: openswmm
3
+ Version: 5.3.0.dev0
4
+ Summary: A python package for EPA SWMM preprocessing, solver, and post-processing.
5
+ Author-email: Caleb Buahin <caleb.buahin@gmail.com>
6
+ Maintainer-email: Caleb Buahin <caleb.buahin@gmail.com>
7
+ License: Copyright 2026 HydroCouple
8
+
9
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
14
+
15
+ This project contains original material has been released as part of various USEPA SWMM software over the years. These reside in the
16
+ public domain and cannot be claimed. This project also contains new material prepared by the United States
17
+ Government for which domestic copyright protection is not available under 17
18
+ USC § 105.
19
+ Project-URL: Homepage, https://github.com/HydroCouple/Stormwater-Management-Model
20
+ Project-URL: Documentation, https://github.com/HydroCouple/Stormwater-Management-Model
21
+ Project-URL: Source Code, https://github.com/HydroCouple/Stormwater-Management-Model
22
+ Project-URL: Bug Tracker, https://github.com/HydroCouple/Stormwater-Management-Model/issues
23
+ Project-URL: Repository, https://github.com/HydroCouple/Stormwater-Management-Model
24
+ Project-URL: Changelog, https://github.com/HydroCouple/Stormwater-Management-Model/blob/master/CHANGELOG.md
25
+ Keywords: SWMM,storm water,modeling,water,hydrology,hydraulics,wastewater,machine learning,AI,GIS,environmental engineering,civil engineering
26
+ Classifier: Development Status :: 3 - Alpha
27
+ Classifier: Intended Audience :: Developers
28
+ Classifier: Intended Audience :: Science/Research
29
+ Classifier: Operating System :: OS Independent
30
+ Classifier: Programming Language :: Python :: 3.8
31
+ Classifier: Programming Language :: Python :: 3.9
32
+ Classifier: Programming Language :: Python :: 3.10
33
+ Classifier: Programming Language :: Python :: 3.11
34
+ Classifier: Programming Language :: Python :: 3.12
35
+ Classifier: Programming Language :: Python :: 3.13
36
+ Classifier: Programming Language :: C
37
+ Classifier: Programming Language :: C++
38
+ Classifier: Topic :: Scientific/Engineering
39
+ Classifier: Topic :: Scientific/Engineering :: Hydrology
40
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
41
+ Classifier: Topic :: Scientific/Engineering :: Physics
42
+ Classifier: Topic :: Software Development :: Libraries
43
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
44
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
45
+ Classifier: Topic :: Scientific/Engineering :: GIS
46
+ Requires-Python: >=3.8
47
+ Description-Content-Type: text/markdown
48
+ License-File: LICENSE
49
+ Dynamic: description
50
+ Dynamic: description-content-type
51
+ Dynamic: license-file
52
+
53
+ EPA ORD Stormwater Management Model (SWMM)
54
+ ==========================================
55
+
56
+ Stormwater Management Model (SWMM) computational engine and output post-processing codebase
57
+
58
+ ## Build Status
59
+ [![Build and Unit Testing](https://github.com/HydroCouple/Stormwater-Management-Model/actions/workflows/unit_testing.yml/badge.svg)](https://github.com/HydroCouple/Stormwater-Management-Model/actions/workflows/unit_testing.yml)
60
+ [![Build and Regression Testing](https://github.com/HydroCouple/Stormwater-Management-Model/actions/workflows/regression_testing.yml/badge.svg)](https://github.com/HydroCouple/Stormwater-Management-Model/actions/workflows/regression_testing.yml)
61
+ [![Docs](https://github.com/HydroCouple/Stormwater-Management-Model/actions/workflows/build_docs.yml/badge.svg)](https://github.com/HydroCouple/Stormwater-Management-Model/actions/workflows/build_docs.yml)
62
+ [![Deployment](https://github.com/HydroCouple/Stormwater-Management-Model/actions/workflows/deploy.yml/badge.svg)](https://github.com/HydroCouple/Stormwater-Management-Model/actions/workflows/deploy.yml)
63
+ [![Documentation](https://github.com/HydroCouple/Stormwater-Management-Model/actions/workflows/build-and-test.yml/badge.svg?branch=docs)](https://github.com/HydroCouple/Stormwater-Management-Model/actions/workflows/build-and-test.yml)
64
+ [![Issues](https://img.shields.io/github/issues/HydroCouple/Stormwater-Management-Model)](https://github.com/HydroCouple/Stormwater-Management-Model/issues)
65
+
66
+ ## Python Binding
67
+ [![PyPi](https://img.shields.io/pypi/v/openswmm.svg)](https://pypi.org/project/openswmm)
68
+ [![PythonVersion](https://img.shields.io/pypi/pyversions/openswmm.svg)](https://pypi.org/project/openswmm)
69
+ [![Wheel](https://img.shields.io/pypi/wheel/openswmm.svg)](https://pypi.org/project/openswmm)
70
+ [![Downloads](https://pepy.tech/badge/openswmm)](https://pepy.tech/project/openswmm)
71
+ [![Downloads](https://pepy.tech/badge/openswmm/month)](https://pepy.tech/project/openswmm)
72
+ [![Downloads](https://pepy.tech/badge/openswmm/week)](https://pepy.tech/project/openswmm)
73
+
74
+ ## Introduction
75
+ This is the official SWMM source code repository maintained by US EPA Office of Research and Development, Center For Environmental Solutions & Emergency Response, Water Infrastructure Division located in Cincinnati, Ohio.
76
+
77
+ SWMM is a dynamic hydrology-hydraulic water quality simulation model. It is used for single event or long-term (continuous) simulation of runoff quantity and quality from primarily urban areas. SWMM source code is written in the C Programming Language and released in the Public Domain.
78
+
79
+ ## Build Instructions
80
+
81
+ The 'src' folder of this repository contains the C source code for
82
+ version of Storm Water Management Model's computational
83
+ engine. Consult the included 'Roadmap.txt' file for an overview of
84
+ the various code modules. The code can be compiled into both a shared
85
+ object library and a command line executable. Under Windows, the
86
+ library file (swmm5.dll) is used to power SWMM's graphical user
87
+ interface.
88
+
89
+ Also included is a python interface for the SWMM computational engine and output
90
+ post-processing application programming interfaces located in the python folder.
91
+
92
+ The 'CMakeLists.txt' file is a script used by CMake (https://cmake.org/)
93
+ to build the SWMM binaries. CMake is a cross-platform build tool
94
+ that generates platform native build systems for many compilers. To
95
+ check if the required version is installed on your system, enter from
96
+ a console window and check that the version is 3.5 or higher.
97
+
98
+ ```bash
99
+ cmake --version
100
+ ```
101
+
102
+ To build the SWMM engine library and its command line executable
103
+ using CMake and the Microsoft Visual Studio C compiler on Windows:
104
+
105
+ 1. Open a console window and navigate to the directory where this
106
+ Readme file resides (which should have 'src' as a sub-directory
107
+ underneath it).
108
+
109
+ 2. Use the following command to create the directory for storing the built binaries:
110
+
111
+ ```bash
112
+ mkdir build
113
+ ```
114
+
115
+ 3. Then the following CMake commands to build the binaries:
116
+
117
+ ``` bash
118
+ cmake -G <compiler> -B build
119
+ cmake --build ./build --config Release
120
+ ```
121
+
122
+ where `<compiler>` is the name of the compiler being used
123
+ in double quotes (e.g., "Visual Studio 17 2022" for windows, "Ninja" for linux, or "Xcode" for macos). The resulting engine shared libraries (i.e., swmm5.dll), command line executable (i.e., runswmm.exe), and output processing libraries (i.e., swmm-output.dll)
124
+ will appear in the build\Release directory.
125
+
126
+ ### Python Bindings (Experimental)
127
+
128
+ Experimental python bindings for the SWMM API are being developed to support regression and benchmark testing as well as for other applications. _**These bindings are still under development and testing and has yet to be cleared through US EPA ORD's official quality assurance review process**_. The exprimental python bindings can be built and installed locally using the following command.
129
+
130
+ ```bash
131
+ cd python
132
+ python -m pip install -r requirements.txt
133
+ python -m pip install .
134
+ ```
135
+ Users may also build python wheels for installation or distribution. Once the python bindings
136
+ have been validated and cleared through EPA's quality assuracnce clearance process, they will be available for installation via package indexing repositories such as pypi.
137
+
138
+ Example usage of python bindings can be found below. More extensive documentation will be provided once cleared.
139
+
140
+ ```python
141
+
142
+ from openswmmcore import solver
143
+ from openswmmcore.solver import Solver
144
+ from openswmmcore.output import Output
145
+
146
+ # Alternative 1 to run SWMM
147
+
148
+ with Solver(inp_file="input_file.inp") as swmm_solver:
149
+
150
+ # Open swmm file and starts the simulation
151
+ swmm_solver.start()
152
+
153
+ # Set initialization parameters e.g., time step stride, start date, end date etc.
154
+ swmm_solver.time_stride = 600
155
+
156
+ for elapsed_time, current_datetime in swmm_solver:
157
+
158
+ # Get and set attributes per timestep
159
+ print(current_datetime)
160
+
161
+ swmm_solver.set_value(
162
+ object_type=solver.SWMMObjects.RAIN_GAGE,
163
+ property_type=solver.SWMMRainGageProperties.GAGE_RAINFALL,
164
+ index="RG1",
165
+ value=3.6
166
+ )
167
+
168
+ # Alternative 2 to run SWMM
169
+ swmm_solver = Solver(inp_file="input_file.inp")
170
+ swmm_solver.initialize()
171
+
172
+ for elapsed_time, current_datetime in swmm_solver:
173
+ # Get and set attributes per timestep
174
+ print(current_datetime)
175
+
176
+ swmm_solver.finalize()
177
+ # or
178
+ # swmm_solver.end()
179
+ # swmm_solver.report()
180
+ # swmm_solver.close()
181
+
182
+ # Alternative 3 to run SWMM
183
+ swmm_solver = Solver(inp_file="input_file.inp")
184
+ swmm_solver.execute()
185
+
186
+ # To read output file
187
+
188
+ swmm_output = Output(output_file='output_file.out')
189
+
190
+ # Dict[datetime, float]
191
+ link_timeseries = swmm_output.get_link_timeseries(
192
+ element_index="C1",
193
+ attribute=output.LinkAttribute.FLOW_RATE,
194
+ )
195
+
196
+ ```
197
+
198
+ ## Unit and Regression Testing
199
+
200
+ Unit tests and regression tests have been developed for both the natively compiled SWMM computational engine and output toolkit as well as their respective python bindings. Unit tests for the natively compiled toolkits use the Boost 1.67.0 library and can be compiled by adding DBUILD_TESTS=ON flag during the cmake build phase as shown below:
201
+
202
+ ```bash
203
+ ctest --test-dir . -DBUILD_TESTS=ON --config Debug --output-on-failure
204
+ ```
205
+
206
+ Unit testing on the python bindings may be executed using the following command after installation.
207
+
208
+ ```bash
209
+ cd python\tests
210
+ pytest .
211
+ ```
212
+
213
+ Regression tests are executed using the python bindings using the pytest and pytest-regressions extension using the following commands.
214
+
215
+ ```bash
216
+ cd ci
217
+ pytest --data-dir <path-to-regression-testing-files> --atol <absolute-tolerance> --rtol <relative-tolerance> --benchmark-compare --benchmark-json=PATH
218
+ ```
219
+
220
+ ## Find Out More
221
+ The source code distributed here is identical to the code found at the official [SWMM website](https://www.epa.gov/water-research/storm-water-management-model-swmm).
222
+ The SWMM website also hosts the official manuals and installation binaries for the SWMM software.
223
+
224
+ A live web version of the SWMM documentation of the API and user manuals can be found on the [SWMM GitHub Pages website](https://usepa.github.io/Stormwater-Management-Model). Note that this is an experimental version that is still under development and has yet to go through EPA'S official quality assurance review process.
225
+
226
+ ## Disclaimer
227
+ The United States Environmental Protection Agency (EPA) GitHub project code is provided on an "as is" basis and the user assumes responsibility for its use. EPA has relinquished control of the information and no longer has responsibility to protect the integrity, confidentiality, or availability of the information. Any reference to specific commercial products, processes, or services by service mark, trademark, manufacturer, or otherwise, does not constitute or imply their endorsement, recommendation or favoring by EPA. The EPA seal and logo shall not be used in any manner to imply endorsement of any commercial product or activity by EPA or the United States Government.
228
+
@@ -0,0 +1,176 @@
1
+ EPA ORD Stormwater Management Model (SWMM)
2
+ ==========================================
3
+
4
+ Stormwater Management Model (SWMM) computational engine and output post-processing codebase
5
+
6
+ ## Build Status
7
+ [![Build and Unit Testing](https://github.com/HydroCouple/Stormwater-Management-Model/actions/workflows/unit_testing.yml/badge.svg)](https://github.com/HydroCouple/Stormwater-Management-Model/actions/workflows/unit_testing.yml)
8
+ [![Build and Regression Testing](https://github.com/HydroCouple/Stormwater-Management-Model/actions/workflows/regression_testing.yml/badge.svg)](https://github.com/HydroCouple/Stormwater-Management-Model/actions/workflows/regression_testing.yml)
9
+ [![Docs](https://github.com/HydroCouple/Stormwater-Management-Model/actions/workflows/build_docs.yml/badge.svg)](https://github.com/HydroCouple/Stormwater-Management-Model/actions/workflows/build_docs.yml)
10
+ [![Deployment](https://github.com/HydroCouple/Stormwater-Management-Model/actions/workflows/deploy.yml/badge.svg)](https://github.com/HydroCouple/Stormwater-Management-Model/actions/workflows/deploy.yml)
11
+ [![Documentation](https://github.com/HydroCouple/Stormwater-Management-Model/actions/workflows/build-and-test.yml/badge.svg?branch=docs)](https://github.com/HydroCouple/Stormwater-Management-Model/actions/workflows/build-and-test.yml)
12
+ [![Issues](https://img.shields.io/github/issues/HydroCouple/Stormwater-Management-Model)](https://github.com/HydroCouple/Stormwater-Management-Model/issues)
13
+
14
+ ## Python Binding
15
+ [![PyPi](https://img.shields.io/pypi/v/openswmm.svg)](https://pypi.org/project/openswmm)
16
+ [![PythonVersion](https://img.shields.io/pypi/pyversions/openswmm.svg)](https://pypi.org/project/openswmm)
17
+ [![Wheel](https://img.shields.io/pypi/wheel/openswmm.svg)](https://pypi.org/project/openswmm)
18
+ [![Downloads](https://pepy.tech/badge/openswmm)](https://pepy.tech/project/openswmm)
19
+ [![Downloads](https://pepy.tech/badge/openswmm/month)](https://pepy.tech/project/openswmm)
20
+ [![Downloads](https://pepy.tech/badge/openswmm/week)](https://pepy.tech/project/openswmm)
21
+
22
+ ## Introduction
23
+ This is the official SWMM source code repository maintained by US EPA Office of Research and Development, Center For Environmental Solutions & Emergency Response, Water Infrastructure Division located in Cincinnati, Ohio.
24
+
25
+ SWMM is a dynamic hydrology-hydraulic water quality simulation model. It is used for single event or long-term (continuous) simulation of runoff quantity and quality from primarily urban areas. SWMM source code is written in the C Programming Language and released in the Public Domain.
26
+
27
+ ## Build Instructions
28
+
29
+ The 'src' folder of this repository contains the C source code for
30
+ version of Storm Water Management Model's computational
31
+ engine. Consult the included 'Roadmap.txt' file for an overview of
32
+ the various code modules. The code can be compiled into both a shared
33
+ object library and a command line executable. Under Windows, the
34
+ library file (swmm5.dll) is used to power SWMM's graphical user
35
+ interface.
36
+
37
+ Also included is a python interface for the SWMM computational engine and output
38
+ post-processing application programming interfaces located in the python folder.
39
+
40
+ The 'CMakeLists.txt' file is a script used by CMake (https://cmake.org/)
41
+ to build the SWMM binaries. CMake is a cross-platform build tool
42
+ that generates platform native build systems for many compilers. To
43
+ check if the required version is installed on your system, enter from
44
+ a console window and check that the version is 3.5 or higher.
45
+
46
+ ```bash
47
+ cmake --version
48
+ ```
49
+
50
+ To build the SWMM engine library and its command line executable
51
+ using CMake and the Microsoft Visual Studio C compiler on Windows:
52
+
53
+ 1. Open a console window and navigate to the directory where this
54
+ Readme file resides (which should have 'src' as a sub-directory
55
+ underneath it).
56
+
57
+ 2. Use the following command to create the directory for storing the built binaries:
58
+
59
+ ```bash
60
+ mkdir build
61
+ ```
62
+
63
+ 3. Then the following CMake commands to build the binaries:
64
+
65
+ ``` bash
66
+ cmake -G <compiler> -B build
67
+ cmake --build ./build --config Release
68
+ ```
69
+
70
+ where `<compiler>` is the name of the compiler being used
71
+ in double quotes (e.g., "Visual Studio 17 2022" for windows, "Ninja" for linux, or "Xcode" for macos). The resulting engine shared libraries (i.e., swmm5.dll), command line executable (i.e., runswmm.exe), and output processing libraries (i.e., swmm-output.dll)
72
+ will appear in the build\Release directory.
73
+
74
+ ### Python Bindings (Experimental)
75
+
76
+ Experimental python bindings for the SWMM API are being developed to support regression and benchmark testing as well as for other applications. _**These bindings are still under development and testing and has yet to be cleared through US EPA ORD's official quality assurance review process**_. The exprimental python bindings can be built and installed locally using the following command.
77
+
78
+ ```bash
79
+ cd python
80
+ python -m pip install -r requirements.txt
81
+ python -m pip install .
82
+ ```
83
+ Users may also build python wheels for installation or distribution. Once the python bindings
84
+ have been validated and cleared through EPA's quality assuracnce clearance process, they will be available for installation via package indexing repositories such as pypi.
85
+
86
+ Example usage of python bindings can be found below. More extensive documentation will be provided once cleared.
87
+
88
+ ```python
89
+
90
+ from openswmmcore import solver
91
+ from openswmmcore.solver import Solver
92
+ from openswmmcore.output import Output
93
+
94
+ # Alternative 1 to run SWMM
95
+
96
+ with Solver(inp_file="input_file.inp") as swmm_solver:
97
+
98
+ # Open swmm file and starts the simulation
99
+ swmm_solver.start()
100
+
101
+ # Set initialization parameters e.g., time step stride, start date, end date etc.
102
+ swmm_solver.time_stride = 600
103
+
104
+ for elapsed_time, current_datetime in swmm_solver:
105
+
106
+ # Get and set attributes per timestep
107
+ print(current_datetime)
108
+
109
+ swmm_solver.set_value(
110
+ object_type=solver.SWMMObjects.RAIN_GAGE,
111
+ property_type=solver.SWMMRainGageProperties.GAGE_RAINFALL,
112
+ index="RG1",
113
+ value=3.6
114
+ )
115
+
116
+ # Alternative 2 to run SWMM
117
+ swmm_solver = Solver(inp_file="input_file.inp")
118
+ swmm_solver.initialize()
119
+
120
+ for elapsed_time, current_datetime in swmm_solver:
121
+ # Get and set attributes per timestep
122
+ print(current_datetime)
123
+
124
+ swmm_solver.finalize()
125
+ # or
126
+ # swmm_solver.end()
127
+ # swmm_solver.report()
128
+ # swmm_solver.close()
129
+
130
+ # Alternative 3 to run SWMM
131
+ swmm_solver = Solver(inp_file="input_file.inp")
132
+ swmm_solver.execute()
133
+
134
+ # To read output file
135
+
136
+ swmm_output = Output(output_file='output_file.out')
137
+
138
+ # Dict[datetime, float]
139
+ link_timeseries = swmm_output.get_link_timeseries(
140
+ element_index="C1",
141
+ attribute=output.LinkAttribute.FLOW_RATE,
142
+ )
143
+
144
+ ```
145
+
146
+ ## Unit and Regression Testing
147
+
148
+ Unit tests and regression tests have been developed for both the natively compiled SWMM computational engine and output toolkit as well as their respective python bindings. Unit tests for the natively compiled toolkits use the Boost 1.67.0 library and can be compiled by adding DBUILD_TESTS=ON flag during the cmake build phase as shown below:
149
+
150
+ ```bash
151
+ ctest --test-dir . -DBUILD_TESTS=ON --config Debug --output-on-failure
152
+ ```
153
+
154
+ Unit testing on the python bindings may be executed using the following command after installation.
155
+
156
+ ```bash
157
+ cd python\tests
158
+ pytest .
159
+ ```
160
+
161
+ Regression tests are executed using the python bindings using the pytest and pytest-regressions extension using the following commands.
162
+
163
+ ```bash
164
+ cd ci
165
+ pytest --data-dir <path-to-regression-testing-files> --atol <absolute-tolerance> --rtol <relative-tolerance> --benchmark-compare --benchmark-json=PATH
166
+ ```
167
+
168
+ ## Find Out More
169
+ The source code distributed here is identical to the code found at the official [SWMM website](https://www.epa.gov/water-research/storm-water-management-model-swmm).
170
+ The SWMM website also hosts the official manuals and installation binaries for the SWMM software.
171
+
172
+ A live web version of the SWMM documentation of the API and user manuals can be found on the [SWMM GitHub Pages website](https://usepa.github.io/Stormwater-Management-Model). Note that this is an experimental version that is still under development and has yet to go through EPA'S official quality assurance review process.
173
+
174
+ ## Disclaimer
175
+ The United States Environmental Protection Agency (EPA) GitHub project code is provided on an "as is" basis and the user assumes responsibility for its use. EPA has relinquished control of the information and no longer has responsibility to protect the integrity, confidentiality, or availability of the information. Any reference to specific commercial products, processes, or services by service mark, trademark, manufacturer, or otherwise, does not constitute or imply their endorsement, recommendation or favoring by EPA. The EPA seal and logo shall not be used in any manner to imply endorsement of any commercial product or activity by EPA or the United States Government.
176
+
@@ -0,0 +1,31 @@
1
+ # Description: CMake configuration for openswmmcore python library
2
+ # Created by: Caleb Buahin (EPA/ORD/CESER/WID)
3
+ # Created on: 2024-11-19
4
+
5
+ # Add Cython targets for openswmmcore
6
+ add_cython_target(_openswmm _openswmm.pyx CXX PY3)
7
+
8
+ # Create Python extension modules
9
+ add_library(_openswmm MODULE ${_openswmm})
10
+
11
+ set_target_properties(_openswmm
12
+ PROPERTIES
13
+ VERSION ${LIBRARY_VERSION}
14
+ SOVERSION ${LIBRARY_SOVERSION}
15
+ )
16
+
17
+ python_extension_module(_openswmm)
18
+
19
+ # Install the openswmmcore module
20
+ install(TARGETS _openswmm LIBRARY DESTINATION openswmm)
21
+
22
+ # Include the current source directory
23
+ target_include_directories(
24
+ _openswmm
25
+ PUBLIC
26
+ ${CMAKE_CURRENT_SOURCE_DIR}
27
+ )
28
+
29
+ # Add subdirectories
30
+ add_subdirectory(solver)
31
+ add_subdirectory(output)
@@ -0,0 +1,42 @@
1
+ """
2
+ openswmm Python API
3
+
4
+ This module provides a Python interface to the openswmm library.
5
+ """
6
+ import os
7
+ import platform
8
+ import sys
9
+ import importlib.metadata
10
+
11
+ # Platform-specific DLL/library path configuration
12
+ if platform.system() == "Windows":
13
+ lib_dir = os.path.join(sys.prefix, "bin")
14
+ if hasattr(os, "add_dll_directory"):
15
+ conda_exists = os.path.exists(os.path.join(sys.prefix, "conda-meta"))
16
+ if conda_exists:
17
+ os.environ["CONDA_DLL_SEARCH_MODIFICATION_ENABLE"] = "1"
18
+ os.add_dll_directory(lib_dir)
19
+ else:
20
+ os.environ["PATH"] = lib_dir + ";" + os.environ["PATH"]
21
+
22
+ elif platform.system() == "Linux":
23
+ lib_dir = os.path.join(sys.prefix, "lib")
24
+ sys.path.append(lib_dir)
25
+ os.environ["LD_LIBRARY_PATH"] = lib_dir + ":" + os.environ.get("LD_LIBRARY_PATH", "")
26
+
27
+ elif platform.system() == "Darwin": # macOS
28
+ lib_dir = os.path.join(sys.prefix, "lib")
29
+ sys.path.append(lib_dir)
30
+ os.environ["DYLD_LIBRARY_PATH"] = lib_dir + ":" + os.environ.get("DYLD_LIBRARY_PATH", "")
31
+
32
+ lib_dir = os.path.join(sys.prefix, "bin")
33
+ os.environ["DYLD_LIBRARY_PATH"] = lib_dir + ":" + os.environ.get("DYLD_LIBRARY_PATH", "")
34
+
35
+ # Get version from package metadata
36
+ __version__ = importlib.metadata.version('openswmm')
37
+
38
+ # Import submodules
39
+ from openswmm.solver import *
40
+ from openswmm.output import *
41
+
42
+ __all__ = ['__version__']
@@ -0,0 +1,12 @@
1
+ # cython: language_level=3str
2
+ # Description: Cython module for encoding and decoding SWMM datetimes
3
+ # Created by: Caleb Buahin (EPA/ORD/CESER/WID)
4
+ # Created on: 2024-11-19
5
+
6
+ # python imports
7
+
8
+ # third-party imports
9
+
10
+ # project imports
11
+ from openswmm cimport openswmm
12
+
File without changes
File without changes
@@ -0,0 +1,10 @@
1
+ # Description: Cython module for encoding and decoding SWMM datetimes
2
+ # Created by: Caleb Buahin (EPA/ORD/CESER/WID)
3
+ # Created on: 2024-11-19
4
+
5
+ # cython: language_level=3
6
+ # python imports
7
+
8
+ # third-party imports
9
+
10
+ # project imports
@@ -0,0 +1,45 @@
1
+ # CMake configuration for openswmmcore python library
2
+ #
3
+ # Created by: Caleb Buahin (EPA/ORD/CESER/WID)
4
+ # Created on: 2024-11-19
5
+
6
+ add_cython_target(_output _output.pyx LANGUAGE CXX PY3)
7
+
8
+ # Add Cython target
9
+ add_library(_output MODULE ${_output})
10
+
11
+ # Add library
12
+ target_link_libraries(
13
+ _output
14
+ OpenSWMMCore::openswmmcore
15
+ OpenSWMMCore::openswmmcore_output
16
+ )
17
+
18
+ # Specify that this is a Python extension module
19
+ python_extension_module(_output)
20
+
21
+ if(APPLE)
22
+ set(INSTALL_LIB_ROOT "@loader_path;@rpath;@loader_path/../../../..;${OUTFILE_BUILD_DIR}")
23
+ set(BUILD_LIB_ROOT "@loader_path;@rpath;${OUTFILE_BUILD_DIR}")
24
+ elseif(UNIX)
25
+ set(INSTALL_LIB_ROOT "$ORIGIN;$ORIGIN/../../../..;${OUTFILE_BUILD_DIR}")
26
+ set(BUILD_LIB_ROOT "$ORIGIN;${OUTFILE_BUILD_DIR}")
27
+ endif()
28
+
29
+ # Set up rpath for runswmm inside install package
30
+ set_target_properties(_output
31
+ PROPERTIES
32
+ BUILD_RPATH "${BUILD_LIB_ROOT}"
33
+ INSTALL_RPATH "${INSTALL_LIB_ROOT}"
34
+ BUILD_WITH_INSTALL_RPATH True
35
+ )
36
+
37
+ # Install the target
38
+ install(TARGETS _output LIBRARY DESTINATION openswmm/output)
39
+
40
+ # Include directories
41
+ target_include_directories(
42
+ _output
43
+ PUBLIC
44
+ ${CMAKE_CURRENT_SOURCE_DIR}
45
+ )
@@ -0,0 +1 @@
1
+ from .output cimport *
@@ -0,0 +1,13 @@
1
+ from ._output import (
2
+ UnitSystem,
3
+ FlowUnits,
4
+ ConcentrationUnits,
5
+ ElementType,
6
+ TimeAttribute,
7
+ SubcatchAttribute,
8
+ NodeAttribute,
9
+ LinkAttribute,
10
+ SystemAttribute,
11
+ SWMMOutputException,
12
+ Output,
13
+ )