Skip to content

Commit

Permalink
better clean up of pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusMNoack committed Dec 15, 2022
1 parent 1587098 commit cb13a5a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 49 deletions.
52 changes: 5 additions & 47 deletions fvgp/gp2Scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,15 @@ def compute_covariance(self, x1,x2,hyperparameters, variances,client):
actor_futures.append(self.SparsePriorCovariance.add_to_diag(variances)) ##add to diag on actor
#clean up
actor_futures[-1].result()
self.covariance_dask_client.cancel(actor_futures)
self.covariance_dask_client.cancel(futures)
del futures
del actor_futures

#########
if self.info:
print("total prior covariance compute time: ", time.time() - start_time, "Non-zero count: ", self.SparsePriorCovariance.get_result().result().count_nonzero())
print("Sparsity: ",self.SparsePriorCovariance.get_result().result().count_nonzero()/float(self.point_number)**2)
#client.run(gc.collect)


def free_workers(self, futures, finished_futures):
Expand All @@ -273,10 +277,6 @@ def assign_future_2_worker(self, future_key, worker_address):
def get_idle_worker(self,idle_workers):
return idle_workers.pop()

#def add_idle_worker(self,worker,idle_workers):
# return idle_workers.add(worker)


##################################################################################
##################################################################################
##################################################################################
Expand All @@ -301,14 +301,6 @@ def _init_dask_client(self,dask_client):
print("Scheduler Address: ", dask_client.scheduler_info()["address"])
return dask_client, compute_worker_set,actor_worker

#def _update_worker_set(self,client, current_worker_set):
# worker_info = list(client.scheduler_info()["workers"].keys())
# if not worker_info: raise Exception("No workers available")
# new_worker_set = set(worker_info).difference(current_worker_set)
# print("updated workers. new workers: ", new_worker_set)
# return new_worker_set


##################################################################################
##################################################################################
##################################################################################
Expand Down Expand Up @@ -411,7 +403,6 @@ def log_likelihood(self,hyperparameters = None):
client = self.covariance_dask_client
mean = np.zeros((self.point_number)) #self.mean_function(self,self.x_data,hyperparameters) * 0.0
#if mean.ndim > 1: raise Exception("Your mean function did not return a 1d numpy array!")
#if recompute_xK is True:
if hyperparameters is None: x,K = self.covariance_value_prod,self.SparsePriorCovariance
else:
self.SparsePriorCovariance.reset_prior().result()
Expand All @@ -422,39 +413,6 @@ def log_likelihood(self,hyperparameters = None):
res = -(0.5 * (y.T @ x)) - (0.5 * logdet) - (0.5 * n * np.log(2.0*np.pi))
return res

##################################################################################
##################################################################################
##################################################################################
##################################################################################
######################LINEAR ALGEBRA##############################################
##################################################################################
##################################################################################
##################################################################################
##################################################################################
#def slogdet(self, A):
# """
# fvGPs slogdet method based on torch
# """
# sign = 1.
# B = splu(A.tocsc())
# upper_diag = abs(B.U.diagonal())
# res = np.sum(np.log(upper_diag))
# return sign, res


#def solve(self, A, b):
# #####for sparsity:
# try:
# x,info = solve.cg(A,b, maxiter = 20)
# except Exception as e:
# #print("fvGP: Sparse solve did not work out.")
# #print("reason: ", str(e))
# info = 1
# if info > 0:
# #print("cg did not work out, let's do a minres")
# x,info = solve.minres(A,b, show = self.info)
# return x
##################################################################################
##################################################################################
##################################################################################
##################################################################################
Expand Down
4 changes: 2 additions & 2 deletions fvgp/sparse_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def reset_prior(self):
self.sparse_covariance = sparse.coo_matrix((self.n,self.n))
return 0

def imsert_many(self, list_of_3_tuples):
def insert_many(self, list_of_3_tuples):
l = list_of_3_tuples
bg = self.sparse_covariance
row_list = [bg.row]
Expand Down Expand Up @@ -63,7 +63,7 @@ def get_future_results(self, futures, info = False):
if info: print("Collected Future ", future.key, " has finished its work in", ketime," seconds. time stamp: ",time.time() - self.st)
res.append((SparseCov_sub,ranges[0],ranges[1]))

self.imsert_many(res)
self.insert_many(res)
return 0

def add_to_diag(self,vector):
Expand Down

0 comments on commit cb13a5a

Please sign in to comment.