unaiverse 0.1.6__cp314-cp314-win_amd64.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.

Potentially problematic release.


This version of unaiverse might be problematic. Click here for more details.

Files changed (50) hide show
  1. unaiverse/__init__.py +19 -0
  2. unaiverse/agent.py +2008 -0
  3. unaiverse/agent_basics.py +1846 -0
  4. unaiverse/clock.py +191 -0
  5. unaiverse/dataprops.py +1209 -0
  6. unaiverse/hsm.py +1880 -0
  7. unaiverse/modules/__init__.py +18 -0
  8. unaiverse/modules/cnu/__init__.py +17 -0
  9. unaiverse/modules/cnu/cnus.py +536 -0
  10. unaiverse/modules/cnu/layers.py +261 -0
  11. unaiverse/modules/cnu/psi.py +60 -0
  12. unaiverse/modules/hl/__init__.py +15 -0
  13. unaiverse/modules/hl/hl_utils.py +411 -0
  14. unaiverse/modules/networks.py +1509 -0
  15. unaiverse/modules/utils.py +680 -0
  16. unaiverse/networking/__init__.py +16 -0
  17. unaiverse/networking/node/__init__.py +18 -0
  18. unaiverse/networking/node/connpool.py +1261 -0
  19. unaiverse/networking/node/node.py +2223 -0
  20. unaiverse/networking/node/profile.py +446 -0
  21. unaiverse/networking/node/tokens.py +79 -0
  22. unaiverse/networking/p2p/__init__.py +198 -0
  23. unaiverse/networking/p2p/go.mod +127 -0
  24. unaiverse/networking/p2p/go.sum +548 -0
  25. unaiverse/networking/p2p/golibp2p.py +18 -0
  26. unaiverse/networking/p2p/golibp2p.pyi +135 -0
  27. unaiverse/networking/p2p/lib.go +2714 -0
  28. unaiverse/networking/p2p/lib.go.sha256 +1 -0
  29. unaiverse/networking/p2p/lib_types.py +312 -0
  30. unaiverse/networking/p2p/message_pb2.py +63 -0
  31. unaiverse/networking/p2p/messages.py +265 -0
  32. unaiverse/networking/p2p/mylogger.py +77 -0
  33. unaiverse/networking/p2p/p2p.py +929 -0
  34. unaiverse/networking/p2p/proto-go/message.pb.go +616 -0
  35. unaiverse/networking/p2p/unailib.cp314-win_amd64.pyd +0 -0
  36. unaiverse/streamlib/__init__.py +15 -0
  37. unaiverse/streamlib/streamlib.py +210 -0
  38. unaiverse/streams.py +770 -0
  39. unaiverse/utils/__init__.py +16 -0
  40. unaiverse/utils/ask_lone_wolf.json +27 -0
  41. unaiverse/utils/lone_wolf.json +19 -0
  42. unaiverse/utils/misc.py +305 -0
  43. unaiverse/utils/sandbox.py +293 -0
  44. unaiverse/utils/server.py +435 -0
  45. unaiverse/world.py +175 -0
  46. unaiverse-0.1.6.dist-info/METADATA +365 -0
  47. unaiverse-0.1.6.dist-info/RECORD +50 -0
  48. unaiverse-0.1.6.dist-info/WHEEL +5 -0
  49. unaiverse-0.1.6.dist-info/licenses/LICENSE +43 -0
  50. unaiverse-0.1.6.dist-info/top_level.txt +1 -0
@@ -0,0 +1,210 @@
1
+ """
2
+ █████ █████ ██████ █████ █████ █████ █████ ██████████ ███████████ █████████ ██████████
3
+ ░░███ ░░███ ░░██████ ░░███ ░░███ ░░███ ░░███ ░░███░░░░░█░░███░░░░░███ ███░░░░░███░░███░░░░░█
4
+ ░███ ░███ ░███░███ ░███ ██████ ░███ ░███ ░███ ░███ █ ░ ░███ ░███ ░███ ░░░ ░███ █ ░
5
+ ░███ ░███ ░███░░███░███ ░░░░░███ ░███ ░███ ░███ ░██████ ░██████████ ░░█████████ ░██████
6
+ ░███ ░███ ░███ ░░██████ ███████ ░███ ░░███ ███ ░███░░█ ░███░░░░░███ ░░░░░░░░███ ░███░░█
7
+ ░███ ░███ ░███ ░░█████ ███░░███ ░███ ░░░█████░ ░███ ░ █ ░███ ░███ ███ ░███ ░███ ░ █
8
+ ░░████████ █████ ░░█████░░████████ █████ ░░███ ██████████ █████ █████░░█████████ ██████████
9
+ ░░░░░░░░ ░░░░░ ░░░░░ ░░░░░░░░ ░░░░░ ░░░ ░░░░░░░░░░ ░░░░░ ░░░░░ ░░░░░░░░░ ░░░░░░░░░░
10
+ A Collectionless AI Project (https://collectionless.ai)
11
+ Registration/Login: https://unaiverse.io
12
+ Code Repositories: https://github.com/collectionlessai/
13
+ Main Developers: Stefano Melacci (Project Leader), Christian Di Maio, Tommaso Guidi
14
+ """
15
+ import math
16
+ import torch
17
+ from unaiverse.streams import BufferedDataStream, DataProps
18
+
19
+
20
+ class AllHotLabelStream(BufferedDataStream):
21
+ """
22
+ A buffered stream that simply repeat a single-element tensor valued "ones" (float), associated to some text labels
23
+ """
24
+
25
+ def __init__(self, labels: list[str],
26
+ device: torch.device = torch.device('cpu')):
27
+ super().__init__(props=DataProps(name=AllHotLabelStream.__name__,
28
+ data_type="tensor",
29
+ data_desc="dummy stream",
30
+ tensor_shape=(1, len(labels)),
31
+ tensor_labels=labels,
32
+ tensor_dtype=str(torch.float),
33
+ tensor_labeling_rule="geq0.5"),
34
+ is_static=True)
35
+
36
+ self.set(torch.ones((1, len(labels)), dtype=torch.float32, device=device))
37
+ self.restart()
38
+
39
+
40
+ class Random(BufferedDataStream):
41
+
42
+ def __init__(self, std: float, shape: tuple[int] | None = (1,),
43
+ device: torch.device = torch.device('cpu')):
44
+ super().__init__(props=DataProps(name="rand",
45
+ data_type="tensor",
46
+ data_desc="stream of random numbers",
47
+ tensor_shape=shape,
48
+ tensor_dtype=str(torch.float)))
49
+ self.std = std
50
+ self.device = device
51
+ self.restart()
52
+
53
+ def __getitem__(self, idx: int) -> torch.Tensor | None:
54
+ y = self.std * torch.rand(self.props.tensor_shape, device=self.device)
55
+ return self.props.adapt_tensor_to_tensor_labels(y), self.clock.get_cycle() - self.first_cycle
56
+
57
+
58
+ class Sin(BufferedDataStream):
59
+
60
+ def __init__(self, freq: float, phase: float, delta: float,
61
+ device: torch.device = torch.device('cpu')):
62
+ super().__init__(props=DataProps(name="sin",
63
+ data_type="tensor",
64
+ data_desc="stream of samples from the sin function",
65
+ tensor_shape=(1, 1),
66
+ tensor_dtype=str(torch.float)))
67
+ self.freq = freq
68
+ self.phase = phase
69
+ self.period = 1. / self.freq
70
+ self.delta = delta
71
+ self.device = device
72
+ self.restart()
73
+
74
+ def __getitem__(self, idx: int) -> torch.Tensor | None:
75
+ t = idx * self.delta + self.phase * self.period
76
+ y = torch.sin(torch.tensor([[2. * math.pi * self.freq * t]], device=self.device))
77
+ return self.props.adapt_tensor_to_tensor_labels(y), self.clock.get_cycle() - self.first_cycle
78
+
79
+
80
+ class Square(BufferedDataStream):
81
+
82
+ def __init__(self, freq: float, ampl: float, phase: float, delta: float,
83
+ device: torch.device = torch.device('cpu')):
84
+ super().__init__(props=DataProps(name="square",
85
+ data_type="tensor",
86
+ data_desc="stream of samples from the square function",
87
+ tensor_shape=(1, 1),
88
+ tensor_dtype=str(torch.float)))
89
+ self.freq = freq
90
+ self.ampl = ampl
91
+ self.phase = phase
92
+ self.period = 1. / self.freq
93
+ self.delta = delta
94
+ self.device = device
95
+ self.restart()
96
+
97
+ def __getitem__(self, idx: int) -> torch.Tensor | None:
98
+ t = idx * self.delta + self.phase * self.period
99
+ y = self.ampl * torch.tensor([[(-1.) ** (math.floor(2. * self.freq * t))]], device=self.device)
100
+ return self.props.adapt_tensor_to_tensor_labels(y), self.clock.get_cycle() - self.first_cycle
101
+
102
+
103
+ class CombSin(BufferedDataStream):
104
+
105
+ def __init__(self, f_cap: float | list, c_cap: float | list, order: int, delta: float,
106
+ device: torch.device = torch.device('cpu')):
107
+ super().__init__(props=DataProps(name="combsin",
108
+ data_type="tensor",
109
+ data_desc="stream of samples from combined sin functions",
110
+ tensor_shape=(1, 1),
111
+ tensor_dtype=str(torch.float)))
112
+ if isinstance(f_cap, float):
113
+ self.freqs = f_cap * torch.rand(order)
114
+ elif isinstance(f_cap, list):
115
+ self.freqs = torch.tensor(f_cap)
116
+ else:
117
+ raise Exception(f"expected float or list for f_cap, not {type(f_cap)}")
118
+ self.phases = torch.zeros_like(self.freqs)
119
+ if isinstance(c_cap, float):
120
+ self.coeffs = c_cap * (2 * torch.rand(order) - 1)
121
+ elif isinstance(c_cap, list):
122
+ self.coeffs = torch.tensor(c_cap)
123
+ else:
124
+ raise Exception(f"expected float or list for c_cap, not {type(c_cap)}")
125
+
126
+ # Check all the dimensions
127
+ assert len(self.coeffs) == len(self.freqs), \
128
+ (f"specify the same number of coefficients and frequencies (got {len(self.coeffs)} "
129
+ f"and {len(self.freqs)} respectively).")
130
+
131
+ self.delta = delta
132
+ self.device = device
133
+ self.restart()
134
+
135
+ def __getitem__(self, idx: int) -> torch.Tensor | None:
136
+ t = idx * self.delta
137
+ y = torch.sum(self.coeffs * torch.sin(2 * math.pi * self.freqs * t + self.phases)).view(1, 1)
138
+ return self.props.adapt_tensor_to_tensor_labels(y), self.clock.get_cycle() - self.first_cycle
139
+
140
+
141
+ class SmoothHFHA(CombSin):
142
+ FEATURES = ['3sin', 'hf', 'ha']
143
+
144
+ def __init__(self, device: torch.device = torch.device('cpu')):
145
+ freqs = [0.11, 0.07, 0.05]
146
+ coeffs = [0.8, 0.16, 0.16]
147
+ super().__init__(f_cap=freqs, c_cap=coeffs, order=3, delta=0.1, device=device)
148
+ self.props.set_name("smoHfHa")
149
+
150
+
151
+ class SmoothHFLA(CombSin):
152
+ FEATURES = ['3sin', 'hf', 'la']
153
+
154
+ def __init__(self, device: torch.device = torch.device('cpu')):
155
+ freqs = [0.11, 0.07, 0.05]
156
+ coeffs = [0.4, 0.08, 0.08]
157
+ super().__init__(f_cap=freqs, c_cap=coeffs, order=3, delta=0.1, device=device)
158
+ self.props.set_name("smoHfLa")
159
+
160
+
161
+ class SmoothLFLA(CombSin):
162
+ FEATURES = ['3sin', 'lf', 'la']
163
+
164
+ def __init__(self, device: torch.device = torch.device('cpu')):
165
+ freqs = [0.11, 0.07, 0.05]
166
+ coeffs = [0.08, 0.08, 0.4]
167
+ super().__init__(f_cap=freqs, c_cap=coeffs, order=3, delta=0.1, device=device)
168
+ self.props.set_name("smoLfLa")
169
+
170
+
171
+ class SmoothLFHA(CombSin):
172
+ FEATURES = ['3sin', 'lf', 'ha']
173
+
174
+ def __init__(self, device: torch.device = torch.device('cpu')):
175
+ freqs = [0.11, 0.07, 0.05]
176
+ coeffs = [0.16, 0.16, 0.8]
177
+ super().__init__(f_cap=freqs, c_cap=coeffs, order=3, delta=0.1, device=device)
178
+ self.props.set_name("smoLfHa")
179
+
180
+
181
+ class SquareHFHA(Square):
182
+ FEATURES = ['square', 'hf', 'ha']
183
+
184
+ def __init__(self, device: torch.device = torch.device('cpu')):
185
+ super().__init__(freq=0.06, phase=0.5, ampl=1.0, delta=0.1, device=device)
186
+ self.props.set_name("squHfHa")
187
+
188
+
189
+ class SquareHFLA(Square):
190
+ FEATURES = ['square', 'hf', 'la']
191
+
192
+ def __init__(self, device: torch.device = torch.device('cpu')):
193
+ super().__init__(freq=0.06, phase=0.5, ampl=0.5, delta=0.1, device=device)
194
+ self.props.set_name("squHfLa")
195
+
196
+
197
+ class SquareLFHA(Square):
198
+ FEATURES = ['square', 'lf', 'ha']
199
+
200
+ def __init__(self, device: torch.device = torch.device('cpu')):
201
+ super().__init__(freq=0.03, phase=0.5, ampl=1.0, delta=0.1, device=device)
202
+ self.props.set_name("squLfHa")
203
+
204
+
205
+ class SquareLFLA(Square):
206
+ FEATURES = ['square', 'lf', 'la']
207
+
208
+ def __init__(self, device: torch.device = torch.device('cpu')):
209
+ super().__init__(freq=0.03, phase=0.5, ampl=0.5, delta=0.1, device=device)
210
+ self.props.set_name("squLfLa")