Repository navigation
Add run_scenarios and storage - #3756
Conversation
|
I have done some more work on this to simplify and streamline it. I can really benefit from feedback at this point, so @tpike3, @EwoutH, and @codebreaker32, please chime in. To help clarify what is going on, please check the sequence diagram below. It shows the flow of information and the basic protocols as specified by this PR. The main thing not yet fully settled is what happens if a model uses a file based DataRecorder. I want to leave that to a future PR. |
codebreaker32
left a comment
There was a problem hiding this comment.
Looks Good To Me!
|
For the record, I pushed an update that back ports some changes identified in the next PR for parallelization support as well as forcing replication_id to always be an int (see #3762). |
|
Bit of a hectic time. Will try to review this weekend. |
|
Thanks for this PR. You can see you built this earlier (with the EMAworkbench) it's impressive! Few questions:
|
|
Thanks for the comments and suggestions. Below my responses.
The generation of samples (e.g., Salib, numpy qmc) and the execution (e.g., ProcessPoolExecutor, MPIPoolExecutor) are out of scope. This series of PRs provides the connection between those libraries and Mesa. Below is a quick example from my testing that shows how it fits together. As you can see, this code uses samples = sp.stats.qmc.LatinHypercube(4, rng=42).random(50)
samples = rescale_samples(samples, np.array([[0.5,1],[0.05, 0.5],[0.2, 0.8],[1,5]]))
samples[0, :] = np.floor(samples[3, :]) # radius needs to be an integer, this means it will be between 1-4.
samples = pd.DataFrame(samples, columns=["density", "minoriy_pc", "homophily", "radius"])
samples.radius = samples.radius.astype(int)
scenarios = SchellingScenario.from_dataframe(samples, replications=2)
with ProcessPoolExecutor(max_workers=4) as executor:
results = run_scenarios(scenarios, RunConfiguration(Schelling, until=100), executor=executor)
print(results)
I am about to start on OnDiskStore and I am inclined to provide a reference implementation using parquet but I will check pyarrow as well. In the parallel case, each worker will have its own file. On a big MPI cluster, you don't want to send large amounts of data over the network.
This will be handled by a later PR. As you can see in #3768, It is one of the last items on the to do list.
I'll have to see now that I am about to start on an
For smal local debug runs, I think it is a fine default. Moreover, an |
| class OutcomeExtractionException(RunStageException): | ||
| """Raised when extracting outcomes from a finished model fails.""" | ||
|
|
||
| origin = FailureOrigin.EXTRACTING |
There was a problem hiding this comment.
I would make this
origin = FailureOrigin = FailureOrigin.Extracting
for consistency
This PR builds on #3753 by adding
run_scenarios, a protocol for storage (Store,Writer, andReference), and an implementation of the protocol for in memory storage (InMemoryStore,InMemoryWriter, andInMemoryReference).The main focus here is hashing out the protocol. For background, see #3483 (comment).
The overarching aim is to replace batch runner with the following basic API
The main challenge is to design all of this such that we can support sequential local running (executor=None), parallel local running (
ProcessPoolExecutor), and HPC (mpi4py.futures.MPIPoolExecutor). This brings with it a wide range of design considerations.Some key considerations are
To satisfy these and other considerations, this PR adds a bunch of things
Storeprotocol that specifies the basic interface of any storage solution. Store always runs root side.Writerprotocol that specifies how output fromRunConfiguration.extract_outputis to be send back to the root process (consideration 1). Writer always runs worker side.Referenceprotocol that specifies the fields in a message being send from the worker to the rootInMemoryStore,InMemoryWriter, andInMemoryReference. A future PR will add a disk based implementation of all three protocols while accounting for consideration 2. Note thatInMemoryStoreis just a simple dict based backend and nothing more fancy. It's here now just to clarify how it all works.run_scenarioswith support for sequential running. This implementation also handles the safe running of scenarios with graceful handling of failing scenarios (consideration 3). A future PR will add support forProcessPoolExecutorandMPIPoolExecutorwhich have the same API so can be handled in the same way.The sequence diagram shown below shows how it all fits together in practice.