hnn-core icon indicating copy to clipboard operation
hnn-core copied to clipboard

BUG: `net.add_poisson_drive()` throws error depending on `rate_constant` type

Open ntolley opened this issue 1 year ago • 2 comments

Weird bug, if you set cell_specific=False and use a rate_constant of type float, you get the following error at simulation time

net = jones_2009_model()
weights_ampa_noise = {'L2_basket': 0.01, 'L2_pyramidal': 0.002,
                      'L5_pyramidal': 0.02}
net.add_poisson_drive('noise_global', rate_constant=2.0, location='distal',
                       weights_ampa=weights_ampa_noise, space_constant=100,
                       n_drive_cells=1, cell_specific=False)
simulate_dipole(net, tstop=100)

image

Now if you set rate_constant=2, an integer instead of a float, the simulation runs fine...

@rythorpe maybe you have an idea? I remember you improved the terminology for n_drive_cells API but this might have existed previously since a uniform poisson drive is a pretty uncommon use case

ntolley avatar Jul 04 '23 12:07 ntolley

It sounds like a bug with type checks and type casting.

On Tue 4 Jul 2023 at 08:06, Nicholas Tolley @.***> wrote:

Weird bug, if you set cell_specific=False and use a rate_constant of type float, you get the following error at simulation time

net = jones_2009_model()weights_ampa_noise = {'L2_basket': 0.01, 'L2_pyramidal': 0.002, 'L5_pyramidal': 0.02}net.add_poisson_drive('noise_global', rate_constant=2.0, location='distal', weights_ampa=weights_ampa_noise, space_constant=100, n_drive_cells=1, cell_specific=False)simulate_dipole(net, tstop=100)

[image: image] https://user-images.githubusercontent.com/55253912/250895599-6235c5bf-adf1-4348-808c-17261ce7fdb6.png

Now if you set rate_constant=2, an integer instead of a float, the simulation runs fine...

@rythorpe https://github.com/rythorpe maybe you have an idea? I remember you improved the terminology for n_drive_cells API but this might have existed previously since a uniform poisson drive is a pretty uncommon use case

— Reply to this email directly, view it on GitHub https://github.com/jonescompneurolab/hnn-core/issues/662, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADY6FIQT25VW42MUBWESJBLXOQBMLANCNFSM6AAAAAAZ5URWLE . You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- Sent from my iPhone

jasmainak avatar Jul 04 '23 14:07 jasmainak

Yeah, I'm guessing the rate_constant variable somewhere gets typecasted differently based on it's target population if it gets entered by the user as type int vs float vs dict. Probably here.

Then there looks like an inconsistency in _drive_cell_event_times() where when the target_type is set to 'any' (i.e., for a non-specific drive that targets all cells), the function assumes the value of drive['dynamics']['rate_constant'] is of type int or float (which it's not, because the float was typecasted into a dict of identical floats in Network.add_poisson_drive()).

I'd suggest just removing the typecasting in Network.add_poisson_drive().

rythorpe avatar Jul 04 '23 22:07 rythorpe

Can we close this @dylansdaniels, or is there still stuff left to do?

rythorpe avatar Jul 11 '24 02:07 rythorpe

This is good to close! I'll do so now 😁

dylansdaniels avatar Jul 11 '24 04:07 dylansdaniels