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] fix logic checking extinput synweights zero #102

Merged
merged 5 commits into from May 28, 2020

Conversation

cjayb
Copy link
Collaborator

@cjayb cjayb commented May 25, 2020

This PR fixes the part of #98 (specifically 94fc21a in feed.py) that botches the alpha-example.

No test written yet, input appreciated! There's a refactor brewing (see also discussion in #98), so perhaps tests should be deferred? To speed up tests, would it make sense to create a 'minimal network'? Not sure that makes sense, but almost 3 min spent on just the full alpha-example isn't sustainable.

Fixes #101

@jasmainak
Copy link
Collaborator

@rythorpe do you want to review this PR since the commit that introduces the problem was yours?

@jasmainak jasmainak requested a review from rythorpe May 25, 2020 20:00
if self.p_ext[key][0] > 0.0:
all_syn_weights_zero = False
if all_syn_weights_zero:
return False
Copy link
Collaborator

Choose a reason for hiding this comment

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

it's a bit weird that this method even returns something because the return value is not used anywhere

Copy link
Contributor

Choose a reason for hiding this comment

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

@cjayb I see, so the error in #101 is caused by one of the synaptic weights from 'OnlyRhythmicDist.param' being zero, thus causing __create_extinput() to return False even though some of the other weights are non-zero?

Copy link
Contributor

Choose a reason for hiding this comment

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

To address @jasmainak's point, this might be a good time to rethink the return values of the __create_ methods in the ExtFeed class. It looks like the code is currently set up to return the number of inputs added to the feed (for troubleshooting purposes?), though this might be unnecessary if we implement good tests.

Copy link
Collaborator

@jasmainak jasmainak May 26, 2020

Choose a reason for hiding this comment

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

yes, +10 for tests! @rythorpe do you have a suggestion for a test based on your experience in #99 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

so the error in #101 is caused by one of the synaptic weights from 'OnlyRhythmicDist.param' being zero

Correct, these are the only non-zero weights:

    'input_dist_A_weight_L2Pyr_ampa': 5.4e-5,
    'input_dist_A_weight_L5Pyr_ampa': 5.4e-5,

The method would return unless all weights were non-zero.

rethink the return values of the __create_ methods in the ExtFeed class

+1 It doesn't seem that the return values are ever used

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Follow the loop logic: it should only end the function if all inputs are zero. Before it would end if any input was <=0.
I’ll update the rst, but I think this was an unintentional mod (bug)

Copy link
Collaborator

@jasmainak jasmainak May 27, 2020

Choose a reason for hiding this comment

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

okayyyy, now I get it

so all you need to do for the unit test is to initialize an ExtFeed object with the right parameters and then check if self.eventvec exists (or is not None. I didn't check exactly whether this class initializes all attributes to None or adds them as and when needed). No computation required at all.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I’ll update the rst, but I think this was an unintentional mod (bug)

yep it should go to the bug section of whats_new.rst

Copy link
Contributor

Choose a reason for hiding this comment

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

Continuing off @jasmainak's suggestion, ideally we'd check the number and type of inputs in the p_ext attribute of an ExtFeed object so that we can be sure all (vs. any) expected inputs were added to the feed. I think this test could be added to the network test script.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

see my latest push: it wasn't enough to check p_ext, since these could be copied in fine, despite __create_extinput not running through to create the eventvec. I think we should test p_ext in create_pext?

@cjayb
Copy link
Collaborator Author

cjayb commented May 26, 2020

Re: tests, I just did

    params_fname = op.join(hnn_core_root, 'param', 'default.json')
    params = read_params(params_fname)
    params.update({'input_dist_A_weight_L2Pyr_ampa': 5.4e-5,
                                 'input_dist_A_weight_L5Pyr_ampa': 5.4e-5,
                                 't0_input_dist': 50})
...    

which adds 'extinput': 33, to spiketype_counts. The assertions against dpl_master will fail, but I'm pretty certain this would have caught the bug in #101.

Still don't like the length of this test, though... Just for the heck of it, I tried

params.update({"N_pyr_x": 2, "N_pyr_y": 2})

and re-run simulate_dipole. The model compiled and ran in just a few seconds, and produced some output

spiketype_counts
{'extinput': 34,
 'evprox1': 11,
 'L5_basket': 5,
 'L2_pyramidal': 13,
 'L2_basket': 6,
 'L5_pyramidal': 31,
 'evdist1': 9,
 'evprox2': 11}

Could this be a strategy? Shall we close this PR, then I try to create a fast test a la the above in a separate one?

@jasmainak
Copy link
Collaborator

@cjayb I like the idea of having tests on a small network! However, I'm not sure if the signals you get out of the smaller network will be as meaningful to know if we broke something?

Re the old tests of comparing to dpl.txt, I would not touch it yet. I think once we have CircleCI running in #97 we can automatically check the plots like in MNE-Python for all the examples. But we need more tests which look like "unit" tests. That is, they check small parts of the code.

@cjayb
Copy link
Collaborator Author

cjayb commented May 26, 2020

My thought was that all the simulations are deterministic, so even though they would be physiologically meaningless, they could serve as unit-like tests? Given that most of what we do involves nrn, we’re going to have to deal with the long compile/run times somehow...

@jasmainak
Copy link
Collaborator

jasmainak commented May 27, 2020

My thought was that all the simulations are deterministic, so even though they would be physiologically meaningless, they could serve as unit-like tests?

But that's not a very good unit test because if you fix a bug that changes the overall output, your test will fail. This is the case with the test where we compare with the old HNN output. The existing test is a bad unit test. It's just better than nothing.

@cjayb
Copy link
Collaborator Author

cjayb commented May 27, 2020

But that's not a very good unit test because if you fix a bug that changes the overall output, your test will fail.

OK, got it.

# Assert number of rhythmic inputs is 2 (distal & proximal)
assert len(net.extinput_list) == 2
for ei in net.extinput_list:
# naming could be better
Copy link
Collaborator

Choose a reason for hiding this comment

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

yes this should be called 'rhythmic'. We've discussed this with @rythorpe !

@jasmainak
Copy link
Collaborator

@cjayb I think your PR looks good to go for me. I played around with it a bit and removed some comments. I hope that's okay for you? I prefer to see clean code through good choice of variable names than explaining it through comments :)

If you're fine, please set the PR title to [MRG] and I'll merge in the morning when I wake up. Thanks a lot for the PR. Looking forward to more contributions in the future! Maybe an easy one is to change the naming of 'extinput' -> 'rhythmic'?

@cjayb cjayb changed the title fix logic checking extinput synweights zero [MRG] fix logic checking extinput synweights zero May 28, 2020
@cjayb
Copy link
Collaborator Author

cjayb commented May 28, 2020

Nice touch with the context manager! I definitely don't mind the edits. Good way to work this: add copious comments while working on PR, remove most once test is written.

Sure, I'll take a stab at the renaming next. Goal will be to create some test(s) while I'm at it.

@jasmainak jasmainak merged commit 917aff4 into jonescompneurolab:master May 28, 2020
@jasmainak
Copy link
Collaborator

Perfect plan! Thanks a lot :-)

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.

alpha simulation fails (NEURON?)
3 participants