Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- bump: minor
changes:
changed:
- Enable Modal simulation API by default instead of GCP Workflows
6 changes: 3 additions & 3 deletions policyengine_api/libs/simulation_api_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@


def get_simulation_api() -> (
Union["SimulationAPI", "SimulationAPIModal"] # noqa: F821
):
Union["SimulationAPI", "SimulationAPIModal"]
): # noqa: F821
"""
Get the appropriate simulation API client based on environment configuration.

Expand All @@ -37,7 +37,7 @@ def get_simulation_api() -> (
If GCP client is requested but GOOGLE_APPLICATION_CREDENTIALS is not set.
"""
use_modal = (
os.environ.get("USE_MODAL_SIMULATION_API", "false").lower() == "true"
os.environ.get("USE_MODAL_SIMULATION_API", "true").lower() == "true"
)

if use_modal:
Expand Down
35 changes: 14 additions & 21 deletions tests/unit/libs/test_simulation_api_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,36 +120,29 @@ def test__given_use_modal_env_false__then_returns_gcp_api(
# Then
assert isinstance(api, SimulationAPI)

def test__given_use_modal_env_not_set__then_returns_gcp_api(
def test__given_use_modal_env_not_set__then_returns_modal_api(
self,
mock_factory_logger,
):
# Given
# Given - default is now Modal when env var is not set
import os

env_copy = dict(os.environ)
env_copy.pop("USE_MODAL_SIMULATION_API", None)
env_copy["GOOGLE_APPLICATION_CREDENTIALS"] = "/path/to/creds.json"

with patch.dict("os.environ", env_copy, clear=True):
with patch(
"policyengine_api.libs.simulation_api.executions_v1.ExecutionsClient"
):
with patch(
"policyengine_api.libs.simulation_api.workflows_v1.WorkflowsClient"
):
from policyengine_api.libs.simulation_api_factory import (
get_simulation_api,
)
from policyengine_api.libs.simulation_api import (
SimulationAPI,
)
from policyengine_api.libs.simulation_api_factory import (
get_simulation_api,
)
from policyengine_api.libs.simulation_api_modal import (
SimulationAPIModal,
)

# When
api = get_simulation_api()
# When
api = get_simulation_api()

# Then
assert isinstance(api, SimulationAPI)
# Then
assert isinstance(api, SimulationAPIModal)

def test__given_use_modal_env_false__then_logs_gcp_selection(
self,
Expand Down Expand Up @@ -189,11 +182,11 @@ def test__given_gcp_selected_without_credentials__then_raises_error(
self,
mock_factory_logger,
):
# Given
# Given - explicitly select GCP without credentials
import os

env_copy = dict(os.environ)
env_copy.pop("USE_MODAL_SIMULATION_API", None)
env_copy["USE_MODAL_SIMULATION_API"] = "false"
env_copy.pop("GOOGLE_APPLICATION_CREDENTIALS", None)

with patch.dict("os.environ", env_copy, clear=True):
Expand Down
Loading