Skip to content

main

Main entry point for stimulus-py cli.

Functions:

  • check_model

    Check model configuration and run initial tests.

  • cli

    Stimulus is an open-science framework for data processing and model training.

  • shuffle_csv

    Shuffle rows in a CSV data file.

  • split_csv

    Split rows in a CSV data file.

  • split_split

    Split a YAML configuration file into multiple YAML files, each containing a unique split.

  • split_transforms

    Split a YAML configuration file into multiple YAML files, each containing a unique transform.

  • transform_csv

    Transform data in a CSV file according to configuration.

  • tune

    Run hyperparameter tuning for a model.

check_model

check_model(
    data: str,
    model: str,
    data_config: str,
    model_config: str,
    optuna_results_dirpath: str,
) -> None

Check model configuration and run initial tests.

Source code in src/stimulus/cli/main.py
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
@cli.command()
@click.option(
    "-d",
    "--data",
    type=click.Path(exists=True),
    required=True,
    help="Path to input csv file",
)
@click.option(
    "-m",
    "--model",
    type=click.Path(exists=True),
    required=True,
    help="Path to model file",
)
@click.option(
    "-e",
    "--data-config",
    type=click.Path(exists=True),
    required=True,
    help="Path to data config file",
)
@click.option(
    "-c",
    "--model-config",
    type=click.Path(exists=True),
    required=True,
    help="Path to yaml config training file",
)
@click.option(
    "-r",
    "--optuna-results-dirpath",
    type=click.Path(),
    default="./optuna_results",
    help="Location for optuna results output directory [default: ./optuna_results]",
)
def check_model(
    data: str,
    model: str,
    data_config: str,
    model_config: str,
    optuna_results_dirpath: str,
) -> None:
    """Check model configuration and run initial tests."""
    from stimulus.cli.check_model import check_model as check_model_func

    check_model_func(
        data_path=data,
        model_path=model,
        data_config_path=data_config,
        model_config_path=model_config,
        optuna_results_dirpath=optuna_results_dirpath,
    )

cli

cli() -> None

Stimulus is an open-science framework for data processing and model training.

Source code in src/stimulus/cli/main.py
11
12
13
14
@click.group(context_settings={"help_option_names": ["-h", "--help"]})
@click.version_option(version("stimulus-py"), "-v", "--version")
def cli() -> None:
    """Stimulus is an open-science framework for data processing and model training."""

shuffle_csv

shuffle_csv(csv: str, yaml: str, output: str) -> None

Shuffle rows in a CSV data file.

Source code in src/stimulus/cli/main.py
 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
@cli.command()
@click.option(
    "-c",
    "--csv",
    type=click.Path(exists=True),
    required=True,
    help="The file path for the csv containing the data in csv format",
)
@click.option(
    "-y",
    "--yaml",
    type=click.Path(exists=True),
    required=True,
    help="The YAML data config",
)
@click.option(
    "-o",
    "--output",
    type=click.Path(),
    required=True,
    help="The output file path to write the shuffled csv",
)
def shuffle_csv(
    csv: str,
    yaml: str,
    output: str,
) -> None:
    """Shuffle rows in a CSV data file."""
    from stimulus.cli.shuffle_csv import shuffle_csv as shuffle_csv_func

    shuffle_csv_func(
        data_csv=csv,
        config_yaml=yaml,
        out_path=output,
    )

split_csv

split_csv(
    csv: str, yaml: str, output: str, *, force: bool
) -> None

Split rows in a CSV data file.

Source code in src/stimulus/cli/main.py
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
@cli.command()
@click.option(
    "-c",
    "--csv",
    type=click.Path(exists=True),
    required=True,
    help="The file path for the csv containing all data",
)
@click.option(
    "-y",
    "--yaml",
    type=click.Path(exists=True),
    required=True,
    help="The YAML config file that holds all parameter info",
)
@click.option(
    "-o",
    "--output",
    type=click.Path(),
    required=True,
    help="The output file path to write the split csv",
)
@click.option(
    "-f",
    "--force",
    is_flag=True,
    default=False,
    help="Overwrite the split column if it already exists in the csv",
)
def split_csv(
    csv: str,
    yaml: str,
    output: str,
    *,
    force: bool,
) -> None:
    """Split rows in a CSV data file."""
    from stimulus.cli.split_csv import split_csv as split_csv_func

    split_csv_func(
        data_csv=csv,
        config_yaml=yaml,
        out_path=output,
        force=force,
    )

split_split

split_split(yaml: str, out_dir: str) -> None

Split a YAML configuration file into multiple YAML files, each containing a unique split.

