Skip to content

Commit 98d9f31

Browse files
authored
Merge pull request #399 from PolicyEngine/fix/deprecate-national-orchestrator
Remove national orchestrator job
2 parents 4647d01 + 40c814c commit 98d9f31

15 files changed

Lines changed: 34 additions & 1024 deletions

File tree

projects/policyengine-api-simulation/src/modal/app.py

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -104,53 +104,3 @@ def run_simulation(params: dict) -> dict:
104104
return result
105105
finally:
106106
logfire.force_flush()
107-
108-
109-
@app.function(
110-
image=simulation_image,
111-
cpu=2.0,
112-
memory=4096,
113-
timeout=7200, # 2 hours to wait for all 52 jobs
114-
retries=0,
115-
secrets=[gcp_secret, logfire_secret],
116-
)
117-
def run_national_with_breakdowns(params: dict) -> dict:
118-
"""
119-
Orchestrate parallel simulations and aggregate results.
120-
121-
Spawns:
122-
- 1 national ECPS simulation (region="us")
123-
- State-level simulations (51 states or 10 test states if _test_mode=True)
124-
125-
Each spawned job runs in its own container via run_simulation.
126-
Returns combined national results with congressional district breakdowns.
127-
128-
If _test_mode=True in params, runs only 10 test states instead of all 51.
129-
"""
130-
import logfire
131-
132-
from src.modal.orchestration import run_national_orchestration
133-
from src.modal.utils.state_codes import TEST_STATE_CODES
134-
135-
configure_logfire()
136-
137-
# Check for test mode
138-
test_mode = params.pop("_test_mode", False)
139-
state_codes = TEST_STATE_CODES if test_mode else None
140-
141-
try:
142-
with logfire.span(
143-
"run_national_with_breakdowns",
144-
input_params=params,
145-
test_mode=test_mode,
146-
) as span:
147-
result = run_national_orchestration(params, run_simulation, state_codes)
148-
span.set_attribute(
149-
"total_districts",
150-
len(
151-
result.get("congressional_district_impact", {}).get("districts", [])
152-
),
153-
)
154-
return result
155-
finally:
156-
logfire.force_flush()

projects/policyengine-api-simulation/src/modal/gateway/endpoints.py

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@ def get_app_name(country: str, version: Optional[str]) -> tuple[str, str]:
5050
return app_name, resolved_version
5151

5252

53-
NATIONAL_WITH_BREAKDOWNS = "national-with-breakdowns"
54-
NATIONAL_WITH_BREAKDOWNS_TEST = "national-with-breakdowns-test"
55-
56-
5753
@router.post("/simulate/economy/comparison", response_model=JobSubmitResponse)
5854
async def submit_simulation(request: SimulationRequest):
5955
"""
@@ -62,57 +58,18 @@ async def submit_simulation(request: SimulationRequest):
6258
Matches the existing Cloud Run API endpoint path.
6359
Routes to the appropriate app based on country and version params.
6460
Returns immediately with job_id for polling.
65-
66-
Special handling for data="national-with-breakdowns":
67-
- Only supported for country="us"
68-
- Spawns 52 parallel simulations (1 national + 51 states)
69-
- Returns aggregated results with congressional district breakdowns
70-
71-
Special handling for data="national-with-breakdowns-test":
72-
- Only supported for country="us"
73-
- Spawns 11 parallel simulations (1 national + 10 test states)
74-
- Returns aggregated results with congressional district breakdowns
7561
"""
7662
try:
7763
app_name, resolved_version = get_app_name(request.country, request.version)
7864
except ValueError as e:
7965
raise HTTPException(status_code=400, detail=str(e))
8066

81-
# Check for national-with-breakdowns special cases
8267
payload = request.model_dump(exclude={"version"})
83-
data_value = payload.get("data")
84-
is_national_breakdowns = data_value in (
85-
NATIONAL_WITH_BREAKDOWNS,
86-
NATIONAL_WITH_BREAKDOWNS_TEST,
87-
)
8868

89-
if is_national_breakdowns:
90-
if request.country.lower() != "us":
91-
raise HTTPException(
92-
status_code=400,
93-
detail="national-with-breakdowns is only supported for country='us'",
94-
)
95-
96-
# Add test_mode flag to payload for orchestration to use
97-
if data_value == NATIONAL_WITH_BREAKDOWNS_TEST:
98-
payload["_test_mode"] = True
99-
logger.info(
100-
f"Routing {request.country}:{resolved_version} to {app_name} "
101-
f"(national-with-breakdowns-test orchestration - 10 states)"
102-
)
103-
else:
104-
logger.info(
105-
f"Routing {request.country}:{resolved_version} to {app_name} "
106-
f"(national-with-breakdowns orchestration - all states)"
107-
)
108-
109-
func_name = "run_national_with_breakdowns"
110-
else:
111-
logger.info(f"Routing {request.country}:{resolved_version} to app {app_name}")
112-
func_name = "run_simulation"
69+
logger.info(f"Routing {request.country}:{resolved_version} to app {app_name}")
11370

11471
# Get function reference from the target app
115-
sim_func = modal.Function.from_name(app_name, func_name)
72+
sim_func = modal.Function.from_name(app_name, "run_simulation")
11673

11774
# Spawn the job (returns immediately)
11875
call = sim_func.spawn(payload)

projects/policyengine-api-simulation/src/modal/orchestration.py

Lines changed: 0 additions & 138 deletions
This file was deleted.

projects/policyengine-api-simulation/src/modal/utils/__init__.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

projects/policyengine-api-simulation/src/modal/utils/state_codes.py

Lines changed: 0 additions & 75 deletions
This file was deleted.

projects/policyengine-api-simulation/tests/fixtures/__init__.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
"""Test fixtures for the simulation API tests."""
22

3-
from tests.fixtures.orchestration import (
4-
MockFunctionCall,
5-
create_mock_run_simulation,
6-
)
73
from tests.fixtures.endpoints import (
84
MockDict,
95
MockFunction,
@@ -12,8 +8,6 @@
128
)
139

1410
__all__ = [
15-
"MockFunctionCall",
16-
"create_mock_run_simulation",
1711
"MockDict",
1812
"MockFunction",
1913
"MockModalFunctionCall",

0 commit comments

Comments
 (0)