Skip to content

Commit f7d519f

Browse files
Generic launch_task_for_single_config_asset script (#428)
1 parent 838d194 commit f7d519f

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

obi_one/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from obi_one.core.path import NamedPath
77
from obi_one.core.run_tasks import (
88
run_task_for_single_config,
9+
run_task_for_single_config_asset,
910
run_task_for_single_configs,
1011
run_tasks_for_generated_scan,
1112
)
@@ -165,6 +166,7 @@
165166
"nbS1VPMInputs",
166167
"rCA1CA3Inputs",
167168
"run_task_for_single_config",
169+
"run_task_for_single_config_asset",
168170
"run_task_for_single_configs",
169171
"run_tasks_for_generated_scan",
170172
"write_circuit_node_set_file",
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import argparse
2+
import logging
3+
import os
4+
5+
import entitysdk
6+
from entitysdk import Client, ProjectContext
7+
8+
from obi_one.core.run_tasks import run_task_for_single_config_asset
9+
10+
L = logging.getLogger(__name__)
11+
12+
13+
def main() -> None:
14+
"""Script to launch a task for a single configuration asset.
15+
16+
Example usage.
17+
18+
python launch_task_for_single_config_asset.py
19+
--entity_type Simulation
20+
--entity_id 1569a81e-b578-4c39-a3a9-f9a05f123db9
21+
--config_asset_id c9edaedf-e5c0-4643-979c-47375f3160e0
22+
--lab_id 123e4567-e89b-12d3-a456-426614174000
23+
--project_id 987e6543-e21b-12d3-a456-426614174999
24+
25+
Environment Variables Required:
26+
OBI_AUTHENTICATION_TOKEN: Your authentication token for the platform.
27+
"""
28+
parser = argparse.ArgumentParser(
29+
description="Script to launch a task for a single configuration asset."
30+
)
31+
32+
parser.add_argument("--entity_type", required=True, help="EntitySDK Entity type as string")
33+
parser.add_argument("--entity_id", required=True, help="Entity ID as string")
34+
parser.add_argument("--config_asset_id", required=True, help="Configuration Asset ID as string")
35+
parser.add_argument("--lab_id", required=True, help="Virtual Lab ID as string")
36+
parser.add_argument("--project_id", required=True, help="Project ID as string.")
37+
38+
args = parser.parse_args()
39+
40+
entity_type_str = args.entity_type
41+
entity_id = args.entity_id
42+
config_asset_id = args.config_asset_id
43+
lab_id = args.lab_id
44+
project_id = args.project_id
45+
46+
entity_type = getattr(entitysdk.models, entity_type_str)
47+
48+
token = os.getenv("OBI_AUTHENTICATION_TOKEN")
49+
50+
project_context = ProjectContext(virtual_lab_id=lab_id, project_id=project_id)
51+
db_client = Client(token_manager=token, project_context=project_context)
52+
53+
run_task_for_single_config_asset(
54+
entity_type=entity_type,
55+
entity_id=entity_id,
56+
config_asset_id=config_asset_id,
57+
db_client=db_client,
58+
)
59+
60+
61+
if __name__ == "__main__":
62+
main()

obi_one/core/run_tasks.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import entitysdk
22

33
from obi_one.core.scan_generation import ScanGenerationTask
4+
from obi_one.core.serialization import deserialize_obi_object_from_json_data
45
from obi_one.core.single import SingleConfigMixin
56
from obi_one.scientific.unions.config_task_map import get_configs_task_type
67

@@ -35,3 +36,32 @@ def run_tasks_for_generated_scan(
3536
run_task_for_single_configs(
3637
scan_generation.single_configs, db_client=db_client, entity_cache=entity_cache
3738
)
39+
40+
41+
def run_task_for_single_config_asset(
42+
entity_type: type[entitysdk.models.entity.Entity],
43+
entity_id: str,
44+
config_asset_id: str,
45+
*,
46+
db_client: entitysdk.client.Client = None,
47+
entity_cache: bool = False,
48+
) -> None:
49+
"""Run the appropriate task for a single configuration stored as an asset.
50+
51+
Example usage:
52+
obi.run_task_for_single_config_asset(entity_type=entitysdk.models.simulation.Simulation,
53+
entity_id="1569a81e-b578-4c39-a3a9-f9a05f123db9",
54+
config_asset_id="c9edaedf-e5c0-4643-979c-47375f3160e0",
55+
db_client=db_client)
56+
57+
"""
58+
content = db_client.download_content(
59+
entity_id=entity_id, entity_type=entity_type, asset_id=config_asset_id
60+
).decode(encoding="utf-8")
61+
62+
single_config = deserialize_obi_object_from_json_data(content)
63+
run_task_for_single_config(
64+
single_config,
65+
db_client=db_client,
66+
entity_cache=entity_cache,
67+
)

0 commit comments

Comments
 (0)