Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only set model_parameters once #2505

Merged
merged 1 commit into from
Nov 13, 2024
Merged
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
16 changes: 11 additions & 5 deletions mesa/visualization/solara_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,11 +382,17 @@ def ModelCreator(
)
user_params, fixed_params = split_model_params(user_params)

# set model_parameters to the default values for all parameters
model_parameters.value = {
**fixed_params,
**{k: v.get("value") for k, v in user_params.items()},
}
# Use solara.use_effect to run the initialization code only once
solara.use_effect(
# set model_parameters to the default values for all parameters
lambda: model_parameters.set(
{
**fixed_params,
**{k: v.get("value") for k, v in user_params.items()},
}
),
[],
)

def on_change(name, value):
model_parameters.value = {**model_parameters.value, name: value}
Expand Down
Loading