## Set up the environment

```
!nvidia-smi
```

    Mon Jun 14 13:19:59 2021
    +-----------------------------------------------------------------------------+
    | NVIDIA-SMI 465.27       Driver Version: 460.32.03    CUDA Version: 11.2     |
    |-------------------------------+----------------------+----------------------+
    | GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
    | Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
    |                               |                      |               MIG M. |
    |===============================+======================+======================|
    |   0  Tesla T4            Off  | 00000000:00:04.0 Off |                    0 |
    | N/A   52C    P8    10W /  70W |      0MiB / 15109MiB |      0%      Default |
    |                               |                      |                  N/A |
    +-------------------------------+----------------------+----------------------+

    +-----------------------------------------------------------------------------+
    | Processes:                                                                  |
    |  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
    |        ID   ID                                                   Usage      |
    |=============================================================================|
    |  No running processes found                                                 |
    +-----------------------------------------------------------------------------+

```
#!pip install pymatgen==2020.12.31
!pip install pymatgen==2019.11.11
!pip install --pre graphdot
!pip install gdown
```

    Requirement already satisfied: pymatgen==2019.11.11 in /usr/local/lib/python3.7/dist-packages (2019.11.11)
    Requirement already satisfied: monty>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from pymatgen==2019.11.11) (2021.6.10)
    Requirement already satisfied: ruamel.yaml>=0.15.6 in /usr/local/lib/python3.7/dist-packages (from pymatgen==2019.11.11) (0.17.9)
    Requirement already satisfied: pydispatcher>=2.0.5 in /usr/local/lib/python3.7/dist-packages (from pymatgen==2019.11.11) (2.0.5)
    Requirement already satisfied: spglib>=1.9.9.44 in /usr/local/lib/python3.7/dist-packages (from pymatgen==2019.11.11) (1.16.1)
    Requirement already satisfied: networkx>=2.2 in /usr/local/lib/python3.7/dist-packages (from pymatgen==2019.11.11) (2.5.1)
    Requirement already satisfied: requests in /usr/local/lib/python3.7/dist-packages (from pymatgen==2019.11.11) (2.23.0)
    Requirement already satisfied: palettable>=3.1.1 in /usr/local/lib/python3.7/dist-packages (from pymatgen==2019.11.11) (3.3.0)
    Requirement already satisfied: pandas in /usr/local/lib/python3.7/dist-packages (from pymatgen==2019.11.11) (1.1.5)
    Requirement already satisfied: scipy>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from pymatgen==2019.11.11) (1.4.1)
    Requirement already satisfied: tabulate in /usr/local/lib/python3.7/dist-packages (from pymatgen==2019.11.11) (0.8.9)
    Requirement already satisfied: sympy in /usr/local/lib/python3.7/dist-packages (from pymatgen==2019.11.11) (1.7.1)
    Requirement already satisfied: matplotlib>=1.5 in /usr/local/lib/python3.7/dist-packages (from pymatgen==2019.11.11) (3.2.2)
    Requirement already satisfied: numpy>=1.14.3 in /usr/local/lib/python3.7/dist-packages (from pymatgen==2019.11.11) (1.19.5)
    Requirement already satisfied: ruamel.yaml.clib>=0.1.2; platform_python_implementation == "CPython" and python_version < "3.10" in /usr/local/lib/python3.7/dist-packages (from ruamel.yaml>=0.15.6->pymatgen==2019.11.11) (0.2.2)
    Requirement already satisfied: decorator<5,>=4.3 in /usr/local/lib/python3.7/dist-packages (from networkx>=2.2->pymatgen==2019.11.11) (4.4.2)
    Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests->pymatgen==2019.11.11) (2020.12.5)
    Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests->pymatgen==2019.11.11) (2.10)
    Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests->pymatgen==2019.11.11) (1.24.3)
    Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests->pymatgen==2019.11.11) (3.0.4)
    Requirement already satisfied: python-dateutil>=2.7.3 in /usr/local/lib/python3.7/dist-packages (from pandas->pymatgen==2019.11.11) (2.8.1)
    Requirement already satisfied: pytz>=2017.2 in /usr/local/lib/python3.7/dist-packages (from pandas->pymatgen==2019.11.11) (2018.9)
    Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.7/dist-packages (from sympy->pymatgen==2019.11.11) (1.2.1)
    Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib>=1.5->pymatgen==2019.11.11) (2.4.7)
    Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib>=1.5->pymatgen==2019.11.11) (1.3.1)
    Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib>=1.5->pymatgen==2019.11.11) (0.10.0)
    Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil>=2.7.3->pandas->pymatgen==2019.11.11) (1.15.0)
    Requirement already satisfied: graphdot in /usr/local/lib/python3.7/dist-packages (0.8a17)
    Requirement already satisfied: pandas>=0.24 in /usr/local/lib/python3.7/dist-packages (from graphdot) (1.1.5)
    Requirement already satisfied: numpy>=1.17 in /usr/local/lib/python3.7/dist-packages (from graphdot) (1.19.5)
    Requirement already satisfied: ase>=3.17 in /usr/local/lib/python3.7/dist-packages (from graphdot) (3.21.1)
    Requirement already satisfied: networkx>=2.4 in /usr/local/lib/python3.7/dist-packages (from graphdot) (2.5.1)
    Requirement already satisfied: sympy>=1.3 in /usr/local/lib/python3.7/dist-packages (from graphdot) (1.7.1)
    Requirement already satisfied: treelib>=1.6.1 in /usr/local/lib/python3.7/dist-packages (from graphdot) (1.6.1)
    Requirement already satisfied: kahypar>=1.1.4 in /usr/local/lib/python3.7/dist-packages (from graphdot) (1.1.6)
    Requirement already satisfied: pymatgen==2019.11.11 in /usr/local/lib/python3.7/dist-packages (from graphdot) (2019.11.11)
    Requirement already satisfied: pycuda>=2019 in /usr/local/lib/python3.7/dist-packages (from graphdot) (2021.1)
    Requirement already satisfied: mendeleev>=0.7 in /usr/local/lib/python3.7/dist-packages (from graphdot) (0.7.0)
    Requirement already satisfied: numba>=0.51.0 in /usr/local/lib/python3.7/dist-packages (from graphdot) (0.51.2)
    Requirement already satisfied: tqdm>=4.55 in /usr/local/lib/python3.7/dist-packages (from graphdot) (4.61.1)
    Requirement already satisfied: scipy>=1.3.0 in /usr/local/lib/python3.7/dist-packages (from graphdot) (1.4.1)
    Requirement already satisfied: python-dateutil>=2.7.3 in /usr/local/lib/python3.7/dist-packages (from pandas>=0.24->graphdot) (2.8.1)
    Requirement already satisfied: pytz>=2017.2 in /usr/local/lib/python3.7/dist-packages (from pandas>=0.24->graphdot) (2018.9)
    Requirement already satisfied: matplotlib>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from ase>=3.17->graphdot) (3.2.2)
    Requirement already satisfied: decorator<5,>=4.3 in /usr/local/lib/python3.7/dist-packages (from networkx>=2.4->graphdot) (4.4.2)
    Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.7/dist-packages (from sympy>=1.3->graphdot) (1.2.1)
    Requirement already satisfied: future in /usr/local/lib/python3.7/dist-packages (from treelib>=1.6.1->graphdot) (0.16.0)
    Requirement already satisfied: pydispatcher>=2.0.5 in /usr/local/lib/python3.7/dist-packages (from pymatgen==2019.11.11->graphdot) (2.0.5)
    Requirement already satisfied: tabulate in /usr/local/lib/python3.7/dist-packages (from pymatgen==2019.11.11->graphdot) (0.8.9)
    Requirement already satisfied: monty>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from pymatgen==2019.11.11->graphdot) (2021.6.10)
    Requirement already satisfied: requests in /usr/local/lib/python3.7/dist-packages (from pymatgen==2019.11.11->graphdot) (2.23.0)
    Requirement already satisfied: ruamel.yaml>=0.15.6 in /usr/local/lib/python3.7/dist-packages (from pymatgen==2019.11.11->graphdot) (0.17.9)
    Requirement already satisfied: spglib>=1.9.9.44 in /usr/local/lib/python3.7/dist-packages (from pymatgen==2019.11.11->graphdot) (1.16.1)
    Requirement already satisfied: palettable>=3.1.1 in /usr/local/lib/python3.7/dist-packages (from pymatgen==2019.11.11->graphdot) (3.3.0)
    Requirement already satisfied: pytools>=2011.2 in /usr/local/lib/python3.7/dist-packages (from pycuda>=2019->graphdot) (2021.2.7)
    Requirement already satisfied: appdirs>=1.4.0 in /usr/local/lib/python3.7/dist-packages (from pycuda>=2019->graphdot) (1.4.4)
    Requirement already satisfied: mako in /usr/local/lib/python3.7/dist-packages (from pycuda>=2019->graphdot) (1.1.4)
    Requirement already satisfied: Pygments<3.0.0,>=2.8.0 in /usr/local/lib/python3.7/dist-packages (from mendeleev>=0.7->graphdot) (2.9.0)
    Requirement already satisfied: six<2.0.0,>=1.15.0 in /usr/local/lib/python3.7/dist-packages (from mendeleev>=0.7->graphdot) (1.15.0)
    Requirement already satisfied: pyfiglet<0.9,>=0.8.post1 in /usr/local/lib/python3.7/dist-packages (from mendeleev>=0.7->graphdot) (0.8.post1)
    Requirement already satisfied: SQLAlchemy<2.0.0,>=1.3.23 in /usr/local/lib/python3.7/dist-packages (from mendeleev>=0.7->graphdot) (1.4.15)
    Requirement already satisfied: colorama<0.5.0,>=0.4.4 in /usr/local/lib/python3.7/dist-packages (from mendeleev>=0.7->graphdot) (0.4.4)
    Requirement already satisfied: llvmlite<0.35,>=0.34.0.dev0 in /usr/local/lib/python3.7/dist-packages (from numba>=0.51.0->graphdot) (0.34.0)
    Requirement already satisfied: setuptools in /usr/local/lib/python3.7/dist-packages (from numba>=0.51.0->graphdot) (57.0.0)
    Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib>=2.0.0->ase>=3.17->graphdot) (0.10.0)
    Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib>=2.0.0->ase>=3.17->graphdot) (2.4.7)
    Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib>=2.0.0->ase>=3.17->graphdot) (1.3.1)
    Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests->pymatgen==2019.11.11->graphdot) (1.24.3)
    Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests->pymatgen==2019.11.11->graphdot) (3.0.4)
    Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests->pymatgen==2019.11.11->graphdot) (2020.12.5)
    Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests->pymatgen==2019.11.11->graphdot) (2.10)
    Requirement already satisfied: ruamel.yaml.clib>=0.1.2; platform_python_implementation == "CPython" and python_version < "3.10" in /usr/local/lib/python3.7/dist-packages (from ruamel.yaml>=0.15.6->pymatgen==2019.11.11->graphdot) (0.2.2)
    Requirement already satisfied: MarkupSafe>=0.9.2 in /usr/local/lib/python3.7/dist-packages (from mako->pycuda>=2019->graphdot) (2.0.1)
    Requirement already satisfied: importlib-metadata; python_version < "3.8" in /usr/local/lib/python3.7/dist-packages (from SQLAlchemy<2.0.0,>=1.3.23->mendeleev>=0.7->graphdot) (4.0.1)
    Requirement already satisfied: greenlet!=0.4.17; python_version >= "3" in /usr/local/lib/python3.7/dist-packages (from SQLAlchemy<2.0.0,>=1.3.23->mendeleev>=0.7->graphdot) (1.1.0)
    Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.7/dist-packages (from importlib-metadata; python_version < "3.8"->SQLAlchemy<2.0.0,>=1.3.23->mendeleev>=0.7->graphdot) (3.4.1)
    Requirement already satisfied: typing-extensions>=3.6.4; python_version < "3.8" in /usr/local/lib/python3.7/dist-packages (from importlib-metadata; python_version < "3.8"->SQLAlchemy<2.0.0,>=1.3.23->mendeleev>=0.7->graphdot) (3.7.4.3)
    Requirement already satisfied: gdown in /usr/local/lib/python3.7/dist-packages (3.6.4)
    Requirement already satisfied: requests in /usr/local/lib/python3.7/dist-packages (from gdown) (2.23.0)
    Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (from gdown) (4.61.1)
    Requirement already satisfied: six in /usr/local/lib/python3.7/dist-packages (from gdown) (1.15.0)
    Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from requests->gdown) (1.24.3)
    Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests->gdown) (2.10)
    Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests->gdown) (3.0.4)
    Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests->gdown) (2020.12.5)

```
%matplotlib inline
import io
import sys
sys.path.append('/usr/local/lib/python3.6/site-packages/')
import os
import urllib
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

import graphdot
from graphdot import Graph
from graphdot.graph.adjacency import AtomicAdjacency
from graphdot.graph.reorder import rcm
from graphdot.kernel.marginalized import MarginalizedGraphKernel # https://graphdot.readthedocs.io/en/latest/apidoc/graphdot.kernel.marginalized.html
from graphdot.kernel.marginalized.starting_probability import Uniform
from graphdot.model.gaussian_process import (
    GaussianProcessRegressor,
    LowRankApproximateGPR
)
from graphdot.kernel.fix import Normalization
import graphdot.microkernel as uX
import ase.io

# for getting all file names into a list under a directory
from os import listdir
# for getting file names that match certain pattern
import glob
import time
```

    /usr/local/lib/python3.7/dist-packages/graphdot/graph/__init__.py:24: UserWarning: Cannot import RDKit, `graph.from_rdkit()` will be unavailable.

      'Cannot import RDKit, `graph.from_rdkit()` will be unavailable.\n'

```
from google.colab import drive
drive.mount('/content/gdrive', force_remount=True)
```

    Mounted at /content/gdrive

```
#cd gdrive/MyDrive/Google\ Colab/Covid-Data
%cd gdrive/MyDrive/Covid-Data/
```

    /content/gdrive/.shortcut-targets-by-id/1wtzMcocuK8kPsz8K0ktjCZPkv567W6M2/Covid-Data

```
!pwd
```

    /content/gdrive/.shortcut-targets-by-id/1wtzMcocuK8kPsz8K0ktjCZPkv567W6M2/Covid-Data

```
#!mkdir /content/pkls
```

## load the data

```
files  = ['uncharged_NSP15_6W01_A_3_H.Orderable_zinc_db_enaHLL.2col.csv.1.xz']
dataset = pd.read_pickle(files[0]) # length of each csv file is 100000
```

```
target = 'energy'
N_train = 1000
N_test = 2000

np.random.seed(0) # with the same seed, multiple runs can have the same selected index
train_sel = np.random.choice(len(dataset), N_train, replace=False)
test_sel = np.random.choice(np.setxor1d(np.arange(len(dataset)), train_sel), N_test, replace=False)
train = dataset.iloc[train_sel]
test = dataset.iloc[test_sel]
```

```
train.head()
```

      energy
      smiles
      graphs

      3582
      -2.874773
      CN(Cc1nc(no1)c2cccc(c2)Br)C(=O)Nc3cccc(c3)OC
      Graph(nodes={'!i': [ 0, 1, 2, 3, 4, 5, 6, 7, 8...

      60498
      -3.469760
      CCOC(=O)c1ccc(c(c1)C)NC(=S)NCCOc2ccc(cc2)C
      Graph(nodes={'!i': [ 0, 1, 2, 3, 4, 5, 6, 7, 8...

      53227
      -0.487984
      Cc1ccc(cc1S(=O)(=O)Nc2ccccc2OC)NC(=O)c3nc4nc(c...
      Graph(nodes={'!i': [ 0, 1, 2, 3, 4, 5, 6, 7, 8...

      21333
      -1.808283
      COc1ccc(cc1OC)CCNC(=O)COc2ccc(cc2)[N@@](Cc3ccc...
      Graph(nodes={'!i': [ 0, 1, 2, 3, 4, 5, 6, 7, 8...

      3885
      -2.457642
      Cc1cc(ccc1NCc2ccc(c(c2OC)C)OC)Br
      Graph(nodes={'!i': [ 0, 1, 2, 3, 4, 5, 6, 7, 8...

### Baseline mode

```
gpr_base = GaussianProcessRegressor(
    # kernel is the covariance function of the gaussian process (GP)
    kernel=Normalization( # kernel equals to normalization -> normalizes a kernel using the cosine of angle formula, k_normalized(x,y) = k(x,y)/sqrt(k(x,x)*k(y,y))
        # graphdot.kernel.fix.Normalization(kernel), set kernel as marginalized graph kernel, which is used to calculate the similarity between 2 graphs
        # implement the random walk-based graph similarity kernel as Kashima, H., Tsuda, K., & Inokuchi, A. (2003). Marginalized kernels between labeled graphs. ICML
        MarginalizedGraphKernel(
            # node_kernel - A kernelet that computes the similarity between individual nodes
            # uX - graphdot.microkernel - microkernels are positive-semidefinite functions between individual nodes and edges of graphs
            node_kernel=uX.Additive( # addition of kernal matrices: sum of k_a(X_a, Y_a) cross for a in features
                # uX.Constant - a kernel that returns a constant value, always mutlipled with other microkernels as an adjustable weight
                #   c, the first input arg. as 0.5, (0.01, 10) the lower and upper bounds of c that is allowed to vary during hyperpara. optimizartion
                # uX.KroneckerDelta - a kronecker delta returns 1 when two features are equal and return h (the first input arg here, which is 0.5 in this case) otherwise
                #   (0.1, 0.9) the lower and upper bounds that h is allowed to vary during hyperpara. optimization
                aromatic=uX.Constant(0.5, (0.01, 10.0)) * uX.KroneckerDelta(0.5,(0.1, 0.9)), # the 2nd element of graphdot.graph.Graph.nodes
                atomic_number=uX.Constant(0.5, (0.01, 10.0)) * uX.KroneckerDelta(0.8,(0.1, 0.9)), # the 3rd element of graphdot.graph.Graph.nodes
                # uX.SquareExponential - Equ. 26 in the paper
                # input arg. length_sacle is a float32, set as 1 in this case, which correspond to approx. 1 of the kernal value.
                # This is used to determins how quicklys should the kernel decay to zero.
                charge=uX.Constant(0.5, (0.01, 10.0)) * uX.SquareExponential(1.0), # the 4th element of graphdot.graph.Graph.nodes
                chiral=uX.Constant(0.5, (0.01, 10.0)) * uX.KroneckerDelta(0.5,(0.1, 0.9)), # the 5th element of graphdot.graph.Graph.nodes
                hcount=uX.Constant(0.5, (0.01, 10.0)) * uX.SquareExponential(1.0), # the 6th element of graphdot.graph.Graph.nodes
                hybridization=uX.Constant(0.5, (0.01, 10.0)) * uX.KroneckerDelta(0.5,(0.1, 0.9)), # the 7th element of graphdot.graph.Graph.nodes
                # uX.Convolution - a convolutional microkernel which averages evaluations of a base microkernel between pairs pf elememts of two variable-length feature sequences
                # uX.KroneckerDelta as the base kernel
                ring_list=uX.Constant(0.5, (0.01, 100.0)) * uX.Convolution(uX.KroneckerDelta(0.5,(0.1, 0.9))) # the 8th element of graphdot.graph.Graph.nodes
            ).normalized,
            # edge_kernel - A kernelet that computes the similarity between individual edge
            edge_kernel=uX.Additive(
                aromatic=uX.Constant(0.5, (0.01, 10.0)) * uX.KroneckerDelta(0.5,(0.1, 0.9)), # the 3rd element of graphdot.graph.Graph.nodes
                conjugated=uX.Constant(0.5, (0.01, 10.0)) * uX.KroneckerDelta(0.5,(0.1, 0.9)), # the 4th element of graphdot.graph.Graph.nodes
                order=uX.Constant(0.5, (0.01, 10.0)) * uX.KroneckerDelta(0.8,(0.1, 0.9)), # the 5th element of graphdot.graph.Graph.nodes
                ring_stereo=uX.Constant(0.5, (0.01, 10.0)) * uX.KroneckerDelta(0.8,(0.1, 0.9)), # the 6th element of graphdot.graph.Graph.nodes
                stereo=uX.Constant(0.5, (0.01, 10.0)) * uX.KroneckerDelta(0.8,(0.1, 0.9)) # the 7th element of graphdot.graph.Graph.nodes
            ).normalized,
            p=Uniform(1.0, p_bounds='fixed'), # the strating probability of the random walk on each node
            q=0.05 # the probability for the random walk to stop during each step
        )
    ),
    alpha=1e-4, # value added to the diagonal of the kernel matrix during fitting
    optimizer=True, # default optimizer of L-BFGS-B based on scipy.optimize.minimize
    normalize_y=True, # normalize the y values so taht the means and variance is 0 and 1, repsectively. Will be reversed when predicions are returned
    regularization='+', # alpha (1e-4 in this case) is added to the diagonals of the kernal matrix
)
```

```
gpr_base.fit(train.graphs, train[target], repeat=3, verbose=True)
```

    |        logP|       dlogP|     y^T.K.y|     log|K| |     Cond(K)|  GPU time|  CPU time|
    |------------|------------|------------|------------|------------|----------|----------|
    |  2.8725e+06|  2.4458e+07|  2.8798e+06|     -7290.9|  8.7024e+06|        22|      0.25|
    |  1.9315e+06|  2.0707e+07|  1.9382e+06|     -6742.8|  8.0237e+06|        20|      0.24|
    |  1.2905e+06|  1.5706e+07|  1.2968e+06|     -6252.2|  7.0835e+06|        19|      0.25|
    |  1.0061e+06|  1.2309e+07|  1.0121e+06|     -5971.8|  6.4171e+06|        18|      0.24|
    |  8.2557e+05|  9.7267e+06|  8.3132e+05|     -5755.4|  5.8209e+06|        17|      0.23|
    |  7.1178e+05|  8.0789e+06|  7.1737e+05|     -5588.8|  5.3655e+06|        17|      0.25|
    |  6.4897e+05|  7.1031e+06|  6.5446e+05|     -5488.6|  5.0424e+06|        17|      0.24|
    |  6.2995e+05|   7.043e+06|  6.3539e+05|     -5435.7|  4.9627e+06|        17|      0.24|
    |  6.1001e+05|  6.6424e+06|  6.1542e+05|     -5413.2|  4.8439e+06|        17|      0.24|
    |   6.055e+05|  6.5416e+06|  6.1091e+05|     -5407.7|  4.7988e+06|        16|      0.24|
    |  6.0285e+05|  6.4988e+06|  6.0825e+05|     -5402.9|  4.7885e+06|        16|      0.24|
    |  6.0601e+05|  6.6651e+06|   6.114e+05|     -5395.9|  4.8317e+06|        17|      0.25|
    |  6.0087e+05|  6.5216e+06|  6.0626e+05|     -5395.1|  4.7916e+06|        17|      0.24|
    |  5.9979e+05|  6.4968e+06|  6.0518e+05|     -5393.3|  4.7859e+06|        17|      0.24|
    |  5.9795e+05|  6.4537e+06|  6.0334e+05|     -5390.4|  4.7776e+06|        17|      0.26|
    |  5.9632e+05|   6.417e+06|  6.0171e+05|     -5388.7|  4.7579e+06|        16|      0.23|
    |  5.9535e+05|  6.4032e+06|  6.0074e+05|     -5387.3|  4.7491e+06|        16|      0.25|
    |  5.9515e+05|  6.4246e+06|  6.0054e+05|     -5386.3|  4.7503e+06|        17|      0.24|
    |  5.9519e+05|  6.4222e+06|  6.0058e+05|     -5386.6|  4.7481e+06|        17|      0.25|
    |  5.9528e+05|  6.4269e+06|  6.0067e+05|     -5386.3|  4.7487e+06|        17|      0.25|
    |  5.9518e+05|  6.4251e+06|  6.0056e+05|     -5386.3|   4.747e+06|        17|      0.24|
    |  5.9522e+05|  6.4263e+06|  6.0061e+05|     -5386.3|   4.748e+06|        17|      0.24|
    |  5.9521e+05|  6.4261e+06|   6.006e+05|     -5386.3|  4.7459e+06|        17|      0.24|
    |  5.9521e+05|  6.4263e+06|   6.006e+05|     -5386.3|  4.7474e+06|        17|      0.25|
    |  5.9516e+05|  6.4253e+06|  6.0055e+05|     -5386.2|  4.7489e+06|        17|      0.25|
    |        logP|       dlogP|     y^T.K.y|     log|K| |     Cond(K)|  GPU time|  CPU time|
    |------------|------------|------------|------------|------------|----------|----------|
    |  1.7413e+06|  2.1782e+07|   1.748e+06|       -6644|  7.5158e+06|        20|      0.24|
    |  1.3451e+06|  1.6773e+07|  1.3514e+06|     -6332.3|  6.9251e+06|        19|      0.25|
    |   1.033e+06|  1.3306e+07|  1.0391e+06|     -6026.9|  6.3155e+06|        19|      0.24|
    |  7.9866e+05|  1.0452e+07|  8.0437e+05|     -5717.2|  5.7392e+06|        19|      0.26|
    |  6.9752e+05|  8.1836e+06|  7.0309e+05|     -5576.4|   5.318e+06|        17|      0.26|
    |  6.4289e+05|   7.195e+06|  6.4837e+05|     -5481.7|  5.0649e+06|        17|      0.23|
    |   6.153e+05|  6.7608e+06|  6.2073e+05|     -5430.1|  4.8862e+06|        17|      0.24|
    |  6.1229e+05|  6.6746e+06|  6.1772e+05|     -5421.4|  4.8115e+06|        16|      0.24|
    |  5.9982e+05|  6.4991e+06|  6.0522e+05|     -5399.3|  4.7705e+06|        16|      0.23|
    |  5.9655e+05|  6.4385e+06|  6.0194e+05|     -5390.8|  4.7638e+06|        17|      0.23|
    |  5.9622e+05|  6.4295e+06|  6.0161e+05|       -5390|  4.7603e+06|        16|      0.25|
    |  5.9531e+05|  6.4019e+06|   6.007e+05|     -5388.4|  4.7574e+06|        16|      0.26|
    |  5.9498e+05|  6.3961e+06|  6.0037e+05|     -5387.3|  4.7535e+06|        16|      0.25|
    |  5.9726e+05|  6.5117e+06|  6.0264e+05|     -5385.9|  4.7837e+06|        17|      0.24|
    |  5.9475e+05|  6.4136e+06|  6.0013e+05|     -5385.8|  4.7581e+06|        17|      0.24|
    |  5.9453e+05|   6.402e+06|  5.9992e+05|       -5386|  4.7582e+06|        16|      0.24|
    |  5.9439e+05|   6.409e+06|  5.9978e+05|     -5385.3|  4.7563e+06|        17|      0.24|
    |  5.9419e+05|  6.4005e+06|  5.9957e+05|     -5385.6|  4.7549e+06|        17|      0.25|
    |  5.9386e+05|  6.3824e+06|  5.9925e+05|     -5386.6|  4.7468e+06|        16|      0.25|
    |  5.9362e+05|  6.3753e+06|  5.9901e+05|     -5386.7|  4.7493e+06|        16|      0.24|
    |  5.9322e+05|  6.3676e+06|  5.9861e+05|     -5387.2|  4.7601e+06|        16|      0.25|
    |  5.9311e+05|   6.373e+06|  5.9849e+05|     -5386.5|  4.7591e+06|        16|      0.26|
    |  5.9318e+05|  6.3877e+06|  5.9857e+05|     -5385.4|  4.7644e+06|        17|      0.25|
    |  5.9334e+05|  6.3815e+06|  5.9873e+05|     -5386.2|  4.7579e+06|        16|      0.23|
    |  5.9312e+05|  6.3728e+06|  5.9851e+05|     -5386.5|  4.7571e+06|        16|      0.25|
    |  5.9326e+05|  6.3759e+06|  5.9864e+05|     -5386.5|  4.7563e+06|        16|      0.25|
    |  5.9319e+05|  6.3747e+06|  5.9858e+05|     -5386.5|  4.7585e+06|        16|      0.24|
    |  5.9323e+05|  6.3755e+06|  5.9862e+05|     -5386.5|  4.7595e+06|        16|      0.25|
    |  5.9327e+05|  6.3764e+06|  5.9866e+05|     -5386.5|  4.7575e+06|        16|      0.24|
    |        logP|       dlogP|     y^T.K.y|     log|K| |     Cond(K)|  GPU time|  CPU time|
    |------------|------------|------------|------------|------------|----------|----------|
    |  3.4092e+06|  2.5343e+07|  3.4168e+06|     -7528.5|  8.7203e+06|        20|      0.24|
    |  2.2467e+06|  2.1995e+07|  2.2536e+06|     -6926.8|  8.0939e+06|        19|      0.25|
    |  1.4704e+06|  1.6957e+07|  1.4768e+06|     -6399.5|  7.2075e+06|        19|      0.24|
    |  1.1068e+06|  1.3411e+07|  1.1129e+06|     -6074.4|  6.5417e+06|        18|      0.23|
    |  8.6387e+05|  1.0661e+07|  8.6966e+05|     -5795.5|   5.954e+06|        18|      0.25|
    |  7.4225e+05|  8.8175e+06|  7.4788e+05|     -5630.3|  5.5341e+06|        18|      0.24|
    |  6.7235e+05|  7.6658e+06|  6.7787e+05|     -5526.8|  5.2141e+06|        17|      0.25|
    |  6.3387e+05|  7.1558e+06|  6.3932e+05|     -5448.8|  4.9899e+06|        17|      0.24|
    |  6.1335e+05|  6.7496e+06|  6.1877e+05|     -5423.9|  4.8814e+06|        17|      0.24|
    |  6.1076e+05|  6.7056e+06|  6.1618e+05|     -5418.4|   4.863e+06|        17|      0.25|
    |  6.0468e+05|  6.6012e+06|  6.1008e+05|     -5406.1|  4.8233e+06|        17|      0.23|
    |  5.9819e+05|  6.4569e+06|  6.0358e+05|     -5396.3|   4.775e+06|        17|      0.23|
    |   5.968e+05|  6.4322e+06|  6.0219e+05|     -5392.3|  4.7729e+06|        17|      0.24|
    |  5.9554e+05|    6.42e+06|  6.0093e+05|       -5389|  4.7546e+06|        17|      0.23|
    |  5.9516e+05|  6.4092e+06|  6.0054e+05|     -5386.2|  4.7716e+06|        17|      0.23|
    |  5.9485e+05|  6.4051e+06|  6.0024e+05|     -5386.6|  4.7631e+06|        17|      0.24|
    |  5.9451e+05|  6.4007e+06|   5.999e+05|       -5387|  4.7598e+06|        17|      0.25|
    |  5.9416e+05|  6.3958e+06|  5.9954e+05|       -5387|  4.7533e+06|        17|      0.25|
    |  5.9357e+05|  6.3871e+06|  5.9896e+05|     -5386.8|   4.753e+06|        17|      0.25|
    |  5.9331e+05|  6.3992e+06|   5.987e+05|     -5386.3|  4.7538e+06|        17|      0.24|
    |  5.9325e+05|  6.3912e+06|  5.9863e+05|     -5386.2|  4.7553e+06|        17|      0.26|
    |   5.931e+05|  6.3778e+06|  5.9848e+05|       -5386|  4.7619e+06|        16|      0.23|
    |   5.931e+05|  6.3773e+06|  5.9848e+05|     -5385.9|  4.7602e+06|        17|      0.24|
    |  5.9305e+05|  6.3763e+06|  5.9843e+05|       -5386|  4.7597e+06|        17|      0.24|
    |  5.9304e+05|  6.3762e+06|  5.9843e+05|       -5386|  4.7621e+06|        17|      0.24|
    |  5.9307e+05|   6.377e+06|  5.9846e+05|       -5386|  4.7615e+06|        16|      0.23|
    |  5.9304e+05|  6.3761e+06|  5.9843e+05|     -5385.9|  4.7637e+06|        17|      0.26|
    |  5.9299e+05|  6.3766e+06|  5.9838e+05|     -5385.9|  4.7612e+06|        17|      0.24|
    |  5.9306e+05|  6.3801e+06|  5.9844e+05|     -5385.9|  4.7599e+06|        17|      0.24|
    |  5.9295e+05|  6.3753e+06|  5.9834e+05|     -5385.9|  4.7634e+06|        16|      0.25|
    |  5.9296e+05|  6.3752e+06|  5.9834e+05|     -5385.9|  4.7608e+06|        17|      0.23|
    |  5.9309e+05|   6.378e+06|  5.9847e+05|     -5385.9|  4.7631e+06|        16|      0.24|
    Optimization result:
          fun: 593087.1156402231
     hess_inv: <25x25 LbfgsInvHessProduct with dtype=float64>
          jac: array([ 6.37396256e+02,  1.29403894e+02,  1.71592132e+01,  7.87202241e+02,
            1.37346463e+04,  2.83923867e+02,  0.00000000e+00, -9.41929416e+01,
            8.31120362e+01, -9.89697568e+02,  1.85028746e-02,  1.18859915e+02,
            5.20268298e+01, -2.37801534e+02,  1.76013556e+04, -5.72112693e+01,
            1.61763990e+03, -2.77147646e+02,  3.02784539e+03,  2.61391651e+02,
            2.67337779e+02,  5.39630844e+01,  0.00000000e+00,  1.97901890e+01,
            2.39186447e+02])
      message: b'CONVERGENCE: REL_REDUCTION_OF_F_<=_FACTR*EPSMCH'
         nfev: 32
          nit: 25
       status: 0
      success: True
            x: array([-9.21034037, -4.60517019, -2.30258509,  1.47773763, -2.30258509,
           -4.60517019,  1.38836933, -3.83292358, -2.25417628,  2.30258509,
           -1.84636793, -3.87778892, -2.30258509,  1.7180289 , -2.30258509,
            1.52931263, -2.30258509,  2.15048481, -2.30258509, -0.16374951,
           -2.30258509, -4.06382248, -0.19078879, -0.36875751, -2.30258509])

    <graphdot.model.gaussian_process.gpr.GaussianProcessRegressor at 0x7fa8f0b23690>

```
#gpr_base.kernel.hyperparameters
```

```
mu = gpr_base.predict(train.graphs)
```

```
plt.scatter(train[target], mu)
plt.plot(np.linspace(-9, 3), np.linspace(-9, 3), c = 'r')
plt.xlim(-9, 3)
plt.ylim(-9, 3)
plt.show()
```

```
print('Training set')
print('MAE:', np.mean(np.abs(train[target] - mu)))
print('RMSE:', np.std(train[target] - mu))
```

    Training set
    MAE: 0.1026528897885943
    RMSE: 0.1559697478035153

```
mu_test = gpr_base.predict(test.graphs)
```

```
plt.scatter(test[target], mu_test)
plt.plot(np.linspace(-9, 3), np.linspace(-9, 3), c = 'r')
plt.xlim(-9, 3)
plt.ylim(-9, 3)
plt.show()
```

```
print('Test set')
print('MAE:', np.mean(np.abs(test[target] - mu_test)))
print('RMSE:', np.std(test[target] - mu_test))
```

    Test set
    MAE: 1.3984523944497356
    RMSE: 1.7902476214464011

### model2

```
gpr2 = GaussianProcessRegressor(
    kernel=Normalization(
        MarginalizedGraphKernel(
            node_kernel=uX.Additive(
                aromatic=uX.Constant(0.5, (0.01, 10.0)) * uX.KroneckerDelta(0.5,(0.1, 0.9)),
                atomic_number=uX.Constant(0.5, (0.01, 10.0)) * uX.KroneckerDelta(0.8,(0.1, 0.9)),
                charge=uX.Constant(0.5, (0.01, 10.0)) * uX.SquareExponential(1.0),
                chiral=uX.Constant(0.5, (0.01, 10.0)) * uX.KroneckerDelta(0.5,(0.1, 0.9)),
                hcount=uX.Constant(0.5, (0.01, 10.0)) * uX.SquareExponential(1.0),
                hybridization=uX.Constant(0.5, (0.01, 10.0)) * uX.KroneckerDelta(0.5,(0.1, 0.9)),
                ring_list=uX.Constant(0.5, (0.01, 100.0)) * uX.Convolution(uX.KroneckerDelta(0.5,(0.1, 0.9)))
            ).normalized,
            edge_kernel=uX.Additive(
                aromatic=uX.Constant(0.5, (0.01, 10.0)) * uX.KroneckerDelta(0.5,(0.1, 0.9)),
                conjugated=uX.Constant(0.5, (0.01, 10.0)) * uX.KroneckerDelta(0.5,(0.1, 0.9)),
                order=uX.Constant(0.5, (0.01, 10.0)) * uX.KroneckerDelta(0.8,(0.1, 0.9)),
                ring_stereo=uX.Constant(0.5, (0.01, 10.0)) * uX.KroneckerDelta(0.8,(0.1, 0.9)),
                stereo=uX.Constant(0.5, (0.01, 10.0)) * uX.KroneckerDelta(0.8,(0.1, 0.9))
            ).normalized,
            p=Uniform(1.0, p_bounds='fixed'),
            q=0.05
        )
    ),
    alpha=1e-5, #different from gpr in alpha where gpr's alpha is 1e-4
    optimizer=True,
    normalize_y=True,
    regularization='+',
)
```

```
gpr2.fit(train.graphs, train[target], repeat=3, verbose=True)
```

    |        logP|       dlogP|     y^T.K.y|     log|K| |     Cond(K)|  GPU time|  CPU time|
    |------------|------------|------------|------------|------------|----------|----------|
    |  3.9342e+06|  7.4014e+07|  3.9413e+06|     -7048.5|  4.2676e+07|        20|      0.25|
    |  2.5581e+06|  4.8127e+07|  2.5648e+06|     -6637.5|   3.185e+07|        19|      0.26|
    |  1.9651e+06|  3.6386e+07|  1.9715e+06|     -6391.2|  2.5862e+07|        19|      0.25|
    |  1.4839e+06|  2.6275e+07|  1.4901e+06|     -6132.7|  2.0389e+07|        19|      0.25|
    |  1.1925e+06|  1.9644e+07|  1.1985e+06|     -5931.7|  1.6716e+07|        18|      0.25|
    |  9.9823e+05|  1.5219e+07|   1.004e+06|     -5762.3|  1.4068e+07|        17|      0.25|
    |   8.735e+05|  1.2618e+07|  8.7912e+05|     -5627.6|  1.2412e+07|        17|      0.25|
    |   8.215e+05|  1.1223e+07|  8.2708e+05|     -5576.1|  1.1158e+07|        16|      0.25|
    |  7.7928e+05|  1.0614e+07|  7.8479e+05|     -5517.2|   1.082e+07|        17|      0.25|
    |  7.6384e+05|  1.0397e+07|  7.6934e+05|     -5493.1|  1.0717e+07|        17|      0.25|
    |  7.5683e+05|  1.0246e+07|  7.6232e+05|     -5483.1|  1.0625e+07|        17|      0.26|
    |  7.8307e+05|  1.0957e+07|  7.8857e+05|     -5492.5|  1.1369e+07|        17|      0.25|
    |  7.5592e+05|  1.0264e+07|   7.614e+05|       -5479|  1.0686e+07|        17|      0.26|
    |  7.5278e+05|  1.0169e+07|  7.5826e+05|     -5475.4|  1.0618e+07|        17|      0.26|
    |  7.5039e+05|  1.0088e+07|  7.5587e+05|     -5472.2|  1.0571e+07|        17|      0.25|
    |  7.4793e+05|  1.0005e+07|   7.534e+05|     -5470.1|  1.0495e+07|        16|      0.27|
    |  7.4681e+05|  9.9805e+06|  7.5228e+05|     -5468.4|  1.0454e+07|        16|      0.25|
    |  7.4544e+05|  9.9933e+06|   7.509e+05|     -5465.7|  1.0403e+07|        17|      0.25|
    |  7.4519e+05|  9.9849e+06|  7.5065e+05|     -5466.5|  1.0374e+07|        16|      0.25|
    |  7.4522e+05|  9.9838e+06|  7.5069e+05|     -5466.8|  1.0376e+07|        17|      0.27|
    |  7.4542e+05|   9.991e+06|  7.5089e+05|     -5466.6|  1.0371e+07|        17|      0.25|
    |  7.4539e+05|  9.9914e+06|  7.5086e+05|     -5466.5|  1.0373e+07|        17|      0.27|
    |  7.4543e+05|  9.9918e+06|   7.509e+05|     -5466.5|  1.0368e+07|        16|      0.25|
    |   7.451e+05|  9.9824e+06|  7.5057e+05|     -5466.5|  1.0392e+07|        16|      0.27|
    |  7.4524e+05|  9.9871e+06|   7.507e+05|     -5466.5|   1.037e+07|        17|      0.27|
    |  7.4525e+05|  9.9861e+06|  7.5072e+05|     -5466.5|  1.0386e+07|        17|      0.27|
    |        logP|       dlogP|     y^T.K.y|     log|K| |     Cond(K)|  GPU time|  CPU time|
    |------------|------------|------------|------------|------------|----------|----------|
    |  2.2754e+06|  4.0939e+07|   2.282e+06|     -6573.6|    2.42e+07|        18|      0.25|
    |  1.7565e+06|  3.1259e+07|  1.7628e+06|     -6332.7|  2.0381e+07|        18|      0.24|
    |  1.2573e+06|   2.224e+07|  1.2633e+06|       -6009|  1.6215e+07|        19|      0.25|
    |    1.05e+06|  1.7608e+07|  1.0558e+06|     -5820.4|  1.4598e+07|        18|      0.25|
    |  8.9771e+05|  1.3272e+07|  9.0338e+05|     -5669.2|  1.2572e+07|        17|      0.27|
    |  8.1417e+05|  1.1552e+07|  8.1973e+05|     -5559.9|  1.1683e+07|        17|      0.25|
    |  7.8461e+05|  1.0854e+07|  7.9014e+05|     -5523.1|  1.1122e+07|        17|      0.26|
    |  7.6515e+05|  1.0363e+07|  7.7064e+05|     -5496.3|  1.0598e+07|        17|      0.26|
    |   7.549e+05|  1.0202e+07|  7.6038e+05|     -5480.5|  1.0455e+07|        17|      0.27|
    |  7.5113e+05|   1.013e+07|   7.566e+05|     -5473.3|  1.0408e+07|        17|      0.25|
    |  7.4842e+05|   1.001e+07|  7.5389e+05|     -5468.3|  1.0405e+07|        16|      0.25|
    |  7.4817e+05|  1.0021e+07|  7.5363e+05|     -5467.8|  1.0392e+07|        16|      0.27|
    |  7.4743e+05|  1.0028e+07|   7.529e+05|     -5467.3|  1.0359e+07|        17|      0.26|
    |  7.4775e+05|   1.007e+07|  7.5321e+05|     -5465.8|   1.042e+07|        17|      0.26|
    |  7.4729e+05|  1.0032e+07|  7.5276e+05|     -5466.8|  1.0374e+07|        17|      0.26|
    |  7.4778e+05|  1.0071e+07|  7.5325e+05|       -5466|  1.0404e+07|        17|      0.26|
    |  7.4737e+05|  1.0035e+07|  7.5284e+05|     -5466.8|  1.0383e+07|        17|      0.26|
    |  7.4755e+05|  1.0041e+07|  7.5301e+05|     -5466.8|  1.0372e+07|        17|      0.25|
    |  7.4755e+05|   1.004e+07|  7.5302e+05|     -5466.8|  1.0377e+07|        17|      0.26|
    |   7.475e+05|  1.0039e+07|  7.5297e+05|     -5466.8|   1.037e+07|        17|      0.25|
    |  7.4752e+05|  1.0039e+07|  7.5298e+05|     -5466.8|  1.0365e+07|        16|      0.26|
    |        logP|       dlogP|     y^T.K.y|     log|K| |     Cond(K)|  GPU time|  CPU time|
    |------------|------------|------------|------------|------------|----------|----------|
    |  5.5724e+06|  1.0057e+08|  5.5798e+06|     -7408.4|  5.0139e+07|        19|      0.24|
    |  3.3661e+06|  6.0838e+07|   3.373e+06|     -6905.1|  3.6581e+07|        19|      0.24|
    |  2.6218e+06|  4.7142e+07|  2.6285e+06|     -6665.4|  3.0491e+07|        18|      0.24|
    |  1.8232e+06|  3.1903e+07|  1.8296e+06|     -6322.8|  2.3196e+07|        18|      0.27|
    |  1.4038e+06|  2.3742e+07|  1.4099e+06|     -6073.7|  1.9114e+07|        18|      0.25|
    |   1.145e+06|  1.8596e+07|  1.1509e+06|     -5877.2|  1.6369e+07|        18|      0.24|
    |   9.735e+05|  1.4838e+07|  9.7923e+05|     -5727.6|  1.4079e+07|        17|      0.24|
    |  8.7366e+05|  1.2752e+07|  8.7928e+05|     -5625.4|  1.2581e+07|        17|      0.24|
    |  8.0328e+05|  1.1112e+07|  8.0883e+05|     -5549.3|  1.1228e+07|        17|      0.24|
    |  7.8049e+05|  1.0893e+07|  7.8599e+05|     -5501.9|  1.1205e+07|        17|      0.26|
    |  7.7098e+05|  1.0617e+07|  7.7648e+05|     -5498.4|  1.0918e+07|        17|      0.25|
    |  7.6746e+05|  1.0503e+07|  7.7296e+05|       -5497|  1.0782e+07|        17|      0.28|
    |  7.6154e+05|  1.0323e+07|  7.6703e+05|       -5492|  1.0603e+07|        17|      0.25|
    |  7.5364e+05|  1.0183e+07|  7.5912e+05|     -5479.7|  1.0515e+07|        17|      0.25|
    |  7.4872e+05|  1.0065e+07|  7.5419e+05|     -5471.1|   1.047e+07|        17|      0.24|
    |  7.4729e+05|  1.0013e+07|  7.5276e+05|     -5469.1|  1.0422e+07|        17|      0.25|
    |  7.4597e+05|  9.9721e+06|  7.5143e+05|     -5467.8|  1.0406e+07|        16|      0.24|
    |  7.4535e+05|   9.987e+06|  7.5081e+05|     -5465.9|  1.0431e+07|        16|      0.24|
    |  7.4442e+05|  9.9833e+06|  7.4989e+05|     -5465.8|  1.0408e+07|        17|      0.25|
    |  7.4428e+05|  9.9827e+06|  7.4975e+05|     -5466.5|  1.0397e+07|        17|      0.24|
    |  7.4425e+05|  9.9819e+06|  7.4972e+05|     -5466.9|  1.0382e+07|        16|      0.24|
    |  7.4408e+05|   9.975e+06|  7.4955e+05|       -5467|  1.0385e+07|        16|      0.24|
    |  7.4382e+05|  9.9587e+06|  7.4928e+05|       -5467|  1.0402e+07|        17|      0.25|
    |  7.4399e+05|  9.9658e+06|  7.4946e+05|     -5466.8|   1.041e+07|        16|      0.24|
    |   7.442e+05|   9.971e+06|  7.4967e+05|       -5467|  1.0428e+07|        17|      0.26|
    |   7.442e+05|  9.9718e+06|  7.4967e+05|       -5467|  1.0405e+07|        17|      0.26|
    |   7.438e+05|  9.9587e+06|  7.4927e+05|       -5467|  1.0409e+07|        16|      0.26|
    |  7.4399e+05|   9.964e+06|  7.4946e+05|       -5467|  1.0401e+07|        17|      0.26|
    |  7.4412e+05|  9.9681e+06|  7.4959e+05|       -5467|  1.0399e+07|        16|      0.25|
    Optimization result:
          fun: 744121.6320021643
     hess_inv: <25x25 LbfgsInvHessProduct with dtype=float64>
          jac: array([ 9.96227102e+02,  2.00432837e+02,  2.60510180e+01, -5.48958596e+02,
            2.06815585e+04,  4.34825299e+02,  0.00000000e+00, -3.24741237e+02,
            1.95474293e+02,  1.10656164e+03,  0.00000000e+00,  1.22750805e+02,
            6.73673262e+01, -1.00813058e+03,  2.60017795e+04, -2.51396161e+01,
            2.21848468e+03, -5.02235333e+02,  4.39914545e+03,  6.69241667e+01,
            3.26864116e+02,  7.34901570e+01,  0.00000000e+00,  3.90059610e+02,
            3.90397116e+02])
      message: b'CONVERGENCE: REL_REDUCTION_OF_F_<=_FACTR*EPSMCH'
         nfev: 29
          nit: 23
       status: 0
      success: True
            x: array([-9.21034037, -4.60517019, -2.30258509,  1.45132733, -2.30258509,
           -4.60517019,  1.38836933, -3.41134142, -2.30258509,  2.29909486,
           -6.69419395, -4.08788863, -2.30258509,  1.6789475 , -2.30258509,
            1.54064497, -2.30258509,  2.21314656, -2.30258509, -0.35101412,
           -2.30258509, -4.06327129, -0.19078879, -0.09102722, -2.30258509])

    <graphdot.model.gaussian_process.gpr.GaussianProcessRegressor at 0x7fa8dbae75d0>

```
mu = gpr2.predict(train.graphs)
plt.scatter(train[target], mu)
#plt.plot(np.linspace(-9, 3), np.linspace(-9, 3), c = 'r')
#plt.xlim(-9, 3)
#plt.ylim(-9, 3)
plt.show()
```

```
print('Training set')
print('MAE:', np.mean(np.abs(train[target] - mu)))
print('RMSE:', np.std(train[target] - mu))
```

    Training set
    MAE: 0.01420440124959926
    RMSE: 0.021649804308151027

```
mu_test = gpr2.predict(test.graphs)
plt.scatter(test[target], mu_test)
plt.show()
```

```
print('Test set')
print('MAE:', np.mean(np.abs(test[target] - mu_test)))
print('RMSE:', np.std(test[target] - mu_test))
```

    Test set
    MAE: 1.517212238428167
    RMSE: 1.943288841802438

```

```


###  Performance improvement work sharing

- Data
- Demo
- API
- Time series data index
- Vectorized concept
- Laws & Disruptive move

```python
import pandas as pd
```

```python
all = pd.read_pickle(f"data/quote_df.pkl")
all
```

      $close
      $factor
      $change
      $volume
      limit_buy
      limit_sell

      instrument
      datetime

      SH600000
      2020-01-02 09:30:00
      159.046677
      12.713563
      NaN
      177660.500000
      False
      False

      2020-01-02 09:31:00
      158.792404
      12.713563
      NaN
      68880.687500
      False
      False

      2020-01-02 09:32:00
      159.046677
      12.713563
      NaN
      79577.617188
      False
      False

      2020-01-02 09:33:00
      159.809494
      12.713563
      NaN
      165822.281250
      False
      False

      2020-01-02 09:34:00
      159.428085
      12.713563
      NaN
      45314.441406
      False
      False

      ...
      ...
      ...
      ...
      ...
      ...
      ...
      ...

      SH600009
      2020-06-30 14:55:00
      219.139130
      3.040221
      NaN
      28780.802734
      False
      False

      2020-06-30 14:56:00
      219.139130
      3.040221
      NaN
      15558.079102
      False
      False

      2020-06-30 14:57:00
      219.139130
      3.040221
      NaN
      230.246414
      False
      False

      2020-06-30 14:58:00
      219.139130
      3.040221
      NaN
      0.000000
      False
      False

      2020-06-30 14:59:00
      219.108734
      3.040221
      NaN
      22465.472656
      False
      False

163500 rows × 6 columns

```python
volume = pd.read_pickle(f"data/volume_df.pkl")
volume
```

      datetime
      2020-01-02
      2020-01-03
      2020-01-06
      2020-01-07
      2020-01-08
      2020-01-09
      2020-01-10
      2020-01-13
      2020-01-14
      2020-01-15
      ...
      2020-06-15
      2020-06-16
      2020-06-17
      2020-06-18
      2020-06-19
      2020-06-22
      2020-06-23
      2020-06-24
      2020-06-29
      2020-06-30

      instrument

      SH600000
      2.261874e+06
      2.396091e+06
      2508010.25
      2514704.250
      2.446962e+06
      2.553695e+06
      2651805.000
      2672115.500
      2.615353e+06
      2.528383e+06
      ...
      1756381.125
      1731880.125
      1.667069e+06
      1578945.875
      1604882.875
      1753198.375
      1803229.625
      1821627.75
      1870240.375
      1891510.250

      SH600004
      3.928184e+06
      4.189268e+06
      4512067.00
      5012114.500
      5.196058e+06
      5.564821e+06
      5843007.000
      6681968.000
      7.288429e+06
      7.365033e+06
      ...
      6330651.000
      6216309.500
      5.872529e+06
      5767695.500
      5221974.000
      5086450.500
      5085257.500
      5237319.50
      5581185.500
      5673297.500

      SH600006
      3.677090e+06
      3.512993e+06
      3473326.75
      3209310.500
      3.290266e+06
      3.676561e+06
      3735112.500
      3675256.750
      3.791545e+06
      3.871834e+06
      ...
      6607741.500
      6620880.500
      6.562849e+06
      6070401.000
      5108298.500
      4345236.500
      3919222.000
      3732892.00
      3667949.250
      3350491.500

      SH600007
      7.471518e+05
      7.798411e+05
      798650.00
      852837.875
      9.240082e+05
      9.653506e+05
      947146.375
      937367.125
      9.143474e+05
      8.438519e+05
      ...
      1080689.000
      1032232.000
      9.300471e+05
      980329.000
      1049706.875
      1437618.125
      1737494.250
      1769172.75
      1774657.625
      1789137.625

      SH600008
      2.073627e+06
      2.103406e+06
      2189824.50
      2180529.250
      2.460642e+06
      2.583131e+06
      2648017.500
      2676629.250
      2.665881e+06
      2.987846e+06
      ...
      2529171.750
      2523233.250
      2.580083e+06
      2596339.250
      2327328.000
      2334081.250
      2259043.000
      2114092.25
      2183888.750
      2090832.000

      SH600009
      1.847804e+06
      2.140634e+06
      2256605.50
      2628696.250
      2.906225e+06
      3.077406e+06
      3336729.250
      3664973.000
      3.747686e+06
      4.049192e+06
      ...
      4232498.500
      4341015.500
      4.239846e+06
      4442293.000
      4316313.500
      4186823.750
      4079572.000
      4018620.50
      3944616.750
      4157829.250

6 rows × 117 columns

### Running time from 1518.555s to 0.007s ⌨

### Speed up QLib backtesting about 200k times 🖥

$$
\begin{equation}
\begin{aligned}
\begin{Bmatrix}
\mathrm{Q}_{\mathcal{s,\space \cdots,\space t}}
\\
\mathrm{V}_{\mathcal{s,\space d}}
\rightarrow\mathrm{V}_{\mathcal{s,\space t}}
\end{Bmatrix}
&\rightarrow\mathrm{I}_{\mathcal{s,\space \cdots,\space t}}
&:\space&\mathscr{F}_{\mathcal{map}}
\\
\frac{1}{n_{s}}\cdot \sum_{\mathcal{s}}\mathrm{I}_{\mathcal{s,\space \cdots,\space t}}
&=
\mathrm{I}_{\mathcal{\cdots,\space t}}
&:\space&\mathscr{F}_{\mathcal{reduce}}
\\
\frac{1}{n_{t\space\in\space d}}\cdot\sum_{\mathcal{t\space\in\space d}}\mathrm{I}_{\mathcal{\cdots,\space t}}
&=
\mathrm{I}_{\mathcal{\cdots,\space d}}
&:\space&\mathscr{F}_{\mathcal{reduce}}
\end{aligned}
\end{equation}
$$

```python
import numpy as np
from matplotlib import cm
import ipyvolume as ipv

k, b, e, s, l, m = (5, 0.1, 1.2, 0.2, 6, 9)
ss = [np.repeat(np.arange(b, e, s), l * m)]
[ss.append(ss[-1] - d) for d in [[(j - b)/k for j in ss[0]] for i in range(k)]]
ss = np.stack(ss)
c = np.tile(np.repeat(np.arange(b, e, s), m), l)
t = np.broadcast_to(np.arange(b, s * m, s), (l, l, m)).reshape(l * l * m)
fig1 = ipv.figure()
xnorm = ss[0] - ss[0].min()
xnorm /= xnorm.ptp()
scatter = ipv.scatter(ss, c, t, color= cm.gist_rainbow(xnorm), marker="sphere")
scatter.connected = True
ipv.xlim(b, e)
ipv.animation_control(scatter, interval=256)
```

```python
ipv.view(300, 50, distance=2)
ipv.show()
```

    VBox(children=(Figure(animation=256.0, camera=PerspectiveCamera(fov=46.0, position=(-1.1133407984528387, 1.532…

```python
import ipyvolume as ipv2
tt=[]
[tt.append(np.copy(t)) for i in range(3)]
tt[1][0::3] = (t[2::3] - t[0::3]) / 2 + t[0::3]
tt[1][1::3] = (t[2::3] - t[1::3]) / 2 + t[1::3]
tt[2][0::3] = t[2::3]
tt[2][1::3] = t[2::3]
tt = np.stack(tt)
s2 = ss[-1][0:54]
c2 = c[0:54]
t2 = tt[:,0:54]
fig2 = ipv2.figure()
znorm = t - t.min()
znorm /= znorm.ptp()
scatter2 = ipv2.scatter(s2, c2, t2, color=cm.gist_rainbow(znorm), marker="sphere")
scatter2.connected = True
ipv2.xlim(b, e)
ipv2.animation_control(scatter2, interval=300)
```

```python
ipv2.view(300, 50, distance=2)
ipv2.show()
```

    VBox(children=(Figure(animation=300.0, camera=PerspectiveCamera(fov=46.0, position=(-1.1133407984528387, 1.532…

### API  🧻

- #### Tsidx
- #### MustelasQuote

## Time series data index

- ### Continuous $\rightarrow$ Scatter
- ### How to do unit test 🖥
- ### How to independently build

## Vectorized concept 🖥

- ### Why vectorize ?
- ### NEP 38 🧻

##  Readability

- #### Message passing paradigm
  - ##### IPC and RPC and multithreading ...
- #### Generator and Coroutine ⌨
- #### All design patterns are instances talk each other⌨
- #### But a huge gap between 2 languages ⌨

## Nature Laws of performance

- ### Good one is not a feature, but bad one is a bug ⌨
- ### Time and space consistency 🧻
- ### Time and space symmetry 🖥


#InSilicoQ

```python
!git clone https://github.com/QaiAbdi/InSilicoQ.git
```

    Cloning into 'InSilicoQ'...
    remote: Enumerating objects: 58, done.
    remote: Counting objects: 100% (58/58), done.
    remote: Compressing objects: 100% (45/45), done.
    remote: Total 58 (delta 22), reused 29 (delta 6), pack-reused 0
    Unpacking objects: 100% (58/58), done.

```python
%cd /content/InSilicoQ
```

    /content/InSilicoQ

```python
!pip install -r requirments.txt
```

    Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from -r requirments.txt (line 1)) (1.19.5)
    Requirement already satisfied: pandas in /usr/local/lib/python3.7/dist-packages (from -r requirments.txt (line 2)) (1.3.5)
    Requirement already satisfied: qiskit in /usr/local/lib/python3.7/dist-packages (from -r requirments.txt (line 3)) (0.34.1)
    Requirement already satisfied: qiskit_machine_learning in /usr/local/lib/python3.7/dist-packages (from -r requirments.txt (line 4)) (0.3.0)
    Requirement already satisfied: rdkit-pypi in /usr/local/lib/python3.7/dist-packages (from -r requirments.txt (line 5)) (2021.9.4)
    Requirement already satisfied: chembl_webresource_client in /usr/local/lib/python3.7/dist-packages (from -r requirments.txt (line 6)) (0.10.7)
    Requirement already satisfied: pubchempy in /usr/local/lib/python3.7/dist-packages (from -r requirments.txt (line 7)) (1.0.4)
    Requirement already satisfied: sklearn in /usr/local/lib/python3.7/dist-packages (from -r requirments.txt (line 8)) (0.0)
    Requirement already satisfied: matplotlib in /usr/local/lib/python3.7/dist-packages (from -r requirments.txt (line 9)) (3.2.2)
    Requirement already satisfied: seaborn in /usr/local/lib/python3.7/dist-packages (from -r requirments.txt (line 10)) (0.11.2)
    Requirement already satisfied: pytz>=2017.3 in /usr/local/lib/python3.7/dist-packages (from pandas->-r requirments.txt (line 2)) (2018.9)
    Requirement already satisfied: python-dateutil>=2.7.3 in /usr/local/lib/python3.7/dist-packages (from pandas->-r requirments.txt (line 2)) (2.8.2)
    Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.7/dist-packages (from python-dateutil>=2.7.3->pandas->-r requirments.txt (line 2)) (1.15.0)
    Requirement already satisfied: qiskit-ibmq-provider==0.18.3 in /usr/local/lib/python3.7/dist-packages (from qiskit->-r requirments.txt (line 3)) (0.18.3)
    Requirement already satisfied: qiskit-aer==0.10.2 in /usr/local/lib/python3.7/dist-packages (from qiskit->-r requirments.txt (line 3)) (0.10.2)
    Requirement already satisfied: qiskit-ignis==0.7.0 in /usr/local/lib/python3.7/dist-packages (from qiskit->-r requirments.txt (line 3)) (0.7.0)
    Requirement already satisfied: qiskit-terra==0.19.1 in /usr/local/lib/python3.7/dist-packages (from qiskit->-r requirments.txt (line 3)) (0.19.1)
    Requirement already satisfied: scipy>=1.0 in /usr/local/lib/python3.7/dist-packages (from qiskit-aer==0.10.2->qiskit->-r requirments.txt (line 3)) (1.7.3)
    Requirement already satisfied: requests-ntlm>=1.1.0 in /usr/local/lib/python3.7/dist-packages (from qiskit-ibmq-provider==0.18.3->qiskit->-r requirments.txt (line 3)) (1.1.0)
    Requirement already satisfied: urllib3>=1.21.1 in /usr/local/lib/python3.7/dist-packages (from qiskit-ibmq-provider==0.18.3->qiskit->-r requirments.txt (line 3)) (1.24.3)
    Requirement already satisfied: requests>=2.19 in /usr/local/lib/python3.7/dist-packages (from qiskit-ibmq-provider==0.18.3->qiskit->-r requirments.txt (line 3)) (2.23.0)
    Requirement already satisfied: websocket-client>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from qiskit-ibmq-provider==0.18.3->qiskit->-r requirments.txt (line 3)) (1.2.3)
    Requirement already satisfied: setuptools>=40.1.0 in /usr/local/lib/python3.7/dist-packages (from qiskit-ignis==0.7.0->qiskit->-r requirments.txt (line 3)) (57.4.0)
    Requirement already satisfied: retworkx>=0.8.0 in /usr/local/lib/python3.7/dist-packages (from qiskit-ignis==0.7.0->qiskit->-r requirments.txt (line 3)) (0.11.0)
    Requirement already satisfied: sympy>=1.3 in /usr/local/lib/python3.7/dist-packages (from qiskit-terra==0.19.1->qiskit->-r requirments.txt (line 3)) (1.7.1)
    Requirement already satisfied: stevedore>=3.0.0 in /usr/local/lib/python3.7/dist-packages (from qiskit-terra==0.19.1->qiskit->-r requirments.txt (line 3)) (3.5.0)
    Requirement already satisfied: ply>=3.10 in /usr/local/lib/python3.7/dist-packages (from qiskit-terra==0.19.1->qiskit->-r requirments.txt (line 3)) (3.11)
    Requirement already satisfied: python-constraint>=1.4 in /usr/local/lib/python3.7/dist-packages (from qiskit-terra==0.19.1->qiskit->-r requirments.txt (line 3)) (1.4.0)
    Requirement already satisfied: psutil>=5 in /usr/local/lib/python3.7/dist-packages (from qiskit-terra==0.19.1->qiskit->-r requirments.txt (line 3)) (5.4.8)
    Requirement already satisfied: dill>=0.3 in /usr/local/lib/python3.7/dist-packages (from qiskit-terra==0.19.1->qiskit->-r requirments.txt (line 3)) (0.3.4)
    Requirement already satisfied: tweedledum<2.0,>=1.1 in /usr/local/lib/python3.7/dist-packages (from qiskit-terra==0.19.1->qiskit->-r requirments.txt (line 3)) (1.1.1)
    Requirement already satisfied: symengine>=0.8 in /usr/local/lib/python3.7/dist-packages (from qiskit-terra==0.19.1->qiskit->-r requirments.txt (line 3)) (0.8.1)
    Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests>=2.19->qiskit-ibmq-provider==0.18.3->qiskit->-r requirments.txt (line 3)) (2021.10.8)
    Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests>=2.19->qiskit-ibmq-provider==0.18.3->qiskit->-r requirments.txt (line 3)) (2.10)
    Requirement already satisfied: chardet<4,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests>=2.19->qiskit-ibmq-provider==0.18.3->qiskit->-r requirments.txt (line 3)) (3.0.4)
    Requirement already satisfied: ntlm-auth>=1.0.2 in /usr/local/lib/python3.7/dist-packages (from requests-ntlm>=1.1.0->qiskit-ibmq-provider==0.18.3->qiskit->-r requirments.txt (line 3)) (1.5.0)
    Requirement already satisfied: cryptography>=1.3 in /usr/local/lib/python3.7/dist-packages (from requests-ntlm>=1.1.0->qiskit-ibmq-provider==0.18.3->qiskit->-r requirments.txt (line 3)) (36.0.1)
    Requirement already satisfied: cffi>=1.12 in /usr/local/lib/python3.7/dist-packages (from cryptography>=1.3->requests-ntlm>=1.1.0->qiskit-ibmq-provider==0.18.3->qiskit->-r requirments.txt (line 3)) (1.15.0)
    Requirement already satisfied: pycparser in /usr/local/lib/python3.7/dist-packages (from cffi>=1.12->cryptography>=1.3->requests-ntlm>=1.1.0->qiskit-ibmq-provider==0.18.3->qiskit->-r requirments.txt (line 3)) (2.21)
    Requirement already satisfied: importlib-metadata>=1.7.0 in /usr/local/lib/python3.7/dist-packages (from stevedore>=3.0.0->qiskit-terra==0.19.1->qiskit->-r requirments.txt (line 3)) (4.10.1)
    Requirement already satisfied: pbr!=2.1.0,>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from stevedore>=3.0.0->qiskit-terra==0.19.1->qiskit->-r requirments.txt (line 3)) (5.8.1)
    Requirement already satisfied: typing-extensions>=3.6.4 in /usr/local/lib/python3.7/dist-packages (from importlib-metadata>=1.7.0->stevedore>=3.0.0->qiskit-terra==0.19.1->qiskit->-r requirments.txt (line 3)) (3.10.0.2)
    Requirement already satisfied: zipp>=0.5 in /usr/local/lib/python3.7/dist-packages (from importlib-metadata>=1.7.0->stevedore>=3.0.0->qiskit-terra==0.19.1->qiskit->-r requirments.txt (line 3)) (3.7.0)
    Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.7/dist-packages (from sympy>=1.3->qiskit-terra==0.19.1->qiskit->-r requirments.txt (line 3)) (1.2.1)
    Requirement already satisfied: scikit-learn>=0.20.0 in /usr/local/lib/python3.7/dist-packages (from qiskit_machine_learning->-r requirments.txt (line 4)) (1.0.2)
    Requirement already satisfied: fastdtw in /usr/local/lib/python3.7/dist-packages (from qiskit_machine_learning->-r requirments.txt (line 4)) (0.3.4)
    Requirement already satisfied: joblib>=0.11 in /usr/local/lib/python3.7/dist-packages (from scikit-learn>=0.20.0->qiskit_machine_learning->-r requirments.txt (line 4)) (1.1.0)
    Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from scikit-learn>=0.20.0->qiskit_machine_learning->-r requirments.txt (line 4)) (3.1.0)
    Requirement already satisfied: Pillow in /usr/local/lib/python3.7/dist-packages (from rdkit-pypi->-r requirments.txt (line 5)) (7.1.2)
    Requirement already satisfied: requests-cache~=0.7.0 in /usr/local/lib/python3.7/dist-packages (from chembl_webresource_client->-r requirments.txt (line 6)) (0.7.5)
    Requirement already satisfied: easydict in /usr/local/lib/python3.7/dist-packages (from chembl_webresource_client->-r requirments.txt (line 6)) (1.9)
    Requirement already satisfied: url-normalize<2.0,>=1.4 in /usr/local/lib/python3.7/dist-packages (from requests-cache~=0.7.0->chembl_webresource_client->-r requirments.txt (line 6)) (1.4.3)
    Requirement already satisfied: pyyaml>=5.4 in /usr/local/lib/python3.7/dist-packages (from requests-cache~=0.7.0->chembl_webresource_client->-r requirments.txt (line 6)) (6.0)
    Requirement already satisfied: attrs<22.0,>=21.2 in /usr/local/lib/python3.7/dist-packages (from requests-cache~=0.7.0->chembl_webresource_client->-r requirments.txt (line 6)) (21.4.0)
    Requirement already satisfied: itsdangerous>=2.0.1 in /usr/local/lib/python3.7/dist-packages (from requests-cache~=0.7.0->chembl_webresource_client->-r requirments.txt (line 6)) (2.0.1)
    Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.7/dist-packages (from matplotlib->-r requirments.txt (line 9)) (0.11.0)
    Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->-r requirments.txt (line 9)) (1.3.2)
    Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.1 in /usr/local/lib/python3.7/dist-packages (from matplotlib->-r requirments.txt (line 9)) (3.0.7)

```python
!python setup.py install
```

    running install
    running bdist_egg
    running egg_info
    creating Insilicoq.egg-info
    writing Insilicoq.egg-info/PKG-INFO
    writing dependency_links to Insilicoq.egg-info/dependency_links.txt
    writing top-level names to Insilicoq.egg-info/top_level.txt
    writing manifest file 'Insilicoq.egg-info/SOURCES.txt'
    adding license file 'LICENSE'
    writing manifest file 'Insilicoq.egg-info/SOURCES.txt'
    installing library code to build/bdist.linux-x86_64/egg
    running install_lib
    running build_py
    creating build
    creating build/lib
    creating build/lib/Insilicoq
    copying Insilicoq/quantum_kernel.py -> build/lib/Insilicoq
    copying Insilicoq/__init__.py -> build/lib/Insilicoq
    creating build/bdist.linux-x86_64
    creating build/bdist.linux-x86_64/egg
    creating build/bdist.linux-x86_64/egg/Insilicoq
    copying build/lib/Insilicoq/quantum_kernel.py -> build/bdist.linux-x86_64/egg/Insilicoq
    copying build/lib/Insilicoq/__init__.py -> build/bdist.linux-x86_64/egg/Insilicoq
    byte-compiling build/bdist.linux-x86_64/egg/Insilicoq/quantum_kernel.py to quantum_kernel.cpython-37.pyc
    byte-compiling build/bdist.linux-x86_64/egg/Insilicoq/__init__.py to __init__.cpython-37.pyc
    creating build/bdist.linux-x86_64/egg/EGG-INFO
    copying Insilicoq.egg-info/PKG-INFO -> build/bdist.linux-x86_64/egg/EGG-INFO
    copying Insilicoq.egg-info/SOURCES.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
    copying Insilicoq.egg-info/dependency_links.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
    copying Insilicoq.egg-info/not-zip-safe -> build/bdist.linux-x86_64/egg/EGG-INFO
    copying Insilicoq.egg-info/top_level.txt -> build/bdist.linux-x86_64/egg/EGG-INFO
    creating dist
    creating 'dist/Insilicoq-0.1-py3.7.egg' and adding 'build/bdist.linux-x86_64/egg' to it
    removing 'build/bdist.linux-x86_64/egg' (and everything under it)
    Processing Insilicoq-0.1-py3.7.egg
    creating /usr/local/lib/python3.7/dist-packages/Insilicoq-0.1-py3.7.egg
    Extracting Insilicoq-0.1-py3.7.egg to /usr/local/lib/python3.7/dist-packages
    Adding Insilicoq 0.1 to easy-install.pth file

    Installed /usr/local/lib/python3.7/dist-packages/Insilicoq-0.1-py3.7.egg
    Processing dependencies for Insilicoq==0.1
    Finished processing dependencies for Insilicoq==0.1

#Succesful Import!

```python
import Insilicoq
help(Insilicoq)
```

    Help on package Insilicoq:

    NAME
        Insilicoq

    PACKAGE CONTENTS
        quantum_kernel

    FILE
        /content/InSilicoQ/Insilicoq/__init__.py

```python
from Insilicoq import qkern_default
```

Testing RDKit

```python
from rdkit import Chem
from rdkit.Chem import Draw
from rdkit.Chem.Draw import IPythonConsole
from rdkit.Chem import Descriptors
from rdkit.Chem import AllChem
from rdkit import DataStructs
import numpy as np
```

```python
mol = Chem.MolFromSmiles('C1CCC1')
mol
```

```python

```


```python
!pip install coremltools
```

    Collecting coremltools
      Downloading coremltools-5.1.0-cp37-none-manylinux1_x86_64.whl (1.6 MB)
         |████████████████████████████████| 1.6 MB 12.7 MB/s
    Requirement already satisfied: sympy in /usr/local/lib/python3.7/dist-packages (from coremltools) (1.7.1)
    Requirement already satisfied: protobuf>=3.1.0 in /usr/local/lib/python3.7/dist-packages (from coremltools) (3.17.3)
    Requirement already satisfied: tqdm in /usr/local/lib/python3.7/dist-packages (from coremltools) (4.62.3)
    Requirement already satisfied: numpy>=1.14.5 in /usr/local/lib/python3.7/dist-packages (from coremltools) (1.19.5)
    Requirement already satisfied: packaging in /usr/local/lib/python3.7/dist-packages (from coremltools) (21.2)
    Requirement already satisfied: six>=1.9 in /usr/local/lib/python3.7/dist-packages (from protobuf>=3.1.0->coremltools) (1.15.0)
    Requirement already satisfied: pyparsing<3,>=2.0.2 in /usr/local/lib/python3.7/dist-packages (from packaging->coremltools) (2.4.7)
    Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.7/dist-packages (from sympy->coremltools) (1.2.1)
    Installing collected packages: coremltools
    Successfully installed coremltools-5.1.0

```python
import os
import torch
import coremltools
```

    WARNING:root:scikit-learn version 1.0.1 is not supported. Minimum required version: 0.17. Maximum required version: 0.19.2. Disabling scikit-learn conversion API.
    WARNING:root:TensorFlow version 2.7.0 has not been tested with coremltools. You may run into unexpected errors. TensorFlow 2.5.0 is the most recent version that has been tested.
    WARNING:root:Keras version 2.7.0 has not been tested with coremltools. You may run into unexpected errors. Keras 2.2.4 is the most recent version that has been tested.
    WARNING:root:Torch version 1.10.0+cu111 has not been tested with coremltools. You may run into unexpected errors. Torch 1.9.1 is the most recent version that has been tested.

```python
!git clone https://github.com/jacopomangiavacchi/animegan2-coreml
```

    Cloning into 'animegan2-coreml'...
    remote: Enumerating objects: 85, done.
    remote: Counting objects: 100% (85/85), done.
    remote: Compressing objects: 100% (78/78), done.
    remote: Total 85 (delta 35), reused 36 (delta 6), pack-reused 0
    Unpacking objects: 100% (85/85), done.

```python
os.chdir(f'./animegan2-coreml')
```

```python
from model import Generator

device = 'cpu'
torch.set_grad_enabled(False)

model = Generator().eval().to(device)
```

```python
ckpt = torch.load(f"weights/celeba_distill.pt", map_location=device)
# ckpt = torch.load(f"weights/face_paint_512_v2.pt", map_location=device)
# ckpt = torch.load(f"weights/paprika.pt", map_location=device)
model.load_state_dict(ckpt)
```

    <All keys matched successfully>

```python
image_sizes = [256, 512, 1024]

for image_size in image_sizes:
    image = torch.randn(1, 3, image_size, image_size)
    output = model(image.to(device))

    # scripted_model = torch.jit.script(model)
    traced = torch.jit.trace(model, image)

    image_input = coremltools.ImageType(name="input_1", shape=(1, 3, image_size, image_size))

    mlmodel = coremltools.converters.convert(
      traced,
      inputs=[image_input],
      minimum_deployment_target=coremltools.target.iOS15,
      compute_units=coremltools.ComputeUnit.ALL,
      convert_to="mlprogram", # "neuralnetwork"
      compute_precision=coremltools.precision.FLOAT16
    )

    mlmodel.save(f'animegan2-celeba-distil-{image_size}.mlpackage')
    spec = coremltools.utils.load_spec(f"animegan2-celeba-distil-{image_size}.mlpackage")

    output = spec.description.output[0]

    output.type.imageType.colorSpace = coremltools.proto.FeatureTypes_pb2.ImageFeatureType.RGB
    output.type.imageType.height = image_size
    output.type.imageType.width = image_size

    coremltools.utils.save_spec(spec, f"animegan2-celeba-distil-{image_size}.mlpackage")
```

    /usr/local/lib/python3.7/dist-packages/torch/nn/functional.py:2359: UserWarning: __floordiv__ is deprecated, and its behavior will change in a future version of pytorch. It currently rounds toward 0 (like the 'trunc' function NOT 'floor'). This results in incorrect rounding for negative values. To keep the current behavior, use torch.div(a, b, rounding_mode='trunc'), or for actual floor division, use torch.div(a, b, rounding_mode='floor').
      _verify_batch_size([input.size(0) * input.size(1) // num_groups, num_groups] + list(input.size()[2:]))
    Converting Frontend ==> MIL Ops: 100%|█████████▉| 295/296 [00:00<00:00, 548.62 ops/s]
    Running MIL Common passes:   0%|          | 0/34 [00:00<?, ? passes/s]/usr/local/lib/python3.7/dist-packages/coremltools/converters/mil/mil/passes/name_sanitization_utils.py:129: UserWarning: Output, '457', of the source model, has been renamed to 'var_457' in the Core ML model.
      warnings.warn(msg.format(var.name, new_name))
    Running MIL Common passes: 100%|██████████| 34/34 [00:00<00:00, 63.95 passes/s]
    Running MIL FP16ComputePrecision pass: 100%|██████████| 1/1 [00:02<00:00,  2.63s/ passes]
    Running MIL Clean up passes: 100%|██████████| 9/9 [00:06<00:00,  1.46 passes/s]
    Converting Frontend ==> MIL Ops: 100%|█████████▉| 295/296 [00:00<00:00, 538.89 ops/s]
    Running MIL Common passes: 100%|██████████| 34/34 [00:00<00:00, 65.50 passes/s]
    Running MIL FP16ComputePrecision pass: 100%|██████████| 1/1 [00:02<00:00,  2.67s/ passes]
    Running MIL Clean up passes: 100%|██████████| 9/9 [00:06<00:00,  1.49 passes/s]
    Converting Frontend ==> MIL Ops: 100%|█████████▉| 295/296 [00:00<00:00, 526.11 ops/s]
    Running MIL Common passes: 100%|██████████| 34/34 [00:00<00:00, 64.26 passes/s]
    Running MIL FP16ComputePrecision pass: 100%|██████████| 1/1 [00:02<00:00,  2.59s/ passes]
    Running MIL Clean up passes: 100%|██████████| 9/9 [00:06<00:00,  1.47 passes/s]

```python
!zip -r /content/animegan2-coreml/animegan2-celeba-distil-1024.zip /content/animegan2-coreml/animegan2-celeba-distil-1024.mlpackage
!zip -r /content/animegan2-coreml/animegan2-celeba-distil-512.zip /content/animegan2-coreml/animegan2-celeba-distil-512.mlpackage
!zip -r /content/animegan2-coreml/animegan2-celeba-distil-256.zip /content/animegan2-coreml/animegan2-celeba-distil-256.mlpackage
```

      adding: content/animegan2-coreml/animegan2-celeba-distil-1024.mlpackage/ (stored 0%)
      adding: content/animegan2-coreml/animegan2-celeba-distil-1024.mlpackage/Manifest.json (deflated 60%)
      adding: content/animegan2-coreml/animegan2-celeba-distil-1024.mlpackage/Data/ (stored 0%)
      adding: content/animegan2-coreml/animegan2-celeba-distil-1024.mlpackage/Data/com.apple.CoreML/ (stored 0%)
      adding: content/animegan2-coreml/animegan2-celeba-distil-1024.mlpackage/Data/com.apple.CoreML/animegan2-celeba-distil-1024.mlmodel (deflated 88%)
      adding: content/animegan2-coreml/animegan2-celeba-distil-1024.mlpackage/Data/com.apple.CoreML/weights/ (stored 0%)
      adding: content/animegan2-coreml/animegan2-celeba-distil-1024.mlpackage/Data/com.apple.CoreML/weights/weight.bin (deflated 8%)
      adding: content/animegan2-coreml/animegan2-celeba-distil-512.mlpackage/ (stored 0%)
      adding: content/animegan2-coreml/animegan2-celeba-distil-512.mlpackage/Manifest.json (deflated 60%)
      adding: content/animegan2-coreml/animegan2-celeba-distil-512.mlpackage/Data/ (stored 0%)
      adding: content/animegan2-coreml/animegan2-celeba-distil-512.mlpackage/Data/com.apple.CoreML/ (stored 0%)
      adding: content/animegan2-coreml/animegan2-celeba-distil-512.mlpackage/Data/com.apple.CoreML/animegan2-celeba-distil-512.mlmodel (deflated 88%)
      adding: content/animegan2-coreml/animegan2-celeba-distil-512.mlpackage/Data/com.apple.CoreML/weights/ (stored 0%)
      adding: content/animegan2-coreml/animegan2-celeba-distil-512.mlpackage/Data/com.apple.CoreML/weights/weight.bin (deflated 8%)
      adding: content/animegan2-coreml/animegan2-celeba-distil-256.mlpackage/ (stored 0%)
      adding: content/animegan2-coreml/animegan2-celeba-distil-256.mlpackage/Manifest.json (deflated 59%)
      adding: content/animegan2-coreml/animegan2-celeba-distil-256.mlpackage/Data/ (stored 0%)
      adding: content/animegan2-coreml/animegan2-celeba-distil-256.mlpackage/Data/com.apple.CoreML/ (stored 0%)
      adding: content/animegan2-coreml/animegan2-celeba-distil-256.mlpackage/Data/com.apple.CoreML/animegan2-celeba-distil-256.mlmodel (deflated 88%)
      adding: content/animegan2-coreml/animegan2-celeba-distil-256.mlpackage/Data/com.apple.CoreML/weights/ (stored 0%)
      adding: content/animegan2-coreml/animegan2-celeba-distil-256.mlpackage/Data/com.apple.CoreML/weights/weight.bin (deflated 8%)

```python
os.chdir(f'..')
```