Source code in src/stimulus/cli/main.py
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
@cli.command()
@click.option(
    "-y",
    "--yaml",
    type=click.Path(exists=True),
    required=True,
    help="The YAML config file that hold all transform - split - parameter info",
)
@click.option(
    "-d",
    "--out-dir",
    type=click.Path(),
    required=False,
    default="./",
    help="The output dir where all the YAMLs are written to. Output YAML will be called split-#[number].yaml transform-#[number].yaml. Default -> ./",
)
def split_split(
    yaml: str,
    out_dir: str,
) -> None:
    """Split a YAML configuration file into multiple YAML files, each containing a unique split."""
    from stimulus.cli.split_split import split_split as split_split_func

    split_split_func(config_yaml=yaml, out_dir_path=out_dir)

split_transforms

split_transforms(yaml: str, out_dir: str) -> None

Split a YAML configuration file into multiple YAML files, each containing a unique transform.

Source code in src/stimulus/cli/main.py
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
@cli.command()
@click.option(
    "-y",
    "--yaml",
    type=click.Path(exists=True),
    required=True,
    help="The YAML config file that hold all the transform per split parameter info",
)
@click.option(
    "-d",
    "--out-dir",
    type=click.Path(),
    required=False,
    default="./",
    help="The output dir where all the YAMLs are written to. Output YAML will be called split_transform-#[number].yaml. Default -> ./",
)
def split_transforms(
    yaml: str,
    out_dir: str,
) -> None:
    """Split a YAML configuration file into multiple YAML files, each containing a unique transform."""
    from stimulus.cli.split_transforms import split_transforms as split_transforms_func

    split_transforms_func(config_yaml=yaml, out_dir_path=out_dir)

transform_csv

transform_csv(csv: str, yaml: str, output: str) -> None

Transform data in a CSV file according to configuration.

Source code in src/stimulus/cli/main.py
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
@cli.command()
@click.option(
    "-c",
    "--csv",
    type=click.Path(exists=True),
    required=True,
    help="The file path for the csv containing the data to transform",
)
@click.option(
    "-y",
    "--yaml",
    type=click.Path(exists=True),
    required=True,
    help="The YAML config file that holds transformation parameters",
)
@click.option(
    "-o",
    "--output",
    type=click.Path(),
    required=True,
    help="The output file path to write the transformed csv",
)
def transform_csv(
    csv: str,
    yaml: str,
    output: str,
) -> None:
    """Transform data in a CSV file according to configuration."""
    from stimulus.cli.transform_csv import main as transform_csv_func

    transform_csv_func(
        data_csv=csv,
        config_yaml=yaml,
        out_path=output,
    )

tune

tune(
    data: str,
    model: str,
    data_config: str,
    model_config: str,
    output: str,
    best_optimizer: str,
    optuna_results_dirpath: str,
) -> None

Run hyperparameter tuning for a model.

Source code in src/stimulus/cli/main.py
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
@cli.command()
@click.option(
    "-d",
    "--data",
    type=click.Path(exists=True),
    required=True,
    help="Path to input csv file",
)
@click.option(
    "-m",
    "--model",
    type=click.Path(exists=True),
    required=True,
    help="Path to model file",
)
@click.option(
    "-e",
    "--data-config",
    type=click.Path(exists=True),
    required=True,
    help="Path to data config file",
)
@click.option(
    "-c",
    "--model-config",
    type=click.Path(exists=True),
    required=True,
    help="Path to yaml config training file",
)
@click.option(
    "-o",
    "--output",
    type=click.Path(),
    default="best_model.safetensors",
    help="Path to save the best model [default: best_model.safetensors]",
)
@click.option(
    "-bo",
    "--best-optimizer",
    type=click.Path(),
    default="best_optimizer.pt",
    help="Path to save the best optimizer [default: best_optimizer.pt]",
)
@click.option(
    "-r",
    "--optuna-results-dirpath",
    type=click.Path(),
    default="./optuna_results",
    help="Location for optuna results output directory",
)
def tune(
    data: str,
    model: str,
    data_config: str,
    model_config: str,
    output: str,
    best_optimizer: str,
    optuna_results_dirpath: str,
) -> None:
    """Run hyperparameter tuning for a model."""
    from stimulus.cli.tuning import tune as tune_func

    tune_func(
        data_path=data,
        model_path=model,
        data_config_path=data_config,
        model_config_path=model_config,
        optuna_results_dirpath=optuna_results_dirpath,
        best_model_path=output,
        best_optimizer_path=best_optimizer,
    )