SolUtil 0.1.0__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 (54) hide show
  1. solutil-0.1.0/.github/workflows/ci-cd.yml +135 -0
  2. solutil-0.1.0/.gitignore +8 -0
  3. solutil-0.1.0/.readthedocs.yaml +29 -0
  4. solutil-0.1.0/LICENSE +21 -0
  5. solutil-0.1.0/PKG-INFO +69 -0
  6. solutil-0.1.0/README.md +43 -0
  7. solutil-0.1.0/SolUtil/__init__.py +5 -0
  8. solutil-0.1.0/SolUtil/_version.py +24 -0
  9. solutil-0.1.0/SolUtil/alternate_solver/__init__.py +1 -0
  10. solutil-0.1.0/SolUtil/alternate_solver/solver.py +127 -0
  11. solutil-0.1.0/SolUtil/energyflow/__init__.py +5 -0
  12. solutil-0.1.0/SolUtil/energyflow/dhs_fault_flow.py +719 -0
  13. solutil-0.1.0/SolUtil/energyflow/dhs_flow.py +395 -0
  14. solutil-0.1.0/SolUtil/energyflow/gas_flow.py +147 -0
  15. solutil-0.1.0/SolUtil/energyflow/hydraulic_mdl.py +232 -0
  16. solutil-0.1.0/SolUtil/energyflow/power_flow.py +338 -0
  17. solutil-0.1.0/SolUtil/energyflow/test/__init__.py +0 -0
  18. solutil-0.1.0/SolUtil/energyflow/test/test_dhs_fault_flow/case_heat_test.xlsx +0 -0
  19. solutil-0.1.0/SolUtil/energyflow/test/test_dhs_fault_flow/case_heat_test0.xlsx +0 -0
  20. solutil-0.1.0/SolUtil/energyflow/test/test_dhs_fault_flow/case_heat_test1.xlsx +0 -0
  21. solutil-0.1.0/SolUtil/energyflow/test/test_dhs_fault_flow.py +27 -0
  22. solutil-0.1.0/SolUtil/energyflow/test/test_dhs_flow/BarryIsland.xlsx +0 -0
  23. solutil-0.1.0/SolUtil/energyflow/test/test_dhs_flow.py +24 -0
  24. solutil-0.1.0/SolUtil/energyflow/test/test_gas_flow/belgium.xlsx +0 -0
  25. solutil-0.1.0/SolUtil/energyflow/test/test_gas_flow.py +20 -0
  26. solutil-0.1.0/SolUtil/energyflow/test/test_load_matpower/case9.m +70 -0
  27. solutil-0.1.0/SolUtil/energyflow/test/test_load_matpower.py +139 -0
  28. solutil-0.1.0/SolUtil/energyflow/test/test_power_flow/case9.xlsx +0 -0
  29. solutil-0.1.0/SolUtil/energyflow/test/test_power_flow.py +98 -0
  30. solutil-0.1.0/SolUtil/error_cal.py +9 -0
  31. solutil-0.1.0/SolUtil/profile.py +9 -0
  32. solutil-0.1.0/SolUtil/sysparser/__init__.py +3 -0
  33. solutil-0.1.0/SolUtil/sysparser/_array_utils.py +6 -0
  34. solutil-0.1.0/SolUtil/sysparser/dhs_function.py +209 -0
  35. solutil-0.1.0/SolUtil/sysparser/eps_function.py +395 -0
  36. solutil-0.1.0/SolUtil/sysparser/ngs_function.py +160 -0
  37. solutil-0.1.0/SolUtil/tf2ss.py +14 -0
  38. solutil-0.1.0/SolUtil.egg-info/PKG-INFO +69 -0
  39. solutil-0.1.0/SolUtil.egg-info/SOURCES.txt +52 -0
  40. solutil-0.1.0/SolUtil.egg-info/dependency_links.txt +1 -0
  41. solutil-0.1.0/SolUtil.egg-info/requires.txt +10 -0
  42. solutil-0.1.0/SolUtil.egg-info/scm_file_list.json +48 -0
  43. solutil-0.1.0/SolUtil.egg-info/scm_version.json +8 -0
  44. solutil-0.1.0/SolUtil.egg-info/top_level.txt +1 -0
  45. solutil-0.1.0/docs/Makefile +20 -0
  46. solutil-0.1.0/docs/__init__.py +0 -0
  47. solutil-0.1.0/docs/make.bat +35 -0
  48. solutil-0.1.0/docs/requirements.txt +23 -0
  49. solutil-0.1.0/docs/source/__init__.py +0 -0
  50. solutil-0.1.0/docs/source/conf.py +83 -0
  51. solutil-0.1.0/docs/source/index.rst +29 -0
  52. solutil-0.1.0/pyproject.toml +47 -0
  53. solutil-0.1.0/requirements.txt +2 -0
  54. solutil-0.1.0/setup.cfg +4 -0
@@ -0,0 +1,135 @@
1
+ name: CI/CD
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+ types: [opened, synchronize, reopened, closed]
7
+ branches:
8
+ - '*'
9
+
10
+ jobs:
11
+ built_in_tests:
12
+
13
+ runs-on: windows-latest
14
+
15
+ steps:
16
+ - name: Checkout repository
17
+ uses: actions/checkout@v6
18
+
19
+ - name: Install IPOPT
20
+ shell: pwsh
21
+ env:
22
+ IPOPT_VERSION: 3.14.12 # 检查最新版本 https://github.com/coin-or/Ipopt/releases
23
+ run: |
24
+ # 下载预编译的Windows二进制文件
25
+ $url = "https://github.com/coin-or/Ipopt/releases/download/releases%2F$env:IPOPT_VERSION/Ipopt-$env:IPOPT_VERSION-win64-msvs2019-md.zip"
26
+ Invoke-WebRequest -Uri $url -OutFile Ipopt.zip
27
+
28
+ # 解压文件
29
+ Expand-Archive -Path Ipopt.zip -DestinationPath .
30
+
31
+ # 设置环境变量(当前Job后续步骤生效)
32
+ $ipoptPath = "$pwd\Ipopt-$env:IPOPT_VERSION-win64-msvs2019-md\bin"
33
+ echo "IPOPT_PATH=$ipoptPath" >> $env:GITHUB_ENV
34
+ echo "$ipoptPath" >> $env:GITHUB_PATH
35
+
36
+ - uses: actions/setup-python@v6
37
+ with:
38
+ python-version: '3.11'
39
+ - name: Set up uv
40
+ uses: astral-sh/setup-uv@v7
41
+ with:
42
+ enable-cache: true
43
+
44
+ - name: Install dependencies
45
+ run: |
46
+ uv sync --group dev
47
+
48
+ - name: Run Tests
49
+ run: |
50
+ uv run pytest -n auto -vv
51
+
52
+ build:
53
+ name: Build distribution
54
+ if: startsWith(github.ref, 'refs/tags/')
55
+ needs: built_in_tests
56
+ runs-on: ubuntu-latest
57
+
58
+ steps:
59
+ - uses: actions/checkout@v6
60
+ with:
61
+ # setuptools_scm derives the version from the tag
62
+ fetch-depth: 0
63
+ - name: Set up Python
64
+ uses: actions/setup-python@v6
65
+ with:
66
+ python-version: "3.x"
67
+ - name: Install pypa/build
68
+ run: >-
69
+ python3 -m
70
+ pip install
71
+ build
72
+ --user
73
+ - name: Build a binary wheel and a source tarball
74
+ run: python3 -m build
75
+ - name: Store the distribution packages
76
+ uses: actions/upload-artifact@v4
77
+ with:
78
+ name: python-package-distributions
79
+ path: dist/
80
+
81
+ publish-to-pypi:
82
+ name: Publish Python distribution to PyPI
83
+ needs: build
84
+ runs-on: ubuntu-latest
85
+ environment:
86
+ name: pypi
87
+ url: https://pypi.org/project/SolUtil/
88
+ permissions:
89
+ id-token: write
90
+
91
+ steps:
92
+ - name: Download all the dists
93
+ uses: actions/download-artifact@v4
94
+ with:
95
+ name: python-package-distributions
96
+ path: dist/
97
+ - name: Publish distribution to PyPI
98
+ uses: pypa/gh-action-pypi-publish@release/v1
99
+
100
+ github-release:
101
+ name: Sign the Python distribution with Sigstore and upload them to GitHub Release
102
+ needs: publish-to-pypi
103
+ runs-on: ubuntu-latest
104
+
105
+ permissions:
106
+ contents: write
107
+ id-token: write
108
+
109
+ steps:
110
+ - name: Download all the dists
111
+ uses: actions/download-artifact@v4
112
+ with:
113
+ name: python-package-distributions
114
+ path: dist/
115
+ - name: Sign the dists with Sigstore
116
+ uses: sigstore/gh-action-sigstore-python@v3.0.0
117
+ with:
118
+ inputs: >-
119
+ ./dist/*.tar.gz
120
+ ./dist/*.whl
121
+ - name: Create GitHub Release
122
+ env:
123
+ GITHUB_TOKEN: ${{ github.token }}
124
+ run: >-
125
+ gh release create
126
+ '${{ github.ref_name }}'
127
+ --repo '${{ github.repository }}'
128
+ --notes ""
129
+ - name: Upload artifact signatures to GitHub Release
130
+ env:
131
+ GITHUB_TOKEN: ${{ github.token }}
132
+ run: >-
133
+ gh release upload
134
+ '${{ github.ref_name }}' dist/**
135
+ --repo '${{ github.repository }}'
@@ -0,0 +1,8 @@
1
+
2
+ /.idea
3
+ /SolUtil.egg-info
4
+ SolUtil/_version.py
5
+ *.pyc
6
+ /SolUtil/energyflow/test/__pycache__
7
+ /docs/build
8
+ *.DS_Store
@@ -0,0 +1,29 @@
1
+ # .readthedocs.yaml
2
+ # Read the Docs configuration file
3
+ # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details
4
+
5
+ # Required
6
+ version: 2
7
+
8
+ # Set the OS, Python version and other tools you might need
9
+ build:
10
+ os: ubuntu-22.04
11
+ tools:
12
+ python: "3.11"
13
+
14
+ # Build documentation in the "docs/" directory with Sphinx
15
+ sphinx:
16
+ configuration: docs/source/conf.py
17
+
18
+ # Optionally build your docs in additional formats such as PDF and ePub
19
+ # formats:
20
+ # - pdf
21
+ # - epub
22
+
23
+ # Optional but recommended, declare the Python requirements required
24
+ # to build your documentation
25
+ # See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
26
+ python:
27
+ install:
28
+ - requirements: docs/requirements.txt
29
+ - requirements: requirements.txt
solutil-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Ruizhi Yu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
solutil-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,69 @@
1
+ Metadata-Version: 2.4
2
+ Name: SolUtil
3
+ Version: 0.1.0
4
+ Summary: The util lib for Solverz
5
+ Author-email: Ruizhi Yu <rz.yu@foxmail.com>
6
+ Project-URL: Repository, https://github.com/rzyu45/SolUtil
7
+ Classifier: Programming Language :: Python :: 3.10
8
+ Classifier: Programming Language :: Python :: 3.11
9
+ Classifier: Programming Language :: Python :: 3.12
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: matplotlib
16
+ Requires-Dist: matpowercaseframes>=2.1
17
+ Requires-Dist: networkx
18
+ Requires-Dist: numpy
19
+ Requires-Dist: openpyxl
20
+ Requires-Dist: pandas
21
+ Requires-Dist: scipy
22
+ Requires-Dist: Solverz>=0.11.0
23
+ Requires-Dist: tqdm
24
+ Requires-Dist: pyomo
25
+ Dynamic: license-file
26
+
27
+ # Solverz Utilities
28
+
29
+ This lib provides the simulation routines for integrated energy systems, including electric power, natural gas and heat.
30
+
31
+ A simple usage of this library can be
32
+
33
+ ```python
34
+ from SolUtil import GasFlow
35
+ gf = GasFlow('belgium.xlsx')
36
+ gf.run()
37
+ print(gf.Pi) # get the node Pressure results
38
+ print(gf.f) # get the pipe mass-flow results
39
+ ```
40
+
41
+ The required `.xlsx` data format can be found in SolUtil/energyflow/test directory for reference.
42
+
43
+ ## Installation
44
+
45
+ ```
46
+ pip install SolUtil
47
+ ```
48
+
49
+ ## Requirements
50
+
51
+ This package requires the `ipopt` optimization solver.
52
+
53
+ On `windows`, download the latest release [here](https://github.com/coin-or/Ipopt/releases). Then add the `bin`
54
+ directory to the system path. Make sure that you can call `ipopt` in your terminal.
55
+
56
+ On `macos`, use `brew install ipopt` to perform the installation.
57
+
58
+ ## MATPOWER case files
59
+
60
+ The power flow also reads a MATPOWER case file directly:
61
+
62
+ ```python
63
+ from SolUtil import PowerFlow
64
+ pf = PowerFlow('case118.m')
65
+ pf.run()
66
+ print(pf.Vm, pf.Va) # get the bus voltage magnitudes and angles
67
+ ```
68
+
69
+ A `.m` file is parsed with `matpowercaseframes` and prepared as MATPOWER `runpf` prepares it: generators out of service are dropped, the generators in service at one bus are summed, a PV or reference bus without a generator in service becomes a PQ bus, and every generator bus starts at its voltage setpoint. For large cases it is much faster to read than the `.xlsx` format.
@@ -0,0 +1,43 @@
1
+ # Solverz Utilities
2
+
3
+ This lib provides the simulation routines for integrated energy systems, including electric power, natural gas and heat.
4
+
5
+ A simple usage of this library can be
6
+
7
+ ```python
8
+ from SolUtil import GasFlow
9
+ gf = GasFlow('belgium.xlsx')
10
+ gf.run()
11
+ print(gf.Pi) # get the node Pressure results
12
+ print(gf.f) # get the pipe mass-flow results
13
+ ```
14
+
15
+ The required `.xlsx` data format can be found in SolUtil/energyflow/test directory for reference.
16
+
17
+ ## Installation
18
+
19
+ ```
20
+ pip install SolUtil
21
+ ```
22
+
23
+ ## Requirements
24
+
25
+ This package requires the `ipopt` optimization solver.
26
+
27
+ On `windows`, download the latest release [here](https://github.com/coin-or/Ipopt/releases). Then add the `bin`
28
+ directory to the system path. Make sure that you can call `ipopt` in your terminal.
29
+
30
+ On `macos`, use `brew install ipopt` to perform the installation.
31
+
32
+ ## MATPOWER case files
33
+
34
+ The power flow also reads a MATPOWER case file directly:
35
+
36
+ ```python
37
+ from SolUtil import PowerFlow
38
+ pf = PowerFlow('case118.m')
39
+ pf.run()
40
+ print(pf.Vm, pf.Va) # get the bus voltage magnitudes and angles
41
+ ```
42
+
43
+ A `.m` file is parsed with `matpowercaseframes` and prepared as MATPOWER `runpf` prepares it: generators out of service are dropped, the generators in service at one bus are summed, a PV or reference bus without a generator in service becomes a PQ bus, and every generator bus starts at its voltage setpoint. For large cases it is much faster to read than the `.xlsx` format.
@@ -0,0 +1,5 @@
1
+ from .sysparser import *
2
+ from .error_cal import calrmse
3
+ from .profile import TimeProf
4
+ from .energyflow import *
5
+ from .alternate_solver import *
@@ -0,0 +1,24 @@
1
+ # file generated by vcs-versioning
2
+ # don't change, don't track in version control
3
+ from __future__ import annotations
4
+
5
+ __all__ = [
6
+ "__version__",
7
+ "__version_tuple__",
8
+ "version",
9
+ "version_tuple",
10
+ "__commit_id__",
11
+ "commit_id",
12
+ ]
13
+
14
+ version: str
15
+ __version__: str
16
+ __version_tuple__: tuple[int | str, ...]
17
+ version_tuple: tuple[int | str, ...]
18
+ commit_id: str | None
19
+ __commit_id__: str | None
20
+
21
+ __version__ = version = '0.1.0'
22
+ __version_tuple__ = version_tuple = (0, 1, 0)
23
+
24
+ __commit_id__ = commit_id = 'gcfe3f09a8'
@@ -0,0 +1 @@
1
+ from .solver import alternate_sol
@@ -0,0 +1,127 @@
1
+ import numpy as np
2
+ from Solverz.solvers.solution import daesol
3
+ from Solverz import Rodas, TimeSeriesParam, Opt, load, save_result, fdae_solver, implicit_trapezoid, save
4
+ from Solverz.variable.variables import Vars
5
+ from Solverz.utilities.address import Address
6
+ from copy import deepcopy
7
+ import tqdm
8
+
9
+ from time import perf_counter
10
+
11
+
12
+ def create_yc(y1, y2, sys1_param, sys2_param):
13
+ # coupling variable
14
+ a = Address() # address
15
+ for varname in sys1_param:
16
+ a.add(varname, y2[varname].shape[0])
17
+ for varname in sys2_param:
18
+ a.add(varname, y1[varname].shape[0])
19
+
20
+ array = np.zeros((a.total_size,))
21
+ for varname in sys1_param:
22
+ array[a[varname]] = y2[varname]
23
+ for varname in sys2_param:
24
+ array[a[varname]] = y1[varname]
25
+
26
+ return Vars(a, array)
27
+
28
+
29
+ def update_yc(yc, y1, y2, sys1_param, sys2_param):
30
+ yc1 = deepcopy(yc)
31
+ for varname in sys1_param:
32
+ yc1[varname] = y2[varname]
33
+ for varname in sys2_param:
34
+ yc1[varname] = y1[varname]
35
+ return yc1
36
+
37
+
38
+ def alternate_sol(sys1,
39
+ sys2,
40
+ y0_1,
41
+ y0_2,
42
+ solver1,
43
+ solver2,
44
+ Dt,
45
+ tspan,
46
+ sys1_param,
47
+ sys2_param,
48
+ ite_tol=1e-5):
49
+ """
50
+ sys1 small step size, sys2 big step size
51
+ """
52
+ bar = tqdm.tqdm(total=tspan[-1] - tspan[0])
53
+
54
+ start = perf_counter()
55
+
56
+ flag = False
57
+
58
+ t0 = tspan[0]
59
+ tend = tspan[1]
60
+ step = 0
61
+ t = t0
62
+ T = tend
63
+ sol1 = daesol()
64
+ sol2 = daesol()
65
+
66
+ yc0 = create_yc(y0_1, y0_2, sys1_param, sys2_param)
67
+
68
+ while t < T:
69
+ err = 1
70
+ ite = 0
71
+
72
+ y1_1 = deepcopy(y0_1)
73
+ y1_2 = deepcopy(y0_2)
74
+
75
+ while err > 1e-5:
76
+ ite = ite + 1
77
+
78
+ sol2 = solver2(sys2, [t, t + Dt], y0_2, Opt(step_size=Dt))
79
+ y1_2 = sol2.Y[-1]
80
+
81
+ for varname in sys1_param:
82
+ sys1.p[varname] = TimeSeriesParam(varname,
83
+ sol2.Y[varname].reshape((-1, )),
84
+ sol2.T)
85
+
86
+ sol1 = solver1(sys1,
87
+ [t, t + Dt],
88
+ y0_1,
89
+ Opt(step_size=Dt))
90
+ y1_1 = sol1.Y[-1]
91
+
92
+ yc1 = update_yc(yc0, y1_1, y1_2, sys1_param, sys2_param)
93
+
94
+ err = np.max(np.abs(yc0 - yc1))
95
+
96
+ yc0.array[:] = yc1.array[:]
97
+
98
+ for varname in sys2_param:
99
+ sys2.p[varname] = TimeSeriesParam(varname,
100
+ sol1.Y[varname].reshape((-1, )),
101
+ sol1.T)
102
+
103
+ if ite > 100:
104
+ print("Cannot converge within 100 iterations!")
105
+ break
106
+
107
+ if step == 0:
108
+ sol1.append(sol1)
109
+ sol2.append(sol2)
110
+ else:
111
+ sol1.append(sol1[-1:])
112
+ sol2.append(sol2[-1:])
113
+ step = step + 1
114
+ y0_1 = deepcopy(y1_1)
115
+ y0_2 = deepcopy(y1_2)
116
+
117
+ t = t + Dt
118
+ bar.update(Dt)
119
+
120
+ if flag:
121
+ bar.close()
122
+ break
123
+
124
+ end = perf_counter()
125
+ print(f'Time elapsed: {end - start}s!')
126
+
127
+ return sol1, sol2
@@ -0,0 +1,5 @@
1
+ from .gas_flow import *
2
+ from .dhs_flow import *
3
+ from .dhs_fault_flow import DhsFaultFlow
4
+ from .power_flow import *
5
+ from .hydraulic_mdl import hydraulic_opt_mdl