mesa icon indicating copy to clipboard operation
mesa copied to clipboard

Deploy the code

Open AlABarazi opened this issue 5 years ago • 2 comments

Hi, Is it possible to deploy the simulation model to the web? Could someone please guided me to some readings?

AlABarazi avatar Oct 15 '20 06:10 AlABarazi

It is possible, but we don't have a clear guide / tool on to how to do that now. The basic idea is that you need to deploy the model on a server where the relevant port is open to the web. I previously had some success deploying Mesa models to Glitch, e.g. https://glitch.com/edit/#!/mesa-prisoner-dilemma , but it looks like they made some changes to their system which broke the deployment and I haven't had a chance to go through and figure out how to fix it.

This is an area I think we'd love to have someone with web app engineering experience help out!

dmasad avatar Oct 18 '20 19:10 dmasad

Good news! It seems to be fairly easy to publish mesa models on heroku!

Once you have a repo of your model you only need to add a Procfile with a single line: web: python run.py -p=$PORT and make sure you run your server on the right port, e.g. (inside run.py):

from server import server
import os

port = int(os.getenv("PORT", 4200))

server.launch(port=port, open_browser=False)

You can view it in action for this repo (fork from schelling-example-repo) at https://young-anchorage-45437.herokuapp.com/#

You only need a free heroku account. You should follow the tutorial to deploy a python app to get a brief understanding about heroku. Afterwards just deploy your model :)

Just a note though: I wouldn't use this right now for simultaneous access to the same model. Weirdly enough the server seems to share some state but not all. This is something that should be fixed with mesa.

I will also try to add some more detailed instructions in the readme on the deployment and submit a PR to the mesa-schelling-example.

Corvince avatar Oct 23 '20 09:10 Corvince