projectmesa / mesa

Mesa is an open-source Python library for agent-based modeling, ideal for simulating complex systems and exploring emergent behaviors.
https://mesa.readthedocs.io
Other
2.39k stars 863 forks source link

Barebone examples without using the tornado server #693

Open rht opened 5 years ago

rht commented 5 years ago

What's the problem this feature will solve?

Currently, even the simplest example requires a web server to be run. However, not every model needs to be visualized, especially the ones that don't need the 2D grid structure.

Describe the solution you'd like

Several simple examples of models that are concise enough to fit in one file, to showcase the modularity of the library, and also that it can be experimented live on a repl.it instance.

Corvince commented 5 years ago

I think the examples are really more to (literally) show off models.

How to run a model without visualization is also already covered in the beginning of the introductory tutorial. Given that is boils down to model = Model(); model.step() I don't think we need to point that out more often. If you mean something like that the mesa runserver command always opens some kind of visualization, we would have to think about different output to the console. What would someone expect as an output from a model run? Exit code 0 ?

Please also take a look at the bank reserves example. It showcases a batch run (without any visualization involved). We also have several examples that include jupyter notebooks, which run without the tornado server.

But maybe you can elaborate a bit more on the following points, I am not sure I get them correctly:

Several simple examples of models that are concise enough to fit in one file, to showcase the modularity of the library, and also that it can be experimented live on a repl.it instance.

How does putting everything into one file (again, see intro tutorial for that) showcase modularity? And I have no experience with repl.it, but it seems to support multiple files?

All that said I think most (probably all) mesa developers are always happy to include more examples, so please feel free to submit.

rht commented 5 years ago

I wasn't aware of the introductory tutorial.

Please also take a look at the bank reserves example. It showcases a batch run (without any visualization involved).

Since it is a new example, it is not in the list at https://github.com/projectmesa/mesa/blob/master/examples/Readme.md. And the batch_runner description comes after I have assumed that the example requires a server to run.

We also have several examples that include jupyter notebooks, which run without the tornado server.

To run a .ipynb would still require a server to be run. Although some people might find jupyter notebooks more intuitive to run than a .py on IDLE.

What I meant by 'modularity' is that the library can be used piecemeal without the visualization server, and that it can be concise enough to be described fully in 1 file. The result can be in the form of numbers or a plot, definitely not just exit 0.

Corvince commented 5 years ago

I wasn't aware of the introductory tutorial.

Ah, that probably explains your confusion.

Please also take a look at the bank reserves example. It showcases a batch run (without any visualization involved).

Since it is a new example, it is not in the list

Oh good catch, nice to know!

We also have several examples that include jupyter notebooks, which run without the tornado server.

To run a .ipynb would still require a server to be run. Although some people might find jupyter notebooks more intuitive to run than a .py on IDLE.

Sorry, I wrote that a bit confusing. What I meant was that inside the notebooks (which can easily be viewed on e.g. GitHub) users can see how to run the models without a server.

What I meant by 'modularity' is that the library can be used piecemeal without the visualization server, and that it can be concise enough to be described fully in 1 file.

I disagree that this needs to be mentioned explicitly since this is true for everything written in Python. But lets hear what others think about this

jackiekazil commented 5 years ago

I understand what @rht is getting at and see the value. I just don't know how to do this organizations in docs or examples to demonstrate this without making it super confusing on top of the basic model and the advanced models we already have.

thoughts?

dmasad commented 5 years ago

One easy way to do this would be to simply add a __main__ to Schelling and some of the other simple models, and have it instantiate a model, run it, and print some summary statistics. @rht Do you think that would address what you have in mind?

rht commented 5 years ago

to Schelling and some of the other simple models

Though, virtually all the existing example models require a grid representation. One option is to find a classic example that doesn't require grid.

and print some summary statistics.

The other option is to somehow print an ASCII grid (possibly with colors and custom unicode to represent an agent in a cell) as another visualization mode.

rht commented 5 years ago

The other option is to somehow print an ASCII grid (possibly with colors and custom unicode to represent an agent in a cell) as another visualization mode.

I saw there is an unused class SchellingTextVisualization at examples/Schelling/server.py. I assume this concern (of running a model without a viz server) has been considered in the past.