-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1825 from InstituteforDiseaseModeling/1810-fix
1810 fix
- Loading branch information
Showing
63 changed files
with
958 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[COMMON] | ||
# Number of threads idmtools will use for analysis and other multi-threaded activities | ||
max_threads = 16 | ||
|
||
# How many simulations per threads during simulation creation | ||
sims_per_thread = 20 | ||
|
||
# Maximum number of LOCAL simulation ran simultaneously | ||
max_local_sims = 6 | ||
|
||
# Maximum number of workers processing in parallel | ||
max_workers = 16 | ||
|
||
# Maximum batch size to retrieve simulations | ||
batch_size = 10 | ||
|
||
id_generator = item_sequence | ||
|
||
[item_sequence] | ||
id_format_str = {{ item_name }}{{ '%%07d' | format(data[item_name] | int) }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import os | ||
import sys | ||
from functools import partial | ||
from typing import Any, Dict | ||
from pathlib import Path | ||
from idmtools import IdmConfigParser | ||
from idmtools.builders import SimulationBuilder | ||
from idmtools.core.platform_factory import Platform | ||
from idmtools.entities.experiment import Experiment | ||
from idmtools.entities.simulation import Simulation | ||
from idmtools.entities.templated_simulation import TemplatedSimulations | ||
from idmtools_models.python.json_python_task import JSONConfiguredPythonTask | ||
from idmtools_test.utils.utils import clear_id_cache | ||
|
||
# NOTE TO USER | ||
# You need to define your own SlurmNative configuration block before running this example | ||
# Please update 'idmtools_item_sequence_example.ini' accordingly | ||
|
||
platform = Platform('SlurmNative') | ||
clear_id_cache() | ||
parser = IdmConfigParser() | ||
parser._load_config_file(file_name='idmtools_item_sequence_example.ini') | ||
parser.ensure_init(file_name='idmtools_item_sequence_example.ini', force=True) | ||
sequence_file = Path(IdmConfigParser.get_option("item_sequence", "sequence_file", | ||
Path().home().joinpath(".idmtools", "itemsequence", "index.json"))) | ||
if sequence_file.exists(): | ||
sequence_file.unlink() | ||
|
||
task = JSONConfiguredPythonTask(script_path=os.path.join("..", "..", "..", "examples", "python_model", "inputs", "python_model_with_deps", "Assets", "model.py"), | ||
parameters=(dict(c=0))) | ||
|
||
ts = TemplatedSimulations(base_task=task) | ||
experiment = Experiment.from_template(ts) | ||
builder = SimulationBuilder() | ||
|
||
def param_update(simulation: Simulation, param: str, value: Any) -> Dict[str, Any]: | ||
simulation.task.set_parameter(param, value) | ||
simulation.tags['id'] = simulation.id | ||
return {param: value} | ||
|
||
builder.add_sweep_definition(partial(param_update, param="a"), range(2)) | ||
builder.add_sweep_definition(partial(param_update, param="b"), range(2)) | ||
experiment.simulations.add_builder(builder) | ||
|
||
experiment.tags['id'] = experiment.id | ||
experiment.simulations = list(experiment.simulations) | ||
|
||
with platform: | ||
experiment.run(wait_until_done=True) | ||
sys.exit(0 if experiment.succeeded else -1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
===================== | ||
ID Generation Plugins | ||
===================== | ||
|
||
**1. Create a file to host the plugin callback for generator (under idmtools_core/idmtools/plugins). The plugin must have the following format**:: | ||
|
||
from idmtools.core.interfaces.ientity import IEntity | ||
|
||
from idmtools.registry.hook_specs import function_hook_impl | ||
|
||
@function_hook_impl | ||
|
||
def idmtools_generate_id(item: IEntity) -> str: | ||
Args: | ||
item: Item for which ID is being generated | ||
Returns: | ||
return <your id implementation here> | ||
|
||
|
||
The key things in this file are:: | ||
|
||
@function_hook_impl | ||
def idmtools_generate_id(item: 'IEntity') -> str: | ||
|
||
This registers the plugin type with idmtools. By using the name idmtools_generate_id, we know you are defining a callback for ids. | ||
The callback must match the expected signature. | ||
|
||
|
||
**2. Modify setup.py 'idmtools_hooks' to include the new id generation plugin**:: | ||
|
||
entry_points=dict( | ||
idmtools_hooks=[ | ||
"idmtools_id_generate_<name> = <path to plugin>" | ||
] | ||
), | ||
|
||
The *label* of the id plugin must start with **idmtools_id_generate_** | ||
The letters after **idmtools_id_generate_** will be used to select generator in the config. | ||
|
||
**3. Modify .ini config file to specify the desired id generator.** | ||
|
||
In the .ini configuration file under the 'COMMON' section, use the 'id_generator' option to specify the desired id plugin. | ||
|
||
For example, if you want to use the uuid generation plugin ('idmtools_id_generate_uuid'), in the .ini file, you would set the following:: | ||
|
||
[COMMON] | ||
id_generator = uuid | ||
|
||
Similarly, if you want to use the item_sequence plugin ('idmtools_id_generate_item_sequence'), you would specify the following in the .ini file:: | ||
|
||
[COMMON] | ||
id_generator = item_sequence | ||
|
||
The item_sequence plugin allows you to use sequential ids for items in your experiment (experiments themselves as well as simulations, etc). | ||
You can customize use of this plugin by defining an 'item_sequence' section in the .ini file and using the variables: | ||
|
||
* *sequence_file*: Json file that is used to store the last-used numbers for item ids. For example, if we have one experiment that was defined with two simulations, this file would keep track of the most recently used ids with the following: {"Simulation": 2, "Experiment": 1}. To note: the sequences start at 0. The default value for this filename (if it is not defined by the user) is index.json, which would be created in the user's home directory (at '.idmtools/itemsequence/index.json'). If a sequence_file IS specified, it is stored in the current working directory unless otherwise specified by a full path. If an item is generated that does not have the item_type attribute (i.e. Platform), its sequence will be stored under the 'Unknown' key in this json file. After an experiment is run, there will be a backup of this sequence file generated at the same location ({sequence_file_name}.json.bak); this is called as a post_run hook (specified under 'idmtools_platform_post_run' in item_sequence.py). | ||
* *id_format_str*: This defines the desired format of the item ids (using the sequential id numbers stored in the sequence_file). In this string, one may access the sequential ids by using 'data[item_name]' (which would resolve to the next id #) as well as the 'item_name' (i.e. 'Simulation', 'Experiment'). The default for this value is '{item_name}{data[item_name]:07d}' (which would yield ids of 'Simulation0000000', 'Simulation0000001', etc). | ||
|
||
Configuration format:: | ||
|
||
[item_sequence] | ||
sequence_file = <custom file name>.json | ||
id_format_str = '<custom string format>' | ||
|
||
The configuration string format should be a jinja2 template. See https://jinja.palletsprojects.com/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
========================= | ||
Plugin Documentation | ||
========================= | ||
|
||
.. toctree:: | ||
:maxdepth: 3 | ||
:titlesonly: | ||
|
||
id-generator-plugins |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ pytest-xdist~=3.1 | |
pytest~=7.2.0 | ||
xmlrunner~=1.7.7 | ||
pytest-lazy-fixture | ||
jinja2~=3.1.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.