forked from frankschindler/OptimizedTensorContraction
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrn_annealing.py
32 lines (25 loc) · 1007 Bytes
/
rn_annealing.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import sys
import numpy as np
import fn_tensors as fnt
import fn_annealing as fna
from scipy import optimize as opt
from copy import deepcopy
from joblib import Parallel, delayed
L = 10 #sys.argv[1]
datroot = 'dataRandom' + str(L)
ntrials = 40
graph = np.load(datroot+'/graph.npy',allow_pickle = True)
bdims = np.load(datroot+'/bdims.npy',allow_pickle = True)
num_bonds = len(bdims)
num_greedy = np.load(datroot+'/numlist_greedy.npy').astype(int)[0]
def to_be_annealed(perm):
perm = (1+np.argsort(perm))
return fnt.logcontract(deepcopy(graph), bdims, perm)
def trials():
res = fna.dual_annealing(to_be_annealed, [[0,1] for i in range(num_bonds)], maxiter=1000000000000, maxfun = 1*num_greedy)
return res.history, 1+np.argsort(res.x)
data = Parallel(n_jobs=ntrials)(delayed(trials)() for i in range(ntrials))
historylist = [el[0] for el in data]
bpermlist = [el[1] for el in data]
np.save(datroot+'/historylist_annealing',historylist)
np.save(datroot+'/bpermlist_annealing',bpermlist)