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

Feat: Added Command Console #2697

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Sahil-Chhoker
Copy link
Collaborator

Summary

Adds a command console in mesa as per #2683.
Closes #2683.

Implementation

This feature consists of four main classes:

  1. ConsoleEntry: Defines how the data is entered into the console.
  2. CaptureOutput: A context manager for capturing stdout and stderr output.
  3. InteractiveConsole: A custom interactive Python console with output capturing capabilities. This class extends code.InteractiveConsole for a console like behaviour.
  4. ConsoleManager: A console manager for executing Python code interactively. This class provides functionality to execute Python code in an interactive console environment, maintain command history, and handle multi-line code blocks.

For more information refer to the docstrings in the file.

Usage Examples

from mesa.visualization.command_console import CommandConsole
from .agents import myAgent
import numpy as np
import math

page = SolaraViz(
    model,
    components=[CommandConsole], # Pass the CommandConsole as a component
    model_params=model_params,
    name="Test Model",
    additional_imports={ # additional imports to be used in command console
        "myAgent": myAgent,
        "np": np,
        "math": math,
    }
)
page

How it looks:

image

Copy link

Performance benchmarks:

Model Size Init time [95% CI] Run time [95% CI]
BoltzmannWealth small 🔵 +0.3% [-0.0%, +0.7%] 🔵 +0.6% [+0.5%, +0.8%]
BoltzmannWealth large 🔵 +16.2% [-2.4%, +51.4%] 🔵 -0.5% [-1.4%, +0.2%]
Schelling small 🔵 -0.0% [-0.2%, +0.2%] 🔵 -0.7% [-0.9%, -0.6%]
Schelling large 🔵 -6.0% [-14.4%, -0.0%] 🔵 -1.6% [-2.3%, -0.9%]
WolfSheep small 🔵 -0.1% [-0.3%, +0.1%] 🔵 -0.1% [-0.3%, +0.0%]
WolfSheep large 🔵 +0.2% [-0.2%, +0.5%] 🔵 -0.4% [-1.1%, +0.3%]
BoidFlockers small 🔵 -2.1% [-2.7%, -1.5%] 🔵 -0.3% [-0.5%, -0.2%]
BoidFlockers large 🔵 -1.2% [-1.7%, -0.7%] 🔵 -0.3% [-0.4%, -0.1%]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Release notes label visualisation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Interactive console in solara web interface.
1 participant