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

[MRG + 1] ENH: try making HNN GUI with ipywidgets #76

Merged
merged 88 commits into from
Jul 11, 2022

Conversation

jasmainak
Copy link
Collaborator

@jasmainak jasmainak commented Sep 14, 2019

Here is a demo of the GUI with ipywidgets.

Try on Mybinder!!!

Some advantages of this approach:

  • Easier to maintain. We can probably get 95% of the functionality with 1000 lines of clean code as opposed to maintaining 8000 lines of messy code
  • Easy to install/deploy in classroom environment
  • You can easily add new features (e.g., Nick's work related to connectivity).
  • Ability to spin up HNN from the mobile and host a demo on Brown website using JupyterHub :-)
  • Potential to integrate with MNE source localization 'notebook' backend

To run this example, you'll need ipywidgets and voila. First make sure you have the latest version of jupyter

$ conda install jupyter

Then install the dependencies:

$ pip install ipywidgets voila

Finally do:

$ voila hnn_widget.ipynb

voila is not strictly necessary. You can also do:

$ jupyter-notebook hnn_widget.ipynb

and run the first cell.

You should see:

current dipole spikes
image image

PS: If we want interactive plots, we could potentially leverage ipympl but I would say, let's start with something simple

HNN-core examples tested

  • Evoked example
  • Rhythmic (alpha) example
  • Gamma example

TODO / Wishlist

  • Demo on binder
  • Tab for simulation parameters (tstop etc)
  • Bound tstop of drives by tstop of simulation
  • Run button twice
  • Connectivity sliders should update the connectivity
  • Make it work also for .param file
  • Update readme
  • Updating slider doesn't update connectivity? Fixed
  • Ability to overlay results from previous simulation
  • Don't instantiate Network until run button is pressed?
  • Run multiple trials
  • Add drive using radio button + "Add" button instead of dropdown
  • Implement widgets for optimization + LFP/CSD (+ connectivity?)
  • Distal should not show L5 Basket
  • Button to delete drives
  • Cell properties tab
  • Add tests
  • Stop button
  • whats new
  • separate callbacks from layout
  • GUI Scripts

@codecov-io
Copy link

codecov-io commented Sep 14, 2019

Codecov Report

Merging #76 (18b98a6) into master (00ebb0f) will decrease coverage by 0.26%.
The diff coverage is n/a.

❗ Current head 18b98a6 differs from pull request most recent head cd7bb0d. Consider uploading reports for the commit cd7bb0d to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master      #76      +/-   ##
==========================================
- Coverage   90.69%   90.43%   -0.27%     
==========================================
  Files          14       14              
  Lines        2365     2425      +60     
==========================================
+ Hits         2145     2193      +48     
- Misses        220      232      +12     
Impacted Files Coverage Δ
hnn_core/network.py 93.05% <0.00%> (-1.44%) ⬇️
hnn_core/parallel_backends.py 82.70% <0.00%> (-0.87%) ⬇️
hnn_core/network_builder.py 92.16% <0.00%> (+0.27%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 00ebb0f...cd7bb0d. Read the comment docs.

@jasmainak
Copy link
Collaborator Author

Now that HNN-core is cleaned up, I'd like to revisit this for 0.2. A dashboard-GUI might be much easier to maintain in the long run.

@jasmainak jasmainak added this to the 0.2 milestone Mar 31, 2021
@jasmainak
Copy link
Collaborator Author

jasmainak commented Apr 13, 2021

@stephanie-r-jones @ntolley @rythorpe @cjayb

related to today's discussion, I want to bring to your attention this GUI code I wrote long time ago. It's less than 100 lines of code at the moment and can already do this:

image
image
image

I'm sure the left panel can be modified to add some tabs for modifying different kinds of parameters.

And then you can use voila to hide the code. If someone wants to pair up and try to improve this, I'd be up for it. Clone this branch and give it a shot I would say!

@ntolley
Copy link
Contributor

ntolley commented Apr 14, 2021

@jasmainak this is awesome! Once I wrap up my open PR's I'd be interested in testing this out. Given the simplicity of ipywidgets, I think it will provide a nice space to improve on the essential functionality for the GUI (taking a lot from the existing version).

@jasmainak
Copy link
Collaborator Author

jasmainak commented Apr 14, 2021

wonderful, thanks for the encouragement! I pushed another tiny update to the UI

@jasmainak jasmainak changed the title ENH: try making HNN GUI with ipywidgets [WIP] ENH: try making HNN GUI with ipywidgets Apr 16, 2021
@jasmainak jasmainak force-pushed the hnn_gui branch 2 times, most recently from 1533641 to 1e5dbca Compare April 16, 2021 14:06
@codecov-commenter
Copy link

codecov-commenter commented Apr 17, 2021

Codecov Report

Merging #76 (471058f) into master (bab8196) will decrease coverage by 2.88%.
The diff coverage is 63.63%.

@@            Coverage Diff             @@
##           master      #76      +/-   ##
==========================================
- Coverage   90.51%   87.63%   -2.89%     
==========================================
  Files          18       19       +1     
  Lines        3415     3792     +377     
==========================================
+ Hits         3091     3323     +232     
- Misses        324      469     +145     
Impacted Files Coverage Δ
hnn_core/gui/gui.py 62.53% <62.53%> (ø)
hnn_core/params.py 90.83% <88.23%> (-0.08%) ⬇️
hnn_core/parallel_backends.py 81.49% <0.00%> (-0.83%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bab8196...471058f. Read the comment docs.

hnn_core/gui.py Outdated
sliders = list()
for d in param_keys:
slider = FloatLogSlider(
value=params[d], min=-5, max=1, step=0.2,
Copy link
Contributor

@ntolley ntolley Apr 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dynamic range may differ between neurotransmitters, might be worth considering different min/maxes for GABA vs. AMPA

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this in log scale! But yes totally open to suggestions to improve the interface here

hnn_core/gui.py Outdated
_get_sliders(params,
['gbar_L2Pyr_L5Pyr', 'gbar_L2Basket_L5Pyr'])]

# accordians to group local-connectivity by cel type
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# accordians to group local-connectivity by cel type
# accordians to group local-connectivity by cell type

@ntolley
Copy link
Contributor

ntolley commented Apr 19, 2021

Playing around with the GUI, personally I'm a big fan of the dashboard layout. Quick note, the drop down for the drives defaults to a blank value, is this intentional?
image

@jasmainak
Copy link
Collaborator Author

yeah, it's a bit intentional for now. You need to change the dropdown for a drive to be added. I think we need to change it ultimately to be a radio + "add" button. I'm just trying to get an MVP working first. Did you try the mybinder link above??

@ntolley
Copy link
Contributor

ntolley commented Apr 19, 2021

Just tried it now! Really awesome to have that working on binder. The barrier for entry is getting even lower now that there is a pip install and an immediately usable GUI from the the web.

@rythorpe
Copy link
Contributor

This is super cool @jasmainak! +100 for the dashboard GUI configuration. The code is a lot simpler with a modular design.

When X-forwarding the current hnn-gui hosted on a computing cluster, I've often noticed that having multiple application windows open can cause my system to freeze up with fluctuations in my internet speed/bandwidth. I'm curious to see if using ipywidgets will improve this.

@jasmainak
Copy link
Collaborator Author

You should give it a try! Here are two links to get you started:

https://docs.anaconda.com/anaconda/user-guide/tasks/remote-jupyter-notebook/
https://voila.readthedocs.io/en/stable/using.html#as-a-jupyter-server-extension

I think it should also be pretty doable to configure it for an entire class. I have worked with Isabel for the MNE workshops and she set up a JupyterHub in Brown. It worked pretty well.

@jasmainak jasmainak force-pushed the hnn_gui branch 2 times, most recently from c0db431 to 353d8c0 Compare April 21, 2021 22:02
hnn_core/gui.py Outdated
Comment on lines 46 to 48
variables['net'].connectivity = list()
# XXX: hack until there is a proper API
variables['net'].self._set_default_connections()
Copy link
Collaborator Author

@jasmainak jasmainak Apr 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ntolley food for thought for you what should be the right API here

EDIT: maybe Network shouldn't be instantiated in GUI until the run button is clicked ?

@jasmainak
Copy link
Collaborator Author

When I click on "Add drive" I get the following error:

image

@jasmainak
Copy link
Collaborator Author

okay I'm done for now. Let me know once the error is fixed and I'll do another round :)

@chenghuzi
Copy link
Collaborator

okay I'm done for now. Let me know once the error is fixed and I'll do another round :)

Fixed in 3d9082d

@chenghuzi
Copy link
Collaborator

@chenghuzi I'm undoing the Black code formatting everywhere. Please disable it in your editor ... it's too distracting.

Sure, as you like :)

MANIFEST.in Show resolved Hide resolved
README.rst Show resolved Hide resolved
Comment on lines +69 to +88
default_data = {
'weights_ampa': {
'L5_pyramidal': 0.,
'L2_pyramidal': 0.,
'L5_basket': 0.,
'L2_basket': 0.
},
'weights_nmda': {
'L5_pyramidal': 0.,
'L2_pyramidal': 0.,
'L5_basket': 0.,
'L2_basket': 0.
},
'delays': {
'L5_pyramidal': 0.1,
'L2_pyramidal': 0.1,
'L5_basket': 0.1,
'L2_basket': 0.1
},
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is perhaps opening a large can of worms, but what happens when we want to add an hnn-core model that contain more or less cell types than the ones we currently have? Will we need to update the hardcoded cell types here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep. But the widgets will also need to be updated ... no point in generalizing just this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I'm missing something crucial here, I feel like the GUI code should be as independent from specific network attributes as possible. If we hardcode these values in now, we're just repeating the same mistakes of the past GUI.

As a solution, I propose that we first have the user specify which network model to load into the GUI environment, and then instantiate cell specific widgets based on the cell types and properties contained in that Network instance.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that would be a great feature to have ... at the moment, we don't yet allow the user to modify cell properties (e.g., the constants in the mechanisms). I think we should discuss what would be a reasonable and "easy" thing to fix in the code. I propose that we merge this PR and after that spend a week on maintenance -- writing tests, refactoring, making it more future proof etc. I highly recommend pulling the PR and trying to play around with the code to get a sense of what is possible and what is not.

@jasmainak
Copy link
Collaborator Author

@chenghuzi I still have this problem:

image

Note how the button next to proximal can't be selected. Make sure to pull my last commit before fixing it.

@jasmainak
Copy link
Collaborator Author

another issue is that the location is not aligned with the rest of the parameters. See:

image

hnn_core/gui/gui.py Outdated Show resolved Hide resolved
hnn_core/gui/gui.py Outdated Show resolved Hide resolved
@jasmainak
Copy link
Collaborator Author

we're close @chenghuzi ! I can see the light for this PR :) Just some more tweaks and we can merge. Also please set the PR title to MRG when it's ready on your end

@jasmainak
Copy link
Collaborator Author

image

one more issue. There should be some check in the callback that returns if the simulation has not yet been run (don't use try/except)

@chenghuzi
Copy link
Collaborator

another issue is that the location is not aligned with the rest of the parameters. See:

image

Now I put that in the title, which should make it more clear
image

@chenghuzi
Copy link
Collaborator

@chenghuzi I still have this problem:

image

Note how the button next to proximal can't be selected. Make sure to pull my last commit before fixing it.

I tried on a very small browser window and it didn't happen. This is weird... Anyway, I'll change the alignment from HBox to Vbox, which should provide enough width for each of them.

image

@chenghuzi
Copy link
Collaborator

image

one more issue. There should be some check in the callback that returns if the simulation has not yet been run (don't use try/except)

Fixed

@chenghuzi chenghuzi changed the title [WIP] ENH: try making HNN GUI with ipywidgets [MRG] ENH: try making HNN GUI with ipywidgets Jul 11, 2022
@jasmainak jasmainak changed the title [MRG] ENH: try making HNN GUI with ipywidgets [MRG + 1] ENH: try making HNN GUI with ipywidgets Jul 11, 2022
@jasmainak
Copy link
Collaborator Author

So it turns out I can't approve my own PR ;-) I think @rythorpe or @ntolley you'll have to be the judges here and merge when ready. Please merge by "rebase and merge" to keep the commits.

@rythorpe
Copy link
Contributor

I'll give it another run through and (hopefully!) rebase and merge by this afternoon. Stay tuned!

@rythorpe rythorpe mentioned this pull request Jul 11, 2022
8 tasks
Copy link
Contributor

@rythorpe rythorpe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great @chenghuzi and @jasmainak! I've created a follow issue with some enhancement nitpicks that we can discuss and/or address in the next few PRs.

@rythorpe rythorpe merged commit 9850f20 into jonescompneurolab:master Jul 11, 2022
@rythorpe
Copy link
Contributor

Thanks @chenghuzi and @jasmainak for pushing this forward. We've now got ourselves a new GUI 🎉

@jasmainak
Copy link
Collaborator Author

Great work @chenghuzi ! 🥳 🥳 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants