mostlyai 4.2.8__tar.gz → 4.2.9__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 (85) hide show
  1. {mostlyai-4.2.8 → mostlyai-4.2.9}/PKG-INFO +4 -4
  2. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/__init__.py +1 -1
  3. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_local/execution/jobs.py +123 -94
  4. mostlyai-4.2.9/mostlyai/sdk/_local/execution/plan.py +226 -0
  5. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_local/execution/step_create_data_report.py +3 -1
  6. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_local/execution/step_create_model_report.py +2 -2
  7. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_local/generators.py +16 -3
  8. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_local/server.py +12 -0
  9. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_local/synthetic_datasets.py +8 -7
  10. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/client/base.py +2 -4
  11. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/domain.py +57 -20
  12. {mostlyai-4.2.8 → mostlyai-4.2.9}/pyproject.toml +4 -4
  13. mostlyai-4.2.8/mostlyai/sdk/_local/execution/plan.py +0 -179
  14. {mostlyai-4.2.8 → mostlyai-4.2.9}/.gitignore +0 -0
  15. {mostlyai-4.2.8 → mostlyai-4.2.9}/LICENSE +0 -0
  16. {mostlyai-4.2.8 → mostlyai-4.2.9}/README.md +0 -0
  17. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/__init__.py +0 -0
  18. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/auto_detect.py +0 -0
  19. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/base.py +0 -0
  20. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/context.py +0 -0
  21. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/conversions.py +0 -0
  22. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/db/__init__.py +0 -0
  23. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/db/base.py +0 -0
  24. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/db/bigquery.py +0 -0
  25. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/db/databricks.py +0 -0
  26. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/db/hive.py +0 -0
  27. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/db/mssql.py +0 -0
  28. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/db/mysql.py +0 -0
  29. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/db/oracle.py +0 -0
  30. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/db/postgresql.py +0 -0
  31. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/db/snowflake.py +0 -0
  32. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/db/sqlite.py +0 -0
  33. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/db/types_coercion.py +0 -0
  34. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/dtype.py +0 -0
  35. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/exceptions.py +0 -0
  36. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/file/__init__.py +0 -0
  37. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/file/base.py +0 -0
  38. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/file/container/__init__.py +0 -0
  39. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/file/container/aws.py +0 -0
  40. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/file/container/azure.py +0 -0
  41. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/file/container/bucket_based.py +0 -0
  42. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/file/container/gcs.py +0 -0
  43. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/file/container/minio.py +0 -0
  44. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/file/table/__init__.py +0 -0
  45. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/file/table/csv.py +0 -0
  46. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/file/table/feather.py +0 -0
  47. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/file/table/json.py +0 -0
  48. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/file/table/parquet.py +0 -0
  49. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/file/utils.py +0 -0
  50. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/language_model.py +0 -0
  51. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/metadata_objects.py +0 -0
  52. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/non_context.py +0 -0
  53. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/progress_callback.py +0 -0
  54. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/pull.py +0 -0
  55. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/pull_context.py +0 -0
  56. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/pull_utils.py +0 -0
  57. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/push.py +0 -0
  58. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/util/__init__.py +0 -0
  59. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/util/common.py +0 -0
  60. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_data/util/kerberos.py +0 -0
  61. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_local/__init__.py +0 -0
  62. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_local/cli.py +0 -0
  63. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_local/connectors.py +0 -0
  64. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_local/execution/__init__.py +0 -0
  65. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_local/execution/step_analyze_training_data.py +0 -0
  66. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_local/execution/step_deliver_data.py +0 -0
  67. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_local/execution/step_encode_training_data.py +0 -0
  68. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_local/execution/step_finalize_generation.py +0 -0
  69. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_local/execution/step_finalize_training.py +0 -0
  70. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_local/execution/step_generate_data.py +0 -0
  71. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_local/execution/step_generate_model_report_data.py +0 -0
  72. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_local/execution/step_pull_training_data.py +0 -0
  73. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_local/execution/step_train_model.py +0 -0
  74. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_local/progress.py +0 -0
  75. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_local/routes.py +0 -0
  76. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/_local/storage.py +0 -0
  77. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/client/__init__.py +0 -0
  78. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/client/_base_utils.py +0 -0
  79. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/client/_naming_conventions.py +0 -0
  80. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/client/_utils.py +0 -0
  81. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/client/api.py +0 -0
  82. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/client/connectors.py +0 -0
  83. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/client/exceptions.py +0 -0
  84. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/client/generators.py +0 -0
  85. {mostlyai-4.2.8 → mostlyai-4.2.9}/mostlyai/sdk/client/synthetic_datasets.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mostlyai
3
- Version: 4.2.8
3
+ Version: 4.2.9
4
4
  Summary: Synthetic Data SDK
5
5
  Project-URL: homepage, https://app.mostly.ai/
6
6
  Project-URL: repository, https://github.com/mostly-ai/mostlyai
@@ -57,7 +57,7 @@ Requires-Dist: fastapi<0.116,>=0.115.6; extra == 'local'
57
57
  Requires-Dist: filelock>=3.16.1; extra == 'local'
58
58
  Requires-Dist: gcsfs>=2023.1.0; extra == 'local'
59
59
  Requires-Dist: joblib>=1.2.0; extra == 'local'
60
- Requires-Dist: mostlyai-engine==1.1.4; extra == 'local'
60
+ Requires-Dist: mostlyai-engine==1.1.5; extra == 'local'
61
61
  Requires-Dist: mostlyai-qa==1.5.5; extra == 'local'
62
62
  Requires-Dist: networkx<4,>=3.0; extra == 'local'
63
63
  Requires-Dist: openpyxl>=3.1.5; extra == 'local'
@@ -77,7 +77,7 @@ Requires-Dist: fastapi<0.116,>=0.115.6; extra == 'local-cpu'
77
77
  Requires-Dist: filelock>=3.16.1; extra == 'local-cpu'
78
78
  Requires-Dist: gcsfs>=2023.1.0; extra == 'local-cpu'
79
79
  Requires-Dist: joblib>=1.2.0; extra == 'local-cpu'
80
- Requires-Dist: mostlyai-engine[cpu]==1.1.4; extra == 'local-cpu'
80
+ Requires-Dist: mostlyai-engine[cpu]==1.1.5; extra == 'local-cpu'
81
81
  Requires-Dist: mostlyai-qa[cpu]==1.5.5; extra == 'local-cpu'
82
82
  Requires-Dist: networkx<4,>=3.0; extra == 'local-cpu'
83
83
  Requires-Dist: openpyxl>=3.1.5; extra == 'local-cpu'
@@ -98,7 +98,7 @@ Requires-Dist: fastapi<0.116,>=0.115.6; extra == 'local-gpu'
98
98
  Requires-Dist: filelock>=3.16.1; extra == 'local-gpu'
99
99
  Requires-Dist: gcsfs>=2023.1.0; extra == 'local-gpu'
100
100
  Requires-Dist: joblib>=1.2.0; extra == 'local-gpu'
101
- Requires-Dist: mostlyai-engine[gpu]==1.1.4; extra == 'local-gpu'
101
+ Requires-Dist: mostlyai-engine[gpu]==1.1.5; extra == 'local-gpu'
102
102
  Requires-Dist: mostlyai-qa[gpu]==1.5.5; extra == 'local-gpu'
103
103
  Requires-Dist: networkx<4,>=3.0; extra == 'local-gpu'
104
104
  Requires-Dist: openpyxl>=3.1.5; extra == 'local-gpu'
@@ -15,4 +15,4 @@
15
15
  from mostlyai.sdk.client.api import MostlyAI
16
16
 
17
17
  __all__ = ["MostlyAI"]
18
- __version__ = "4.2.8" # Do not set this manually. Use poetry version [params].
18
+ __version__ = "4.2.9" # Do not set this manually. Use poetry version [params].
@@ -153,9 +153,12 @@ def _copy_model(generator_dir: Path, model_label: str, workspace_dir: Path):
153
153
  shutil.copytree(model_path, workspace_dir / "ModelStore")
154
154
 
155
155
 
156
- def _copy_statistics(generator_dir: Path, model_label: str, workspace_dir: Path):
156
+ def _copy_statistics(generator_dir: Path, model_label: str, workspace_dir: Path) -> bool:
157
157
  statistics_path = generator_dir / "ModelQAStatistics" / model_label
158
- shutil.copytree(statistics_path, workspace_dir / "ModelQAStatistics")
158
+ if statistics_path.exists():
159
+ shutil.copytree(statistics_path, workspace_dir / "ModelQAStatistics")
160
+ return True
161
+ return False
159
162
 
160
163
 
161
164
  def _set_overall_accuracy(generator: Generator) -> None:
@@ -297,12 +300,8 @@ class Execution:
297
300
  TaskType.train_tabular: self.execute_task_train,
298
301
  TaskType.train_language: self.execute_task_train,
299
302
  TaskType.finalize_training: self.execute_task_finalize_training,
300
- TaskType.generate_tabular: self.execute_task_generate,
301
- TaskType.generate_language: self.execute_task_generate,
302
- TaskType.finalize_generation: self.execute_task_finalize_generation,
303
- TaskType.probe_tabular: self.execute_task_generate,
304
- TaskType.probe_language: self.execute_task_generate,
305
- TaskType.finalize_probing: self.execute_task_finalize_probing,
303
+ TaskType.generate: self.execute_task_generate,
304
+ TaskType.probe: self.execute_task_generate,
306
305
  }
307
306
  for task in self._execution_plan.tasks:
308
307
  handler = task_handlers.get(task.type)
@@ -380,105 +379,132 @@ class Execution:
380
379
  upload_model_data_callback=None, # not applicable in local mode
381
380
  )
382
381
 
383
- # step: GENERATE_MODEL_REPORT_DATA
384
- execute_step_generate_model_report_data(
385
- workspace_dir=workspace_dir,
386
- model_type=model_type,
387
- update_progress=update_progress_fn(step_code=StepCode.generate_model_report_data),
388
- )
382
+ step_codes = [s.step_code for s in task.steps]
383
+ if StepCode.generate_model_report_data in step_codes:
384
+ # step: GENERATE_MODEL_REPORT_DATA
385
+ execute_step_generate_model_report_data(
386
+ workspace_dir=workspace_dir,
387
+ model_type=model_type,
388
+ update_progress=update_progress_fn(step_code=StepCode.generate_model_report_data),
389
+ )
389
390
 
390
- # step: CREATE_MODEL_REPORT
391
- model_metrics = execute_step_create_model_report(
392
- generator=generator,
393
- model_type=model_type,
394
- target_table_name=task.target_table_name,
395
- workspace_dir=workspace_dir,
396
- update_progress=update_progress_fn(step_code=StepCode.create_model_report),
397
- )
398
- # update generator with model metrics
399
- if model_type == ModelType.tabular:
400
- tgt_table.tabular_model_metrics = model_metrics
401
- else:
402
- tgt_table.language_model_metrics = model_metrics
391
+ # step: CREATE_MODEL_REPORT
392
+ model_metrics = execute_step_create_model_report(
393
+ generator=generator,
394
+ model_type=model_type,
395
+ target_table_name=task.target_table_name,
396
+ workspace_dir=workspace_dir,
397
+ update_progress=update_progress_fn(step_code=StepCode.create_model_report),
398
+ )
399
+ # update generator with model metrics
400
+ if model_type == ModelType.tabular:
401
+ tgt_table.tabular_model_metrics = model_metrics
402
+ else:
403
+ tgt_table.language_model_metrics = model_metrics
403
404
 
404
405
  def execute_task_finalize_training(self, task: Task):
405
406
  pass
406
407
 
407
408
  def execute_task_generate(self, task: Task):
408
- # gather common step arguments
409
409
  generator = self._generator
410
410
  synthetic_dataset = self._synthetic_dataset
411
- is_probe = task.type in (TaskType.probe_tabular, TaskType.probe_language)
412
- model_type = (
413
- ModelType.tabular
414
- if task.type in (TaskType.generate_tabular, TaskType.probe_tabular)
415
- else ModelType.language
416
- )
417
- model_label = f"{task.target_table_name}:{model_type.value.lower()}"
418
- sd_table = next(t for t in synthetic_dataset.tables if t.name == task.target_table_name)
419
411
  synthetic_dataset_dir = self._home_dir / "synthetic-datasets" / synthetic_dataset.id
420
412
  generator_dir = self._home_dir / "generators" / generator.id
421
- workspace_dir = self._job_workspace_dir / model_label
422
- workspace_dir.mkdir()
423
- update_progress_fn = partial(
424
- LocalProgressCallback, resource_path=synthetic_dataset_dir, model_label=model_label
425
- )
426
413
 
427
- # copy AI model to workspace
428
- _copy_model(generator_dir=generator_dir, model_label=model_label, workspace_dir=workspace_dir)
414
+ visited_tables = set()
415
+ table_lookup = {table.name: table for table in synthetic_dataset.tables}
429
416
 
430
- # step: GENERATE_DATA
431
- if sd_table.configuration.sample_seed_connector_id is not None:
432
- sample_seed = _fetch_sample_seed(
433
- home_dir=self._home_dir,
434
- connector_id=sd_table.configuration.sample_seed_connector_id,
417
+ for step in task.steps:
418
+ model_type = (
419
+ ModelType.tabular
420
+ if step.step_code in {StepCode.generate_data_tabular, StepCode.create_data_report_tabular}
421
+ else ModelType.language
435
422
  )
436
- else:
437
- sample_seed = None
438
- schema = create_generation_schema(
439
- generator=generator,
440
- job_workspace_dir=self._job_workspace_dir,
441
- step="pull_context_data",
442
- )
443
- execute_step_generate_data(
444
- generator=generator,
445
- synthetic_dataset=synthetic_dataset,
446
- target_table_name=task.target_table_name,
447
- model_type=model_type,
448
- sample_seed=sample_seed,
449
- schema=schema,
450
- workspace_dir=workspace_dir,
451
- update_progress=update_progress_fn(step_code=StepCode.generate_data),
452
- )
453
423
 
454
- if not is_probe:
455
- # copy QA statistics to workspace
456
- _copy_statistics(generator_dir=generator_dir, model_label=model_label, workspace_dir=workspace_dir)
457
- # step: GENERATE_DATA_REPORT
458
- execute_step_create_data_report(
459
- generator=generator,
460
- target_table_name=task.target_table_name,
461
- model_type=model_type,
462
- workspace_dir=workspace_dir,
463
- update_progress=update_progress_fn(step_code=StepCode.create_data_report),
424
+ model_label = f"{step.target_table_name}:{model_type.value.lower()}"
425
+ workspace_dir = self._job_workspace_dir / model_label
426
+ workspace_dir.mkdir(exist_ok=True)
427
+
428
+ update_progress = partial(
429
+ LocalProgressCallback, resource_path=synthetic_dataset_dir, model_label=model_label
464
430
  )
465
431
 
466
- # as a last step of LANGUAGE model generation, merge context and generated data
467
- if model_type == ModelType.language:
468
- _merge_tabular_language_data(workspace_dir=workspace_dir)
469
- # overwrite tabular SyntheticData with tabular+language SyntheticData
470
- tabular_workspace_dir = self._job_workspace_dir / f"{task.target_table_name}:tabular"
471
- tabular_workspace_dir.mkdir(parents=True, exist_ok=True)
472
- shutil.rmtree(tabular_workspace_dir / "SyntheticData", ignore_errors=True)
473
- shutil.move(workspace_dir / "SyntheticData", tabular_workspace_dir / "SyntheticData")
432
+ if step.step_code in {StepCode.generate_data_tabular, StepCode.generate_data_language}:
433
+ # step: GENERATE_DATA
434
+ _copy_model(generator_dir=generator_dir, model_label=model_label, workspace_dir=workspace_dir)
435
+
436
+ visited_tables.add(step.target_table_name)
437
+
438
+ table = table_lookup[step.target_table_name]
439
+ sample_seed = (
440
+ _fetch_sample_seed(
441
+ home_dir=self._home_dir, connector_id=table.configuration.sample_seed_connector_id
442
+ )
443
+ if table.configuration.sample_seed_connector_id
444
+ else None
445
+ )
446
+
447
+ schema = create_generation_schema(
448
+ generator=generator,
449
+ job_workspace_dir=self._job_workspace_dir,
450
+ step="pull_context_data",
451
+ )
452
+
453
+ execute_step_generate_data(
454
+ generator=generator,
455
+ synthetic_dataset=synthetic_dataset,
456
+ target_table_name=step.target_table_name,
457
+ model_type=model_type,
458
+ sample_seed=sample_seed,
459
+ schema=schema,
460
+ workspace_dir=workspace_dir,
461
+ update_progress=update_progress(step_code=step.step_code),
462
+ )
463
+
464
+ elif step.step_code in {StepCode.create_data_report_tabular, StepCode.create_data_report_language}:
465
+ model_report_available = _copy_statistics(
466
+ generator_dir=generator_dir, model_label=model_label, workspace_dir=workspace_dir
467
+ )
468
+ if not model_report_available:
469
+ continue
470
+ # step: GENERATE_DATA_REPORT
471
+ execute_step_create_data_report(
472
+ generator=generator,
473
+ target_table_name=step.target_table_name,
474
+ model_type=model_type,
475
+ workspace_dir=workspace_dir,
476
+ update_progress=update_progress(step_code=step.step_code),
477
+ )
478
+
479
+ elif step.step_code in {StepCode.finalize_generation, StepCode.finalize_probing}:
480
+ # for every LANGUAGE model generation, merge context and generated data
481
+ for table in visited_tables:
482
+ language_path = self._job_workspace_dir / f"{table}:{ModelType.language.value.lower()}"
483
+ if language_path.exists():
484
+ _merge_tabular_language_data(workspace_dir=language_path)
485
+
486
+ tabular_workspace = self._job_workspace_dir / f"{table}:{ModelType.tabular.value.lower()}"
487
+ tabular_workspace.mkdir(parents=True, exist_ok=True)
488
+ shutil.rmtree(tabular_workspace / "SyntheticData", ignore_errors=True)
489
+ shutil.move(language_path / "SyntheticData", tabular_workspace / "SyntheticData")
490
+
491
+ finalize_method = (
492
+ self.execute_finalize_generation
493
+ if step.step_code == StepCode.finalize_generation
494
+ else self.execute_finalize_probing
495
+ )
496
+ finalize_method()
497
+
498
+ elif step.step_code == StepCode.deliver_data:
499
+ self.execute_deliver_data()
474
500
 
475
- def execute_task_finalize_generation(self, task: Task):
501
+ def execute_finalize_generation(self):
476
502
  schema = create_generation_schema(
477
503
  generator=self._generator,
478
504
  job_workspace_dir=self._job_workspace_dir,
479
505
  step="finalize_generation",
480
506
  )
481
- # step: FINALIZE_GENERATION
507
+
482
508
  usage = execute_step_finalize_generation(
483
509
  schema=schema,
484
510
  is_probe=False,
@@ -489,20 +515,23 @@ class Execution:
489
515
  step_code=StepCode.finalize_generation,
490
516
  ),
491
517
  )
492
- # update total rows and datapoints
518
+
493
519
  update_total_rows_and_datapoints(self._synthetic_dataset, usage)
494
520
 
495
- # step: DELIVER_DATA
521
+ def execute_deliver_data(self):
496
522
  schema = create_generation_schema(
497
523
  generator=self._generator,
498
524
  job_workspace_dir=self._job_workspace_dir,
499
525
  step="deliver_data",
500
526
  )
527
+
501
528
  delivery = self._synthetic_dataset.delivery
502
- if delivery is not None and delivery.destination_connector_id is not None:
503
- connector = read_connector_from_json(self._home_dir / "connectors" / delivery.destination_connector_id)
504
- else:
505
- connector = None
529
+ connector = (
530
+ read_connector_from_json(self._home_dir / "connectors" / delivery.destination_connector_id)
531
+ if delivery and delivery.destination_connector_id
532
+ else None
533
+ )
534
+
506
535
  execute_step_deliver_data(
507
536
  generator=self._generator,
508
537
  delivery=delivery,
@@ -511,7 +540,7 @@ class Execution:
511
540
  job_workspace_dir=self._job_workspace_dir,
512
541
  )
513
542
 
514
- def execute_task_finalize_probing(self, task: Task):
543
+ def execute_finalize_probing(self):
515
544
  schema = create_generation_schema(
516
545
  generator=self._generator,
517
546
  job_workspace_dir=self._job_workspace_dir,
@@ -573,7 +602,7 @@ def execute_generation_job(synthetic_dataset_id: str, home_dir: Path):
573
602
 
574
603
  _mark_in_progress(resource=synthetic_dataset, resource_dir=synthetic_dataset_dir)
575
604
  # PLAN
576
- plan = make_synthetic_dataset_execution_plan(generator)
605
+ plan = make_synthetic_dataset_execution_plan(generator, synthetic_dataset)
577
606
  # EXECUTE
578
607
  execution = Execution(
579
608
  execution_plan=plan,
@@ -607,7 +636,7 @@ def execute_probing_job(synthetic_dataset_id: str, home_dir: Path) -> list[Probe
607
636
  generator = read_generator_from_json(generator_dir)
608
637
 
609
638
  # PLAN
610
- plan = make_synthetic_dataset_execution_plan(generator, is_probe=True)
639
+ plan = make_synthetic_dataset_execution_plan(generator, synthetic_dataset, is_probe=True)
611
640
  # EXECUTE
612
641
  execution = Execution(
613
642
  execution_plan=plan, generator=generator, synthetic_dataset=synthetic_dataset, home_dir=home_dir
@@ -0,0 +1,226 @@
1
+ # Copyright 2025 MOSTLY AI
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ from pydantic import BaseModel, Field, ConfigDict
15
+ from collections import deque
16
+ from mostlyai.sdk.domain import (
17
+ ModelEncodingType,
18
+ Generator,
19
+ SourceTable,
20
+ StepCode,
21
+ TaskType,
22
+ ModelType,
23
+ SyntheticDataset,
24
+ )
25
+ import uuid
26
+
27
+ TABULAR_MODEL_ENCODING_TYPES = [v for v in ModelEncodingType if v.startswith(ModelType.tabular)] + [
28
+ ModelEncodingType.auto
29
+ ]
30
+ LANGUAGE_MODEL_ENCODING_TYPES = [v for v in ModelEncodingType if v.startswith(ModelType.language)]
31
+
32
+ TRAINING_TASK_STEPS: list[StepCode] = [
33
+ StepCode.pull_training_data,
34
+ StepCode.analyze_training_data,
35
+ StepCode.encode_training_data,
36
+ StepCode.train_model,
37
+ ]
38
+ TRAINING_TASK_REPORT_STEPS: list[StepCode] = [
39
+ StepCode.generate_model_report_data,
40
+ StepCode.create_model_report,
41
+ ]
42
+ FINALIZE_TRAINING_TASK_STEPS: list[StepCode] = [
43
+ StepCode.finalize_training,
44
+ ]
45
+ FINALIZE_GENERATION_TASK_STEPS: list[StepCode] = [
46
+ StepCode.finalize_generation,
47
+ StepCode.deliver_data,
48
+ ]
49
+
50
+
51
+ def _get_keys(table: SourceTable) -> list[str]:
52
+ keys = [fk.column for fk in (table.foreign_keys or [])]
53
+ if table.primary_key:
54
+ keys.append(table.primary_key)
55
+ return keys
56
+
57
+
58
+ def has_tabular_model(table: SourceTable) -> bool:
59
+ return table.tabular_model_configuration is not None
60
+
61
+
62
+ def has_language_model(table: SourceTable) -> bool:
63
+ return table.language_model_configuration is not None
64
+
65
+
66
+ def get_model_type_generation_steps_map(include_report: bool) -> dict[ModelType, list[StepCode]]:
67
+ return {
68
+ ModelType.tabular: [StepCode.generate_data_tabular]
69
+ + ([StepCode.create_data_report_tabular] if include_report else []),
70
+ ModelType.language: [StepCode.generate_data_language]
71
+ + ([StepCode.create_data_report_language] if include_report else []),
72
+ }
73
+
74
+
75
+ class Step(BaseModel):
76
+ model_config = ConfigDict(populate_by_name=True)
77
+
78
+ id: str = Field(default_factory=lambda: str(uuid.uuid4()))
79
+ step_code: StepCode = Field(alias="stepCode")
80
+ target_table_name: str | None = Field(None, alias="targetTableName", title="Target Table Name")
81
+
82
+
83
+ class Task(BaseModel):
84
+ model_config = ConfigDict(populate_by_name=True)
85
+
86
+ id: str
87
+ parent_task_id: str | None = Field(None, alias="parentTaskId", title="Parent Task Id")
88
+ target_table_name: str | None = Field(None, alias="targetTableName", title="Target Table Name")
89
+ type: TaskType
90
+ steps: list[Step] | None
91
+
92
+
93
+ class ExecutionPlan(BaseModel):
94
+ tasks: list[Task]
95
+
96
+ def add_task(
97
+ self,
98
+ task_type: TaskType,
99
+ parent: Task | None = None,
100
+ target_table_name: str | None = None,
101
+ include_report: bool = True,
102
+ ) -> Task:
103
+ def get_steps(task_type: TaskType) -> list[Step] | None:
104
+ match task_type:
105
+ case TaskType.train_tabular | TaskType.train_language:
106
+ return [
107
+ Step(step_code=code)
108
+ for code in TRAINING_TASK_STEPS + (TRAINING_TASK_REPORT_STEPS if include_report else [])
109
+ ]
110
+ case TaskType.finalize_training:
111
+ return [Step(step_code=code) for code in FINALIZE_TRAINING_TASK_STEPS]
112
+ case _:
113
+ return None
114
+
115
+ task = Task(
116
+ id=str(uuid.uuid4()),
117
+ type=task_type,
118
+ parent_task_id=parent.id if parent else None,
119
+ target_table_name=target_table_name,
120
+ steps=get_steps(task_type),
121
+ )
122
+ self.tasks.append(task)
123
+ return task
124
+
125
+ def add_task_with_steps(self, task_type: TaskType, parent: Task | None = None, steps: list[Step] = None) -> Task:
126
+ task = Task(
127
+ id=str(uuid.uuid4()),
128
+ type=task_type,
129
+ parent_task_id=parent.id if parent else None,
130
+ steps=steps or [],
131
+ )
132
+ self.tasks.append(task)
133
+ return task
134
+
135
+
136
+ def make_generator_execution_plan(generator: Generator) -> ExecutionPlan:
137
+ execution_plan = ExecutionPlan(tasks=[])
138
+ sync_task = execution_plan.add_task(TaskType.sync)
139
+ for table in generator.tables:
140
+ if has_tabular_model(table):
141
+ execution_plan.add_task(
142
+ TaskType.train_tabular,
143
+ parent=sync_task,
144
+ target_table_name=table.name,
145
+ include_report=table.tabular_model_configuration.enable_model_report,
146
+ )
147
+ if has_language_model(table):
148
+ execution_plan.add_task(
149
+ TaskType.train_language,
150
+ parent=sync_task,
151
+ target_table_name=table.name,
152
+ include_report=table.language_model_configuration.enable_model_report,
153
+ )
154
+ execution_plan.add_task(TaskType.sync)
155
+ # post_training_sync = execution_plan.add_task(TaskType.sync)
156
+ # finalize_task = execution_plan.add_task(TaskType.finalize_training, parent=post_training_sync)
157
+ # execution_plan.add_task(TaskType.sync, parent=finalize_task)
158
+ return execution_plan
159
+
160
+
161
+ def make_synthetic_dataset_execution_plan(
162
+ generator: Generator, synthetic_dataset: SyntheticDataset | None = None, is_probe: bool = False
163
+ ) -> ExecutionPlan:
164
+ execution_plan = ExecutionPlan(tasks=[])
165
+ sync_task = execution_plan.add_task(TaskType.sync)
166
+ generate_task_type = TaskType.probe if is_probe else TaskType.generate
167
+ finalize_step_code = StepCode.finalize_probing if is_probe else StepCode.finalize_generation
168
+ generate_steps = []
169
+
170
+ def add_generation_steps(table: SourceTable):
171
+ if synthetic_dataset:
172
+ synthetic_table = next(t for t in synthetic_dataset.tables if t.name == table.name)
173
+ enable_data_report = synthetic_table.configuration.enable_data_report
174
+ else:
175
+ enable_data_report = True
176
+ if has_tabular_model(table):
177
+ steps = [Step(step_code=StepCode.generate_data_tabular, target_table_name=table.name)]
178
+ if not is_probe and enable_data_report:
179
+ steps.append(Step(step_code=StepCode.create_data_report_tabular, target_table_name=table.name))
180
+ generate_steps.extend(steps)
181
+
182
+ if has_language_model(table):
183
+ steps = [Step(step_code=StepCode.generate_data_language, target_table_name=table.name)]
184
+ if not is_probe and enable_data_report:
185
+ steps.append(Step(step_code=StepCode.create_data_report_language, target_table_name=table.name))
186
+ generate_steps.extend(steps)
187
+
188
+ # Identify root tables (tables without a foreign key referencing them)
189
+ root_tables = sorted(
190
+ (table for table in generator.tables if not any(fk.is_context for fk in table.foreign_keys or [])),
191
+ key=lambda t: t.name,
192
+ )
193
+
194
+ # Process each root table and its subtree
195
+ for root_table in root_tables:
196
+ add_generation_steps(root_table)
197
+
198
+ # Traverse child tables using BFS
199
+ queue = deque([root_table.name])
200
+ while queue:
201
+ current_table_name = queue.popleft()
202
+
203
+ child_tables = sorted(
204
+ (
205
+ table
206
+ for table in generator.tables
207
+ if any(
208
+ fk.referenced_table == current_table_name and fk.is_context for fk in table.foreign_keys or []
209
+ )
210
+ ),
211
+ key=lambda t: t.name,
212
+ )
213
+
214
+ for child_table in child_tables:
215
+ add_generation_steps(child_table)
216
+ queue.append(child_table.name)
217
+
218
+ # Add last common step(s)
219
+ if generate_steps:
220
+ generate_steps.append(Step(step_code=finalize_step_code))
221
+ if not is_probe:
222
+ generate_steps.append(Step(step_code=StepCode.deliver_data))
223
+ generate_task = execution_plan.add_task_with_steps(generate_task_type, steps=generate_steps, parent=sync_task)
224
+ execution_plan.add_task(TaskType.sync, parent=generate_task)
225
+
226
+ return execution_plan
@@ -30,7 +30,9 @@ def execute_step_create_data_report(
30
30
  ):
31
31
  # create model report and return metrics
32
32
  create_report(
33
- step_code=StepCode.create_data_report,
33
+ step_code=StepCode.create_data_report_tabular
34
+ if model_type == ModelType.tabular
35
+ else StepCode.create_data_report_language,
34
36
  generator=generator,
35
37
  workspace_dir=workspace_dir,
36
38
  model_type=model_type,
@@ -155,7 +155,7 @@ def create_report(
155
155
  ctx_data=sorted(report_ctx_input_path.glob("part.*-val.parquet")) if has_context else None,
156
156
  **pull_kwargs,
157
157
  )
158
- else: # step_code == StepCode.create_data_report:
158
+ else: # step_code == StepCode.create_data_report_*:
159
159
  syn_tgt_data, syn_ctx_data = pull_data_for_report(
160
160
  tgt_data=workspace.generated_data.fetch_all(),
161
161
  ctx_data=workspace.ctx_data.fetch_all() if has_context else None,
@@ -190,7 +190,7 @@ def create_report(
190
190
  )
191
191
  # convert metrics from QA domain to SDK domain (if applicable)
192
192
  metrics = ModelMetrics(**metrics.model_dump()) if metrics else None
193
- else: # if step_code == StepCode.create_data_report:
193
+ else: # if step_code == StepCode.create_data_report_*:
194
194
  # generate Data QA report
195
195
  (workspace_dir / "DataQAReports").mkdir(exist_ok=True, parents=True)
196
196
  _ = qa.report_from_statistics(
@@ -20,7 +20,12 @@ from mostlyai.sdk._local.storage import (
20
20
  write_job_progress_to_json,
21
21
  read_generator_from_json,
22
22
  )
23
- from mostlyai.sdk._local.execution.plan import has_tabular_model, has_language_model, TRAINING_TASK_STEPS
23
+ from mostlyai.sdk._local.execution.plan import (
24
+ has_tabular_model,
25
+ has_language_model,
26
+ TRAINING_TASK_STEPS,
27
+ TRAINING_TASK_REPORT_STEPS,
28
+ )
24
29
  from mostlyai.sdk.client._base_utils import convert_to_df
25
30
  from mostlyai.sdk.domain import (
26
31
  GeneratorConfig,
@@ -96,7 +101,15 @@ def create_generator(home_dir: Path, config: GeneratorConfig) -> Generator:
96
101
  if check
97
102
  ]
98
103
  for model_type in model_types:
99
- for step in TRAINING_TASK_STEPS:
104
+ model_configuration = (
105
+ table.tabular_model_configuration
106
+ if model_type == ModelType.tabular
107
+ else table.language_model_configuration
108
+ )
109
+ steps = TRAINING_TASK_STEPS + (
110
+ TRAINING_TASK_REPORT_STEPS if model_configuration.enable_model_report else []
111
+ )
112
+ for step in steps:
100
113
  progress_steps.append(
101
114
  ProgressStep(
102
115
  task_type=TaskType.train_tabular
@@ -136,7 +149,7 @@ def get_generator_config(home_dir: Path, generator_id: str) -> GeneratorConfig:
136
149
  foreign_keys=[SourceForeignKeyConfig.model_construct(**k.model_dump()) for k in t.foreign_keys]
137
150
  if t.foreign_keys
138
151
  else None,
139
- columns=[SourceColumnConfig.model_construct(**c.model_dump()) for c in t.columns]
152
+ columns=[SourceColumnConfig.model_construct(**c.model_dump()) for c in t.columns if c.included]
140
153
  if t.columns
141
154
  else None,
142
155
  )
@@ -18,6 +18,8 @@ from pathlib import Path
18
18
 
19
19
  from threading import Thread
20
20
 
21
+ from fastapi.responses import JSONResponse
22
+ from pydantic import ValidationError
21
23
  import rich
22
24
  from fastapi import FastAPI
23
25
  import uvicorn
@@ -66,6 +68,7 @@ class LocalServer:
66
68
  )
67
69
  routes = Routes(self.home_dir)
68
70
  self._app.include_router(routes.router)
71
+ self.register_exception_handlers()
69
72
  self._server = None
70
73
  self._thread = None
71
74
  self.start() # Automatically start the server during initialization
@@ -116,3 +119,12 @@ class LocalServer:
116
119
  if self._server and self._server.started:
117
120
  print("Automatically shutting down server")
118
121
  self.stop()
122
+
123
+ def register_exception_handlers(self):
124
+ @self._app.exception_handler(Exception)
125
+ async def global_exception_handler(request, exc):
126
+ if isinstance(exc, ValidationError):
127
+ return JSONResponse(status_code=422, content={"detail": str(exc)})
128
+ # for fastapi.HTTPException: it will be raised as is
129
+ # for other unhandled exceptions: client will receive a 500 Internal Server Error
130
+ raise exc