Substra
federated_experiment
run_federated_experiment(strategy, n_centers=2, backend='subprocess', register_data=False, simulate=True, centers_root_directory=None, assets_directory=None, compute_plan_name='FedPyDESeq2Experiment', dataset_name='TCGA', remote_timeout=86400, clean_models=True, save_filepath=None, credentials_path=None, dataset_datasamples_keys_path=None, cp_id_path=None, fedpydeseq2_wheel_path=None)
Run a federated experiment with the given strategy.
In remote mode, if the data is already registered, the assets_directory and centers_root_directory are not used (register_data=False).
Otherwise, the assets_directory and centers_root_directory must be provided. The assets_directory is expected to contain the opener.py and description.md files, used to create the dataset for all centers. The centers_root_directory is expected to contain a subdirectory for each center, in the following form:
These directories contain the necessary data for each center and are passed to the DataSampleSpec object to register the data to substra.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
strategy
|
ComputePlanBuilder
|
The strategy to use for the federated experiment. |
required |
n_centers
|
int
|
The number of centers to use in the experiment. |
2
|
backend
|
BackendType
|
The backend to use for the experiment. Can be one of "subprocess", "docker", or "remote". |
'subprocess'
|
register_data
|
bool
|
Whether to register the data. If True, the assets_directory and centers_root_directory must be provided. Can be False only in "remote" mode. |
False
|
simulate
|
bool
|
Whether to simulate the experiment. If True, the experiment must be run in subprocess mode. |
True
|
centers_root_directory
|
Optional[Path]
|
The path to the root directory containing the data for each center. This is only used if register_data is True. |
None
|
assets_directory
|
Optional[Path]
|
The path to the assets directory. It must contain the opener.py file and the description.md file. This is only used if register_data is True. |
None
|
compute_plan_name
|
str
|
The name of the compute plan. |
'FedPyDESeq2Experiment'
|
dataset_name
|
str
|
The name of the dataset to use, to be passed to the DatasetSpec object and used to create the path of the yaml file storing the dataset and datasample keys. |
'TCGA'
|
remote_timeout
|
int
|
The timeout for the remote backend in seconds. |
86400
|
clean_models
|
bool
|
Whether to clean the models after the experiment. |
True
|
save_filepath
|
Optional[Union[str, Path]]
|
The path to save the results. If None, the results are not saved. |
None
|
credentials_path
|
Optional[Union[str, Path]]
|
The path to the credentials file. By default, will be set to Path(file).parent / "credentials/credentials.yaml" This file is used only in remote mode, and is expected to be a dictionary with the following structure: The first organization is assumed to be the algorithm provider. The other organizations are the data providers. |
None
|
dataset_datasamples_keys_path
|
Optional[Union[str, Path]]
|
The path to the file containing the dataset and datasamples keys.
If None, and if backend is "remote", will be set to
Path(file).parent / "credentials/ |
None
|
cp_id_path
|
str or Path
|
The path to a file where we save the necessary information to retrieve the compute plan. This parameter is only used in remote mode. If None, this information is not saved. If a path is provided, the information is saved in a yaml file with the following structure: |
None
|
fedpydeseq2_wheel_path
|
Optional[Union[str, Path]]
|
The path to the wheel file of the fedpydeseq2 package. If provided and the backend is remote, this wheel will be added to the dependencies. |
None
|
Returns:
Type | Description |
---|---|
dict
|
Result of the strategy, which are assumed to be contained in the results attribute of the last round of the aggregation node. |
Source code in fedpydeseq2/substra_utils/federated_experiment.py
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 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 |
|
utils
cancel_compute_plan(cp_id_path)
Cancel a compute plan.
We assume that we are in the remote setting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cp_id_path
|
str or Path
|
required |
Source code in fedpydeseq2/substra_utils/utils.py
check_datasample_folder(datasample_folder)
Sanity check for the datasample folder.
Check if the datasample folder contains only two csv files: counts_data.csv and metadata.csv and nothing else.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
datasample_folder
|
Path
|
Path to the datasample folder. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the datasample folder does not contain exactly two files named 'counts_data.csv' and 'metadata.csv'. |
Source code in fedpydeseq2/substra_utils/utils.py
get_client(backend_type, org_name=None, credentials_path=None)
Return a substra client for a given organization.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
backend_type
|
str
|
Name of the backend to connect to. Should be "subprocess", "docker" or "remote" |
required |
org_name
|
str, optional.
|
Name of the organization to connect to. Required when using remote backend. |
None
|
credentials_path
|
str or Path
|
Path to the credentials file. By default, will be set to Path(file).parent / "credentials/credentials.yaml" |
None
|
Source code in fedpydeseq2/substra_utils/utils.py
get_dependencies(backend_type, fedpydeseq2_wheel_path=None)
Return a substra Dependency in regard to the backend_type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
backend_type
|
BackendType
|
Name of the backend to connect to. Should be "subprocess", "docker" or "remote" |
required |
fedpydeseq2_wheel_path
|
str | Path | None
|
Path to the wheel file of the fedpydeseq2 package. If provided and the backend is remote or docker, this wheel will be used instead of downloading it. |
None
|
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the wheel file cannot be downloaded or found. |
Source code in fedpydeseq2/substra_utils/utils.py
get_n_centers_from_datasamples_file(datasamples_file)
Return the number of centers from a datasamples file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
datasamples_file
|
str | Path
|
Path to the yaml file containing the datasamples keys of the dataset. |
required |
Returns:
Type | Description |
---|---|
int
|
Number of centers in the datasamples file. |