wasm4pm 26.6.10

High-performance process mining algorithms in WebAssembly for JavaScript/TypeScript
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
/**
 * Configuration Schema for wasm4pm Engine
 * Defines all configuration structures, validation, and execution profiles
 */
import { Wasm4pmError, ErrorCode, ErrorRecovery } from './errors.js';
/**
 * Supported data source formats
 */
export var SourceFormat;
(function (SourceFormat) {
  SourceFormat['XES'] = 'xes';
  SourceFormat['CSV'] = 'csv';
  SourceFormat['JSON'] = 'json';
  SourceFormat['PARQUET'] = 'parquet';
  SourceFormat['ARROW'] = 'arrow';
})(SourceFormat || (SourceFormat = {}));
/**
 * Execution profile names and their characteristics
 */
export var ExecutionProfile;
(function (ExecutionProfile) {
  /** Fast discovery: DFG + statistics (1-5ms per 100 events) */
  ExecutionProfile['FAST'] = 'fast';
  /** Balanced: Alpha++, stats, conformance, variants (20-50ms per 100 events) */
  ExecutionProfile['BALANCED'] = 'balanced';
  /** High quality: Multiple algorithms, comprehensive analysis (100-500ms per 100 events) */
  ExecutionProfile['QUALITY'] = 'quality';
  /** Streaming mode: Streaming DFG and conformance checking */
  ExecutionProfile['STREAM'] = 'stream';
  /** Research mode: All algorithms including genetic, PSO, A*, simulated annealing */
  ExecutionProfile['RESEARCH'] = 'research';
})(ExecutionProfile || (ExecutionProfile = {}));
/**
 * Execution mode determines WASM runtime behavior
 */
export var ExecutionMode;
(function (ExecutionMode) {
  /** Compute everything synchronously */
  ExecutionMode['SYNC'] = 'sync';
  /** Offload to Web Workers (browser only) */
  ExecutionMode['WORKER'] = 'worker';
  /** Stream results incrementally */
  ExecutionMode['STREAMING'] = 'streaming';
})(ExecutionMode || (ExecutionMode = {}));
/**
 * Types of pipeline steps
 */
export var StepType;
(function (StepType) {
  // Discovery algorithms
  StepType['DFG'] = 'dfg';
  StepType['ALPHA_PLUS_PLUS'] = 'alpha_plus_plus';
  StepType['HEURISTIC_MINER'] = 'heuristic_miner';
  StepType['INDUCTIVE_MINER'] = 'inductive_miner';
  StepType['GENETIC'] = 'genetic';
  StepType['PSO'] = 'pso';
  StepType['A_STAR'] = 'a_star';
  StepType['ILP'] = 'ilp';
  StepType['ACO'] = 'aco';
  StepType['SIMULATED_ANNEALING'] = 'simulated_annealing';
  // Analysis
  StepType['STATISTICS'] = 'statistics';
  StepType['CONFORMANCE'] = 'conformance';
  StepType['VARIANTS'] = 'variants';
  StepType['PERFORMANCE'] = 'performance';
  StepType['CLUSTERING'] = 'clustering';
  // Utilities
  StepType['FILTER'] = 'filter';
  StepType['TRANSFORM'] = 'transform';
  StepType['VALIDATE'] = 'validate';
})(StepType || (StepType = {}));
/**
 * Validates a configuration object for structural correctness
 * Returns an array of validation issues (empty if valid)
 *
 * @param config - Configuration object to validate
 * @returns Array of ValidationIssue objects (empty if valid)
 */
export function validateConfig(config) {
  const issues = [];
  // Type check
  if (!config || typeof config !== 'object') {
    return [
      {
        path: '$',
        type: 'type_error',
        message: 'Configuration must be a non-null object',
        suggestion: 'Ensure config is passed as an object literal or parsed JSON',
      },
    ];
  }
  const cfg = config;
  // Check version
  if (cfg.version !== '1.0') {
    issues.push({
      path: 'version',
      type: 'invalid',
      message: `Invalid or missing version. Expected "1.0", got ${cfg.version}`,
      suggestion: 'Set version to "1.0"',
    });
  }
  // Check source
  if (!cfg.source || typeof cfg.source !== 'object') {
    issues.push({
      path: 'source',
      type: 'missing',
      message: 'source configuration is required',
      suggestion: 'Add a source configuration object with format and content',
    });
  } else {
    const source = cfg.source;
    if (!source.format || !Object.values(SourceFormat).includes(source.format)) {
      issues.push({
        path: 'source.format',
        type: 'invalid',
        message: `Invalid or missing source format. Expected one of: ${Object.values(SourceFormat).join(', ')}`,
        suggestion: `Set source.format to a valid format`,
      });
    }
    if (!source.content || typeof source.content !== 'string') {
      issues.push({
        path: 'source.content',
        type: 'missing',
        message: 'source.content is required and must be a string',
        suggestion: 'Provide the source data as a string',
      });
    }
  }
  // Check execution
  if (!cfg.execution || typeof cfg.execution !== 'object') {
    issues.push({
      path: 'execution',
      type: 'missing',
      message: 'execution configuration is required',
      suggestion: 'Add an execution configuration object with a profile',
    });
  } else {
    const execution = cfg.execution;
    if (!execution.profile || !Object.values(ExecutionProfile).includes(execution.profile)) {
      issues.push({
        path: 'execution.profile',
        type: 'invalid',
        message: `Invalid or missing execution profile. Expected one of: ${Object.values(ExecutionProfile).join(', ')}`,
        suggestion: 'Set execution.profile to a valid profile name',
      });
    }
    if (execution.mode && !Object.values(ExecutionMode).includes(execution.mode)) {
      issues.push({
        path: 'execution.mode',
        type: 'invalid',
        message: `Invalid execution mode. Expected one of: ${Object.values(ExecutionMode).join(', ')}`,
        suggestion: 'Set execution.mode to a valid execution mode or omit it',
      });
    }
    if (execution.maxEvents !== undefined && typeof execution.maxEvents !== 'number') {
      issues.push({
        path: 'execution.maxEvents',
        type: 'type_error',
        message: 'execution.maxEvents must be a number',
      });
    }
    if (execution.maxMemoryMB !== undefined && typeof execution.maxMemoryMB !== 'number') {
      issues.push({
        path: 'execution.maxMemoryMB',
        type: 'type_error',
        message: 'execution.maxMemoryMB must be a number',
      });
    }
    if (execution.timeoutMs !== undefined && typeof execution.timeoutMs !== 'number') {
      issues.push({
        path: 'execution.timeoutMs',
        type: 'type_error',
        message: 'execution.timeoutMs must be a number',
      });
    }
  }
  // Validate pipeline if provided
  if (cfg.pipeline && Array.isArray(cfg.pipeline)) {
    const pipeline = cfg.pipeline;
    pipeline.forEach((step, idx) => {
      if (!step || typeof step !== 'object') {
        issues.push({
          path: `pipeline[${idx}]`,
          type: 'type_error',
          message: 'Pipeline step must be an object',
        });
      } else {
        const s = step;
        if (!s.id || typeof s.id !== 'string') {
          issues.push({
            path: `pipeline[${idx}].id`,
            type: 'missing',
            message: 'Pipeline step must have an id (string)',
          });
        }
        if (!s.type || !Object.values(StepType).includes(s.type)) {
          issues.push({
            path: `pipeline[${idx}].type`,
            type: 'invalid',
            message: `Invalid step type. Expected one of: ${Object.values(StepType).join(', ')}`,
          });
        }
      }
    });
  }
  return issues;
}
/**
 * Asserts that a configuration is valid, throwing a Wasm4pmError if not
 * Type guard that narrows the type to Wasm4pmConfig
 *
 * @param config - Configuration to validate
 * @throws Wasm4pmError - If validation fails
 */
export function assertConfigValid(config) {
  const issues = validateConfig(config);
  if (issues.length > 0) {
    const issueMessages = issues.map((issue) => `${issue.path}: ${issue.message}`).join('; ');
    throw new Wasm4pmError(
      `Configuration validation failed: ${issueMessages}`,
      ErrorCode.CONFIG_INVALID,
      {
        nextAction: ErrorRecovery.RECONFIGURE,
        context: { issues },
      }
    );
  }
}
/**
 * Resolves an execution profile to a default pipeline of steps
 * Returns the recommended sequence of algorithms and analyses for the profile
 *
 * @param profile - Execution profile
 * @returns Array of PipelineStep objects representing the default pipeline
 */
export function resolveProfile(profile) {
  switch (profile) {
    case ExecutionProfile.FAST:
      return [
        {
          id: 'step_dfg',
          type: StepType.DFG,
          required: true,
          parallelizable: true,
        },
        {
          id: 'step_stats',
          type: StepType.STATISTICS,
          required: true,
          dependsOn: ['step_dfg'],
          parallelizable: true,
        },
      ];
    case ExecutionProfile.BALANCED:
      return [
        {
          id: 'step_alpha',
          type: StepType.ALPHA_PLUS_PLUS,
          required: true,
          parallelizable: true,
        },
        {
          id: 'step_stats',
          type: StepType.STATISTICS,
          required: true,
          dependsOn: ['step_alpha'],
          parallelizable: true,
        },
        {
          id: 'step_conformance',
          type: StepType.CONFORMANCE,
          required: true,
          dependsOn: ['step_alpha'],
          parallelizable: true,
        },
        {
          id: 'step_variants',
          type: StepType.VARIANTS,
          required: true,
          dependsOn: ['step_alpha'],
          parallelizable: true,
        },
      ];
    case ExecutionProfile.QUALITY:
      return [
        // Primary algorithm with alternatives
        {
          id: 'step_genetic',
          type: StepType.GENETIC,
          required: true,
          parallelizable: true,
          parameters: { generations: 50, populationSize: 30 },
        },
        {
          id: 'step_ilp',
          type: StepType.ILP,
          required: false,
          dependsOn: ['step_genetic'],
          parallelizable: true,
          parameters: { timeout: 10000 },
        },
        {
          id: 'step_heuristic',
          type: StepType.HEURISTIC_MINER,
          required: true,
          parallelizable: true,
        },
        // Comprehensive analysis
        {
          id: 'step_stats',
          type: StepType.STATISTICS,
          required: true,
          dependsOn: ['step_genetic'],
          parallelizable: true,
        },
        {
          id: 'step_conformance',
          type: StepType.CONFORMANCE,
          required: true,
          dependsOn: ['step_genetic'],
          parallelizable: true,
        },
        {
          id: 'step_variants',
          type: StepType.VARIANTS,
          required: true,
          dependsOn: ['step_genetic'],
          parallelizable: true,
        },
        {
          id: 'step_performance',
          type: StepType.PERFORMANCE,
          required: true,
          dependsOn: ['step_genetic'],
          parallelizable: true,
        },
      ];
    case ExecutionProfile.STREAM:
      return [
        {
          id: 'step_stream_dfg',
          type: StepType.DFG,
          required: true,
          parallelizable: true,
          parameters: { streaming: true },
        },
        {
          id: 'step_stream_conformance',
          type: StepType.CONFORMANCE,
          required: true,
          dependsOn: ['step_stream_dfg'],
          parallelizable: true,
          parameters: { streaming: true },
        },
      ];
    case ExecutionProfile.RESEARCH:
      return [
        // All discovery algorithms
        {
          id: 'step_dfg',
          type: StepType.DFG,
          required: true,
          parallelizable: true,
        },
        {
          id: 'step_alpha',
          type: StepType.ALPHA_PLUS_PLUS,
          required: true,
          parallelizable: true,
        },
        {
          id: 'step_genetic',
          type: StepType.GENETIC,
          required: true,
          parallelizable: true,
          parameters: { generations: 100, populationSize: 50 },
        },
        {
          id: 'step_pso',
          type: StepType.PSO,
          required: true,
          parallelizable: true,
          parameters: { particles: 30, iterations: 100 },
        },
        {
          id: 'step_astar',
          type: StepType.A_STAR,
          required: true,
          parallelizable: true,
        },
        {
          id: 'step_aco',
          type: StepType.ACO,
          required: true,
          parallelizable: true,
          parameters: { ants: 20, iterations: 50 },
        },
        {
          id: 'step_annealing',
          type: StepType.SIMULATED_ANNEALING,
          required: true,
          parallelizable: true,
          parameters: { temperature: 100, coolingRate: 0.95 },
        },
        {
          id: 'step_ilp',
          type: StepType.ILP,
          required: false,
          parallelizable: true,
          parameters: { timeout: 30000 },
        },
        // Full analysis
        {
          id: 'step_stats',
          type: StepType.STATISTICS,
          required: true,
          dependsOn: ['step_dfg'],
          parallelizable: true,
        },
        {
          id: 'step_conformance',
          type: StepType.CONFORMANCE,
          required: true,
          dependsOn: ['step_alpha'],
          parallelizable: true,
        },
        {
          id: 'step_variants',
          type: StepType.VARIANTS,
          required: true,
          dependsOn: ['step_dfg'],
          parallelizable: true,
        },
        {
          id: 'step_performance',
          type: StepType.PERFORMANCE,
          required: true,
          dependsOn: ['step_dfg'],
          parallelizable: true,
        },
        {
          id: 'step_clustering',
          type: StepType.CLUSTERING,
          required: true,
          dependsOn: ['step_dfg'],
          parallelizable: true,
        },
      ];
    default:
      const _exhaustive = profile;
      throw new Wasm4pmError(`Unknown execution profile: ${profile}`, ErrorCode.CONFIG_INVALID, {
        nextAction: ErrorRecovery.RECONFIGURE,
      });
  }
}
//# sourceMappingURL=config.js.map