feat: Add Modal simulation API alongside GCP Workflows #3065
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #3064
Requires PolicyEngine/policyengine-api-v2#383
Summary
Adds Modal simulation API support alongside the existing GCP Workflows implementation, allowing the economy report endpoint to use either backend via environment variable configuration.
Changes
New Files
policyengine_api/libs/simulation_api_modal.py- HTTP client for Modal APIpolicyengine_api/libs/simulation_api_factory.py- Factory to select GCP or Modal backendtests/unit/libs/test_simulation_api_modal.py- Unit tests for Modal client (20 tests)tests/unit/libs/test_simulation_api_factory.py- Unit tests for factory (7 tests)tests/fixtures/libs/simulation_api_modal.py- Test fixtures for Modal clienttests/fixtures/libs/simulation_api_factory.py- Test fixtures for factoryModified Files
policyengine_api/constants.py- Added status constants for GCP and Modalpolicyengine_api/services/economy_service.py- Uses factory, handles both status formatssetup.py- Addedhttpx>=0.27.0dependencytests/fixtures/services/economy_service.py- Added Modal test fixturestests/unit/services/test_economy_service.py- Added Modal status tests (5 tests)How to Enable Modal
By default (
USE_MODAL_SIMULATION_APIunset orfalse), the existing GCP Workflows backend is used.Test plan
SimulationAPIModal(20 tests)EconomyService(5 tests)Notes
model_versionfield is mapped toversionfor the Modal APIdata_versionis removed as Modal doesn't use itexecution_idcolumn works with both ID formatspolicyengine_usversion to match a version deployed on Modal🤖 Generated with Claude Code