|
| 1 | +import getpass |
| 2 | +import uuid |
| 3 | +from jobmon.client.tool import Tool # type: ignore |
| 4 | +from pathlib import Path |
| 5 | +import geopandas as gpd # type: ignore |
| 6 | +from idd_forecast_mbp import constants as rfc |
| 7 | + |
| 8 | +repo_name = rfc.repo_name |
| 9 | +package_name = rfc.package_name |
| 10 | + |
| 11 | +hold_variables = { |
| 12 | + 'malaria': ['DAH', 'flood', 'gdppc', 'suitability'], |
| 13 | + 'dengue': ['gdppc', 'suitability', 'urban'], |
| 14 | +} |
| 15 | +run_hold_variables = False |
| 16 | + |
| 17 | +template_name = f'{repo_name}_06_03_create_and_combine' |
| 18 | + |
| 19 | +run_date = "2025_07_24" |
| 20 | +run_date = '2025_08_04' |
| 21 | +run_date = '2025_08_28' |
| 22 | +dah_scenarios = rfc.dah_scenarios |
| 23 | +dah_scenarios = ['Baseline', 'Constant'] |
| 24 | +dah_scenarios = ['Baseline'] |
| 25 | +# dah_scenarios = ['reference', 'better', 'worse'] |
| 26 | + |
| 27 | +causes = rfc.cause_map |
| 28 | +# causes = ['dengue'] |
| 29 | +ssp_scenarios = rfc.ssp_scenarios |
| 30 | +# ssp_scenarios = ['ssp245'] |
| 31 | + |
| 32 | + |
| 33 | +# Script directory |
| 34 | +SCRIPT_ROOT = rfc.REPO_ROOT / repo_name / "src" / package_name / "06_upload" |
| 35 | + |
| 36 | +draws = rfc.draws |
| 37 | + |
| 38 | +# Jobmon setup |
| 39 | +user = getpass.getuser() |
| 40 | + |
| 41 | +log_dir = Path("/mnt/team/idd/pub/") |
| 42 | +log_dir.mkdir(parents=True, exist_ok=True) |
| 43 | +# Create directories for stdout and stderr |
| 44 | +stdout_dir = log_dir / "stdout" |
| 45 | +stderr_dir = log_dir / "stderr" |
| 46 | +stdout_dir.mkdir(parents=True, exist_ok=True) |
| 47 | +stderr_dir.mkdir(parents=True, exist_ok=True) |
| 48 | + |
| 49 | +# Project |
| 50 | +project = "proj_rapidresponse" # Adjust this to your project name if needed |
| 51 | +queue = 'all.q' |
| 52 | + |
| 53 | +wf_uuid = uuid.uuid4() |
| 54 | +tool_name = f"{package_name}_create_summaries_{wf_uuid}" |
| 55 | +tool = Tool(name=tool_name) |
| 56 | + |
| 57 | +# Create a workflow |
| 58 | +workflow = tool.create_workflow( |
| 59 | + name=f"{tool_name}_workflow_{wf_uuid}", |
| 60 | + max_concurrently_running=10000, # Adjust based on system capacity |
| 61 | +) |
| 62 | + |
| 63 | +# Compute resources |
| 64 | +workflow.set_default_compute_resources_from_dict( |
| 65 | + cluster_name="slurm", |
| 66 | + dictionary={ |
| 67 | + "memory": "15G", |
| 68 | + "cores": 1, |
| 69 | + "runtime": "60m", |
| 70 | + "queue": queue, |
| 71 | + "project": project, |
| 72 | + "stdout": str(stdout_dir), |
| 73 | + "stderr": str(stderr_dir), |
| 74 | + } |
| 75 | +) |
| 76 | + |
| 77 | +memory = "100G" |
| 78 | + |
| 79 | +# Define the task template for processing each year batch |
| 80 | +task_template = tool.get_task_template( |
| 81 | + template_name=template_name, |
| 82 | + default_cluster_name="slurm", |
| 83 | + default_compute_resources={ |
| 84 | + "memory": memory, |
| 85 | + "cores": 10, |
| 86 | + "runtime": "60m", |
| 87 | + "queue": queue, |
| 88 | + "project": project, |
| 89 | + "stdout": str(stdout_dir), |
| 90 | + "stderr": str(stderr_dir), |
| 91 | + }, |
| 92 | + command_template=( |
| 93 | + "python {script_root}/create_and_combine_as_draws.py " |
| 94 | + "--cause {{cause}} " |
| 95 | + "--ssp_scenario {{ssp_scenario}} " |
| 96 | + "--dah_scenario {{dah_scenario}} " |
| 97 | + "--measure {{measure}} " |
| 98 | + "--hold_variable {{hold_variable}} " |
| 99 | + "--run_date {{run_date}}" |
| 100 | + ).format(script_root=SCRIPT_ROOT), |
| 101 | + node_args=["cause", "ssp_scenario", "dah_scenario", "measure", "hold_variable", "run_date"], |
| 102 | + task_args=[], |
| 103 | + op_args=[], |
| 104 | +) |
| 105 | + |
| 106 | + |
| 107 | +tasks = [] |
| 108 | + |
| 109 | +for cause in causes: |
| 110 | + for ssp_scenario in ssp_scenarios: |
| 111 | + for measure in ['mortality', 'incidence']: |
| 112 | + if cause == "malaria": |
| 113 | + for dah_scenario in dah_scenarios: |
| 114 | + # Create the primary task |
| 115 | + task = task_template.create_task( |
| 116 | + cause=cause, |
| 117 | + ssp_scenario=ssp_scenario, |
| 118 | + dah_scenario=dah_scenario, |
| 119 | + measure=measure, |
| 120 | + hold_variable='None', |
| 121 | + run_date=run_date, |
| 122 | + ) |
| 123 | + tasks.append(task) |
| 124 | + else: |
| 125 | + # Create the primary task |
| 126 | + task = task_template.create_task( |
| 127 | + cause=cause, |
| 128 | + ssp_scenario=ssp_scenario, |
| 129 | + dah_scenario='None', |
| 130 | + measure=measure, |
| 131 | + hold_variable='None', |
| 132 | + run_date=run_date, |
| 133 | + ) |
| 134 | + tasks.append(task) |
| 135 | +if run_hold_variables: |
| 136 | + for cause in causes: |
| 137 | + for hold_variable in hold_variables[cause]: |
| 138 | + for ssp_scenario in rfc.ssp_scenarios: |
| 139 | + for measure in ['mortality', 'incidence']: |
| 140 | + if cause == "malaria": |
| 141 | + for dah_scenario in dah_scenarios: |
| 142 | + # Create the primary task |
| 143 | + task = task_template.create_task( |
| 144 | + cause=cause, |
| 145 | + ssp_scenario=ssp_scenario, |
| 146 | + dah_scenario=dah_scenario, |
| 147 | + measure=measure, |
| 148 | + hold_variable=hold_variable, |
| 149 | + run_date=run_date |
| 150 | + ) |
| 151 | + tasks.append(task) |
| 152 | + else: |
| 153 | + # Create the primary task |
| 154 | + task = task_template.create_task( |
| 155 | + cause=cause, |
| 156 | + ssp_scenario=ssp_scenario, |
| 157 | + dah_scenario=None, |
| 158 | + measure=measure, |
| 159 | + hold_variable=hold_variable, |
| 160 | + run_date=run_date |
| 161 | + ) |
| 162 | + tasks.append(task) |
| 163 | + |
| 164 | +print(f"Number of tasks: {len(tasks)}") |
| 165 | + |
| 166 | +if tasks: |
| 167 | + workflow.add_tasks(tasks) |
| 168 | + print("✅ Tasks successfully added to workflow.") |
| 169 | +else: |
| 170 | + print("⚠️ No tasks added to workflow. Check task generation.") |
| 171 | + |
| 172 | +try: |
| 173 | + workflow.bind() |
| 174 | + print("✅ Workflow successfully bound.") |
| 175 | + print(f"Running workflow with ID {workflow.workflow_id}.") |
| 176 | + print("For full information see the Jobmon GUI:") |
| 177 | + print(f"https://jobmon-gui.ihme.washington.edu/#/workflow/{workflow.workflow_id}") |
| 178 | +except Exception as e: |
| 179 | + print(f"❌ Workflow binding failed: {e}") |
| 180 | + |
| 181 | +try: |
| 182 | + status = workflow.run() |
| 183 | + print(f"Workflow {workflow.workflow_id} completed with status {status}.") |
| 184 | +except Exception as e: |
| 185 | + print(f"❌ Workflow submission failed: {e}") |
0 commit comments