Commit b0e4d42e authored by Federico Julian Camerota Verdu's avatar Federico Julian Camerota Verdu
Browse files

Updated notebooks

parent fa13d7b4
......@@ -28,10 +28,16 @@
import os
import cudf
import cuml
```
%% Cell type:code id:bf0f03fd tags:
``` python
import numba.cuda
```
%% Cell type:markdown id:fe49c4d6 tags:
## INITIAL PREPARATIONS
%% Cell type:code id:narrow-retention tags:
......@@ -108,17 +114,21 @@
## PCA ANALYSIS
%% Cell type:code id:b285e57b tags:
``` python
%%timeit
md_pca = cuml.PCA(n_components=2)
pca_trj = trj.xyz[:,:,:]
pca_trj = pca_trj.reshape(pca_trj.shape[0] , -1 )
#df = cudf.DataFrame(pca_trj)
df = cu.array(pca_trj)
proj = md_pca.fit_transform(df)
%%time
model = cuml.PCA(n_components=2)
model_trj = trj.xyz[:,:,:]
model_trj = model_trj.reshape(model_trj.shape[0] , -1 )
#df = cudf.DataFrame(model_trj)
#df = cu.array(model_trj)
#df = cudf.from_pandas(pd.DataFrame(model_trj))
#df = cudf.DataFrame(numba.cuda.to_device(model_trj))
df = numba.cuda.to_device(model_trj)
proj = model.fit_transform(df)
```
%% Cell type:markdown id:d577fc8b tags:
%%time
......
......@@ -58,26 +58,25 @@
```
%% Cell type:code id:2b526c33 tags:
``` python
%%time
Ref = md.load(topol)
```
%% Cell type:code id:a3a47162 tags:
``` python
%%time
Ref.center_coordinates()
top = Ref.topology
```
%% Cell type:code id:710a340a tags:
``` python
cluster = LocalCUDACluster()
#cluster = LocalCUDACluster(n_workers=4, protocol="ucx", enable_nvlink=True)
cluster = LocalCUDACluster(n_workers=4)
client = Client(cluster)
```
%% Cell type:markdown id:2ed57674 tags:
......@@ -86,30 +85,26 @@
%% Cell type:code id:8935173a tags:
``` python
def rmsd(a, b):
a = da.from_array(cu.array(a))
#a = a.map_blocks(cu.array)
#b = da.from_array(b)
b = da.from_array(cu.array(b))
#b = b.map_blocks(cu.array)
a = da.from_array(a)
a = a.map_blocks(cu.array)
b = da.from_array(b)
b = b.map_blocks(cu.array)
N = b.shape[0]
#if a.shape[1:] != b.shape[1:]:
# raise ValueError('a and b must have same shape')
return da.sqrt(da.sum((a - b) ** 2) / N)
a -= b
return da.sqrt(da.sum(da.power(a, 2)) / N)
```
%% Cell type:markdown id:d75ca8e1 tags:
### First load, then compute
%% Cell type:code id:3abf6f02 tags:
``` python
%%time
trj = md.load(trajs,top=topol)
```
%% Cell type:code id:qualified-house tags:
......@@ -139,41 +134,16 @@
%% Cell type:code id:bd26ba99 tags:
``` python
%%time
#kmeans_model = dask_kmeans(n_clusters=2)
kmeans_model = dask_pca(n_components=2)
```
%% Cell type:code id:ed7f2f68 tags:
``` python
%%time
# Snapshots are already loaded at 500ps intervals
pca_trj = trj.xyz[:,:,:]
pca_trj = pca_trj.reshape(pca_trj.shape[0] , -1 )
```
%% Cell type:code id:d7b70474 tags:
``` python
%time
dask_df = from_pandas(pd.DataFrame(pca_trj), npartitions=4)
model = dask_pca(n_components=2)
model_trj = trj.xyz[:,:,:]
model_trj = model_trj.reshape(model_trj.shape[0] , -1 )
dask_df = from_pandas(pd.DataFrame(model_trj), npartitions=4)
dask_df = dask_df.map_partitions(cudf.from_pandas)
```
%% Cell type:code id:anticipated-edition tags:
``` python
%%time
proj = kmeans_model.fit_transform(dask_df)
```
%% Cell type:code id:651d9a95 tags:
``` python
%%time
proj = model.fit_transform(dask_df)
proj = proj.compute()
```
%% Cell type:code id:0beba1b7 tags:
......
......@@ -66,11 +66,11 @@
```
%% Cell type:code id:710a340a tags:
``` python
cluster = dask.distributed.LocalCluster()
cluster = dask.distributed.LocalCluster(n_workers=4)
client = Client(cluster)
```
%% Cell type:markdown id:2ed57674 tags:
......@@ -101,25 +101,23 @@
```
%% Cell type:code id:qualified-house tags:
``` python
tic = time.time()
%%timeit
trj.center_coordinates()
rmsd(trj.xyz, Ref.xyz).compute()
toc = time.time()
toc - tic
```
%% Cell type:markdown id:5147257b tags:
### Iterate and compute
%% Cell type:code id:d5b26b6f tags:
``` python
%%time
%%timeit
for chunks in md.iterload(trajs, top=top):
chunks.center_coordinates()
rmsd(chunks.xyz, Ref.xyz).compute()
```
......@@ -129,15 +127,15 @@
%% Cell type:code id:bd26ba99 tags:
``` python
%%time
kmeans_model = dask_pca(n_components=2)
pca_trj = trj.xyz[:,:,:]
pca_trj = pca_trj.reshape(pca_trj.shape[0] , -1 )
dask_df = from_pandas(pd.DataFrame(pca_trj), npartitions=4)
proj = kmeans_model.fit_transform(dask_df)
model = dask_pca(n_components=2)
model_trj = trj.xyz[:,:,:]
model_trj = model_trj.reshape(model_trj.shape[0] , -1 )
dask_df = from_pandas(pd.DataFrame(model_trj), npartitions=4)
proj = model.fit_transform(dask_df)
proj = proj.compute()
```
%% Cell type:code id:cc4b204e tags:
......
......@@ -101,14 +101,14 @@
%% Cell type:code id:9129076c tags:
``` python
%%timeit
md_pca = PCA(n_clusters=2)
pca_trj = trj.xyz[:,:,:]
pca_trj = pca_trj.reshape(pca_trj.shape[0] , -1 )
proj = md_pca.fit_transform(pca_trj)
model = PCA(n_clusters=2)
model_trj = trj.xyz[:,:,:]
model_trj = model_trj.reshape(pca_trj.shape[0] , -1 )
proj = model.fit_transform(pca_trj)
```
%% Cell type:markdown id:0475e0a8 tags:
%%time
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment