ThGaskin / NeuralABM

Neural parameter calibration for multi-agent models. Uses neural networks to estimate marginal densities on parameters and networks
29 stars 13 forks source link

Run the SIR neural network with different data #63

Closed Zaaccckkkk closed 5 months ago

Zaaccckkkk commented 5 months ago

Hi Thomas,

I wanna test how the basic SIR sde works on the Birlin data.

I see that you did not load the data in the "data" file, instead you generate synthetic data by yourself. So can I create a run-specific configuration file for loading the data Data: load_from_dir: "../../../data/Covid/Berlin_data" and simply run utopya run CovidinSIR where CovidinSIR is a copied version of SIR model from utopya models copy SIR?

It seems something went wrong. CovidinSIR is not an available model.

Regards, Zhentian Wu

Zaaccckkkk commented 5 months ago

Seems the "not an available model" error comes from not register the CovidinSIR model, do I do this in the .utopya-project.yml?

ThGaskin commented 5 months ago

I run the Covid model using the Berlin data -- see the Berlin_data run configuration (Covid/cfgs/Berlin/run.yml). You can run using utopya run Covid --cs Berlin. If you want to run the SIR model with the Berlin data then the way you suggest is correct.

After copying a model you will need to register it by calling utopya models register from-manifest path/to/model_info.yml.

Zaaccckkkk commented 5 months ago

Hi Thomas,

Thanks for your quick reply. The registration you suggest works fine.

By using a different data (like the data for Berlin), I just want to get the idea of how to reuse your Neural network for other datasets.

However, I seem to get into some kind of file-name dilemma. My model copied from SIR is called SIR2. Inside SIR2, all the YAML files starts with SIR22_ and the Available models: shows up is called SIR22. (I named my model CovidinSIR before, and it becomes CovidinCOVIDINSIR everywhere) Basically, Python repeats the last bits automatically. This causes errors after utopya run SIR22:

` Traceback (most recent call last): File "/Users/wuzhentian/Desktop/Agent-based models/ABM_venv/lib/python3.9/site-packages/dantro/_import_tools.py", line 235, in import_module_from_path mod = importlib.import_module(mod_str) File "/Users/wuzhentian/opt/anaconda3/lib/python3.9/importlib/init.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1030, in _gcd_import File "", line 1007, in _find_and_load File "", line 984, in _find_and_load_unlocked ModuleNotFoundError: No module named 'SIR22'

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/Users/wuzhentian/Desktop/Agent-based models/NeuralABM/models/SIR2/run.py", line 16, in SIR22 = import_module_from_path(mod_path=up(up(file)), mod_str="SIR22") File "/Users/wuzhentian/Desktop/Agent-based models/ABM_venv/lib/python3.9/site-packages/dantro/_import_tools.py", line 239, in import_module_from_path raise ImportError( ImportError: Failed importing module 'SIR22'! Make sure that /Users/wuzhentian/Desktop/Agent-based models/NeuralABM/models/init.py can be loaded without errors (with its parent directory being part of sys.path) and that the mod_str argument is correct. To debug, inspect the chained traceback.`

No sure where went wrong.

ThGaskin commented 5 months ago

This line in run.py and NN.py is wrong:

SIR22 = import_module_from_path(mod_path=up(up(file)), mod_str="SIR22")

It should be

SIR2 = import_module_from_path(mod_path=up(up(file)), mod_str="SIR2")

Don't know what happened there

Zaaccckkkk commented 5 months ago

Thanks! That does solve most of the problems. I manage to get thing "all done". Just one tiny problem: "An error occurred during plotting with UniversePlotCreator for 'densities_from_joint'! For a full error traceback, specify debug: True in the plot configuration or run the PlotManager in debug mode.

BadOperationName: Could not find an operation or meta-operation named 'SIR22_densities_from_joint'!"

Did not find any suitable candidates in Available options. Tried SIR2_densities_from_joint as well. Other 3 graphs are generated well.

ThGaskin commented 5 months ago

The operation is called SIR_densities_from_joint — remove the 2

On 28 May 2024, at 23:05, Zaaccckkkk @.***> wrote:

Thanks! That does solve most of the problems. I manage to get thing "all done". Just one tiny problem: "An error occurred during plotting with UniversePlotCreator for 'densities_from_joint'! For a full error traceback, specify debug: True in the plot configuration or run the PlotManager in debug mode.

BadOperationName: Could not find an operation or meta-operation named 'SIR22_densities_from_joint'!"

Did not find any suitable candidates in Available options. Tried SIR2_densities_from_joint as well. Other 3 graphs are generated well.

— Reply to this email directly, view it on GitHubhttps://github.com/ThGaskin/NeuralABM/issues/63#issuecomment-2136101831, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AFIAUYWTQZAN3BJNDXK2ICTZETWQ7AVCNFSM6AAAAABINE6W7KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZWGEYDCOBTGE. You are receiving this because you commented.Message ID: @.***>

Zaaccckkkk commented 5 months ago

I have change the SIR22_densities_from_joint in models/SIR2/SIR22_plots.yml and model_plot/SIR2/trajectories_from_densities.py.

Seems same error occurs:

BadOperationName: Could not find an operation or meta-operation named 'SIR_densities_from_joint'!

ThGaskin commented 5 months ago

There is probably an import error somewhere earlier in the log. I suspect the model names are messed up because you’ve got both SIR2 and SIR22 …

On 28 May 2024, at 23:53, Zaaccckkkk @.***> wrote:

I have change the SIR22_densities_from_joint in models/SIR2/SIR22_plots.yml and model_plot/SIR2/trajectories_from_densities.py.

Seems same error occurs:

BadOperationName: Could not find an operation or meta-operation named 'SIR_densities_from_joint'!

— Reply to this email directly, view it on GitHubhttps://github.com/ThGaskin/NeuralABM/issues/63#issuecomment-2136168531, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AFIAUYXGR5CC4J5KQQMGW3DZET4ETAVCNFSM6AAAAABINE6W7KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZWGE3DQNJTGE. You are receiving this because you commented.Message ID: @.***>

Zaaccckkkk commented 5 months ago

Truly appreciate your patience. I might look into the naming problem myself. Simply adding a run-specific file into the SIR file works just fine.

Many thanks!