mostlyai 4.0.2__tar.gz → 4.0.4__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 (84) hide show
  1. {mostlyai-4.0.2 → mostlyai-4.0.4}/PKG-INFO +64 -21
  2. {mostlyai-4.0.2 → mostlyai-4.0.4}/README.md +51 -9
  3. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/__init__.py +1 -1
  4. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/db/base.py +1 -2
  5. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/db/databricks.py +1 -1
  6. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/dtype.py +4 -4
  7. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/file/base.py +1 -1
  8. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/file/container/azure.py +1 -1
  9. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/file/table/json.py +1 -1
  10. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/pull_utils.py +2 -2
  11. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/push.py +1 -1
  12. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_local/execution/step_create_model_report.py +4 -5
  13. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_local/execution/step_generate_model_report_data.py +4 -4
  14. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_local/routes.py +26 -7
  15. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_local/storage.py +9 -2
  16. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_local/synthetic_datasets.py +8 -1
  17. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/client/_utils.py +5 -4
  18. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/client/base.py +2 -2
  19. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/domain.py +5 -6
  20. {mostlyai-4.0.2 → mostlyai-4.0.4}/pyproject.toml +17 -13
  21. {mostlyai-4.0.2 → mostlyai-4.0.4}/.gitignore +0 -0
  22. {mostlyai-4.0.2 → mostlyai-4.0.4}/LICENSE +0 -0
  23. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/__init__.py +0 -0
  24. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/auto_detect.py +0 -0
  25. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/base.py +0 -0
  26. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/context.py +0 -0
  27. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/conversions.py +0 -0
  28. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/db/__init__.py +0 -0
  29. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/db/bigquery.py +0 -0
  30. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/db/hive.py +0 -0
  31. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/db/mssql.py +0 -0
  32. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/db/mysql.py +0 -0
  33. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/db/oracle.py +0 -0
  34. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/db/postgresql.py +0 -0
  35. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/db/snowflake.py +0 -0
  36. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/db/sqlite.py +0 -0
  37. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/db/types_coercion.py +0 -0
  38. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/exceptions.py +0 -0
  39. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/file/__init__.py +0 -0
  40. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/file/container/__init__.py +0 -0
  41. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/file/container/aws.py +0 -0
  42. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/file/container/bucket_based.py +0 -0
  43. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/file/container/gcs.py +0 -0
  44. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/file/container/minio.py +0 -0
  45. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/file/table/__init__.py +0 -0
  46. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/file/table/csv.py +0 -0
  47. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/file/table/feather.py +0 -0
  48. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/file/table/parquet.py +0 -0
  49. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/file/utils.py +0 -0
  50. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/language_model.py +0 -0
  51. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/metadata_objects.py +0 -0
  52. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/non_context.py +0 -0
  53. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/progress_callback.py +0 -0
  54. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/pull.py +0 -0
  55. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/pull_context.py +0 -0
  56. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/util/__init__.py +0 -0
  57. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/util/common.py +0 -0
  58. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_data/util/kerberos.py +0 -0
  59. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_local/__init__.py +0 -0
  60. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_local/cli.py +0 -0
  61. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_local/connectors.py +0 -0
  62. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_local/execution/__init__.py +0 -0
  63. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_local/execution/jobs.py +0 -0
  64. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_local/execution/plan.py +0 -0
  65. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_local/execution/step_analyze_training_data.py +0 -0
  66. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_local/execution/step_create_data_report.py +0 -0
  67. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_local/execution/step_deliver_data.py +0 -0
  68. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_local/execution/step_encode_training_data.py +0 -0
  69. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_local/execution/step_finalize_generation.py +0 -0
  70. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_local/execution/step_finalize_training.py +0 -0
  71. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_local/execution/step_generate_data.py +0 -0
  72. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_local/execution/step_pull_training_data.py +0 -0
  73. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_local/execution/step_train_model.py +0 -0
  74. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_local/generators.py +0 -0
  75. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_local/progress.py +0 -0
  76. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/_local/server.py +0 -0
  77. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/client/__init__.py +0 -0
  78. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/client/_base_utils.py +0 -0
  79. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/client/_naming_conventions.py +0 -0
  80. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/client/api.py +0 -0
  81. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/client/connectors.py +0 -0
  82. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/client/exceptions.py +0 -0
  83. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/client/generators.py +0 -0
  84. {mostlyai-4.0.2 → mostlyai-4.0.4}/mostlyai/sdk/client/synthetic_datasets.py +0 -0
@@ -1,10 +1,10 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mostlyai
3
- Version: 4.0.2
4
- Summary: MOSTLY AI - Python Client
5
- Project-URL: Homepage, https://app.mostly.ai/
6
- Project-URL: Documentation, https://mostly-ai.github.io/mostlyai/
7
- Project-URL: Source, https://github.com/mostly-ai/mostlyai
3
+ Version: 4.0.4
4
+ Summary: Synthetic Data SDK
5
+ Project-URL: homepage, https://app.mostly.ai/
6
+ Project-URL: repository, https://github.com/mostly-ai/mostlyai
7
+ Project-URL: documentation, https://mostly-ai.github.io/mostlyai/
8
8
  Author-email: MOSTLY AI <dev@mostly.ai>
9
9
  License-Expression: Apache-2.0
10
10
  License-File: LICENSE
@@ -23,13 +23,14 @@ Classifier: Programming Language :: Python :: 3.12
23
23
  Classifier: Programming Language :: Python :: 3.13
24
24
  Classifier: Topic :: Software Development :: Libraries
25
25
  Classifier: Typing :: Typed
26
- Requires-Python: <3.13,>=3.10
26
+ Requires-Python: >=3.10
27
27
  Requires-Dist: adlfs<2024,>=2023.4.0
28
28
  Requires-Dist: azure-storage-blob<13,>=12.16.0
29
29
  Requires-Dist: cloudpathlib[azure,gs,s3]<0.18,>=0.17.0
30
30
  Requires-Dist: cryptography<44,>=43.0.1
31
31
  Requires-Dist: environs<10,>=9.5.0
32
32
  Requires-Dist: fastparquet<2024,>=2023.4.0
33
+ Requires-Dist: filelock>=3.16.1
33
34
  Requires-Dist: gcsfs<2024,>=2023.1.0
34
35
  Requires-Dist: gputil<2,>=1.4.0
35
36
  Requires-Dist: greenlet<4,>=3.1.1
@@ -66,21 +67,21 @@ Requires-Dist: kerberos<2,>=1.3.1; extra == 'hive'
66
67
  Requires-Dist: pyhive[hive-pure-sasl]<0.8,>=0.7.0; extra == 'hive'
67
68
  Provides-Extra: local
68
69
  Requires-Dist: fastapi<0.116,>=0.115.6; extra == 'local'
69
- Requires-Dist: mostlyai-engine==1.0.1; extra == 'local'
70
- Requires-Dist: mostlyai-qa==1.5.0; extra == 'local'
70
+ Requires-Dist: mostlyai-engine==1.0.2; extra == 'local'
71
+ Requires-Dist: mostlyai-qa==1.5.1; extra == 'local'
71
72
  Requires-Dist: python-multipart>=0.0.20; extra == 'local'
72
73
  Requires-Dist: uvicorn<0.35,>=0.34.0; extra == 'local'
73
74
  Provides-Extra: local-cpu
74
75
  Requires-Dist: fastapi<0.116,>=0.115.6; extra == 'local-cpu'
75
- Requires-Dist: mostlyai-engine[cpu]==1.0.1; extra == 'local-cpu'
76
- Requires-Dist: mostlyai-qa==1.5.0; extra == 'local-cpu'
76
+ Requires-Dist: mostlyai-engine[cpu]==1.0.2; extra == 'local-cpu'
77
+ Requires-Dist: mostlyai-qa==1.5.1; extra == 'local-cpu'
77
78
  Requires-Dist: python-multipart>=0.0.20; extra == 'local-cpu'
78
79
  Requires-Dist: torch>=2.5.1; extra == 'local-cpu'
79
80
  Requires-Dist: uvicorn<0.35,>=0.34.0; extra == 'local-cpu'
80
81
  Provides-Extra: local-gpu
81
82
  Requires-Dist: fastapi<0.116,>=0.115.6; extra == 'local-gpu'
82
- Requires-Dist: mostlyai-engine[gpu]==1.0.1; extra == 'local-gpu'
83
- Requires-Dist: mostlyai-qa==1.5.0; extra == 'local-gpu'
83
+ Requires-Dist: mostlyai-engine[gpu]==1.0.2; extra == 'local-gpu'
84
+ Requires-Dist: mostlyai-qa==1.5.1; extra == 'local-gpu'
84
85
  Requires-Dist: python-multipart>=0.0.20; extra == 'local-gpu'
85
86
  Requires-Dist: torch>=2.5.1; extra == 'local-gpu'
86
87
  Requires-Dist: uvicorn<0.35,>=0.34.0; extra == 'local-gpu'
