jonescompneurolab / hnn-core

Simulation and optimization of neural circuits for MEG/EEG source estimates
https://jonescompneurolab.github.io/hnn-core/
BSD 3-Clause "New" or "Revised" License
53 stars 52 forks source link

Optimization with calcium model #567

Open JBruce32 opened 1 year ago

JBruce32 commented 1 year ago

Hello, I am following the optimization tutorial. My question is about the part of the code where you load in the parameter file. So I created my parameters using hnn-core and I don't know how to save them into a json parameter file. I tried to use the GUI to create the file, but then realized that the GUI uses the jones_2009_model and not the calcium_model which I used. Can you please tell me how to generate a parameter file using hnn-core?

jasmainak commented 1 year ago

I don't think we have a function to write these files out ... we really need to get to it soon. You can probably pickle it in the meanwhile but it's not a long-term solution.

Can we aim to hammer some of these long-lasting issues out in a sprint in Nov @chenghuzi @rythorpe @ntolley ? Would be good to start planning for it ...

ntolley commented 1 year ago

Agreed, could plan to do it after SfN! (it ends November 16th).

Before may work depending on how much last minute poster making me and @rythorpe have to do

JBruce32 commented 1 year ago

Okay, one more question how did you get the default.json parameter file that is being used in the parameter optimization example? Did you produce it with the GUI?

ntolley commented 1 year ago

@JBruce32 the default parameter file comes from the parameter tuned network used in Jones et al. 2009

It's broadly the same structure as the .param files from HNN-GUI (however a .json is written like a dictionary where all the elements is enclosed in curly braces).

We technically have a read_param() function that works with .param files, but as referenced above we are planning to move away from this for a more long term solution.

If there are specific values/properties you're looking to change you can check out the docs/examples or let us know! The current API allows you to modify any property defined in the .param file without editing the files directly.

JBruce32 commented 1 year ago

Okay, so looking at the docs/examples I came across the hnn_core.params.write function. Here is a snippet:

  def write(self, fname):
      """Write param values to a file.

      Parameters
      ----------
      fname : str
          Full path to the output file (.json)
      """
      with open(fname, 'w') as fp:
          json.dump(self, fp)

Does this function allow me to store my model parameters in a json file at all? If so, how can I use this function given my network object?

Thanks

ntolley commented 1 year ago

Hi @JBruce32, unfortunately this function is not used for writing the details of the Network to a file (internally this function is useful for testing purposes).

For context, the .params or .json files are currently used to instantiate the model with default values in line with the old HNN-GUI. We're working on a good method/format to write the Network parameters to a file, but for now I think the best solution will be to either: 1) Pickle the entire Network object, or 2) just store the code which contains your parameter modifications using the hnn-core API.

The parameters of the provided networks such as jones_2009_model() and law_2021_model() will not change, so if you just keep track of your specific parameter changes then that will be sufficient for reproducibility. Definitely let me know if you need help/guidance for the suggestions listed above.