Repository navigation
Save Parquet File for Single-cells during Colony Simulation without MongoDB? #389
Description
Activity
Thanks for trying out the model and for the issue report. I developed the Parquet emitter and all the workflow infrastructure after the colony publication. Since no one in the lab is running colony simulations right now, I did not test or update the colony code (including
ecoli_engine_process.py) to support the new emitter and other infrastructure. That is also why colonies are not mentioned in our public documentation.If you are interested in running colony simulations, your best bet is to use the release of the model associated with the publication, which used MongoDB as the exclusive emitter. I would not recommend it though as that version lacks a lot of the updates, optimizations, and enhancements of the latest version. Is there a specific reason why you are interested in colony simulations? If not, I would recommend running batches of simulations using workflows instead.
If you want to try modernizing
ecoli_engine_process.py, I'll address the issues you've encountered one-by-one.Issue 1:
NumpyRandomStateSerializerSerialization/Deserialization MismatchThis is a legitimate bug that I was unaware of because none of our current workflows emit NumPy
RandomStateobjects. Feel free to create a PR with the proposed fix.Issue 2: Parquet Emitter Cannot Handle
pint.Quantityin Config MetadataI became aware of this recently and fixed it in
ecoli_master_sim.pyon our private clone of the repo. A big batch of these private changes should make their way into the public repo over the next month or so. You can make the same fix inecoli_engine_process.pyby callingserialize_valueon themetadatacreated in this line.Issue 3:
emit_configSetting Not Passed to EngineThis option is confusingly named. It does not control whether the
vEcoliconfig JSON is emitted. That config JSON is included inmetadataas described above, which is always emitted. Instead, this is avivarium-coreoption that tells the Engine whether to include the serialized initial state in the configuration emit. That being said, the fact that theemit_*options do not currently do anything inecoli_engine_process.pyis a real bug (they are honored inecoli_master_sim.py, which we actively use). Feel free to make a PR adding those options. I'll just note that these are already set to False by default (here invEcoliand here invivarium-core), so setting them False in your config will not do anything even after this fix.Issue 4: Parquet Emitter Assumes
agentsKey in Data StructureThis is an interesting issue. Instead of having the Parquet emitter handle both types of simulation states, I think it makes more sense to modify the inner simulation of
ecoli_engine_process.pyto match the simulation state ofecoli_master_sim.py, which puts everything under("agents", <agent ID>,). This would be a more involved fix, but I prefer that to adding further complexity to the Parquet emitter. Feel free to give that a shot if you want.Thank you for your quick response! I am using the colony simulation because I am interested in the E. Coli colony behaviour generally, and think it would be more beneficial to apply any ML accelerator in colony content. I am in an early stage of this research project, so I haven't had a specialised case for the simulation.
Therefore, I am trying to run ecoli_engine_process.py instead of tet_amp_sim.py - because I think the latter includes some customised processes for antibiotic response?
Sure, I can send the pull requests if these fixes are valid.
For your suggestion about Issue 4, can you explain a bit more what you would recommend to do the fix? It sounds better for me if I can avoid setting up MongoDB for the current simulation.
On the other hand, will the referred release of the model include information about MongoDB setup guidance? I would appreciate it if you could give me some guidance about it.
Thanks again!
At the moment, the only advantage of the colony model is that you can place all the cells in a shared environment. However, there are currently very few processes that leverage this fact. We have a process that models each cell as a physical entity that experiences Brownian motion and displaces other cells (but does not model cell adhesion, pili, flagella, etc.). We also have processes that model the diffusion and reaction of species in the external environment (e.g. diffusion of antibiotics and hydrolysis by beta-lactamases released during cell lysis).
To be perfectly honest, the value that we got from colony sims in the antibiotics paper was greatly limited by the computational demands of running so many concurrent simulations. For reference, we ran all the simulations in that paper using the largest VMs on Google Cloud at the time (224 vCPUs, 896GB RAM). Even then, it took many hours just to reach 512 cells (at which point, we hit the memory limit). Long story short, we got almost no new insight from simulating so few cells in the same environment instead of running thousands of independent, non-interacting cell lineages (vertical vs horizontal scaling).
Almost all ongoing work in the lab is being done using independent simulations. This paradigm is what the new workflow infrastructure was built to support. Unless you have access to extremely well-equipped machines, you would be able to generate a lot more meaningful data using workflows instead of colony sims.
I'll work on addressing issue number 4 in a separate PR. The
EngineProcessclass is crazy complicated, and it's taking me a moment to remember how everything works. I have most of the issues ironed out, but one open question is how to handle emits from the outer simulation (external environment, cell positions) vs the inner simulation (internal molecule counts, etc). The best idea I have right now is to emit their data under two different experiment IDs, appending_outerand_innerto the user-configured experiment ID.Regarding MongoDB, the MongoDB emitter is built into
vivarium-core, so you can refer to their documentation for setup instructions. I just want to note that we no longer use the MongoDB emitter in our current work, so the query patterns and analysis scripts that you write for that output will not transfer.Reacted by Ningyuan XuLong story short, there are a bunch of changes in our private repo that we are unfortunately not able to bring into the public repo right now, including many important bug fixes and improvements. One of those bug fixes solves the test failure on your PR (see here). Other improvements simplify the process of adding support for arbitrary SLURM clusters, which would make it even easier for you to run very large batches of sims through the workflow API. I also want to point out it is already possible to run workflows on arbitrary SLURM clusters following these slightly more complicated instructions.
With regards to colony sims, I spent some time today fixing issue 4 on this branch of my fork. Feel free to try this code, but be warned that I don't have any spare bandwidth to work on this and cannot provide any further documentation or guarantees. As such, I'd still strongly recommend sticking to workflows instead of colony sims, if possible.
Sorry for the huge delay and for not being able to help you further with this. Thanks again for your patience and interest in the model!
@thalassemia
Hi, thank you again for your support. Would you mind sharing the link to the branch fixing issue 4 again? The previous link is not working.I have been focusing on single-cell simulations and am now returning to colony simulations, so I would like to load the updated version of the model. I know it has been a while since we last discussed this, and I would appreciate if you could recommend a version of the model with the fix merged (for example, the commit
49cd560merged into master on Mar 30) in case the customised fork is hard to find.Thanks again for your help!
Hi @katha815. Sorry, I deleted my local fork a while back. I merged my changes with the latest
masterand pushed them to thecolony-sim-emitbranch on this repo. I haven't tested that it still works and am very busy these days, but I hope that's enough to get you started!Reacted by Ningyuan XuI have loaded the colony-sim-emit branch into my fork and encountered a few issues. I have made several changes to ensure individual cell tracing runs smoothly while also keeping the emit_step customizable for colony simulations. The relevant pull request with these fixes is available here: #442.
Problem Description
I am using
ecoli_engine_process.pyfor colony simulation under baseline conditions. While I can successfully save snapshots of the colony state, I continuously encounter errors when trying to emit Parquet files for single-cell data. I wonder if anyone has successfully done this without an online emitter?The errors and attempted debugging steps are shown below. I noticed the implemented antibiotic simulation uses an online database as the emitter, so I included observations about that in the last section.
It could be a different underlying reason why my simulation failed, and I would appreciate any insights or suggestions!
Environment
spatial.jsoninheritance with"emitter": "parquet"Goal
Resume a colony simulation from a saved JSON state file (
baseline_2gen_seed_0_colony_t6000.json) and output to Parquet files.My Configuration File
configs/colony_baseline_test2.json:{ "inherit_from": ["spatial.json"], "description": "Test2: read from trial1, run for another generation, save parquet per cell, save final state", "initial_colony_file": "baseline_2gen_seed_0_colony_t6000", "seed": 0, "sim_data_path": "out/all_media_conditions1/parca/kb/simData.cPickle", "emitter": "parquet", "emitter_arg": { "out_dir": "out/colony_runs/baseline_3rd_gen_seed_0" }, "emit_config": false, "max_duration": 9000, "save": true, "save_times": [9000], "colony_save_prefix": "baseline_3rd_gen", "parallel": false, "engine_process_reports": [ ["boundary"], ["bulk"], ["listeners"], ["environment", "exchange"] ] }Issue 1:
NumpyRandomStateSerializerSerialization/Deserialization MismatchCommand:
Error:
Possible Root Cause:
serialize()at line 70-72 appears to output Python tuple format:('MT19937', [...])deserialize()at line 82 usesorjson.loads()which expects JSON array format:["MT19937", [...]]File:
ecoli/library/serialize.pyOriginal code (lines 78-85):
Attempted Fix: Replace
orjson.loads()withast.literal_eval()to handle Python tuple format:Issue 2: Parquet Emitter Cannot Handle
pint.Quantityin Config MetadataError (after attempting to fix Issue 1):
Possible Root Cause:
spatial.jsoncontainspint.Quantityvalues (e.g.,"!units[50 micrometer]")np_dtype()doesn't appear to handlepint.Quantity, and falls back to Polarspl.Series([v])also seems unable to handlepint.QuantityobjectsFile:
ecoli/library/parquet_emitter.pyOriginal code (line 967):
Attempted Fix: Convert unsupported types to string:
Issue 3:
emit_configSetting Not Passed to EngineNote: Even after the
str(v)fix, I attempted to disable config emission via JSON config"emit_config": false, but it appeared to have no effect.Possible Root Cause:
ecoli_engine_process.pydoes not seem to pass theemit_configparameter to the Engine constructor.File:
ecoli/experiments/ecoli_engine_process.pyOriginal code (around line 465):
Attempted Fix: Add
emit_configparameter:Issue 4: Parquet Emitter Assumes
agentsKey in Data StructureError (after attempting to fix Issues 1-3):
Possible Root Cause:
ParquetEmitter.emit()appears to expect adata["data"]["agents"]structure (outer simulation)agentswrapperinner_emitterin the EngineProcess configFile:
ecoli/library/parquet_emitter.py(line 1007)Observations on Implemented Antibiotic Simulation
The
tet_amp_sim.pyuses a different configuration that appears to avoid these issues:pint.QuantityNumpyRandomStateagentskey structure assumptionsSummary Table
serialize.pyast.literal_eval()pint.Quantitynot supportedparquet_emitter.pystr(v)emit_confignot passed to Engineecoli_engine_process.pyagentskey handlingparquet_emitter.py