From bec100f9c5e0d2cc4891d9d3dc992487a7046155 Mon Sep 17 00:00:00 2001 From: Max Ghenis Date: Tue, 26 May 2026 12:42:00 -0400 Subject: [PATCH] Move MicroPlex storage config to PolicyEngine --- README.md | 14 +++++++------- docs/_config.yml | 6 +++--- pyproject.toml | 8 ++++---- scripts/build_block_geography.py | 4 +++- scripts/load_pe_targets.py | 18 ++++++++++++++---- scripts/run_supabase_calibration.py | 16 +++++++++++----- scripts/targets_dashboard.py | 2 +- tests/test_supabase_client.py | 8 ++++++-- 8 files changed, 49 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 0068a28..403a8e8 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,8 @@ Multi-source microdata synthesis and survey reweighting. [![PyPI](https://img.shields.io/pypi/v/microplex.svg)](https://pypi.org/project/microplex/) -[![Tests](https://github.com/CosilicoAI/microplex/actions/workflows/test.yml/badge.svg)](https://github.com/CosilicoAI/microplex/actions/workflows/test.yml) -[![Docs](https://github.com/CosilicoAI/microplex/actions/workflows/docs.yml/badge.svg)](https://cosilicoai.github.io/microplex) +[![Tests](https://github.com/PolicyEngine/microplex/actions/workflows/test.yml/badge.svg)](https://github.com/PolicyEngine/microplex/actions/workflows/test.yml) +[![Docs](https://github.com/PolicyEngine/microplex/actions/workflows/docs.yml/badge.svg)](https://policyengine.github.io/microplex) ## Overview @@ -145,11 +145,11 @@ print(f"Using {stats['n_nonzero']} of {stats['n_records']} records") ## Documentation -Full documentation at [cosilicoai.github.io/microplex](https://cosilicoai.github.io/microplex) +Full documentation at [policyengine.github.io/microplex](https://policyengine.github.io/microplex) -- [Tutorial](https://cosilicoai.github.io/microplex/tutorial.html) -- [API Reference](https://cosilicoai.github.io/microplex/api.html) -- [Benchmarks](https://cosilicoai.github.io/microplex/benchmarks.html) +- [Tutorial](https://policyengine.github.io/microplex/tutorial.html) +- [API Reference](https://policyengine.github.io/microplex/api.html) +- [Benchmarks](https://policyengine.github.io/microplex/benchmarks.html) ## Benchmarks @@ -166,7 +166,7 @@ See [benchmarks/](benchmarks/) for synthesis method comparisons: author = {Ghenis, Max}, title = {microplex: Multi-source microdata synthesis and survey reweighting}, year = {2025}, - url = {https://github.com/CosilicoAI/microplex} + url = {https://github.com/PolicyEngine/microplex} } ``` diff --git a/docs/_config.yml b/docs/_config.yml index 88efb42..62e3808 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -1,5 +1,5 @@ title: microplex -author: Cosilico +author: PolicyEngine logo: "" execute: @@ -7,7 +7,7 @@ execute: timeout: 300 repository: - url: https://github.com/CosilicoAI/microplex + url: https://github.com/PolicyEngine/microplex path_to_book: docs branch: main @@ -18,7 +18,7 @@ sphinx: config: html_theme: sphinx_book_theme html_theme_options: - repository_url: https://github.com/CosilicoAI/micro + repository_url: https://github.com/PolicyEngine/microplex use_repository_button: true use_issues_button: true autodoc_member_order: bysource diff --git a/pyproject.toml b/pyproject.toml index baced51..ef78ec0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,7 @@ description = "Microdata synthesis and reweighting using normalizing flows" readme = "README.md" license = "MIT" authors = [ - { name = "Cosilico", email = "hello@cosilico.ai" } + { name = "PolicyEngine", email = "hello@policyengine.org" } ] keywords = [ "microdata", @@ -88,9 +88,9 @@ all = [ ] [project.urls] -Homepage = "https://github.com/CosilicoAI/microplex" -Documentation = "https://cosilicoai.github.io/microplex" -Repository = "https://github.com/CosilicoAI/microplex" +Homepage = "https://github.com/PolicyEngine/microplex" +Documentation = "https://policyengine.github.io/microplex" +Repository = "https://github.com/PolicyEngine/microplex" [tool.hatch.build.targets.wheel] packages = ["src/microplex"] diff --git a/scripts/build_block_geography.py b/scripts/build_block_geography.py index 6c46ae5..5168856 100644 --- a/scripts/build_block_geography.py +++ b/scripts/build_block_geography.py @@ -261,7 +261,9 @@ def build_block_probabilities(blocks: pd.DataFrame) -> pd.DataFrame: def upload_to_supabase(df: pd.DataFrame, table_name: str) -> bool: """Upload processed data to Supabase PostgreSQL.""" - db_url = os.environ.get("COSILICO_SUPABASE_DB_URL") + db_url = os.environ.get("POLICYENGINE_SUPABASE_DB_URL") or os.environ.get( + "COSILICO_SUPABASE_DB_URL" + ) if not db_url or not HAVE_PSYCOPG2: print(f" Skipping Supabase upload (no connection)") return False diff --git a/scripts/load_pe_targets.py b/scripts/load_pe_targets.py index 24c63f7..f4bb4df 100644 --- a/scripts/load_pe_targets.py +++ b/scripts/load_pe_targets.py @@ -12,9 +12,14 @@ from typing import List, Dict, Any, Tuple from dataclasses import dataclass, field -# Supabase connection -SUPABASE_URL = "https://nsupqhfchdtqclomlrgs.supabase.co" -SUPABASE_KEY = os.environ.get("COSILICO_SUPABASE_SERVICE_KEY") +# Supabase connection. Prefer PolicyEngine-owned secrets while accepting the +# old names during the migration window. +SUPABASE_URL = os.environ.get("POLICYENGINE_SUPABASE_URL") or os.environ.get( + "SUPABASE_URL" +) +SUPABASE_KEY = os.environ.get( + "POLICYENGINE_SUPABASE_SERVICE_KEY" +) or os.environ.get("COSILICO_SUPABASE_SERVICE_KEY") PE_BASE = "https://raw.githubusercontent.com/PolicyEngine/policyengine-us-data/main/policyengine_us_data/storage/calibration_targets" @@ -38,9 +43,14 @@ class BatchSupabaseClient: """Supabase client optimized for batch operations.""" def __init__(self, url: str, key: str, schema: str = "microplex"): + if not url: + raise ValueError( + "POLICYENGINE_SUPABASE_URL must be set before loading " + "PolicyEngine calibration targets." + ) if not key: raise ValueError( - "COSILICO_SUPABASE_SERVICE_KEY must be set before loading " + "POLICYENGINE_SUPABASE_SERVICE_KEY must be set before loading " "PolicyEngine calibration targets." ) self.base_url = f"{url}/rest/v1" diff --git a/scripts/run_supabase_calibration.py b/scripts/run_supabase_calibration.py index 8caa41b..616ff53 100644 --- a/scripts/run_supabase_calibration.py +++ b/scripts/run_supabase_calibration.py @@ -105,14 +105,20 @@ class SupabaseCalibrationLoader: } def __init__(self): - self.url = os.environ.get( - "SUPABASE_URL", - "https://nsupqhfchdtqclomlrgs.supabase.co" + self.url = os.environ.get("POLICYENGINE_SUPABASE_URL") or os.environ.get( + "SUPABASE_URL" ) - self.key = os.environ.get("COSILICO_SUPABASE_SERVICE_KEY") + self.key = os.environ.get( + "POLICYENGINE_SUPABASE_SERVICE_KEY" + ) or os.environ.get("COSILICO_SUPABASE_SERVICE_KEY") + if not self.url: + raise ValueError( + "POLICYENGINE_SUPABASE_URL must be set before running " + "Supabase calibration." + ) if not self.key: raise ValueError( - "COSILICO_SUPABASE_SERVICE_KEY must be set before running " + "POLICYENGINE_SUPABASE_SERVICE_KEY must be set before running " "Supabase calibration." ) self.base_url = f"{self.url}/rest/v1" diff --git a/scripts/targets_dashboard.py b/scripts/targets_dashboard.py index 28e6769..d5ad5db 100644 --- a/scripts/targets_dashboard.py +++ b/scripts/targets_dashboard.py @@ -486,7 +486,7 @@ def generate_html_dashboard( diff --git a/tests/test_supabase_client.py b/tests/test_supabase_client.py index 56d58b3..1bfd7bc 100644 --- a/tests/test_supabase_client.py +++ b/tests/test_supabase_client.py @@ -235,8 +235,12 @@ class TestBatchIntegration: @pytest.fixture def live_client(self): """Create a client connected to real Supabase.""" - url = os.environ.get("SUPABASE_URL") - key = os.environ.get("COSILICO_SUPABASE_SERVICE_KEY") + url = os.environ.get("POLICYENGINE_SUPABASE_URL") or os.environ.get( + "SUPABASE_URL" + ) + key = os.environ.get( + "POLICYENGINE_SUPABASE_SERVICE_KEY" + ) or os.environ.get("COSILICO_SUPABASE_SERVICE_KEY") if not url or not key: pytest.skip("No Supabase credentials - skipping integration test") if SupabaseClient is None: