2

I am using this mesa framework which has two main files: model.py and server.py. The simulation as built runs exactly once but I would like to run it several times ex 5 times but save the values for each run. I am using the command line to run the code and after each run I can click the 'Reset' button 'Reset' button to run the simulation again. The code currently clears everything when I click 'Reset' but I was wondering if it is possible to save the results of the simulation somewhere so I can calculate averages after multiple iterations. I thought of creating a monte carlo simulation but realized that is not possible because it requires human intervention to run and monte carlo simulations run on their own.

Now I want to simplify and be able to save all values after each iteration. This sounds easy but due to the nature of the framework, I am unsure if this possible. I need to be able to store the values before this is called again

server = ModularServer(
Schelling, [canvas_element, happy_element, happy_chart], "Schelling", model_params

Does anyone have any ideas if this can be accomplished? I spent the past few days on this and am unsure if this is possible. I checked stackoverflow for similar questions but did not find any.

Sorry for all the updates, I tried to simplify to the basic problem.

Thanks in advance for any help.

ithoughtso
  • 103
  • 8

2 Answers2

1

help if any has a solution i need to save my runs to a file in MESA

Eugene
  • 11
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – targhs Nov 14 '21 at 20:51
  • That is a good idea, I will try sending the output of each run to a file and run it multiple times. Thank you! – ithoughtso Nov 18 '21 at 23:18
0

You can run the model without using the GUI.

def run_n_times(n=5):
    """Run the model the given number of times

    n: the number of times to run the model
    """
    for run_number in range(n):
        model = SchellingModel(20, 20, 0.8, 0.2, 4)
        while model.running:
            model.step()
            # processing/logging for each step
        # processing/logging/saving of results for this run
   # Aggregate the results of all runs and return or save

It might be useful to create a new random seed before each run and store that seed so you can replay a given run in the GUI.

rcriii
  • 687
  • 6
  • 9