deberka-jordan 0.0.1__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 (44) hide show
  1. deberka_jordan-0.0.1/CHANGELOG.md +39 -0
  2. deberka_jordan-0.0.1/CITATION.cff +34 -0
  3. deberka_jordan-0.0.1/LICENSE +21 -0
  4. deberka_jordan-0.0.1/PKG-INFO +172 -0
  5. deberka_jordan-0.0.1/README.md +138 -0
  6. deberka_jordan-0.0.1/README.ru.md +136 -0
  7. deberka_jordan-0.0.1/docs/en/api.md +80 -0
  8. deberka_jordan-0.0.1/docs/en/cli.md +57 -0
  9. deberka_jordan-0.0.1/docs/en/publishing.md +14 -0
  10. deberka_jordan-0.0.1/docs/en/quickstart.md +72 -0
  11. deberka_jordan-0.0.1/docs/en/theory.md +124 -0
  12. deberka_jordan-0.0.1/docs/ru/api.md +78 -0
  13. deberka_jordan-0.0.1/docs/ru/cli.md +56 -0
  14. deberka_jordan-0.0.1/docs/ru/publishing.md +14 -0
  15. deberka_jordan-0.0.1/docs/ru/quickstart.md +72 -0
  16. deberka_jordan-0.0.1/docs/ru/theory.md +115 -0
  17. deberka_jordan-0.0.1/examples/01_quickstart.py +66 -0
  18. deberka_jordan-0.0.1/examples/02_netting_log.py +38 -0
  19. deberka_jordan-0.0.1/examples/03_two_phase_fake.py +34 -0
  20. deberka_jordan-0.0.1/pyproject.toml +234 -0
  21. deberka_jordan-0.0.1/pyproject.toml.orig +143 -0
  22. deberka_jordan-0.0.1/scripts/check_commit_msg.py +78 -0
  23. deberka_jordan-0.0.1/scripts/commit-msg +4 -0
  24. deberka_jordan-0.0.1/scripts/install_hooks.sh +7 -0
  25. deberka_jordan-0.0.1/src/deberka_jordan/__init__.py +105 -0
  26. deberka_jordan-0.0.1/src/deberka_jordan/churn.py +214 -0
  27. deberka_jordan-0.0.1/src/deberka_jordan/cli.py +210 -0
  28. deberka_jordan-0.0.1/src/deberka_jordan/csvio.py +84 -0
  29. deberka_jordan-0.0.1/src/deberka_jordan/execute.py +194 -0
  30. deberka_jordan-0.0.1/src/deberka_jordan/kvm.py +91 -0
  31. deberka_jordan-0.0.1/src/deberka_jordan/measure.py +194 -0
  32. deberka_jordan-0.0.1/src/deberka_jordan/order.py +74 -0
  33. deberka_jordan-0.0.1/src/deberka_jordan/plan.py +361 -0
  34. deberka_jordan-0.0.1/src/deberka_jordan/py.typed +0 -0
  35. deberka_jordan-0.0.1/tests/test_churn.py +77 -0
  36. deberka_jordan-0.0.1/tests/test_cli.py +38 -0
  37. deberka_jordan-0.0.1/tests/test_docs.py +41 -0
  38. deberka_jordan-0.0.1/tests/test_examples.py +22 -0
  39. deberka_jordan-0.0.1/tests/test_execute.py +78 -0
  40. deberka_jordan-0.0.1/tests/test_factor.py +194 -0
  41. deberka_jordan-0.0.1/tests/test_kvm.py +74 -0
  42. deberka_jordan-0.0.1/tests/test_measure.py +53 -0
  43. deberka_jordan-0.0.1/tests/test_plan.py +144 -0
  44. deberka_jordan-0.0.1/tests/test_pool.py +283 -0
@@ -0,0 +1,39 @@
1
+ # Changelog
2
+
3
+ ## [0.0.1] — 2026-11-11
4
+
5
+ First release: the reallocation plans of article 2 (A. Ferubko, O. Kazakov, BGITU). The project was
6
+ built under the working name `jordanplan-deberka` (module `jordanplan`) and renamed to
7
+ `deberka-jordan` (module `deberka_jordan`, command `deberka-jordan`) before publication.
8
+
9
+ - `SignedMeasure` with Hahn and Jordan decompositions.
10
+ - `jordan_plan`: least-volume plan with dead band, bounds and rationing.
11
+ - Netting of proposal logs: `netting_report`, `netting_by_cycle`.
12
+ - Orders and the pool invariant: `two_phase`, `recipients_first`, `shuffled`, `pairwise`.
13
+ - Executors `execute_two_phase`, `execute_simultaneous`, simulator `RateLimitedSim`.
14
+ - Oscillation index, `replay_reserve`, `deadband_sweep`, `choose_deadband`.
15
+ - Optional `deberka_jordan.kvm.LibvirtBackend`, tested with fake domains.
16
+ - Command line tool `deberka_jordan`.
17
+ - Volume unit (default 1, bytes): `sequential_volume`, `netting_report`, `netting_by_cycle`
18
+ take `factor`, and `plan_volume(plan, *, factor=1.0)` is the volume of a plan. The default
19
+ `factor=1` counts each byte moved between two consumers once; `factor=2` gives the balloon
20
+ operations (a deflation at the donor and an inflation at the recipient). Must be finite and
21
+ positive (`ValueError`), a number (`TypeError`). The gain does not depend on it.
22
+ - `Plan.volume` is `plan_volume(plan)` with the default `pool="max"`: `max(take, give)`, the
23
+ bytes moved (equal to `Plan.operations / 2` when the pool does not change).
24
+ `Plan.operations = Σ |ν({i})|` is the balloon-operation measure of Claim 1.
25
+ `lower_bound_volume` is that measure (operations).
26
+ - Command line `plan --factor` and `net --factor` (default 1); the JSON output adds
27
+ `volume_factor`.
28
+ The `deadband` volume is not scaled: a dead-band jump is one operation on one consumer.
29
+ - Pool term of the plan volume: `plan_volume(plan, *, factor=1.0, pool="max", pool_weight=0.5)`.
30
+ `pool="max"` (default) counts a byte moved into or out of the pool as a byte:
31
+ `factor · max(take, give)`. `pool="weighted"` gives `factor · (min(take, give) + pool_weight ·
32
+ |pool change|)`; `pool_weight=0.5` reproduces the balloon operations over two of earlier
33
+ versions. Errors: `pool` not a string (`TypeError`) or not in `("max", "weighted")`
34
+ (`ValueError`); `pool_weight` not a real number (`TypeError`) or not finite and
35
+ non-negative (`ValueError`). For a plan that does not change the pool all modes coincide.
36
+ `netting_report` has no pool term: its logs are transfers between consumers.
37
+ - Command line `plan --pool-mode {max,weighted}` (default `max`) and `--pool-weight W`
38
+ (default 0.5); the `plan` output adds `volume_pool_mode` and `volume_pool_weight`. The
39
+ free pool level stays `--pool`.
@@ -0,0 +1,34 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use this software, please cite it as below."
3
+ type: software
4
+ title: "deberka-jordan: reallocation plans for a shared resource by the Hahn-Jordan decomposition"
5
+ abstract: >-
6
+ A Python library for reallocation cycles of a shared resource as signed
7
+ measures: the Hahn and Jordan decompositions, the least-volume netting of
8
+ proposals, a safe two-phase order that never overdraws the pool, an executor
9
+ that waits for freed memory, the oscillation index and the dead-band choice
10
+ on demand traces, and a libvirt balloon backend for KVM virtual machines.
11
+ version: 0.0.1
12
+ date-released: 2026-11-11
13
+ license: MIT
14
+ repository-code: "https://github.com/89605502155/deberka-jordan"
15
+ url: "https://github.com/89605502155/deberka-jordan"
16
+ keywords:
17
+ - Hahn decomposition
18
+ - Jordan decomposition
19
+ - signed measure
20
+ - resource allocation
21
+ - memory ballooning
22
+ - KVM
23
+ - libvirt
24
+ authors:
25
+ - family-names: Ferubko
26
+ given-names: Andrey
27
+ email: ferubko1999@yandex.ru
28
+ orcid: "https://orcid.org/0009-0006-5625-137X"
29
+ affiliation: "Bryansk State Engineering-Technological University (BGITU)"
30
+ - family-names: Kazakov
31
+ given-names: Oleg
32
+ email: kazakov@bgitu.ru
33
+ orcid: "https://orcid.org/0000-0001-9665-8138"
34
+ affiliation: "Bryansk State Engineering-Technological University (BGITU)"
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Andrey Ferubko, Oleg Kazakov
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.
@@ -0,0 +1,172 @@
1
+ Metadata-Version: 2.4
2
+ Name: deberka-jordan
3
+ Version: 0.0.1
4
+ Summary: Reallocation plans for a shared resource from the Hahn-Jordan decomposition: least-volume netting, a safe two-phase order, oscillation index and dead-band choice, with a libvirt balloon backend
5
+ Keywords: signed-measure,jordan-decomposition,hahn-decomposition,resource-allocation,netting,dead-band,memory-ballooning,kvm,libvirt,virtual-machines
6
+ Author: Andrey Ferubko, Oleg Kazakov
7
+ Author-email: Andrey Ferubko <ferubko1999@yandex.ru>, Oleg Kazakov <kazakov@bgitu.ru>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Intended Audience :: System Administrators
14
+ Classifier: Operating System :: POSIX :: Linux
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
22
+ Classifier: Topic :: System :: Monitoring
23
+ Classifier: Topic :: System :: Operating System Kernels :: Linux
24
+ Classifier: Typing :: Typed
25
+ Requires-Dist: libvirt-python>=8.0 ; extra == 'kvm'
26
+ Requires-Python: >=3.11
27
+ Project-URL: Homepage, https://github.com/89605502155/deberka-jordan
28
+ Project-URL: Documentation, https://github.com/89605502155/deberka-jordan/tree/main/docs
29
+ Project-URL: Repository, https://github.com/89605502155/deberka-jordan
30
+ Project-URL: Issues, https://github.com/89605502155/deberka-jordan/issues
31
+ Project-URL: Changelog, https://github.com/89605502155/deberka-jordan/blob/main/CHANGELOG.md
32
+ Provides-Extra: kvm
33
+ Description-Content-Type: text/markdown
34
+
35
+ # deberka-jordan
36
+
37
+ [![PyPI](https://img.shields.io/pypi/v/deberka-jordan.svg)](https://pypi.org/project/deberka-jordan/)
38
+ [![Python](https://img.shields.io/pypi/pyversions/deberka-jordan.svg)](https://pypi.org/project/deberka-jordan/)
39
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/89605502155/deberka-jordan/blob/main/LICENSE)
40
+
41
+ **Reallocation plans for a shared resource from the Hahn–Jordan decomposition.**
42
+
43
+ A reallocation cycle among consumers of one pool (memory of a host, CPU quota,
44
+ bandwidth) is a signed measure on the set "pool and consumers". deberka-jordan
45
+ computes:
46
+
47
+ * the Hahn decomposition of the cycle: donors and recipients;
48
+ * the Jordan plan, the netting of all proposals of a cycle with the least
49
+ volume of operations, `W = Σ |ν({i})|`; the volume in bytes is `plan_volume`
50
+ (default `pool="max"`, see the theory);
51
+ * a safe two-phase order (donors first, then recipients) that never overdraws
52
+ the pool, and an executor that waits for the memory actually freed;
53
+ * the oscillation index `κ` of a controller on the time axis and a dead band `h`
54
+ chosen by the replay of a demand trace.
55
+
56
+ The first target is KVM memory ballooning through libvirt; nothing in the core
57
+ is specific to it.
58
+
59
+ Русская версия: [README.ru.md](https://github.com/89605502155/deberka-jordan/blob/main/README.ru.md).
60
+ Documentation: [English](https://github.com/89605502155/deberka-jordan/tree/main/docs/en) ·
61
+ [Русский](https://github.com/89605502155/deberka-jordan/tree/main/docs/ru) ·
62
+ [Changelog](https://github.com/89605502155/deberka-jordan/blob/main/CHANGELOG.md) ·
63
+ [Issues](https://github.com/89605502155/deberka-jordan/issues)
64
+
65
+ The library accompanies article 2 of the series by Andrey Ferubko and Oleg Kazakov,
66
+ Bryansk State Engineering-Technological University (BGITU). Theory:
67
+ [docs/en/theory.md](https://github.com/89605502155/deberka-jordan/blob/main/docs/en/theory.md).
68
+
69
+ ## Installation
70
+
71
+ ```sh
72
+ pip install deberka-jordan # core: no dependencies
73
+ pip install "deberka-jordan[kvm]" # plus libvirt-python for live domains
74
+ ```
75
+
76
+ Requires Python 3.11 or newer.
77
+
78
+ ## Quick start
79
+
80
+ ```python
81
+ from deberka_jordan import SignedMeasure, jordan_plan, min_pool, netting_report
82
+ from deberka_jordan import recipients_first, two_phase
83
+
84
+ nu = SignedMeasure({"a": 3.0, "b": -1.0, "c": -2.0})
85
+ print(nu.total(), nu.total_variation()) # 0.0 6.0
86
+
87
+ current = {"vm1": 2000.0, "vm2": 3000.0, "vm3": 1500.0, "vm4": 2500.0} # MiB
88
+ target = {"vm1": 2600.0, "vm2": 2500.0, "vm3": 1530.0, "vm4": 2100.0}
89
+ plan = jordan_plan(current, target, pool_free=100.0, deadband=64.0)
90
+ print(plan.volume) # 900.0 MiB: 600 between consumers + 300 into the pool (pool="max")
91
+ print(min_pool(two_phase(plan), 100.0)) # 100.0: the pool never goes below its start
92
+ print(min_pool(recipients_first(plan), 100.0)) # -500.0: the wrong order overdraws it
93
+
94
+ report = netting_report([("vm1", "vm2", 300.0), ("vm2", "vm3", 300.0), ("vm3", "vm1", 100.0)])
95
+ print(report.sequential_volume, report.jordan_volume) # 700.0 200.0 (bytes)
96
+ ```
97
+
98
+ Command line, on a state file with the columns `consumer,current,target`:
99
+
100
+ deberka-jordan plan state.csv --pool 100 --deadband 64
101
+ deberka-jordan net proposals.csv --out netting.csv
102
+ deberka-jordan deadband trace.csv --h 0,64,128 --reserve 256
103
+
104
+ ## How it differs from existing packages
105
+
106
+ The Hahn and Jordan decompositions are classical measure theory (Halmos, §28–29).
107
+ PyPI has packages for matrices and for topological data analysis that carry the
108
+ same names, and none of them does what this library does:
109
+
110
+ * `jordan-form` computes the Jordan normal form of a matrix, a different object;
111
+ * `multipers` works with persistence modules in topological data analysis.
112
+
113
+ Packages for resource allocation (quota schedulers, job placement) pick targets,
114
+ they do not net a cycle of proposals into the least volume of operations, and
115
+ they do not give a safe order of operations for a pool.
116
+
117
+ | Feature | deberka-jordan | `jordan-form`, `multipers`, allocation schedulers |
118
+ |---|---|---|
119
+ | Hahn and Jordan decompositions of a finite signed measure on consumers and a pool | yes | no |
120
+ | Least-volume netting of a cycle, `W = Σ |ν({i})|`, with the sequential baseline | yes | no |
121
+ | Safe two-phase order that never overdraws the pool, with an executor that waits for freed memory | yes | no |
122
+ | Oscillation index `κ` and dead band `h` chosen on a demand trace | yes | no |
123
+ | Libvirt balloon backend (optional) | yes | no |
124
+
125
+ ## Modules
126
+
127
+ | Module | Contents |
128
+ |---|---|
129
+ | `measure` | `SignedMeasure`, `HahnDecomposition`, `JordanDecomposition` |
130
+ | `plan` | `jordan_plan`, `Plan`, `ration`, netting: `netting_report`, `netting_by_cycle` |
131
+ | `order` | `two_phase`, `recipients_first`, `shuffled`, `pairwise`, `min_pool`, `is_safe` |
132
+ | `execute` | `execute_two_phase`, `execute_simultaneous`, `RateLimitedSim` |
133
+ | `churn` | `kappa`, `replay_reserve`, `deadband_sweep`, `choose_deadband`, `cycles_bound` |
134
+ | `kvm` | `LibvirtBackend`, `host_mem_available` (optional, needs libvirt-python) |
135
+
136
+ ## When it helps
137
+
138
+ The numbers of the article are measured on the testbed and are not in this
139
+ package. The examples show the mechanisms on small inputs:
140
+ `examples/02_netting_log.py` (a ring of proposals nets 74 % of the volume, a
141
+ fan-out does not net at all) and `examples/03_two_phase_fake.py` (the executor
142
+ moves memory in the safe order).
143
+
144
+ ## Development
145
+
146
+ ```sh
147
+ uv sync
148
+ uv run ruff check . && uv run ruff format --check .
149
+ uv run mypy
150
+ uv run pytest
151
+ bash scripts/install_hooks.sh # once per clone: commit message limits
152
+ ```
153
+
154
+ Commit messages in this repository have a subject of at most 8 characters and no
155
+ body. The hook is installed by `scripts/install_hooks.sh` and runs
156
+ `scripts/check_commit_msg.py`.
157
+
158
+ ## Citation
159
+
160
+ See [CITATION.cff](https://github.com/89605502155/deberka-jordan/blob/main/CITATION.cff)
161
+ or the "Cite this repository" button on GitHub.
162
+
163
+ ## Authors
164
+
165
+ - Andrey Ferubko, [ORCID 0009-0006-5625-137X](https://orcid.org/0009-0006-5625-137X)
166
+ - Oleg Kazakov, [ORCID 0000-0001-9665-8138](https://orcid.org/0000-0001-9665-8138)
167
+
168
+ Bryansk State Engineering-Technological University (BGITU).
169
+
170
+ ## License
171
+
172
+ MIT. Copyright (c) 2026 Andrey Ferubko, Oleg Kazakov. See [LICENSE](https://github.com/89605502155/deberka-jordan/blob/main/LICENSE).
@@ -0,0 +1,138 @@
1
+ # deberka-jordan
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/deberka-jordan.svg)](https://pypi.org/project/deberka-jordan/)
4
+ [![Python](https://img.shields.io/pypi/pyversions/deberka-jordan.svg)](https://pypi.org/project/deberka-jordan/)
5
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/89605502155/deberka-jordan/blob/main/LICENSE)
6
+
7
+ **Reallocation plans for a shared resource from the Hahn–Jordan decomposition.**
8
+
9
+ A reallocation cycle among consumers of one pool (memory of a host, CPU quota,
10
+ bandwidth) is a signed measure on the set "pool and consumers". deberka-jordan
11
+ computes:
12
+
13
+ * the Hahn decomposition of the cycle: donors and recipients;
14
+ * the Jordan plan, the netting of all proposals of a cycle with the least
15
+ volume of operations, `W = Σ |ν({i})|`; the volume in bytes is `plan_volume`
16
+ (default `pool="max"`, see the theory);
17
+ * a safe two-phase order (donors first, then recipients) that never overdraws
18
+ the pool, and an executor that waits for the memory actually freed;
19
+ * the oscillation index `κ` of a controller on the time axis and a dead band `h`
20
+ chosen by the replay of a demand trace.
21
+
22
+ The first target is KVM memory ballooning through libvirt; nothing in the core
23
+ is specific to it.
24
+
25
+ Русская версия: [README.ru.md](https://github.com/89605502155/deberka-jordan/blob/main/README.ru.md).
26
+ Documentation: [English](https://github.com/89605502155/deberka-jordan/tree/main/docs/en) ·
27
+ [Русский](https://github.com/89605502155/deberka-jordan/tree/main/docs/ru) ·
28
+ [Changelog](https://github.com/89605502155/deberka-jordan/blob/main/CHANGELOG.md) ·
29
+ [Issues](https://github.com/89605502155/deberka-jordan/issues)
30
+
31
+ The library accompanies article 2 of the series by Andrey Ferubko and Oleg Kazakov,
32
+ Bryansk State Engineering-Technological University (BGITU). Theory:
33
+ [docs/en/theory.md](https://github.com/89605502155/deberka-jordan/blob/main/docs/en/theory.md).
34
+
35
+ ## Installation
36
+
37
+ ```sh
38
+ pip install deberka-jordan # core: no dependencies
39
+ pip install "deberka-jordan[kvm]" # plus libvirt-python for live domains
40
+ ```
41
+
42
+ Requires Python 3.11 or newer.
43
+
44
+ ## Quick start
45
+
46
+ ```python
47
+ from deberka_jordan import SignedMeasure, jordan_plan, min_pool, netting_report
48
+ from deberka_jordan import recipients_first, two_phase
49
+
50
+ nu = SignedMeasure({"a": 3.0, "b": -1.0, "c": -2.0})
51
+ print(nu.total(), nu.total_variation()) # 0.0 6.0
52
+
53
+ current = {"vm1": 2000.0, "vm2": 3000.0, "vm3": 1500.0, "vm4": 2500.0} # MiB
54
+ target = {"vm1": 2600.0, "vm2": 2500.0, "vm3": 1530.0, "vm4": 2100.0}
55
+ plan = jordan_plan(current, target, pool_free=100.0, deadband=64.0)
56
+ print(plan.volume) # 900.0 MiB: 600 between consumers + 300 into the pool (pool="max")
57
+ print(min_pool(two_phase(plan), 100.0)) # 100.0: the pool never goes below its start
58
+ print(min_pool(recipients_first(plan), 100.0)) # -500.0: the wrong order overdraws it
59
+
60
+ report = netting_report([("vm1", "vm2", 300.0), ("vm2", "vm3", 300.0), ("vm3", "vm1", 100.0)])
61
+ print(report.sequential_volume, report.jordan_volume) # 700.0 200.0 (bytes)
62
+ ```
63
+
64
+ Command line, on a state file with the columns `consumer,current,target`:
65
+
66
+ deberka-jordan plan state.csv --pool 100 --deadband 64
67
+ deberka-jordan net proposals.csv --out netting.csv
68
+ deberka-jordan deadband trace.csv --h 0,64,128 --reserve 256
69
+
70
+ ## How it differs from existing packages
71
+
72
+ The Hahn and Jordan decompositions are classical measure theory (Halmos, §28–29).
73
+ PyPI has packages for matrices and for topological data analysis that carry the
74
+ same names, and none of them does what this library does:
75
+
76
+ * `jordan-form` computes the Jordan normal form of a matrix, a different object;
77
+ * `multipers` works with persistence modules in topological data analysis.
78
+
79
+ Packages for resource allocation (quota schedulers, job placement) pick targets,
80
+ they do not net a cycle of proposals into the least volume of operations, and
81
+ they do not give a safe order of operations for a pool.
82
+
83
+ | Feature | deberka-jordan | `jordan-form`, `multipers`, allocation schedulers |
84
+ |---|---|---|
85
+ | Hahn and Jordan decompositions of a finite signed measure on consumers and a pool | yes | no |
86
+ | Least-volume netting of a cycle, `W = Σ |ν({i})|`, with the sequential baseline | yes | no |
87
+ | Safe two-phase order that never overdraws the pool, with an executor that waits for freed memory | yes | no |
88
+ | Oscillation index `κ` and dead band `h` chosen on a demand trace | yes | no |
89
+ | Libvirt balloon backend (optional) | yes | no |
90
+
91
+ ## Modules
92
+
93
+ | Module | Contents |
94
+ |---|---|
95
+ | `measure` | `SignedMeasure`, `HahnDecomposition`, `JordanDecomposition` |
96
+ | `plan` | `jordan_plan`, `Plan`, `ration`, netting: `netting_report`, `netting_by_cycle` |
97
+ | `order` | `two_phase`, `recipients_first`, `shuffled`, `pairwise`, `min_pool`, `is_safe` |
98
+ | `execute` | `execute_two_phase`, `execute_simultaneous`, `RateLimitedSim` |
99
+ | `churn` | `kappa`, `replay_reserve`, `deadband_sweep`, `choose_deadband`, `cycles_bound` |
100
+ | `kvm` | `LibvirtBackend`, `host_mem_available` (optional, needs libvirt-python) |
101
+
102
+ ## When it helps
103
+
104
+ The numbers of the article are measured on the testbed and are not in this
105
+ package. The examples show the mechanisms on small inputs:
106
+ `examples/02_netting_log.py` (a ring of proposals nets 74 % of the volume, a
107
+ fan-out does not net at all) and `examples/03_two_phase_fake.py` (the executor
108
+ moves memory in the safe order).
109
+
110
+ ## Development
111
+
112
+ ```sh
113
+ uv sync
114
+ uv run ruff check . && uv run ruff format --check .
115
+ uv run mypy
116
+ uv run pytest
117
+ bash scripts/install_hooks.sh # once per clone: commit message limits
118
+ ```
119
+
120
+ Commit messages in this repository have a subject of at most 8 characters and no
121
+ body. The hook is installed by `scripts/install_hooks.sh` and runs
122
+ `scripts/check_commit_msg.py`.
123
+
124
+ ## Citation
125
+
126
+ See [CITATION.cff](https://github.com/89605502155/deberka-jordan/blob/main/CITATION.cff)
127
+ or the "Cite this repository" button on GitHub.
128
+
129
+ ## Authors
130
+
131
+ - Andrey Ferubko, [ORCID 0009-0006-5625-137X](https://orcid.org/0009-0006-5625-137X)
132
+ - Oleg Kazakov, [ORCID 0000-0001-9665-8138](https://orcid.org/0000-0001-9665-8138)
133
+
134
+ Bryansk State Engineering-Technological University (BGITU).
135
+
136
+ ## License
137
+
138
+ MIT. Copyright (c) 2026 Andrey Ferubko, Oleg Kazakov. See [LICENSE](https://github.com/89605502155/deberka-jordan/blob/main/LICENSE).
@@ -0,0 +1,136 @@
1
+ # deberka-jordan
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/deberka-jordan.svg)](https://pypi.org/project/deberka-jordan/)
4
+ [![Python](https://img.shields.io/pypi/pyversions/deberka-jordan.svg)](https://pypi.org/project/deberka-jordan/)
5
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/89605502155/deberka-jordan/blob/main/LICENSE)
6
+
7
+ **Планы перераспределения общего ресурса на основе разложения Хана–Жордана.**
8
+
9
+ Цикл перераспределения между потребителями одного пула (память хоста, квота CPU,
10
+ полоса) — это знакопеременная мера на множестве «пул и потребители».
11
+ deberka-jordan вычисляет:
12
+
13
+ * разложение Хана цикла: доноры и получатели;
14
+ * план Жордана: взаимозачёт всех предложений цикла с наименьшим объёмом операций,
15
+ `W = Σ |ν({i})|`; объём в байтах даёт `plan_volume` (по умолчанию `pool="max"`,
16
+ см. теорию);
17
+ * безопасный двухфазный порядок (сначала доноры, затем получатели), который не
18
+ уводит пул в минус, и исполнитель, который ждёт фактически освобождённой памяти;
19
+ * индекс колебаний `κ` контроллера на оси времени и порог нечувствительности `h`,
20
+ выбранный проигрыванием трассы потребности.
21
+
22
+ Первая цель — баллонирование памяти ВМ KVM через libvirt; ядро библиотеки от неё
23
+ не зависит.
24
+
25
+ English version: [README.md](https://github.com/89605502155/deberka-jordan/blob/main/README.md).
26
+ Документация: [English](https://github.com/89605502155/deberka-jordan/tree/main/docs/en) ·
27
+ [Русский](https://github.com/89605502155/deberka-jordan/tree/main/docs/ru) ·
28
+ [Журнал изменений](https://github.com/89605502155/deberka-jordan/blob/main/CHANGELOG.md) ·
29
+ [Задачи](https://github.com/89605502155/deberka-jordan/issues)
30
+
31
+ Библиотека сопровождает статью 2 серии А. Ферубко и О. Д. Казакова, Брянский государственный
32
+ инженерно-технологический университет (БГИТУ). Теория:
33
+ [docs/ru/theory.md](https://github.com/89605502155/deberka-jordan/blob/main/docs/ru/theory.md).
34
+
35
+ ## Установка
36
+
37
+ ```sh
38
+ pip install deberka-jordan # ядро: без зависимостей
39
+ pip install "deberka-jordan[kvm]" # плюс libvirt-python для живых доменов
40
+ ```
41
+
42
+ Нужен Python 3.11 или новее.
43
+
44
+ ## Быстрый старт
45
+
46
+ ```python
47
+ from deberka_jordan import SignedMeasure, jordan_plan, min_pool, netting_report
48
+ from deberka_jordan import recipients_first, two_phase
49
+
50
+ nu = SignedMeasure({"a": 3.0, "b": -1.0, "c": -2.0})
51
+ print(nu.total(), nu.total_variation()) # 0.0 6.0
52
+
53
+ current = {"vm1": 2000.0, "vm2": 3000.0, "vm3": 1500.0, "vm4": 2500.0} # МиБ
54
+ target = {"vm1": 2600.0, "vm2": 2500.0, "vm3": 1530.0, "vm4": 2100.0}
55
+ plan = jordan_plan(current, target, pool_free=100.0, deadband=64.0)
56
+ print(plan.volume) # 900.0 МиБ: 600 между потребителями + 300 в пул (pool="max")
57
+ print(min_pool(two_phase(plan), 100.0)) # 100.0: безопасный порядок, пул не ниже старта
58
+ print(min_pool(recipients_first(plan), 100.0)) # -500.0: неверный порядок уводит пул в минус
59
+
60
+ report = netting_report([("vm1", "vm2", 300.0), ("vm2", "vm3", 300.0), ("vm3", "vm1", 100.0)])
61
+ print(report.sequential_volume, report.jordan_volume) # 700.0 200.0 (байты)
62
+ ```
63
+
64
+ Командная строка, на файле состояния с колонками `consumer,current,target`:
65
+
66
+ deberka-jordan plan state.csv --pool 100 --deadband 64
67
+ deberka-jordan net proposals.csv --out netting.csv
68
+ deberka-jordan deadband trace.csv --h 0,64,128 --reserve 256
69
+
70
+ ## Отличия от существующих пакетов
71
+
72
+ Разложения Хана и Жордана — классическая теория меры (Халмош, §28–29). На PyPI есть
73
+ пакеты с такими же названиями для матриц и топологического анализа данных, и ни один
74
+ из них не делает того, что делает эта библиотека:
75
+
76
+ * `jordan-form` вычисляет жорданову форму матрицы, это другой объект;
77
+ * `multipers` работает с персистентными модулями в топологическом анализе данных.
78
+
79
+ Пакеты распределения ресурсов (планировщики квот, размещение задач) выбирают цели,
80
+ но не сворачивают цикл предложений к наименьшему объёму операций и не дают безопасного
81
+ порядка операций для пула.
82
+
83
+ | Возможность | deberka-jordan | `jordan-form`, `multipers`, планировщики распределения |
84
+ |---|---|---|
85
+ | Разложения Хана и Жордана конечной знакопеременной меры на потребителях и пуле | да | нет |
86
+ | Взаимозачёт цикла с наименьшим объёмом `W = Σ |ν({i})|` и базой «поочерёдно» | да | нет |
87
+ | Безопасный двухфазный порядок без уходящего в минус пула, исполнитель ждёт освобождения памяти | да | нет |
88
+ | Индекс колебаний `κ` и порог нечувствительности `h`, выбранный на трассе потребности | да | нет |
89
+ | Бэкенд баллона libvirt (необязательный) | да | нет |
90
+
91
+ ## Модули
92
+
93
+ | Модуль | Содержимое |
94
+ |---|---|
95
+ | `measure` | `SignedMeasure`, `HahnDecomposition`, `JordanDecomposition` |
96
+ | `plan` | `jordan_plan`, `Plan`, `ration`, взаимозачёт: `netting_report`, `netting_by_cycle` |
97
+ | `order` | `two_phase`, `recipients_first`, `shuffled`, `pairwise`, `min_pool`, `is_safe` |
98
+ | `execute` | `execute_two_phase`, `execute_simultaneous`, `RateLimitedSim` |
99
+ | `churn` | `kappa`, `replay_reserve`, `deadband_sweep`, `choose_deadband`, `cycles_bound` |
100
+ | `kvm` | `LibvirtBackend`, `host_mem_available` (необязательный, нужен libvirt-python) |
101
+
102
+ ## Когда это помогает
103
+
104
+ Числа статьи получены на стенде и в этот пакет не входят. Примеры показывают механизмы
105
+ на небольших входах: `examples/02_netting_log.py` (кольцо предложений даёт взаимозачёт
106
+ 74 % объёма, веер предложений не сворачивается совсем) и `examples/03_two_phase_fake.py`
107
+ (исполнитель переносит память в безопасном порядке).
108
+
109
+ ## Разработка
110
+
111
+ ```sh
112
+ uv sync
113
+ uv run ruff check . && uv run ruff format --check .
114
+ uv run mypy
115
+ uv run pytest
116
+ bash scripts/install_hooks.sh # один раз в клоне: ограничения сообщений коммитов
117
+ ```
118
+
119
+ Сообщения коммитов в этом репозитории: тема не длиннее 8 символов, тела нет. Хук ставит
120
+ `scripts/install_hooks.sh` и запускает `scripts/check_commit_msg.py`.
121
+
122
+ ## Цитирование
123
+
124
+ См. [CITATION.cff](https://github.com/89605502155/deberka-jordan/blob/main/CITATION.cff)
125
+ или кнопку «Cite this repository» на GitHub.
126
+
127
+ ## Авторы
128
+
129
+ - Ферубко Андрей, [ORCID 0009-0006-5625-137X](https://orcid.org/0009-0006-5625-137X)
130
+ - Казаков Олег Дмитриевич, [ORCID 0000-0001-9665-8138](https://orcid.org/0000-0001-9665-8138)
131
+
132
+ Брянский государственный инженерно-технологический университет (БГИТУ).
133
+
134
+ ## Лицензия
135
+
136
+ MIT. Copyright (c) 2026 Andrey Ferubko, Oleg Kazakov. См. [LICENSE](https://github.com/89605502155/deberka-jordan/blob/main/LICENSE).
@@ -0,0 +1,80 @@
1
+ # API
2
+
3
+ All names are re-exported from the package `deberka_jordan`. Units are free but
4
+ must be consistent; the examples use MiB.
5
+
6
+ ## Measure (`deberka_jordan.measure`)
7
+
8
+ `SignedMeasure(atoms, *, tol=0.0)` is a mapping `atom -> ν({atom})`.
9
+
10
+ | Member | Meaning |
11
+ |---|---|
12
+ | `from_allocations(current, target, *, pool=None)` | Measure of the cycle; with `pool` the pool atom closes it |
13
+ | `from_transfers(transfers)` | Netting: sum of `(source, recipient, amount)` per atom |
14
+ | `nu(subset)` | `ν(A)` for a set of atoms |
15
+ | `total()`, `total_variation()` | `ν(X)` and `|ν|(X)` |
16
+ | `restrict(subset)`, `without(*atoms)` | Restrictions |
17
+ | `hahn()` | `HahnDecomposition(positive, negative)` |
18
+ | `jordan()` | `JordanDecomposition(plus, minus)`; `.variation` is `|ν|` |
19
+
20
+ `POOL` is the default name of the pool atom.
21
+
22
+ ## Plan (`deberka_jordan.plan`)
23
+
24
+ `jordan_plan(current, target, pool_free, *, deadband=0, force=(), floor=None,
25
+ ceiling=None, priority=None) -> Plan`
26
+
27
+ The plan has `donors`, `recipients`, `skipped`, `rationed`, `pool_before` and the
28
+ properties `take`, `give`, `pool_change`, `pool_after`, `volume` (bytes, `pool="max"`), `operations` (balloon operations), `peak`,
29
+ `is_empty`, and the methods `measure(pool)` and `targets(current)`.
30
+
31
+ | Function | Meaning |
32
+ |---|---|
33
+ | `ration(demand, budget, priority=None)` | Split an insufficient budget, in proportion or by priority |
34
+ | `net_transfers(transfers)` | Netted measure over consumers |
35
+ | `sequential_volume(transfers, *, factor=1.0)` | `factor · Σ amount`; the default `factor=1` gives the bytes transferred, `factor=2` the balloon operations |
36
+ | `lower_bound_volume(nu, pool=POOL)` | `W = Σ |ν({i})|` over consumers: balloon operations; in bytes `W / 2` |
37
+ | `netting_report(transfers, cycle=None, *, factor=1.0)` | `NettingReport` with `ratio` and `gain`; the Jordan volume is `(factor / 2) Σ |net|`, the gain does not depend on `factor` |
38
+ | `plan_volume(plan, *, factor=1.0, pool="max", pool_weight=0.5)` | `factor · (min(take, give) + w · |pool change|)`; `w = 1` for `pool="max"` (default, the bytes moved; `plan.volume`), `w = pool_weight` for `pool="weighted"`; `pool="weighted", pool_weight=0.5, factor=2` is `plan.operations` |
39
+ | `netting_by_cycle(rows, *, factor=1.0)` | One report per cycle of `(cycle, source, recipient, amount)` rows |
40
+
41
+ ## Orders (`deberka_jordan.order`)
42
+
43
+ `Op(consumer, delta)`. `two_phase(plan)` (donors first, the safe order),
44
+ `recipients_first(plan)`, `shuffled(plan, rng=None)`, `pairwise(transfers)`,
45
+ `pool_trajectory(ops, pool_free)`, `min_pool(ops, pool_free)`,
46
+ `is_safe(ops, pool_free, tol=1e-9)`.
47
+
48
+ ## Executors (`deberka_jordan.execute`)
49
+
50
+ A backend has `now()`, `get_actual(consumer)`, `set_target(consumer, target)` and
51
+ `sleep(dt)`.
52
+
53
+ * `execute_two_phase(backend, plan, current, *, priority=None, timeout_s=30,
54
+ poll_s=0.1, tol=1.0) -> ExecReport`
55
+ * `execute_simultaneous(backend, plan, current, ...)`: a baseline, not safe.
56
+ * `RateLimitedSim(actual, pool_free, take_rate=200, give_rate=800, reclaimable=None,
57
+ step=0.01)`: a simulated actuator with finite speed; it tracks `pool_min`.
58
+
59
+ `ExecReport` has `freed`, `given`, `duration_s`, `pool_min`, `unfinished` and
60
+ `rationed`.
61
+
62
+ ## Churn and dead band (`deberka_jordan.churn`)
63
+
64
+ | Function | Meaning |
65
+ |---|---|
66
+ | `kappa(deltas)`, `WindowStats(variation, net).kappa` | Oscillation index |
67
+ | `window_stats(times, deltas, t_now, window)`, `kappa_series(...)` | Sliding window |
68
+ | `sampled_variation(samples)` | `V = Σ |d_k − d_{k−1}|` |
69
+ | `cycles_bound(samples, h)` | `V / h`, the bound of claim 2.3 |
70
+ | `replay_reserve(demand, dt, *, reserve, deadband, interval=None, theta=64, ...)` | `ReplayResult` |
71
+ | `deadband_sweep(demand, dt, deadbands, **kwargs)` | Replay for each `h` |
72
+ | `choose_deadband(results, kappa_target=0.5)` | Smallest `h` with median `κ` at most the target |
73
+
74
+ ## Live backend (`deberka_jordan.kvm`)
75
+
76
+ `LibvirtBackend(domains, pool=None)`: `domains` maps names to objects with
77
+ `memoryStats()` and `setMemoryFlags()`; `connect(uri, names=None)` opens libvirt
78
+ (needs `libvirt-python`). `snapshot()` returns the balloon sizes in MiB,
79
+ `pool_free()` the free host memory. `host_mem_available(path)` reads
80
+ `MemAvailable` from `/proc/meminfo`.