emod_task
EMODTask
dataclass
Bases: ITask
Central orchestration class for configuring and running EMOD simulations.
EMODTask extends idmtools.ITask and wires together all the components needed for an EMOD
experiment: configuration parameters, campaign interventions, demographics, migration files,
climate data, reporters, and the Eradication binary. It manages both experiment-level assets
(shared across all simulations) and simulation-level assets (unique per simulation).
Two factory methods are provided for creating tasks:
from_defaults— builds everything from schema defaults using user-supplied callback functions (config_builder, campaign_builder, demographics_builder, report_builder). This is the primary entry point and supports parameter sweeps.from_files— loads pre-existing JSON files (config, campaign, demographics, reports) directly, for working with hand-authored or legacy configurations.
During the idmtools lifecycle, pre_creation finalizes the configuration by merging
migrations, wiring reporters into config, setting campaign filenames, and building the command
line. Asset gathering methods (gather_common_assets, gather_transient_assets)
collect the files that idmtools submits to the execution platform (COMPS, SLURM, containers).
Attributes:
| Name | Type | Description |
|---|---|---|
eradication_path |
str
|
Path to the Eradication binary. Can also be set via the
|
demographics |
DemographicsFiles
|
Experiment-level demographics files shared by all simulations. |
migrations |
MigrationFiles
|
Experiment-level migration files shared by all simulations. |
reporters |
Reporters
|
Reporter definitions (e.g. InsetChart, EventReporter) that produce custom_reports.json. |
climate |
ClimateFiles
|
Experiment-level climate input files (air temperature, rainfall, humidity). |
config |
dict
|
EMOD configuration parameters dictionary. Built from schema defaults via
|
config_file_name |
str
|
Filename used when writing the configuration to a simulation asset. |
campaign |
EMODCampaign
|
Campaign object holding intervention events. Serialized to campaign.json for each simulation. |
simulation_demographics |
DemographicsFiles
|
Simulation-level demographics files (e.g. overlays) that vary per simulation. |
simulation_migrations |
MigrationFiles
|
Simulation-level migration files that vary per
simulation. Merged with experiment-level migrations in |
schema_path |
str
|
Path to the EMOD schema.json file used to build default config and campaign objects. |
use_embedded_python |
bool
|
When True, adds |
py_path_list |
list
|
List of paths prepended to |
is_linux |
bool
|
Set to True during |
implicit_configs |
list
|
Accumulated implicit configuration functions from demographics
and campaign builders that are executed during |
sif_filename |
str
|
Filename of the Singularity image (.sif) used on COMPS to create the execution environment. |
sif_path |
Filesystem path to the Singularity image, used on SLURM/File/Process platforms. |
Source code in emodpy/emod_task.py
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 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 | |
__post_init__()
Initialize derived state after dataclass field assignment.
Sets the default executable name to "Eradication", adds "./Assets/python" to the
embedded Python path list, and resolves the Eradication binary path — either from
the explicitly provided eradication_path or from the [emodpy] section of the
idmtools config file.
Source code in emodpy/emod_task.py
add_embedded_python_scripts_from_path(path)
Adds embedded python scripts from the path to the common assets
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Union[str, Path, List[Union[str, Path]]]
|
Relative or absolute path to the file (including the file name) or to a folder containing python scripts. Please note, all the python scripts in a specified folder will be added to the simulation. path may also be a list of such items, each added independently. |
required |
Source code in emodpy/emod_task.py
add_py_path(path_to_add)
Add path to list of python paths prepended to sys.path in embedded interpreter
Returns:
add_serialized_population_files_from_path(path)
Adds serialized population files from the path to the common assets
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Relative or absolute path to the file (including the file name) or to the folder containing the .dtk files. Please note, all the .dtk files in the folder will be added and be used in the simulations. |
required |
Source code in emodpy/emod_task.py
build_default_campaign(schema_path)
staticmethod
Build the default (empty) campaign and set its schema_path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema_path
|
Union[str, Path]
|
Path to the schema file. |
required |
Returns:
| Type | Description |
|---|---|
campaign
|
Fresh initialized campaign module with schema_path set |
Source code in emodpy/emod_task.py
build_default_config(schema_path)
staticmethod
Build the default config object from the schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema_path
|
Union[str, Path]
|
Path to the schema file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ReadOnlyDict |
ReadOnlyDict
|
The default config based on the schema. |
Source code in emodpy/emod_task.py
copy_simulation(base_simulation)
Called when making copies of a simulation. We deep copy parts of the simulation to ensure we don't accidentally share objects between simulations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_simulation
|
Simulation
|
Base Simulation |
required |
Returns:
| Type | Description |
|---|---|
Simulation
|
New Simulation |
Source code in emodpy/emod_task.py
create_campaign_from_callback(builder, verbose=False, bootstrapped=False)
This function is responsible for generating and configuring a campaign using a provided builder function. It also handles the custom events that are generated by the campaign by adding them to the config.
Parameters:
| Name | Type | Description | Default | ||
|---|---|---|---|---|---|
builder
|
Callable
|
Function that creates and adds interventions to the campaign module. The function needs to take the campaign module as the first required argument, which can then be followed by parameters that you want to modify within the interventions. These additional parameters are then available to be modified in a sweep. The function must return the campaign module at the end. Example::
|
required | ||
verbose
|
bool
|
If True, prints debug information about the generated file. |
False
|
||
bootstrapped
|
bool
|
Set to True if the campaign builder will build a campaign from scratch itself. False if it will accept an initialized campaign from this function instead and then modify it. Default False. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in emodpy/emod_task.py
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 | |
create_demographics_from_callback(builder, from_sweep=False, verbose=False)
Creates a demographics file using a builder function and manages its storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
builder
|
Callable
|
A function that generates the demographics object. |
required |
from_sweep
|
bool
|
If True, the demographics file is stored in a temporary location. |
False
|
verbose
|
bool
|
If True, prints debug information about the generated file. |
False
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in emodpy/emod_task.py
from_defaults(schema_path, eradication_path=None, config_builder=None, campaign_builder=None, demographics_builder=None, report_builder=None, embedded_python_scripts_path=None, serialized_population_files=None, bootstrapped=False)
classmethod
Create a task from emod-api defaults and functions to update them.
Parameters:
| Name | Type | Description | Default | ||
|---|---|---|---|---|---|
schema_path
|
str
|
Path to processed schema.json, including the filename. |
required | ||
eradication_path
|
str
|
Path to Eradication binary, including the filename. You can also add Eradication as an asset. |
None
|
||
config_builder
|
Callable
|
Function that sets parameters for config. The function must have config object as the
parameter and return the config object. Inside the function, the config object will be modified in
the following way: config.parameters. Example::
|
None
|
||
campaign_builder
|
Callable
|
Function that creates and adds interventions to the campaign module. The function needs to take the campaign module as the first required argument, which can then be followed by parameters that you want to modify within the interventions. These additional parameters are then available to be modified in a sweep. The function must return the campaign module at the end. Example::
|
None
|
||
demographics_builder
|
Callable
|
Function that builds the demographics configuration and optional migration configuration. Example::
|
None
|
||
report_builder
|
Callable[[Reporters], Reporters]
|
Function that creates reports to be used in the experiment. The function must have Reporters object as the parameter and return that object. It is assumed that all the reporters come from the reporters that are part of EMOD main code. EMOD also supports reporters as custom plug-in dlls, however, not through the current emodpy system. Example::
|
None
|
||
embedded_python_scripts_path
|
Union[str, Path, List[Union[str, Path]]]
|
Path to folder with python scripts or a list of paths to specific python scripts. When path to folder, all python scripts in the folder will be added to the experiment. embedded_python_scripts_path may also be a list of such items, each added independently. Note: We no longer support passing in a function for this parameter. |
None
|
||
serialized_population_files
|
Union[str, List[str]]
|
Path to folder containing .dtk serialized population files or specific .dtk file, including the filename. All .dtk files in the folder will be added and used in the experiment. |
None
|
||
bootstrapped
|
bool
|
Set to True if the campaign builder will build a campaign from scratch itself. False if it will accept an initialized campaign from this function instead and then modify it. Default False. |
False
|
Returns:
| Type | Description |
|---|---|
EMODTask
|
EMODTask |
Source code in emodpy/emod_task.py
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 491 492 493 494 495 496 | |
from_files(eradication_path=None, config_path=None, campaign_path=None, demographics_paths=None, custom_reports_path=None, embedded_python_scripts_path=None, serialized_population_files=None, asset_path=None)
classmethod
Load custom EMOD files when creating [EMODTask][].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eradication_path
|
str
|
Path to Eradication binary, including the filename. |
None
|
config_path
|
str
|
Path to the configuration file, including the filename. |
None
|
campaign_path
|
str
|
Path to the campaign file, including the filename. |
None
|
demographics_paths
|
Union[str, list]
|
Path or a list of paths to the folder containing demographics files or path to a specific demographics file, including the filename. When path to folder, all .json files in the folder will be added to the experiment as demographics files. |
None
|
custom_reports_path
|
str
|
Path to the custom reports file, including the filename. It is assumed that all the reporters in the file come from the reporters that are part of EMOD main code. EMOD also supports reporters as custom plug-in dlls, however, not through the current emodpy system. |
None
|
embedded_python_scripts_path
|
Union[str, list[str]]
|
Path to folder with python scripts or path to a specific python script, including the filename. When path to folder, all python scripts in the folder will be added to the experiment. Note: We no longer support passing in a function for this parameter. |
None
|
serialized_population_files
|
Union[str, list[str]]
|
Path to folder containing .dtk serialized population files or specific .dtk file, including the filename. All .dtk files in the folder will be added and used in the experiment. |
None
|
asset_path
|
str
|
Path to migration and/or climate files. |
None
|
Returns:
| Type | Description |
|---|---|
EMODTask
|
An initialized experiment |
Source code in emodpy/emod_task.py
gather_common_assets()
Gather Experiment Level Assets Returns:
Source code in emodpy/emod_task.py
gather_transient_assets()
Gather assets that are per simulation Returns: AssetCollection
Source code in emodpy/emod_task.py
get_parameter(name, default=None)
Get a parameter in the simulation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the parameter. |
required |
default
|
Optional[Any]
|
Optional, the default value. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The value of the parameter. |
Source code in emodpy/emod_task.py
handle_implicit_configs()
Execute the implicit config functions created by the demographics builder.
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in emodpy/emod_task.py
pre_creation(parent, platform)
Call before a task is executed. This ensures our configuration is properly done
Source code in emodpy/emod_task.py
set_command_line()
Build and set the command line object.
Returns:
Source code in emodpy/emod_task.py
set_parameter(name, value)
Set a value in the EMOD config.json file. This will be deprecated in the future in favour of emod_api.config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of parameter to set |
required |
value
|
any
|
Value to set |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Tags to set |
Source code in emodpy/emod_task.py
set_parameter_partial(parameter)
classmethod
Convenience callback for sweeps
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parameter
|
str
|
Parameter to set |
required |
Returns:
| Type | Description |
|---|---|
partial[Simulation]
|
Partial function |
Source code in emodpy/emod_task.py
set_parameter_sweep_callback(simulation, param, value)
staticmethod
Convenience callback for sweeps
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
Simulation
|
Simulation we are updating |
required |
param
|
str
|
Parameter |
required |
value
|
Any
|
Value |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Tags to set on simulation |
Source code in emodpy/emod_task.py
set_sif(path_to_sif, platform)
Set the singularity image file to use for creating the EMOD execution environment.
Parameters:
| Name | Type | Description | Default | ||
|---|---|---|---|---|---|
path_to_sif
|
Union[Path, str]
|
non-COMPSPlatforms: The file system path to the sif file for creating the EMOD execution environment. COMPSPlatform: Either:
ContainerPlatform: No sif file specification is used. |
required | ||
platform
|
IPlatform
|
Platform object to use for this task. |
required |
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in emodpy/emod_task.py
EMODTaskSpecification
Bases: TaskSpecification
Idmtools implemented each platform and task as a Plugin and idmtools is able to identify them and use them dynamically. For example, idmtools workflow is able to crete each Platform with Plaform Factory and each Task with Task Factory. The link defined in setup.py entrypoint is the way to allow idmtools workflow to identify them.
Take EMODTaskSpecification as an example, idmtools uses it internally and indirectly (user usually doesn't create an instance of it, but idmtools work may do in certain case). This EMODTaskSpecification entry in setup.py has been used in idmtools workflow in two places:
CLI command - check idmtools related packages installed (version including plugins): idmtools version - check available Task: idmtools info plugins task
Source code in emodpy/emod_task.py
get(configuration)
Return an EMODTask object using provided configuration Args: configuration: Configuration for Task
Returns:
| Type | Description |
|---|---|
EMODTask
|
EMODTask for configuration |
Source code in emodpy/emod_task.py
get_description()
Defines a description of the plugin
Returns:
| Type | Description |
|---|---|
str
|
Plugin description |
get_type()
get_version()
Return the version string for EMODTask. This should be the module version so return that
Returns:
| Type | Description |
|---|---|
str
|
Version |