Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using struct type as an argument of paramscan() function for faster simulation #1107

Open
yunhwankim2 opened this issue Nov 21, 2024 · 2 comments
Labels
data related with datacollection enhancement New feature or request simulation running simulations (run! and company)

Comments

@yunhwankim2
Copy link
Contributor

In the Performance Tips section of the documentation, it is recommended to use struct for model properties.
However, when I tried to use paramscan() for simulation, the function requires to input a parameter set in the AbstractDict type, which makes the simulation slower.
How can I use struct type as an argument of paramscan() function? I think it would make the simulation faster.
Thank you.

@Datseris
Copy link
Member

Yeah, you can't use paramscan with a struct container because it uses a dict to make a combinatorial expansion into new dicts. You would need to make a pull request that expands the paramscan function so that it can create custom structs instead of dicts given the type of struct to make. This is probably a rather simple change that would take 5 lines of code or so. You would have to modify dict_list to have 2 inputs, the second being the type of output (instead of the default dict).

If you don't want to do this, then you can instead copy/paste the following lines from the source code of paramscan:

mapfun = parallel ? pmap : map
all_data = ProgressMeter.progress_map(combs; mapfun, progress) do comb
run_single(comb, output_params, initialize; n, kwargs...)
end
df_agent = DataFrame()
df_model = DataFrame()
for (df1, df2) in all_data
append!(df_agent, df1)
append!(df_model, df2)
end
return df_agent, df_model

combs is a vector of all parameter-structs you want to loop your simulation over.

@Datseris Datseris added enhancement New feature or request data related with datacollection simulation running simulations (run! and company) labels Nov 21, 2024
@yunhwankim2
Copy link
Contributor Author

I'm sorry but it seems not simple to me :). My programming skill is not good enough yet.
But I'll keep studying the code to find anything that I can contribute.
Thank you for the reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data related with datacollection enhancement New feature or request simulation running simulations (run! and company)
Projects
None yet
Development

No branches or pull requests

2 participants