Skip to content

Design for an MMMPlotSuite overall#2405

Draft
isofer wants to merge 21 commits into
mainfrom
isofer/mmmplotsuite-overall
Draft

Design for an MMMPlotSuite overall#2405
isofer wants to merge 21 commits into
mainfrom
isofer/mmmplotsuite-overall

Conversation

@isofer
Copy link
Copy Markdown
Contributor

@isofer isofer commented Mar 16, 2026

Summary

Design documents for the MMMPlotSuite v2 major-release rewrite. Contains planning docs that lay out the architecture, API contract, and implementation strategy for decomposing the current 5,150-line monolith into a clean namespace-based structure.

Review focus

Please focus on the first 3 sections of the main design doc (mmmplotsuite-v2-attack-plan-design.md):

  1. Decisions
  2. Target Architecture
  3. Standardized API Contract

Files

  • 2026-03-11-mmmplotsuite-v2-attack-plan-design.md -- The main design doc. Covers architectural decisions, target file layout, standardized API contract, helper removal plan, scope split (major vs follow-up), PR sequence, migration guide, and issue traceability.

  • 2026-03-10-mmmplotsuite-comprehensive-issues.md -- Audit of the current MMMPlotSuite identifying 45 issues across architecture, API consistency, correctness, performance, and testing.

  • 2026-03-10-mmmplotsuite-decomposition-approaches.md -- Analysis of 4 decomposition approaches (flat methods, inheritance, mixins, namespace sub-objects) with trade-offs. Concludes with the namespace sub-objects approach.

  • 2026-03-11-figure-customization-design.md -- Deep dive into the figure customization API: how arviz-plots' PlotCollection integrates, the 6 standard customization parameters, coverage gaps for bar-plot methods, and the visuals / aes_by_visuals pattern.

Copy link
Copy Markdown
Collaborator

@juanitorduz juanitorduz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! I left some initial comments. IMO Variant A + D in the one I personally like the most. I would love the opinion from others like @cetagostini and @williambdean

My only important commetn: Let's not rely on ArviZ 1.0 yet. This weill need much more work and will be coupled with pymc 6 release (sometime this year I think). Hence, we need to revisit this plan to ensure it has the right ArviZ API.

I would also add that we should aim for certain level of consistency with the interactive plots module :)

Comment thread docs/plans/2026-03-10-mmmplotsuite-comprehensive-issues.md Outdated
The duplicated axes-normalization code (flatten + wrap in ndarray) appears in at least
three methods, each with slightly different implementations.

All of this is already handled by `arviz_plots`' `PlotCollection` API
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are still bounded by ArviZ < 1.0


These correspond to GitHub issues #2369–#2378 and #2388, plus additional findings.

### II.1 Return type roulette (GitHub #822, #2369)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we should always return (fig , axes) 🙏

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


> **Backward Compatible:** No (changing return types breaks callers; requires deprecation cycle) — **LOE:** L

### II.2 Inconsistent `original_scale` default (GitHub #2371)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhg, I think we should always plot in original scale and get rid of this parameter once and for all.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is also a value in plotting in the scaled space. So when looking at the idata or using the fundamental plotting functions of PyMC (like plotting traces) they would be in the scaled space. so I think it might be useful to plot in the space where the modeling actually happen.
I wonder what other people think about this. I'll ask in the channel.



`param_stability` is especially problematic — when `dims` is provided, it creates a
*separate figure per dimension value* in a for-loop, calling `plt.show()` on each.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plt.show() should be removed in the codebase

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


These are issues found during code review that have no corresponding GitHub issue.

### IV.1 Copy-paste bugs in `prior_predictive` and its helper
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhg :/ we need to fix these docs indeed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree. in the attack plan

### IV.7 O(n×m) inner loop in `cv_crps`

`_pred_matrix_for_rows` (line 4914): Iterates over every row of `rows_df` and does
`.sel()` per row. For large datasets this is very slow.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we out typical time series are rather small / medium but not really large


## VII. Older / Miscellaneous

### VII.1 Coord name `x` → `channel` (GitHub #1183)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes!


---

## Comparison Matrix
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Option Variant: D + A
Approach D can be combined with Approach A by backing each namespace method with a standalone function. This adds a direct function access layer (e.g., from pymc_marketing.mmm.plotting.sensitivity import sensitivity_analysis) for users who prefer working with functions and for easier unit testing. The trade-off is two public API surfaces to maintain. is the one I personally like the mostt:

@isofer
Copy link
Copy Markdown
Contributor Author

isofer commented Mar 20, 2026

My only important comment: Let's not rely on ArviZ 1.0 yet. This will need much more work and will be coupled with pymc 6 release (sometime this year I think). Hence, we need to revisit this plan to ensure it has the right ArviZ API.

@OriolAbril

@juanitorduz raised a concern about using arviz 1.0 for this plan to rewrite MMMPlotSuite.
Currently I have in my env the following:

arviz                     0.23.4             pyhcf101f3_0    conda-forge
arviz-base                1.0.0              pyhd8ed1ab_0    conda-forge
arviz-plots               1.0.0                    pypi_0    pypi
arviz-stats               1.0.0              pyh5442c79_0    conda-forge
arviz-stats-core          1.0.0              pyhc364b38_0    conda-forge

so the plots are done through arviz-plots 1.0, but I still have arviz 0.23.4 (so my idata is still az.InferenceData for example).
So I would like to have in pyproject.toml the following:

    "arviz>=0.13.0,<1.0.0",
    "arviz-plots[matplotlib]>=1.0.0,<1.1",

This seems to be working fine when I tested it. Do you have any concerns with the setup?

@juanitorduz
Copy link
Copy Markdown
Collaborator

My only important comment: Let's not rely on ArviZ 1.0 yet. This will need much more work and will be coupled with pymc 6 release (sometime this year I think). Hence, we need to revisit this plan to ensure it has the right ArviZ API.

@OriolAbril

@juanitorduz raised a concern about using arviz 1.0 for this plan to rewrite MMMPlotSuite. Currently I have in my env the following:

arviz                     0.23.4             pyhcf101f3_0    conda-forge
arviz-base                1.0.0              pyhd8ed1ab_0    conda-forge
arviz-plots               1.0.0                    pypi_0    pypi
arviz-stats               1.0.0              pyh5442c79_0    conda-forge
arviz-stats-core          1.0.0              pyhc364b38_0    conda-forge

so the plots are done through arviz-plots 1.0, but I still have arviz 0.23.4 (so my idata is still az.InferenceData for example). So I would like to have in pyproject.toml the following:

    "arviz>=0.13.0,<1.0.0",
    "arviz-plots[matplotlib]>=1.0.0,<1.1",

This seems to be working fine when I tested it. Do you have any concerns with the setup?

if we can make this work it would be great :)

isofer and others added 12 commits March 23, 2026 17:25
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…e breakdown

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…PR list

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

2 participants