pythagoras 0.21.4__py3-none-any.whl → 0.22.0__py3-none-any.whl

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.
@@ -1,7 +1,5 @@
1
1
  from .OK_const import *
2
2
  from .protected_portal_core_classes import *
3
3
  from .protected_decorators import *
4
- from .GPU_pre_validators import *
5
- from .python_packages_pre_validators import *
6
- from .RAM_pre_validators import *
7
4
  from .system_utils import *
5
+ from .basic_pre_validators import *
@@ -0,0 +1,47 @@
1
+ from .._070_protected_code_portals import SimplePreValidatorFn
2
+ from .OK_const import OKClass
3
+
4
+
5
+ def _at_least_X_CPU_cores_free_check(n:int)-> OKClass | None:
6
+ cores = pth.get_unused_cpu_cores()
7
+ if cores >= n-0.1:
8
+ return pth.OK
9
+
10
+
11
+ def unused_cpu(cores:int) -> SimplePreValidatorFn:
12
+ assert isinstance(cores, int)
13
+ assert cores > 0
14
+ return SimplePreValidatorFn(_at_least_X_CPU_cores_free_check).fix_kwargs(n=cores)
15
+
16
+
17
+ def _at_least_X_G_RAM_free_check(x:int)-> OKClass | None:
18
+ ram = pth.get_unused_ram_mb() / 1024
19
+ if ram >= x-0.1:
20
+ return pth.OK
21
+
22
+
23
+ def unused_ram(Gb:int) -> SimplePreValidatorFn:
24
+ assert isinstance(Gb, int)
25
+ assert Gb > 0
26
+ return SimplePreValidatorFn(_at_least_X_G_RAM_free_check).fix_kwargs(x=Gb)
27
+
28
+
29
+ def _check_python_package_and_install_if_needed(package_name)-> OKClass | None:
30
+ assert isinstance(package_name, str)
31
+ import importlib
32
+ try:
33
+ importlib.import_module(package_name)
34
+ return pth.OK
35
+ except:
36
+ pth.install_package(package_name)
37
+ return pth.OK
38
+
39
+
40
+ def installed_packages(*args) -> list[SimplePreValidatorFn]:
41
+ validators = []
42
+ for package_name in args:
43
+ assert isinstance(package_name, str)
44
+ new_validator = SimplePreValidatorFn(_check_python_package_and_install_if_needed)
45
+ new_validator = new_validator.fix_kwargs(package_name=package_name)
46
+ validators.append(new_validator)
47
+ return validators
@@ -3,4 +3,4 @@ from .._060_autonomous_code_portals import autonomous
3
3
  from .._080_pure_code_portals import pure
4
4
  from .._090_swarming_portals import SwarmingPortal
5
5
  from .._100_top_level_API import get_portal
6
- from .._070_protected_code_portals import unused_ram
6
+ from .._070_protected_code_portals import unused_ram, unused_cpu, installed_packages
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pythagoras
3
- Version: 0.21.4
3
+ Version: 0.22.0
4
4
  Summary: Planet-scale distributed computing in Python.
5
5
  Keywords: cloud,ML,AI,serverless,distributed,parallel,machine-learning,deep-learning,pythagoras
6
6
  Author: Volodymyr (Vlad) Pavlov
@@ -31,16 +31,14 @@ pythagoras/_060_autonomous_code_portals/__init__.py,sha256=6c19fffb24a93aef9587f
31
31
  pythagoras/_060_autonomous_code_portals/autonomous_decorators.py,sha256=c315b37cbc30e3929f18e29bda409aad39b6d5d840dcdb8b70c737817d346af6,3947
32
32
  pythagoras/_060_autonomous_code_portals/autonomous_portal_core_classes.py,sha256=c655406ca62ad82632bf3cae7f0b41670e6b8ca8e5f081c4c3c494f074755fb7,5342
33
33
  pythagoras/_060_autonomous_code_portals/names_usage_analyzer.py,sha256=1e0e84854ac630b204878fecde48a16739fd2663709fcee2ec0a8844f4fd4f13,7470
34
- pythagoras/_070_protected_code_portals/GPU_pre_validators.py,sha256=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855,0
35
34
  pythagoras/_070_protected_code_portals/OK_const.py,sha256=17ea314496f44b422f9936585c3bb3749c960bc779b4f74962ec04e3fa4d2494,186
36
- pythagoras/_070_protected_code_portals/RAM_pre_validators.py,sha256=4fee1d8e8dd45bb9d3b4419c968919528defceae6fe89e55ceea43ca2ceae716,1733
37
- pythagoras/_070_protected_code_portals/__init__.py,sha256=4bb7fc29f18fc5018388f6f0c0f4ec66c29185f9e1396f9d106cc8c14ad61fc4,247
35
+ pythagoras/_070_protected_code_portals/__init__.py,sha256=de95bf2b28ee110e70c3dd43ccc13cfb7131d5e643086863114cbfebf127fa67,169
36
+ pythagoras/_070_protected_code_portals/basic_pre_validators.py,sha256=742771f96dd635a8d132ac3da90fd17689fe4b38e06160c8019be4fce7ef1602,1441
38
37
  pythagoras/_070_protected_code_portals/fn_arg_names_checker.py,sha256=e858ce5099868030a39057177f93a893e13d7a210582e6ab636aaaccec898fb0,1230
39
38
  pythagoras/_070_protected_code_portals/list_flattener.py,sha256=9a54b512ad9dc201db348e7908f5ca5f36d171ae3da433511d38023a6ba8d4b5,331
40
39
  pythagoras/_070_protected_code_portals/package_manager.py,sha256=30adf8d75f55b9b2c587dc95f4aa1c2154fa9354d668af6f0d586bb42f0d5b17,2008
41
40
  pythagoras/_070_protected_code_portals/protected_decorators.py,sha256=17459a1ad08e3e95f314636e670bce1dcc992631e38d1c08c5e55f3ee1459c2c,1613
42
41
  pythagoras/_070_protected_code_portals/protected_portal_core_classes.py,sha256=899cf52300deec302c96c6d240651115957f714760e7169640206684bc6a854b,8057
43
- pythagoras/_070_protected_code_portals/python_packages_pre_validators.py,sha256=a4ff97c250cbc94ad379edcab510fe10d4d590de9733bbff437bed71c025cecb,1025
44
42
  pythagoras/_070_protected_code_portals/system_utils.py,sha256=878a22110140c852b3aaf774cb0c0023458360a4ae221fef89ff3a5d02176301,2360
45
43
  pythagoras/_070_protected_code_portals/validator_fn_classes.py,sha256=4afa4bf0629f68e4b1623003272ffd7111ac9cbb739e81fde601049d19b84269,3232
46
44
  pythagoras/_080_pure_code_portals/__init__.py,sha256=8ed33435bb03d96675537fc6a696625332f971698d56c6b22b5ca1bc9d1b4274,1856
@@ -61,7 +59,7 @@ pythagoras/_800_signatures_and_converters/random_signatures.py,sha256=c174f28c04
61
59
  pythagoras/_900_project_stats_collector/__init__.py,sha256=e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855,0
62
60
  pythagoras/_900_project_stats_collector/project_analyzer.py,sha256=d06e9d7b516cb7424ef777e70abe9d5220e09b0b19476326b8974b4dc3917f89,3506
63
61
  pythagoras/__init__.py,sha256=13b5aaf4128704dea052fc03a3a3488f1b14c3638dec45a9a29c74a4fbed7e24,1089
64
- pythagoras/core/__init__.py,sha256=6872efc506b375f46a9577e1a4a1b2e9751a71834c1acda923b6214b32ad7f6e,286
65
- pythagoras-0.21.4.dist-info/WHEEL,sha256=607c46fee47e440c91332c738096ff0f5e54ca3b0818ee85462dd5172a38e793,79
66
- pythagoras-0.21.4.dist-info/METADATA,sha256=8970f6e018587ee4b6be338fb5ab23d592a8e33276803e13da0a58af2079b3b7,4241
67
- pythagoras-0.21.4.dist-info/RECORD,,
62
+ pythagoras/core/__init__.py,sha256=ec31383ee08c1d6ce12785c5b131a021c6abca933684a6757d8ee4fdc3f0923d,318
63
+ pythagoras-0.22.0.dist-info/WHEEL,sha256=607c46fee47e440c91332c738096ff0f5e54ca3b0818ee85462dd5172a38e793,79
64
+ pythagoras-0.22.0.dist-info/METADATA,sha256=ca388d6dfb7253fcf52afb3a14f102877c06b356764ca400081b4d167e57a959,4241
65
+ pythagoras-0.22.0.dist-info/RECORD,,
@@ -1,59 +0,0 @@
1
- from .._070_protected_code_portals import SimplePreValidatorFn
2
- from .._060_autonomous_code_portals import autonomous
3
- from .OK_const import OK, OKClass
4
- from .system_utils import *
5
-
6
-
7
- # def free_ram_bytes(packed_kwargs, fn_addr, required_memory):
8
- # import psutil
9
- # mem_info = psutil.virtual_memory()
10
- # if mem_info.available >= required_memory:
11
- # return OK
12
- #
13
- #
14
- # def RAM_K(limit:int) -> AutonomousFn:
15
- # global free_ram_bytes
16
- # if not isinstance(free_ram_bytes, AutonomousFn):
17
- # free_ram_bytes = autonomous()(free_ram_bytes)
18
- # limit = int(limit/1024)
19
- # assert limit > 0
20
- # return free_ram_bytes.fix_kwargs(required_memory = limit)
21
- #
22
- #
23
- # def RAM_M(limit:int) -> AutonomousFn:
24
- # limit = int(limit/1024)
25
- # return RAM_K(limit)
26
- #
27
- #
28
- # def RAM_G(limit:int) -> AutonomousFn:
29
- # limit = int(limit/1024)
30
- # return RAM_M(limit)
31
- #
32
- #
33
- # def RAM_T(limit:int) -> AutonomousFn:
34
- # limit = int(limit/1024)
35
- # return RAM_G(limit)
36
-
37
- @autonomous()
38
- def at_least_X_G_RAM_free_check(x:int)->bool|OKClass:
39
- ram = pth.get_unused_ram_mb() / 1024
40
- if ram >= x:
41
- return pth.OK
42
- else:
43
- return False
44
-
45
- def unused_ram(Gb:int):
46
- assert isinstance(Gb, int)
47
- assert Gb > 0
48
- return SimplePreValidatorFn(at_least_X_G_RAM_free_check.fix_kwargs(x=Gb))
49
-
50
- at_least_1_G_RAM_free = unused_ram(Gb=1)
51
- at_least_2_G_RAM_free = unused_ram(Gb=2)
52
- at_least_4_G_RAM_free = unused_ram(Gb=4)
53
- at_least_8_G_RAM_free = unused_ram(Gb=8)
54
- at_least_16_G_RAM_free = unused_ram(Gb=16)
55
- at_least_32_G_RAM_free = unused_ram(Gb=32)
56
- at_least_64_G_RAM_free = unused_ram(Gb=64)
57
- at_least_128_G_RAM_free = unused_ram(Gb=128)
58
- at_least_256_G_RAM_free = unused_ram(Gb=256)
59
- at_least_512_G_RAM_free = unused_ram(Gb=512)
@@ -1,29 +0,0 @@
1
- from .._060_autonomous_code_portals import AutonomousFn, autonomous
2
- from .OK_const import OK
3
- from .package_manager import install_package
4
-
5
-
6
- def check_python_package_and_install_if_needed(packed_kwargs, package_name):
7
- assert isinstance(package_name, str)
8
- import importlib
9
- try:
10
- importlib.import_module(package_name)
11
- return OK
12
- except:
13
- install_package(package_name)
14
- return OK
15
-
16
-
17
- def installed_packages(package_names:list[str]|str) -> list[AutonomousFn]:
18
- global check_python_package_and_install_if_needed
19
- if not isinstance(check_python_package_and_install_if_needed, AutonomousFn):
20
- check_python_package_and_install_if_needed = autonomous()(
21
- check_python_package_and_install_if_needed)
22
-
23
- result = []
24
- if isinstance(package_names, str):
25
- package_names = [package_names]
26
- for package_name in package_names:
27
- result.append(check_python_package_and_install_if_needed.fix_kwargs(
28
- package_name=package_name))
29
- return result