Skip to content

Use type(model.value).__init__ in ModelCreator param check#3264

Merged
quaquel merged 1 commit intomesa:mainfrom
falloficarus22:solara-viz-class-to-type-cleanup
Feb 9, 2026
Merged

Use type(model.value).__init__ in ModelCreator param check#3264
quaquel merged 1 commit intomesa:mainfrom
falloficarus22:solara-viz-class-to-type-cleanup

Conversation

@falloficarus22
Copy link
Copy Markdown
Contributor

@falloficarus22 falloficarus22 commented Feb 9, 2026

Summary

This PR performs a focused cleanup in solara_viz.py by replacing __class__ usages with type(...), including the ModelCreator parameter-validation fix.

Bug / Issue

@quaquel’s feedback in #3178 first requested separating the __class__ -> type(...) change, and then suggested including the other __class__ usages in solara-viz as a proper cleanup.

Implementation

Updated solara_viz.py in the following places:

  • model.value.__class__.__name__ -> type(model.value).__name__ (AppBar title)
  • model.value.__class__.__init__ -> type(model.value).__init__ (_check_model_params call)
  • log message class reference now uses type(model.value)
  • model reset instantiation:
    • model.value.__class__(**model_parameters.value) -> type(model.value)(**model_parameters.value)
    • model.value.__class__(simulator=simulator, **model_parameters.value) -> type(model.value)(simulator=simulator, **model_parameters.value)
  • renderer copy instantiation:
    • renderer.__class__(model=model, backend=renderer.backend) -> type(renderer)(model=model, backend=renderer.backend)

No behavioral logic changes beyond the class-reference cleanup.

Testing

Ran targeted visualization tests:

  • test_solara_viz.py
  • Result: 11 passed

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 9, 2026

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🟢 -3.9% [-4.3%, -3.6%] 🔵 -0.4% [-0.6%, -0.3%]
BoltzmannWealth large 🔵 -1.6% [-2.5%, -0.7%] 🔵 -3.9% [-6.5%, -0.9%]
Schelling small 🔵 +0.8% [+0.4%, +1.2%] 🔵 +0.3% [+0.2%, +0.5%]
Schelling large 🔵 +1.0% [-0.1%, +2.0%] 🔵 +7.1% [+2.4%, +12.2%]
WolfSheep small 🔵 +1.2% [+0.9%, +1.4%] 🔵 -0.5% [-0.7%, -0.4%]
WolfSheep large 🔵 +1.3% [+0.0%, +2.3%] 🔵 -0.4% [-1.1%, +0.1%]
BoidFlockers small 🔵 -1.2% [-1.5%, -0.8%] 🔵 -0.5% [-0.7%, -0.3%]
BoidFlockers large 🔵 -0.7% [-1.1%, -0.4%] 🔵 -0.5% [-0.7%, -0.2%]

@quaquel
Copy link
Copy Markdown
Member

quaquel commented Feb 9, 2026

If I recall correctly, there were a bunch of other places where __class__ was used in solara-viz. If so, it might be nice to include those in this PR as well and just do a proper cleanup.

@falloficarus22 falloficarus22 force-pushed the solara-viz-class-to-type-cleanup branch from 8475873 to 4028ee2 Compare February 9, 2026 08:28
@quaquel
Copy link
Copy Markdown
Member

quaquel commented Feb 9, 2026

please update the PR description and then I can merge this.

@quaquel quaquel merged commit 72d6dec into mesa:main Feb 9, 2026
14 checks passed
@falloficarus22 falloficarus22 deleted the solara-viz-class-to-type-cleanup branch February 9, 2026 11:13
@EwoutH EwoutH added maintenance Release notes label visualisation labels Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Release notes label visualisation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants