Advanced Computing Platform for Theoretical Physics
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pengfei Zhou
GI based TN
Commits
4d62a3d8
Commit
4d62a3d8
authored
Aug 18, 2020
by
Pengfei Zhou
Browse files
modify bp
parent
600a3e89
Changes
1
Hide whitespace changes
Inline
Side-by-side
parallel_bp.py
View file @
4d62a3d8
...
...
@@ -6,6 +6,28 @@ from args import args
from
compNB
import
return_opera
import
networkx
as
nx
def
convert
(
filename
,
x
):
with
open
(
filename
,
'r'
)
as
f
:
l
=
f
.
readlines
()
f
.
close
n
=
ord
(
l
[
0
][
0
])
-
63
#number of vertexs
m
=
int
(
n
*
3
/
2
)
p
=
int
(
n
*
(
n
-
1
)
/
2
)
last
=
p
%
6
uptri_edges
=
[]
for
i
in
range
(
1
,
n
,
1
):
for
j
in
range
(
0
,
i
):
uptri_edges
.
append
([
j
,
i
])
edges_index
=
[]
line
=
l
[
x
].
strip
()
bitstring
=
''
for
j
in
range
(
1
,
len
(
line
)):
bitstring
+=
f
'
{
ord
(
line
[
j
])
-
63
:
6
b
}
'
#print(f'{ord(line[j])-63:6b}')
for
i
in
range
(
len
(
bitstring
)):
if
bitstring
[
i
]
==
'1'
:
edges_index
.
append
(
i
)
return
n
,
np
.
array
(
uptri_edges
)[
edges_index
]
def
con_to_spars
(
B
,
E1
,
E2
):
return
torch
.
sparse
.
FloatTensor
(
B
.
t
(),
torch
.
ones
(
B
.
shape
[
0
]),
torch
.
Size
([
E1
.
shape
[
0
],
E2
.
shape
[
0
]]))
...
...
@@ -66,10 +88,18 @@ if __name__ =='__main__' :
torch
.
set_default_dtype
(
torch
.
float64
)
n
=
20
beta
=
1
graph
=
nx
.
random_regular_graph
(
3
,
n
,
seed
=
1
)
#graph = nx.random_regular_graph(3, n, seed=1)
n
,
edges
=
convert
(
'Generated_graphs.20.03.g6'
,
args
.
which
)
G
=
nx
.
Graph
()
G
.
add_nodes_from
(
np
.
arange
(
n
))
G
.
add_edges_from
(
edges
)
n2
,
edges2
=
convert
(
'Generated_graphs.20.03.g6'
,
args
.
which
+
1
)
G1
=
nx
.
Graph
()
G1
.
add_nodes_from
(
np
.
arange
(
n2
))
G1
.
add_edges_from
(
edges2
)
tensor2
=
torch
.
randn
(
args
.
bond
,
args
.
bond
,
dtype
=
torch
.
float64
,
device
=
'cpu'
)
tensor2
=
torch
.
triu
(
tensor2
)
+
torch
.
triu
(
tensor2
,
diagonal
=
1
).
t
()
mf
=
MeanField
(
graph
,
torch
.
exp
(
beta
*
tensor2
),
beta
,
'cpu'
)
mf
=
MeanField
(
G
,
torch
.
exp
(
beta
*
tensor2
),
beta
,
'cpu'
)
fe_bp
=
mf
.
BP
()
print
(
fe_bp
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment