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

Fix bug in render_network #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions vde_metadynamics/render_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ def render_print_val(arg,stride=1,file="CV"):
def render_fc_layer(layer_indx, lp):
output=[]
for i in np.arange(lp.out_features):
if layer_indx==0:
if layer_indx==1:
arg=','.join(["f%d_%d"%(layer_indx-1,j) for j in range(lp.in_features)])
else:
arg=','.join(["l%d_%d"%(layer_indx-1,j) for j in range(lp.in_features)])

weights = ','.join(map(str,lp.weight[i].data.tolist()))
bias =','.join(map(str,lp.bias[i].data.tolist()))
try:
Copy link
Owner

Choose a reason for hiding this comment

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

I am guessing you have 1 feature in the input so this was causing an issue?

Copy link
Author

Choose a reason for hiding this comment

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

I encountered this on the 2-alanine example, so there's 4 (2 sin and 2 cos).

Copy link
Owner

Choose a reason for hiding this comment

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

hmm, weird, i will investigate this further then.

Copy link
Owner

@msultan msultan Sep 12, 2018

Choose a reason for hiding this comment

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

This code gives the correct behavior without in both instances if lp is a list but it is possible that pytorch has changed how it returns the bias when tolist() is called.

In [12]: lp=[1]

In [13]: ','.join(map(str,lp))
Out[13]: '1'

In [14]: lp=[1,2,3,4]

In [15]: ','.join(map(str,lp))
Out[15]: '1,2,3,4'

Copy link
Owner

Choose a reason for hiding this comment

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

basically, we only need a str that can be streamed to text file for plumed

Copy link
Author

@feynmanliang feynmanliang Sep 17, 2018

Choose a reason for hiding this comment

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

Yes, the problem I was running in to was that tolist was returning a scalar, i.e .','.join(map(str, 1)), which results in a TypeError since 1 is not iterable

bias =','.join(map(str,lp.bias[i].data.tolist()))
except TypeError:
bias = str(lb.bias[i].data.tolist())
Copy link
Owner

Choose a reason for hiding this comment

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

this should be lp.bias[i] not lb.bias[i]

Copy link
Author

Choose a reason for hiding this comment

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

Sorry about that, fixed!


# combine without bias
non_bias_label = "l%d_%dnb"%(layer_indx, i)
Expand Down