镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

fix: invalidate optimization grids when scenario inputs change - #1997

Open
AliFozooni wants to merge 1 commit into
google:mainfrom
AliFozooni:fix/optimization-grid-scenario-validation
Open

AliFozooni wants to merge 1 commit into
google:mainfrom
AliFozooni:fix/optimization-grid-scenario-validation

Conversation

@AliFozooni

Copy link
Copy Markdown

Fixes #1996.

Reusing an optimization grid after changing media delivery at the same spend and dates can optimize the old response curves while reporting results for the new scenario. The existing grid validator checks dates, channel names, options, and spend bounds, but not the inputs that generated those curves.

This change fingerprints the filled scenario inputs when building a grid and checks them before reuse. It covers media, reach, frequency, media/RF spend, revenue per KPI, and time coordinates. Equivalent explicit and implicit historical data still share a grid; changing scenario data warns and rebuilds it. The fingerprint keeps no additional copies of the input tensors.

Weekly grids carry the fingerprint into to_optimization_grid. Combining weekly grids preserves it only when all source fingerprints agree. Grids with unknown provenance, including older or manually constructed grids, are rebuilt by BudgetOptimizer rather than being assumed compatible; standalone grid allocation remains available.

Tests exercise the public optimizer and compare rebuilt grids and results against fresh optimization for each scenario input. They also cover returning from an overridden scenario to historical data, unchanged-input reuse, weekly conversion, and combined grids. The reproduction fails on unchanged upstream code because the stale grid is accepted.

Two existing weekly comparison tests used autospecced wraps spies that returned empty mocks on Python 3.11, producing six failures on unchanged upstream. They now execute the real grid construction and assert that BudgetOptimizer reuses the returned grid directly.

Validation (Python 3.11):

  • JAX: all 142 grid tests passed across optimizer_test.py and weekly_optimization_grid_test.py (-k grid).
  • TensorFlow and JAX: 43 focused scenario/reuse tests passed on each backend.
  • TensorFlow and JAX: all 8 weekly comparison tests passed on each backend.
  • Pylint error checks on the two changed production modules passed.
  • git diff --check passed.

Focused reproduction:

MERIDIAN_BACKEND=tensorflow pytest -q meridian/analysis/optimizer_test.py -k scenario_data_changes

@google-cla

google-cla Bot commented Nov 8, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reused optimization grid remains valid after media impressions change

1 participant