@grnsft/if 0.1.3-beta → 0.1.3

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 (62) hide show
  1. package/README.md +2 -21
  2. package/package.json +1 -3
  3. package/src/config/units.yaml +24 -11
  4. package/tsconfig.build.tsbuildinfo +1 -1
  5. package/yarn-error.log +5431 -0
  6. package/build/config/config.d.ts +0 -12
  7. package/build/config/config.js +0 -54
  8. package/build/config/index.d.ts +0 -2
  9. package/build/config/index.js +0 -8
  10. package/build/config/strings.d.ts +0 -19
  11. package/build/config/strings.js +0 -34
  12. package/build/index.d.ts +0 -2
  13. package/build/index.js +0 -53
  14. package/build/lib/models-universe.d.ts +0 -36
  15. package/build/lib/models-universe.js +0 -113
  16. package/build/lib/observatory.d.ts +0 -20
  17. package/build/lib/observatory.js +0 -31
  18. package/build/lib/planet-aggregator.d.ts +0 -6
  19. package/build/lib/planet-aggregator.js +0 -35
  20. package/build/lib/supercomputer.d.ts +0 -37
  21. package/build/lib/supercomputer.js +0 -148
  22. package/build/models/index.d.ts +0 -1
  23. package/build/models/index.js +0 -6
  24. package/build/models/time-sync.d.ts +0 -55
  25. package/build/models/time-sync.js +0 -235
  26. package/build/types/helpers.d.ts +0 -1
  27. package/build/types/helpers.js +0 -3
  28. package/build/types/impl.d.ts +0 -45
  29. package/build/types/impl.js +0 -5
  30. package/build/types/model-interface.d.ts +0 -14
  31. package/build/types/model-interface.js +0 -3
  32. package/build/types/models-universe.d.ts +0 -23
  33. package/build/types/models-universe.js +0 -3
  34. package/build/types/planet-aggregator.d.ts +0 -6
  35. package/build/types/planet-aggregator.js +0 -3
  36. package/build/types/process-args.d.ts +0 -7
  37. package/build/types/process-args.js +0 -3
  38. package/build/types/supercomputer.d.ts +0 -4
  39. package/build/types/supercomputer.js +0 -3
  40. package/build/types/time-sync.d.ts +0 -9
  41. package/build/types/time-sync.js +0 -3
  42. package/build/types/units-dealer.d.ts +0 -3
  43. package/build/types/units-dealer.js +0 -3
  44. package/build/types/units.d.ts +0 -11
  45. package/build/types/units.js +0 -37
  46. package/build/util/args.d.ts +0 -8
  47. package/build/util/args.js +0 -58
  48. package/build/util/errors.d.ts +0 -6
  49. package/build/util/errors.js +0 -25
  50. package/build/util/helpers.d.ts +0 -4
  51. package/build/util/helpers.js +0 -18
  52. package/build/util/units-dealer.d.ts +0 -10
  53. package/build/util/units-dealer.js +0 -32
  54. package/build/util/validations.d.ts +0 -29
  55. package/build/util/validations.js +0 -80
  56. package/build/util/yaml.d.ts +0 -12
  57. package/build/util/yaml.js +0 -36
  58. package/examples/impls/test/time-sync.yml +0 -75
  59. package/examples/ompls/test/time-sync.yml +0 -255
  60. package/examples/ompls/time-sync.yml +0 -212
  61. package/hack-banner.png +0 -0
  62. package/src/models/README.md +0 -266
@@ -1,266 +0,0 @@
1
- # Time sync
2
-
3
- Time sync standardizes the start time, end time and temporal resolution of all output data across an entire graph.
4
-
5
- ## Parameters
6
-
7
- ### Model config
8
- The following should be defined in the model initialization:
9
-
10
- - `start-time`: global start time as ISO 8061 string
11
- - `stop`: global end time as ISO 8061 string
12
- - `interval`: temporal resolution in seconds
13
-
14
- ### Inputs:
15
-
16
- - `inputs`: an array of observations
17
-
18
- ### Returns
19
-
20
- - `inputs`: time-synchronized version of the graph
21
-
22
-
23
- ## Concept
24
-
25
- ### Overview
26
-
27
- A manifest file for a graph might contain many nodes each representing some different part of an application's stack or even different applications running on different machines. It is therefore common to have time series data in each component that is not directly comparable to other components either because the temporal resolution of the data is different, they cover different periods, or there are gaps in some records (e.g. some apps might burst but then go dormant, while others run continuously). This makes post-hoc visualization, analysis and aggregation of data from groups of nodes difficult to achieve. To address this, we created a time synchronization model that takes in non-uniform times series and snaps them all to a regular timeline with uniform start time, end time and temporal resolution.
28
-
29
- We do this by implementing the following logic:
30
-
31
- - Shift readings to nearest whole seconds
32
- - Upsample the time series to a base resolution (1s)
33
- - Resample to desired resolution by batching 1s entries
34
- - Extrapolate or trim to ensure all time series share global start and end dates
35
-
36
- The next section explains each stage in more detail.
37
-
38
- ### Details
39
-
40
- #### Upsampling rules
41
-
42
- A set of `inputs` is naturally a time series because all `observations` include a `timestamp` and a `duration`, measured in seconds.
43
- For each `observation` in `inputs` we check whether the duration is greater than 1 second. If `duration` is greater than 1 second, we create N new `observation` objects, where N is equal to `duration`. This means we have an `observation` for every second between the initial timestamp and the end of the observation period. Each new object receives a timestamp incremented by one second.
44
-
45
- This looks as follows:
46
-
47
- ```
48
- [{timestamp: 2023-12-12T00:00:00.000Z, duration: 5}]
49
-
50
- # becomes
51
- [
52
- {timestamp: 2023-12-12T00:00:01.000Z, duration: 5}
53
- {timestamp: 2023-12-12T00:00:02.000Z, duration: 5}
54
- {timestamp: 2023-12-12T00:00:03.000Z, duration: 5}
55
- {timestamp: 2023-12-12T00:00:04.000Z, duration: 5}
56
- {timestamp: 2023-12-12T00:00:05.000Z, duration: 5}
57
- ]
58
- ```
59
-
60
- Each `observation` actually includes many key-value pairs. The precise content of the `observation` is not known until runtime because it depends on which models have been included in the pipeline. Different values have to be treated differently when we upsample in time. The method we use to upsample depends on the `aggregation-method` defined for each key in `units.yml`.
61
-
62
- If the right way to aggregate a value is to sum it, then the right way to upsample it is to divide by `duration`, effectively spreading the total out evenly across the new, higher resolution, `observations` so that the total across the same bucket of time is unchanged (i.e. if the total for some value is 10 when there is one entry with `duration = 10s`, then the total should still be 10 when there are 10 entries each witch `duration = 1s`).
63
-
64
- On the other hand, if the right way to aggregate a value is to take its average over some time period, the value should be copied unchanged into the newly upsampled `observations`. This is appropriate for values that are proportional or percentages, such as `cpu-util`. Treating these values as constants means the average over the `duration` for an observation is identical whether you consider the initial `observation` or the upsampled set of N `observation`s.
65
-
66
- Constants can simply be copied as-is, because they are constants. Examples might be the `grid-carbon-intensity` - this value does not change depending on how frequently you observe it.
67
-
68
- Therefore, we apply this logic and the resulting flow looks as follows (the `aggregation-method` for `carbon` and `energy` is `sum`, `grid-carbon-intensity` is a constant and `cpu-util` is expressed as a percentage):
69
-
70
- ```
71
- [{timestamp: 2023-12-12T00:00:00.000Z, duration: 5, cpu-util: 12, carbon: 5, energy: 10, grid-carbon-intensity: 471}]
72
-
73
- # becomes
74
-
75
- [
76
- {timestamp: 2023-12-12T00:00:00.000Z, duration: 1, cpu-util: 12, carbon: 1, energy: 2, grid-carbon-intensity: 471},
77
- {timestamp: 2023-12-12T00:00:01.000Z, duration: 1, cpu-util: 12, carbon: 1, energy: 2, grid-carbon-intensity: 471},
78
- {timestamp: 2023-12-12T00:00:02.000Z, duration: 1, cpu-util: 12, carbon: 1, energy: 2, grid-carbon-intensity: 471},
79
- {timestamp: 2023-12-12T00:00:03.000Z, duration: 1, cpu-util: 12, carbon: 1, energy: 2, grid-carbon-intensity: 471},
80
- {timestamp: 2023-12-12T00:00:04.000Z, duration: 1, cpu-util: 12, carbon: 1, energy: 2, grid-carbon-intensity: 471},
81
- {timestamp: 2023-12-12T00:00:05.000Z, duration: 1, cpu-util: 12, carbon: 1, energy: 2, grid-carbon-intensity: 471}
82
- ]
83
- ```
84
-
85
- The end result is that for each `observation`, we upsample the time series to yield 1 second resolution data between `timestamp` and `timestamp + duration`.
86
-
87
- #### Gap-filling
88
-
89
- Sometimes there might be discontinuities in the time series between one `observation` and another. For example we might have two `observations` in a set of `inputs` that have timestamps spaced 10 seconds apart, but the `duration` of the first `observation` is only 5 seconds. in this case, 5 seconds of data are unaccounted for and create a discontinuity in the time series.
90
-
91
- To solve this problem, for all but the first `observation` in the `inputs` array, we grab the `timestamp` and `duration` from the previous `observation` and check that `timestamp[N] + duration[N] == timestamp[N+1]`. If this condition is not satisfied, we backfill the missing data with a "zero-observation" which is identical to the surrounding observations except any values whose `aggregation-method` is `sum` are set to zero. This is equivalent to assuming that when there is no data available, the app being monitored is switched off.
92
-
93
- The end result of this gap-filling is that we have continuous 1 second resolution data that can be resampled to a new temporal resolution.
94
-
95
- ```
96
- [
97
- {timestamp: 2023-12-12T00:00:00.000Z, duration: 5, cpu-util: 12, carbon: 5, energy: 10, grid-carbon-intensity: 471},
98
- {timestamp: 2023-12-12T00:00:08.000Z, duration: 2, cpu-util: 12, carbon: 5, energy: 10, grid-carbon-intensity: 471}
99
- ]
100
-
101
- # There are 2 seconds of missing data between the end of timestamp[0] + duration, and timestamp[1]
102
- # After expansion and infilling, the array becomes:
103
-
104
- [
105
- {timestamp: 2023-12-12T00:00:00.000Z, duration: 1, cpu-util: 12, carbon: 1, energy: 2, grid-carbon-intensity: 471},
106
- {timestamp: 2023-12-12T00:00:01.000Z, duration: 1, cpu-util: 12, carbon: 1, energy: 2, grid-carbon-intensity: 471},
107
- {timestamp: 2023-12-12T00:00:02.000Z, duration: 1, cpu-util: 12, carbon: 1, energy: 2, grid-carbon-intensity: 471},
108
- {timestamp: 2023-12-12T00:00:03.000Z, duration: 1, cpu-util: 12, carbon: 1, energy: 2, grid-carbon-intensity: 471},
109
- {timestamp: 2023-12-12T00:00:04.000Z, duration: 1, cpu-util: 12, carbon: 1, energy: 2, grid-carbon-intensity: 471},
110
- {timestamp: 2023-12-12T00:00:05.000Z, duration: 1, cpu-util: 12, carbon: 1, energy: 2, grid-carbon-intensity: 471},
111
- {timestamp: 2023-12-12T00:00:06.000Z, duration: 1, cpu-util: 0, carbon: 0, energy: 0, grid-carbon-intensity: 471},
112
- {timestamp: 2023-12-12T00:00:07.000Z, duration: 1, cpu-util: 0, carbon: 0, energy: 0, grid-carbon-intensity: 471},
113
- {timestamp: 2023-12-12T00:00:08.000Z, duration: 1, cpu-util: 12, carbon: 2.5, energy: 5, grid-carbon-intensity: 471},
114
- {timestamp: 2023-12-12T00:00:09.000Z, duration: 1, cpu-util: 12, carbon: 2.5, energy: 5, grid-carbon-intensity: 471}
115
- ]
116
- ```
117
-
118
- #### Trimming and padding
119
-
120
- To ensure parity across all the components in a graph, we need to synchronize the start and end times for all time series. To do this, we pass the `time-sync` model plugin some global config: `startTime`, `endTime` and `interval`. The `startTime` is the timestamp where *all* input arrays across the entire graph should begin, and `endTime` is the timestamp where *all* input arrays across the entire graph should end. `interval` is the time resolution we ultimately want to resample to.
121
-
122
- To synchronize the time series start and end we check the first element of `inputs` for each node in the graph and determine whether it is earlier, later or equal to the global start time. If it is equal then no action is required. If the `input` start time is earlier than the global start time, we simply discard entries from the front of the array until the start times are aligned. If the `input` start time is after the global start time, then we pad with our "zero-observation" object - one for every second separating the global start time from the `input` start time. The same process is repeated for the end time - we either trim away `input` data or pad it out with "zero-observation" objects.
123
-
124
- For example, for `startTime = 2023-12-12T00:00:00.000Z` and `endTime = 2023-12-12T00:00:15.000Z`:
125
-
126
- ```
127
- [
128
- {timestamp: 2023-12-12T00:00:05.000Z, duration: 5, cpu-util: 12, carbon: 5, energy: 10, grid-carbon-intensity: 471},
129
- ]
130
-
131
- # There are 5 seconds missing from the start and end. After padding, the array becomes:
132
-
133
- [
134
- {timestamp: 2023-12-12T00:00:00.000Z, duration: 1, cpu-util: 0, carbon: 0, energy: 0, grid-carbon-intensity: 471},
135
- {timestamp: 2023-12-12T00:00:01.000Z, duration: 1, cpu-util: 0, carbon: 0, energy: 0, grid-carbon-intensity: 471},
136
- {timestamp: 2023-12-12T00:00:02.000Z, duration: 1, cpu-util: 0, carbon: 0, energy: 0, grid-carbon-intensity: 471},
137
- {timestamp: 2023-12-12T00:00:03.000Z, duration: 1, cpu-util: 0, carbon: 0, energy: 0, grid-carbon-intensity: 471},
138
- {timestamp: 2023-12-12T00:00:04.000Z, duration: 1, cpu-util: 0, carbon: 0, energy: 0, grid-carbon-intensity: 471},
139
- {timestamp: 2023-12-12T00:00:05.000Z, duration: 1, cpu-util: 12, carbon: 1, energy: 2, grid-carbon-intensity: 471},
140
- {timestamp: 2023-12-12T00:00:06.000Z, duration: 1, cpu-util: 12, carbon: 1, energy: 2, grid-carbon-intensity: 471},
141
- {timestamp: 2023-12-12T00:00:07.000Z, duration: 1, cpu-util: 12, carbon: 1, energy: 2, grid-carbon-intensity: 471},
142
- {timestamp: 2023-12-12T00:00:08.000Z, duration: 1, cpu-util: 12, carbon: 1, energy: 2, grid-carbon-intensity: 471},
143
- {timestamp: 2023-12-12T00:00:09.000Z, duration: 1, cpu-util: 12, carbon: 1, energy: 2, grid-carbon-intensity: 471},
144
- {timestamp: 2023-12-12T00:00:10.000Z, duration: 1, cpu-util: 0, carbon: 0, energy: 0, grid-carbon-intensity: 471},
145
- {timestamp: 2023-12-12T00:00:11.000Z, duration: 1, cpu-util: 0, carbon: 0, energy: 0, grid-carbon-intensity: 471},
146
- {timestamp: 2023-12-12T00:00:12.000Z, duration: 1, cpu-util: 0, carbon: 0, energy: 0, grid-carbon-intensity: 471},
147
- {timestamp: 2023-12-12T00:00:13.000Z, duration: 1, cpu-util: 0, carbon: 0, energy: 0, grid-carbon-intensity: 471},
148
- {timestamp: 2023-12-12T00:00:14.000Z, duration: 1, cpu-util: 0, carbon: 0, energy: 0, grid-carbon-intensity: 471},
149
-
150
- ]
151
- ```
152
-
153
-
154
- #### Resampling rules
155
-
156
- Now we have synchronized, continuous, high resolution time series data, we can resample. To achieve this, we use `interval`, which sets the global temporal resolution for the final, processed time series. `intervalk` is expressed in units of seconds, which means we can simply batch `observations` together in groups of size `interval`. For each value in each object we either sum, average or copy the values into one single summary object representing each time bucket of size `interval` depending on their `aggregation-method` defined in `units.yaml`. The returned array is the final, synchronized time series at the desired temporal resolution.
157
-
158
- ### Assumptions and limitations
159
-
160
- To do time synchronization, we assume:
161
-
162
- - There is no environmental impact for an application when there is no data available.
163
- - Evenly distributing the total for a `duration` across higher resolution `observations` is appropriate, as opposed to having some non-uniform distribution.
164
-
165
-
166
- ## Typescript implementation
167
-
168
- To run the model, you must first create an instance of `SciModel` and call
169
- its `configure()` method. Then, you can call `execute()` to return `sci`.
170
-
171
- ```typescript
172
- const timeSyncModel = new TimeSyncModel();
173
- timeSyncModel.configure('name', {
174
- 'start-time': '2023-12-12T00:00:00.000Z',
175
- 'end-time': '2023-12-12T00:00:30.000Z',
176
- interval: 10
177
- })
178
- const results = timeSyncModel.execute([
179
- {
180
- timestamp: 2023-12-12T00:00:00.000Z
181
- duration: 10
182
- cpu-util: 10
183
- carbon: 100
184
- energy: 100
185
- requests: 300
186
- },
187
- {
188
- timestamp: 2023-12-12T00:00:10.000Z
189
- duration: 10
190
- cpu-util: 20
191
- carbon: 100,
192
- energy: 100,
193
- requests: 380
194
- }
195
- ])
196
- ```
197
-
198
- ## Example impl
199
-
200
- IEF users will typically call the model as part of a pipeline defined in an `impl`
201
- file. In this case, instantiating and configuring the model is handled by
202
- `impact-engine` and does not have to be done explicitly by the user.
203
- The following is an example `impl` that calls `time-sync`:
204
-
205
- ```yaml
206
- name: time-sync-demo
207
- description: impl with 2 levels of nesting with non-uniform timing of observations
208
- tags:
209
- initialize:
210
- models:
211
- - name: teads-curve
212
- model: TeadsCurveModel
213
- path: "@grnsft/if-unofficial-models"
214
- - name: sci-e
215
- model: SciEModel
216
- path: "@grnsft/if-models"
217
- - name: sci-m
218
- path: "@grnsft/if-models"
219
- model: SciMModel
220
- - name: sci-o
221
- model: SciOModel
222
- path: "@grnsft/if-models"
223
- - name: time-synchronization
224
- model: TimeSyncModel
225
- path: builtin
226
- config:
227
- start-time: 2023-12-12T00:00:00.000Z # ISO timestamp
228
- end-time: 2023-12-12T00:01:00.000Z # ISO timestamp
229
- interval: 5 # seconds
230
- graph:
231
- children:
232
- child: # an advanced grouping node
233
- pipeline:
234
- - teads-curve
235
- - sci-e
236
- - sci-m
237
- - sci-o
238
- - time-synchronization
239
- config:
240
- teads-curve:
241
- thermal-design-power: 65
242
- sci-m:
243
- total-embodied-emissions: 251000 # gCO2eq
244
- time-reserved: 3600 # 1 hour in s
245
- expected-lifespan: 126144000 # 4 years in seconds
246
- resources-reserved: 1
247
- total-resources: 1
248
- sci-o:
249
- grid-carbon-intensity: 457 # gCO2/kwh
250
- children:
251
- child-1:
252
- inputs:
253
- - timestamp: 2023-12-12T00:00:00.000Z
254
- duration: 10
255
- cpu-util: 10
256
- carbon: 100
257
- energy: 100
258
- requests: 300
259
- - timestamp: 2023-12-12T00:00:10.000Z
260
- duration: 10
261
- cpu-util: 20
262
- carbon: 200
263
- energy: 200
264
- requests: 380
265
-
266
- ```