@@ -158,22 +159,64 @@ For client mode, initialize with `base_url` and `api_key` obtained from your [ac
158
159
  import pandas as pd
159
160
  from mostlyai.sdk import MostlyAI
160
161
 
161
- # 1) Initialize the SDK in local or client mode
162
+ # load original data
163
+ repo_url = 'https://github.com/mostly-ai/public-demo-data'
164
+ df_original = pd.read_csv(f'{repo_url}/raw/dev/census/census.csv.gz')
165
+
166
+ # initialize the SDK in local or client mode
162
167
  mostly = MostlyAI(local=True)
163
168
  # mostly = MostlyAI(base_url='https://app.mostly.ai', api_key='YOUR_API_KEY')
164
169
 
165
- # 2) Load your original data
166
- trn_df = pd.read_csv('https://github.com/mostly-ai/public-demo-data/raw/dev/census/census.csv.gz')
170
+ # train a synthetic data generator
171
+ g = mostly.train(config={
172
+ 'name': 'US Census Income', # name of the generator
173
+ 'tables': [{ # provide list of table(s)
174
+ 'name': 'census', # name of the table
175
+ 'data': df_original, # the original data as pd.DataFrame
176
+ 'tabular_model_configuration': { # tabular model configuration (optional)
177
+ 'max_training_time': 1, # - limit training time (in minutes)
178
+ # model, max_epochs,,.. # further model configurations (optional)
179
+ 'differential_privacy': { # differential privacy configuration (optional)
180
+ 'max_epsilon': 5.0, # - max epsilon value, used as stopping criterion
181
+ 'delta': 1e-5, # - delta value
182
+ }
183
+ },
184
+ # columns, keys, compute,.. # further table configurations (optional)
185
+ }]
186
+ },
187
+ start=True, # start training immediately (default: True)
188
+ wait=True, # wait for completion (default: True)
189
+ )
190
+ ```
191
+
192
+ Once the generator has been trained, you can use it to generate synthetic data samples. Either via probing:
167
193
 
168
- # 3) Train a synthetic data generator
169
- g = mostly.train(name='census', data=trn_df) # shorthand syntax for 1-table config
194
+ ```python
195
+ # probe for some representative synthetic samples
196
+ df_samples = mostly.probe(g, size=100)
197
+ df_samples
198
+ ```
170
199
 
171
- # 4) Live probe small synthetic samples
172
- df_samples = mostly.probe(g, size=10)
200
+ or by creating a synthetic dataset entity for larger data volumes:
173
201
 
174
- # 5) Generate a full synthetic dataset
202
+ ```python
203
+ # generate a large representative synthetic dataset
175
204
  sd = mostly.generate(g, size=100_000)
176
- syn_df = sd.data()
205
+ df_synthetic = sd.data()
206
+ df_synthetic
207
+ ```
208
+
209
+ or by conditionally probing / generating synthetic data:
210
+
211
+ ```python
212
+ # create 100 seed records of 24y old Mexicans
213
+ df_seed = pd.DataFrame({
214
+ 'age': [24] * 100,
215
+ 'native_country': ['Mexico'] * 100,
216
+ })
217
+ # conditionally probe, based on provided seed
218
+ df_samples = mostly.probe(g, seed=df_seed)
219
+ df_samples
177
220
  ```
178
221
 
179
222
  ## Key Features
@@ -60,22 +60,64 @@ For client mode, initialize with `base_url` and `api_key` obtained from your [ac
60
60
  import pandas as pd
61
61
  from mostlyai.sdk import MostlyAI
62
62
 
63
- # 1) Initialize the SDK in local or client mode
63
+ # load original data
64
+ repo_url = 'https://github.com/mostly-ai/public-demo-data'
65
+ df_original = pd.read_csv(f'{repo_url}/raw/dev/census/census.csv.gz')
66
+
67
+ # initialize the SDK in local or client mode
64
68
  mostly = MostlyAI(local=True)
65
69
  # mostly = MostlyAI(base_url='https://app.mostly.ai', api_key='YOUR_API_KEY')
66
70
 
67
- # 2) Load your original data
68
- trn_df = pd.read_csv('https://github.com/mostly-ai/public-demo-data/raw/dev/census/census.csv.gz')
71
+ # train a synthetic data generator
72
+ g = mostly.train(config={
73
+ 'name': 'US Census Income', # name of the generator
74
+ 'tables': [{ # provide list of table(s)
75
+ 'name': 'census', # name of the table
76
+ 'data': df_original, # the original data as pd.DataFrame
77
+ 'tabular_model_configuration': { # tabular model configuration (optional)
78
+ 'max_training_time': 1, # - limit training time (in minutes)
79
+ # model, max_epochs,,.. # further model configurations (optional)
80
+ 'differential_privacy': { # differential privacy configuration (optional)
81
+ 'max_epsilon': 5.0, # - max epsilon value, used as stopping criterion
82
+ 'delta': 1e-5, # - delta value
83
+ }
84
+ },
85
+ # columns, keys, compute,.. # further table configurations (optional)
86
+ }]
87
+ },
88
+ start=True, # start training immediately (default: True)
89
+ wait=True, # wait for completion (default: True)
90
+ )
91
+ ```
92
+
93
+ Once the generator has been trained, you can use it to generate synthetic data samples. Either via probing:
69
94
 
70
- # 3) Train a synthetic data generator
71
- g = mostly.train(name='census', data=trn_df) # shorthand syntax for 1-table config
95
+ ```python
96
+ # probe for some representative synthetic samples
97
+ df_samples = mostly.probe(g, size=100)
98
+ df_samples
99
+ ```
72
100
 
73
- # 4) Live probe small synthetic samples
74
- df_samples = mostly.probe(g, size=10)
101
+ or by creating a synthetic dataset entity for larger data volumes:
75
102
 
76
- # 5) Generate a full synthetic dataset
103
+ ```python
104
+ # generate a large representative synthetic dataset
77
105
  sd = mostly.generate(g, size=100_000)
78
- syn_df = sd.data()
106
+ df_synthetic = sd.data()
107
+ df_synthetic
108
+ ```
109
+
110
+ or by conditionally probing / generating synthetic data:
111
+
112
+ ```python
113
+ # create 100 seed records of 24y old Mexicans
114
+ df_seed = pd.DataFrame({
115
+ 'age': [24] * 100,
116
+ 'native_country': ['Mexico'] * 100,
117
+ })
118
+ # conditionally probe, based on provided seed
119
+ df_samples = mostly.probe(g, seed=df_seed)
120
+ df_samples
79
121
  ```
80
122
 
81
123
  ## Key Features
@@ -15,4 +15,4 @@
15
15
  from mostlyai.sdk.client.api import MostlyAI
16
16
 
17
17
  __all__ = ["MostlyAI"]
18
- __version__ = "4.0.2" # Do not set this manually. Use poetry version [params].
18
+ __version__ = "4.0.4" # Do not set this manually. Use poetry version [params].
@@ -160,8 +160,7 @@ class DBDType(WrappedDType, abc.ABC):
160
160
  return VirtualTimestamp()
161
161
  else:
162
162
  _LOG.warning(
163
- f"no virtual type for [{self.wrapped}] found; "
164
- f"returning VirtualVarchar({self.DEFAULT_VARCHAR_LENGTH})"
163
+ f"no virtual type for [{self.wrapped}] found; returning VirtualVarchar({self.DEFAULT_VARCHAR_LENGTH})"
165
164
  )
166
165
  return VirtualVarchar(self.DEFAULT_VARCHAR_LENGTH)
167
166
 
@@ -96,7 +96,7 @@ class DatabricksContainer(SqlAlchemyContainer):
96
96
  if self.client_secret: # using service principal
97
97
  if not all([self.client_id, self.client_secret, self.tenant_id]):
98
98
  raise MostlyDataException(
99
- "Provide a token or " "service principal credentials (client_id, client_secret, tenant_id).",
99
+ "Provide a token or service principal credentials (client_id, client_secret, tenant_id).",
100
100
  )
101
101
  credential = ClientSecretCredential(self.tenant_id, self.client_id, self.client_secret)
102
102
  access_token = credential.get_token(f"{AZURE_DATABRICKS_SERVICE}/.default").token
@@ -40,7 +40,7 @@ _LOG = logging.getLogger(__name__)
40
40
 
41
41
  class DType(abc.ABC):
42
42
  def __eq__(self, other):
43
- return type(self) == type(other) and self.__dict__ == other.__dict__
43
+ return type(self) is type(other) and self.__dict__ == other.__dict__
44
44
 
45
45
  @classmethod
46
46
  @abc.abstractmethod
@@ -57,7 +57,7 @@ class DType(abc.ABC):
57
57
  :param other: other object
58
58
  :return: True if equivalent, False otherwise
59
59
  """
60
- if type(self) == type(other):
60
+ if type(self) is type(other):
61
61
  return self.__dict__ == other.__dict__
62
62
  elif isinstance(other, DType):
63
63
  return self.to_virtual() == other.to_virtual()
@@ -174,7 +174,7 @@ class VirtualVarchar(VirtualDType):
174
174
  return self
175
175
  max_length = data.astype(STRING).fillna("").apply(len).max()
176
176
  _LOG.warning(
177
- f"Changing {self} to VirtualVarchar with length={max_length} " f"to encompass data of length{len(data)}"
177
+ f"Changing {self} to VirtualVarchar with length={max_length} to encompass data of length{len(data)}"
178
178
  )
179
179
  return type(self)(length=max_length)
180
180
 
@@ -226,7 +226,7 @@ class WrappedDType(DType):
226
226
  return f"{type(self).__name__}(wrapped={self.wrapped})"
227
227
 
228
228
  def __eq__(self, other):
229
- return type(self) == type(other) and str(self.wrapped) == str(other.wrapped)
229
+ return type(self) is type(other) and str(self.wrapped) == str(other.wrapped)
230
230
 
231
231
  @classmethod
232
232
  @abc.abstractmethod
@@ -309,7 +309,7 @@ class FileDataTable(DataTable, abc.ABC):
309
309
  if do_coerce_dtypes:
310
310
  df = coerce_dtypes_by_encoding(df, self.encoding_types)
311
311
  df = df.reset_index(drop=True)
312
- _LOG.info(f"read {self.DATA_TABLE_TYPE} data `{self.name}` {df.shape} in {time.time()-t0:.2f}s")
312
+ _LOG.info(f"read {self.DATA_TABLE_TYPE} data `{self.name}` {df.shape} in {time.time() - t0:.2f}s")
313
313
  return df
314
314
 
315
315
  def write_data_partitioned(
@@ -61,7 +61,7 @@ class AzureBlobFileContainer(BucketBasedContainer):
61
61
  )
62
62
  else:
63
63
  raise MostlyDataException(
64
- "Provide the account key or " "service principal credentials (client_id, client_secret, tenant_id).",
64
+ "Provide the account key or service principal credentials (client_id, client_secret, tenant_id).",
65
65
  )
66
66
 
67
67
  self.fs = AzureBlobFileSystem(
@@ -100,7 +100,7 @@ class JsonDataTable(FileDataTable):
100
100
  if do_coerce_dtypes:
101
101
  df = coerce_dtypes_by_encoding(df, self.encoding_types)
102
102
  df = df.reset_index(drop=True)
103
- _LOG.info(f"read {self.DATA_TABLE_TYPE} data `{self.name}` {df.shape} in {time.time()-t0:.2f}s")
103
+ _LOG.info(f"read {self.DATA_TABLE_TYPE} data `{self.name}` {df.shape} in {time.time() - t0:.2f}s")
104
104
  return df
105
105
 
106
106
  @functools.cached_property
@@ -78,8 +78,8 @@ def determine_n_partitions(
78
78
  tgt_total_bytes = tgt_n_rows * tgt_n_cols * bytes_per_cell
79
79
  _LOG.info(
80
80
  f"estimated "
81
- f"ctx_total_bytes: {ctx_total_bytes / 1024 ** 2:.2f}MB, "
82
- f"tgt_total_bytes: {tgt_total_bytes / 1024 ** 2:.2f}MB"
81
+ f"ctx_total_bytes: {ctx_total_bytes / 1024**2:.2f}MB, "
82
+ f"tgt_total_bytes: {tgt_total_bytes / 1024**2:.2f}MB"
83
83
  )
84
84
  total_bytes = ctx_total_bytes + tgt_total_bytes
85
85
  n_partitions = max(1, int(np.ceil(total_bytes / max_partition_size)))
@@ -116,7 +116,7 @@ def adapt_dtypes_to_destination(
116
116
  tgt_dtype_cls = type(tgt_dtypes[column])
117
117
  adapted_tgt_dtype = tgt_dtype_cls.from_dtype(encompassing_dtype)
118
118
  _LOG.warning(
119
- f"Changing destination dtype of {column=} " f"from {tgt_dtypes[column]} to {adapted_tgt_dtype}"
119
+ f"Changing destination dtype of {column=} from {tgt_dtypes[column]} to {adapted_tgt_dtype}"
120
120
  )
121
121
  tgt_table.dtypes[column] = adapted_tgt_dtype
122
122
  else:
@@ -138,24 +138,24 @@ def create_report(
138
138
  ctx_columns=ctx_columns if has_context else None,
139
139
  tgt_columns=tgt_columns,
140
140
  ctx_table_name=ctx_table_name if has_context else None,
141
- tgt_table_name=target_table_name,
142
141
  max_sample_size=sample_size,
143
142
  max_sequence_length=1_000,
144
143
  )
145
144
  if step_code == StepCode.create_model_report:
145
+ report_ctx_input_path = workspace_dir / "report-ctx-data"
146
146
  syn_tgt_data, syn_ctx_data = pull_data_for_report(
147
147
  tgt_data=workspace.generated_data.fetch_all(),
148
- ctx_data=workspace.report_ctx_data.fetch_all() if has_context else None,
148
+ ctx_data=sorted(report_ctx_input_path.glob("part.*.parquet")) if has_context else None,
149
149
  **pull_kwargs,
150
150
  )
151
151
  trn_tgt_data, trn_ctx_data = pull_data_for_report(
152
152
  tgt_data=workspace.tgt_trn_data.fetch_all(),
153
- ctx_data=workspace.report_trn_ctx_data.fetch_all() if has_context else None,
153
+ ctx_data=sorted(report_ctx_input_path.glob("part.*-trn.parquet")) if has_context else None,
154
154
  **pull_kwargs,
155
155
  )
156
156
  hol_tgt_data, hol_ctx_data = pull_data_for_report(
157
157
  tgt_data=workspace.tgt_val_data.fetch_all(),
158
- ctx_data=workspace.report_val_ctx_data.fetch_all() if has_context else None,
158
+ ctx_data=sorted(report_ctx_input_path.glob("part.*-val.parquet")) if has_context else None,
159
159
  **pull_kwargs,
160
160
  )
161
161
  else: # step_code == StepCode.create_data_report:
@@ -222,7 +222,6 @@ def pull_data_for_report(
222
222
  ctx_data: Path | list[Path] | None = None,
223
223
  ctx_primary_key: str | None = None,
224
224
  tgt_context_key: str | None = None,
225
- tgt_table_name: str | None = None,
226
225
  ctx_table_name: str | None = None,
227
226
  ctx_columns: list[str] | None = None,
228
227
  tgt_columns: list[str] | None = None,
@@ -42,13 +42,13 @@ def execute_step_generate_model_report_data(
42
42
  if has_context:
43
43
  ctx_stats = workspace.ctx_stats.read()
44
44
  ctx_primary_key = ctx_stats.get("keys", {}).get("primary_key")
45
+ ctx_input_path = workspace_dir / "report-ctx-data"
45
46
  _pull_context_for_report_generation(
46
47
  ctx_data_path=workspace.ctx_data_path,
47
- output_path=workspace.report_ctx_data_path,
48
+ output_path=ctx_input_path,
48
49
  max_sample_size=max_sample_size,
49
50
  ctx_primary_key=ctx_primary_key,
50
51
  )
51
- ctx_input_path = workspace.report_ctx_data_path
52
52
  ctx_data = pd.read_parquet(ctx_input_path)
53
53
  else:
54
54
  ctx_data = None
@@ -82,8 +82,8 @@ def qa_sample_size_heuristic(tgt_stats: dict, model_type: ModelType) -> int:
82
82
  def _pull_context_for_report_generation(
83
83
  *, ctx_data_path: Path, output_path: Path, max_sample_size: int, ctx_primary_key: str
84
84
  ):
85
- ctx_trn_files = sorted(list(ctx_data_path.glob("part.*-trn.parquet")))
86
- ctx_val_files = sorted(list(ctx_data_path.glob("part.*-val.parquet")))
85
+ ctx_trn_files = sorted(ctx_data_path.glob("part.*-trn.parquet"))
86
+ ctx_val_files = sorted(ctx_data_path.glob("part.*-val.parquet"))
87
87
  # fetch keys alone first
88
88
  ctx_trn_keys = pd.concat([pd.read_parquet(f, columns=[ctx_primary_key]) for f in ctx_trn_files], ignore_index=True)
89
89
  ctx_val_keys = pd.concat([pd.read_parquet(f, columns=[ctx_primary_key]) for f in ctx_val_files], ignore_index=True)
@@ -31,6 +31,7 @@ from mostlyai.sdk._local.generators import create_generator as create_generator_
31
31
  from mostlyai.sdk._local import connectors
32
32
  from mostlyai.sdk.domain import (
33
33
  AboutService,
34
+ ConnectorType,
34
35
  CurrentUser,
35
36
  Generator,
36
37
  GeneratorPatchConfig,
@@ -52,6 +53,7 @@ from mostlyai.sdk.domain import (
52
53
  Probe,
53
54
  GeneratorCloneConfig,
54
55
  GeneratorCloneTrainingStatus,
56
+ SyntheticDatasetReportType,
55
57
  )
56
58
  from mostlyai.sdk._local.storage import (
57
59
  read_generator_from_json,
@@ -79,7 +81,7 @@ class Routes:
79
81
  <head>
80
82
  <meta charset="UTF-8">
81
83
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
82
- <title>{ title }</title>
84
+ <title>{title}</title>
83
85
  <style>
84
86
  body {{
85
87
  font-family: monospace;
@@ -93,8 +95,8 @@ class Routes:
93
95
  </style>
94
96
  </head>
95
97
  <body>
96
- <h1>{ title }</h1>
97
- { body }
98
+ <h1>{title}</h1>
99
+ {body}
98
100
  </body>
99
101
  </html>
100
102
  """
@@ -110,7 +112,7 @@ class Routes:
110
112
  async def show_connector(id: str) -> HTMLResponse:
111
113
  connector_dir = self.home_dir / "connectors" / id
112
114
  connector_json = connector_dir / "connector.json"
113
- body = f"<h3>file://{connector_json}</h3>" f"<pre>{connector_json.read_text()}</pre>"
115
+ body = f"<h3>file://{connector_json}</h3><pre>{connector_json.read_text()}</pre>"
114
116
  return HTMLResponse(content=self._html("Connector", body))
115
117
 
116
118
  @self.router.get("/d/generators/{id}", response_class=HTMLResponse, include_in_schema=False)
@@ -320,6 +322,23 @@ class Routes:
320
322
  async def clone_generator(id: str, config: GeneratorCloneConfig = Body(...)) -> Generator:
321
323
  generator_dir = self.home_dir / "generators" / id
322
324
  generator = read_generator_from_json(generator_dir)
325
+ connector_dirs = [
326
+ self.home_dir / "connectors" / t.source_connector_id
327
+ for t in generator.tables
328
+ if t.source_connector_id # if generator is imported, source_connector_id will be None
329
+ ]
330
+ # check if all connectors exist
331
+ connector_dirs = [c for c in connector_dirs if c.is_dir()]
332
+ if len(connector_dirs) < len(generator.tables):
333
+ raise HTTPException(
334
+ status_code=400,
335
+ detail="One or more connectors not found. File upload connectors are deleted after training and generation.",
336
+ )
337
+
338
+ # check if any connectors are file upload
339
+ if any(read_connector_from_json(c).type == ConnectorType.file_upload for c in connector_dirs):
340
+ raise HTTPException(status_code=400, detail="Cannot clone a generator with uploaded files.")
341
+
323
342
  new_generator = create_generator_model(
324
343
  home_dir=self.home_dir, config=GeneratorConfig(**generator.model_dump())
325
344
  )
@@ -452,16 +471,16 @@ class Routes:
452
471
  synthetic_dataset_dir = self.home_dir / "synthetic-datasets" / id
453
472
  shutil.rmtree(synthetic_dataset_dir, ignore_errors=True)
454
473
 
455
- @self.router.get("/generators/{id}/tables/{table_id}/report", response_class=HTMLResponse)
474
+ @self.router.get("/synthetic-datasets/{id}/tables/{table_id}/report", response_class=HTMLResponse)
456
475
  async def get_data_report(id: str, table_id: str, reportType: str, modelType: str) -> HTMLResponse:
457
476
  synthetic_dataset_dir = self.home_dir / "synthetic-datasets" / id
458
477
  synthetic_dataset = read_synthetic_dataset_from_json(synthetic_dataset_dir)
459
478
  table = next((t for t in synthetic_dataset.tables if t.id == table_id), None)
460
- if reportType == "MODEL":
479
+ if reportType == SyntheticDatasetReportType.model.value:
461
480
  reports_dir = self.home_dir / "synthetic-datasets" / id / "ModelQAReports"
462
481
  else:
463
482
  reports_dir = self.home_dir / "synthetic-datasets" / id / "DataQAReports"
464
- fn = reports_dir / f"{table.name}:{reportType.lower()}.html"
483
+ fn = reports_dir / f"{table.name}:{modelType.lower()}.html"
465
484
  return HTMLResponse(content=fn.read_text())
466
485
 
467
486
  @self.router.get("/synthetic-datasets/{id}/generation", response_model=JobProgress)
@@ -18,6 +18,7 @@ import zipfile
18
18
  from io import BytesIO
19
19
 
20
20
  from pydantic import BaseModel
21
+ from filelock import FileLock
21
22
  from mostlyai.sdk.domain import Generator, JobProgress, Connector, SyntheticDataset
22
23
 
23
24
 
@@ -45,7 +46,10 @@ def write_connector_to_json(connector_dir: Path, connector: Connector) -> None:
45
46
 
46
47
  def read_job_progress_from_json(resource_dir: Path) -> JobProgress:
47
48
  progress_file = resource_dir / "job_progress.json"
48
- return JobProgress(**json.loads(progress_file.read_text()))
49
+ lock_file = progress_file.with_suffix(".lock")
50
+ lock = FileLock(lock_file)
51
+ with lock:
52
+ return JobProgress(**json.loads(progress_file.read_text()))
49
53
 
50
54
 
51
55
  def write_job_progress_to_json(resource_dir: Path, job_progress: JobProgress) -> None:
@@ -86,4 +90,7 @@ def write_to_json(file_path: Path, obj: BaseModel) -> None:
86
90
  # serialize with camelCase aliases for platform compatibility
87
91
  by_alias=True,
88
92
  )
89
- file_path.write_text(json_str)
93
+ lock_file = file_path.with_suffix(".lock")
94
+ lock = FileLock(lock_file)
95
+ with lock:
96
+ file_path.write_text(json_str)
@@ -11,7 +11,7 @@
11
11
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  # See the License for the specific language governing permissions and
13
13
  # limitations under the License.
14
-
14
+ import shutil
15
15
  from pathlib import Path
16
16
 
17
17
  from mostlyai.sdk._local.storage import (
@@ -99,6 +99,8 @@ def create_synthetic_dataset(
99
99
  sd_table.configuration.sample_size = size.get(g_table.name, default_sample_size)
100
100
  elif not is_subject:
101
101
  sd_table.configuration.sample_size = None # sample size is not applicable to linked tables
102
+ sd_table.tabular_model_metrics = g_table.tabular_model_metrics
103
+ sd_table.language_model_metrics = g_table.language_model_metrics
102
104
  sd_tables.append(sd_table)
103
105
 
104
106
  # create synthetic dataset
@@ -114,6 +116,11 @@ def create_synthetic_dataset(
114
116
  synthetic_dataset_dir = home_dir / "synthetic-datasets" / synthetic_dataset.id
115
117
  write_synthetic_dataset_to_json(synthetic_dataset_dir, synthetic_dataset)
116
118
 
119
+ # copy ModelQA reports into synthetic dataset directory
120
+ source_reports_dir = generator_dir / "ModelQAReports"
121
+ dest_reports_dir = synthetic_dataset_dir / "ModelQAReports"
122
+ shutil.copytree(source_reports_dir, dest_reports_dir)
123
+
117
124
  # create job progress
118
125
  progress_steps: list[ProgressStep] = []
119
126
  for table in generator.tables:
@@ -39,6 +39,7 @@ from mostlyai.sdk.domain import (
39
39
  SyntheticTableConfig,
40
40
  Connector,
41
41
  SyntheticDataset,
42
+ GeneratorListItem,
42
43
  )
43
44
  from mostlyai.sdk.client._naming_conventions import map_camel_to_snake_case
44
45
 
@@ -123,12 +124,10 @@ def job_wait(
123
124
  # break if step has failed or been canceled
124
125
  if step.status in (ProgressStatus.failed, ProgressStatus.canceled):
125
126
  rich.print(f"[red]Step {step.model_label} {step.step_code.value} {step.status.lower()}")
126
- progress.stop()
127
127
  return
128
128
  # check whether we are done
129
129
  if job.progress.value >= job.progress.max:
130
130
  time.sleep(1) # give the system a moment to update the status
131
- progress.stop()
132
131
  return
133
132
  else:
134
133
  if job.end_date or job.progress in (
@@ -139,8 +138,10 @@ def job_wait(
139
138
  return
140
139
  except KeyboardInterrupt:
141
140
  rich.print(f"[red]Step {step.model_label} {step.step_code.value} {step.status.lower()}")
142
- progress.stop()
143
141
  return
142
+ finally:
143
+ if progress_bar:
144
+ progress.stop()
144
145
 
145
146
 
146
147
  def _get_subject_table_names(generator: Generator) -> list[str]:
@@ -174,7 +175,7 @@ def harmonize_sd_config(
174
175
  size = size if size is not None else {}
175
176
  seed = seed if seed is not None else {}
176
177
 
177
- if isinstance(generator, Generator):
178
+ if isinstance(generator, Generator | GeneratorListItem):
178
179
  generator_id = str(generator.id)
179
180
  elif generator is not None:
180
181
  generator_id = str(generator)
@@ -162,12 +162,12 @@ class _MostlyBaseClient:
162
162
  if response.content:
163
163
  # this section could be split into a separate method
164
164
  response_json = response.json()
165
- if isinstance(response_json, dict) and not response_type == dict:
165
+ if isinstance(response_json, dict) and response_type is not dict:
166
166
  if do_include_client:
167
167
  response_json["client"] = self
168
168
  if isinstance(extra_key_values, dict):
169
169
  response_json["extra_key_values"] = extra_key_values
170
- elif response_type == dict and do_response_dict_snake_case:
170
+ elif response_type is dict and do_response_dict_snake_case:
171
171
  response_json = map_camel_to_snake_case(response_json)
172
172
  return response_type(**response_json) if isinstance(response_json, dict) else response_json
173
173
  else:
@@ -13,7 +13,7 @@
13
13
  # limitations under the License.
14
14
 
15
15
  # generated by datamodel-codegen:
16
- # timestamp: 2025-01-23T15:57:07+00:00
16
+ # timestamp: 2025-01-23T22:58:04+00:00
17
17
 
18
18
  from __future__ import annotations
19
19
 
@@ -2397,7 +2397,7 @@ class Generator(CustomBaseModel):
2397
2397
  file_path.write_bytes(bytes)
2398
2398
  return file_path
2399
2399
 
2400
- def clone(self, training_status: Literal["NEW", "CONTINUE"] = "NEW") -> "Generator":
2400
+ def clone(self, training_status: Literal["NEW", "CONTINUE"] = "NEW") -> Generator:
2401
2401
  """
2402
2402
  Clone the generator.
2403
2403
 
@@ -2447,7 +2447,7 @@ class Generator(CustomBaseModel):
2447
2447
  return file_path
2448
2448
 
2449
2449
  class Training:
2450
- def __init__(self, _generator: "Generator"):
2450
+ def __init__(self, _generator: Generator):
2451
2451
  self.generator = _generator
2452
2452
 
2453
2453
  def start(self) -> None:
@@ -2517,8 +2517,7 @@ class GeneratorConfig(CustomBaseModel):
2517
2517
  ref_table = table_map.get(fk.referenced_table)
2518
2518
  if not ref_table:
2519
2519
  raise ValueError(
2520
- f"Foreign key in table '{table.name}' references a non-existent table: "
2521
- f"'{fk.referenced_table}'."
2520
+ f"Foreign key in table '{table.name}' references a non-existent table: '{fk.referenced_table}'."
2522
2521
  )
2523
2522
  if not ref_table.primary_key:
2524
2523
  raise ValueError(f"Referenced table '{fk.referenced_table}' does not have a primary key.")
@@ -2726,7 +2725,7 @@ class SyntheticDataset(CustomBaseModel):
2726
2725
  return file_path
2727
2726
 
2728
2727
  class Generation:
2729
- def __init__(self, _synthetic_dataset: "SyntheticDataset"):
2728
+ def __init__(self, _synthetic_dataset: SyntheticDataset):
2730
2729
  self.synthetic_dataset = _synthetic_dataset
2731
2730
 
2732
2731
  def start(self) -> None:
@@ -1,9 +1,9 @@
1
1
  [project]
2
2
  name = "mostlyai"
3
- version = "4.0.2"
4
- description = "MOSTLY AI - Python Client"
3
+ version = "4.0.4"
4
+ description = "Synthetic Data SDK"
5
5
  authors = [{ name = "MOSTLY AI", email = "dev@mostly.ai" }]
6
- requires-python = ">=3.10,<3.13"
6
+ requires-python = ">=3.10"
7
7
  readme = "README.md"
8
8
  license = "Apache-2.0"
9
9
  classifiers = [
@@ -57,28 +57,29 @@ dependencies = [
57
57
  "smart-open[gcs, s3, azure]>=6.3.0,<7",
58
58
  "azure-storage-blob>=12.16.0,<13",
59
59
  "adlfs>=2023.4.0,<2024",
60
+ "filelock>=3.16.1",
60
61
  ]
61
62
 
62
63
  [project.optional-dependencies]
63
64
  local = [
64
65
  # local
65
- "mostlyai-engine==1.0.1",
66
- "mostlyai-qa==1.5.0",
66
+ "mostlyai-engine==1.0.2",
67
+ "mostlyai-qa==1.5.1",
67
68
  "fastapi>=0.115.6,<0.116",
68
69
  "uvicorn>=0.34.0,<0.35",
69
70
  "python-multipart>=0.0.20",
70
71
  ]
71
72
  local-gpu = [
72
- "mostlyai-engine[gpu]==1.0.1",
73
- "mostlyai-qa==1.5.0",
73
+ "mostlyai-engine[gpu]==1.0.2",
74
+ "mostlyai-qa==1.5.1",
74
75
  "fastapi>=0.115.6,<0.116",
75
76
  "uvicorn>=0.34.0,<0.35",
76
77
  "python-multipart>=0.0.20",
77
78
  "torch>=2.5.1",
78
79
  ]
79
80
  local-cpu = [
80
- "mostlyai-engine[cpu]==1.0.1",
81
- "mostlyai-qa==1.5.0",
81
+ "mostlyai-engine[cpu]==1.0.2",
82
+ "mostlyai-qa==1.5.1",
82
83
  "fastapi>=0.115.6,<0.116",
83
84
  "uvicorn>=0.34.0,<0.35",
84
85
  "python-multipart>=0.0.20",
@@ -104,7 +105,7 @@ dev = [
104
105
  "pre-commit>=4.0.0,<5",
105
106
  "datamodel-code-generator[http]>=0.26.3,<0.27",
106
107
  "vcrpy>=5.1.0,<6",
107
- "ruff==0.4.4",
108
+ "ruff==0.9.2",
108
109
  "respx>=0.20.2,<0.21",
109
110
  "twine>=6.0.1,<7",
110
111
  "pkginfo>=1.12.0,<2",
@@ -121,9 +122,9 @@ docs = [
121
122
  ]
122
123
 
123
124
  [project.urls]
124
- Homepage = "https://app.mostly.ai/"
125
- Documentation = "https://mostly-ai.github.io/mostlyai/"
126
- Source = "https://github.com/mostly-ai/mostlyai"
125
+ homepage = "https://app.mostly.ai/"
126
+ repository = "https://github.com/mostly-ai/mostlyai"
127
+ documentation = "https://mostly-ai.github.io/mostlyai/"
127
128
 
128
129
  [tool.uv]
129
130
  default-groups = ["dev", "docs"]
@@ -170,3 +171,6 @@ replace = '__version__ = "{new_version}"'
170
171
  [tool.ruff]
171
172
  target-version = "py310"
172
173
  line-length = 120
174
+
175
+ [tool.ruff.lint.per-file-ignores]
176
+ "*.ipynb" = ["E402"]
File without changes
File without changes