In [1]:
# Importing
import theano.tensor as T
import sys, os
sys.path.append("/home/bl3/PycharmProjects/GeMpy/GeMpy")
sys.path.append("/home/bl3/PycharmProjects/pygeomod/pygeomod")
sys.path.append("/home/miguel/PycharmProjects/GeMpy/GeMpy")
import GeoMig

import importlib
importlib.reload(GeoMig)
import numpy as np
import pandas as pn
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

os.environ['CUDA_LAUNCH_BLOCKING'] = '1'
np.set_printoptions(precision = 6, linewidth= 130, suppress =  True)

#%matplotlib inline
%matplotlib notebook

Sandstone Model

First we make a GeMpy instance with most of the parameters default (except range that is given by the project). Then we also fix the extension and the resolution of the domain we want to interpolate. Finally we compile the function, only needed once every time we open the project (the guys of theano they are working on letting loading compiled files, even though in our case it is not a big deal).

General note. So far the reescaling factor is calculated for all series at the same time. GeoModeller does it individually for every potential field. I have to look better what this parameter exactly means


In [2]:
T.jacobian?

In [3]:
# Setting extend, grid and compile
# Setting the extent
sandstone = GeoMig.Interpolator(696000,747000,6863000,6950000,-20000, 2000,
                                range_var = np.float32(110000),
                               u_grade = 9) # Range used in geomodeller

# Setting resolution of the grid
sandstone.set_resolutions(40,40,150)
sandstone.create_regular_grid_3D()

# Compiling
sandstone.theano_compilation_3D()


/home/bl3/anaconda3/lib/python3.5/site-packages/ipykernel/__main__.py:12: DeprecationWarning: stack(*tensors) interface is deprecated, use stack(tensors, axis=0) instead.
/home/bl3/anaconda3/lib/python3.5/site-packages/ipykernel/__main__.py:12: DeprecationWarning: stack(*tensors) interface is deprecated, use stack(tensors, axis=0) instead.
/home/bl3/anaconda3/lib/python3.5/site-packages/ipykernel/__main__.py:12: DeprecationWarning: stack(*tensors) interface is deprecated, use stack(tensors, axis=0) instead.
/home/bl3/anaconda3/lib/python3.5/site-packages/ipykernel/__main__.py:12: DeprecationWarning: stack(*tensors) interface is deprecated, use stack(tensors, axis=0) instead.
/home/bl3/anaconda3/lib/python3.5/site-packages/ipykernel/__main__.py:12: DeprecationWarning: stack(*tensors) interface is deprecated, use stack(tensors, axis=0) instead.

Loading data from geomodeller

So there are 3 series, 2 of one single layer and 1 with 2. Therefore we need 3 potential fields, so lets begin.


In [4]:
sandstone.load_data_csv("foliations", os.pardir+"/input_data/a_Foliations.csv")
sandstone.load_data_csv("interfaces", os.pardir+"/input_data/a_Points.csv")
pn.set_option('display.max_rows', 25)
sandstone.Foliations


Out[4]:
X Y Z azimuth dip polarity formation
0 739426.627684 6.891935e+06 75.422691 220.000000 70.000 1 SimpleBIF
1 717311.112372 6.891941e+06 -1497.488309 90.000000 60.000 1 SimpleBIF
2 723415.321182 6.891939e+06 -5298.154309 10.000000 20.000 1 SimpleMafic1
3 742907.686575 6.891935e+06 -2786.869309 250.000000 60.000 1 SimpleMafic1
4 712584.536312 6.891942e+06 -582.769334 90.014000 60.000 1 SimpleMafic1
5 724309.279198 6.905712e+06 -3763.862995 90.000000 50.000 1 SimpleMafic1
6 728653.933257 6.905715e+06 -4196.807995 269.962000 9.090 1 SimpleMafic1
7 732788.182361 6.905718e+06 -1680.306995 269.962000 60.000 1 SimpleMafic1
8 727261.874621 6.877214e+06 -5666.992176 360.000000 20.000 1 SimpleMafic1
9 718902.531298 6.900479e+06 -1882.895297 83.123000 20.726 1 SimpleMafic1
10 733335.732778 6.903151e+06 -1538.629297 255.407000 51.633 1 SimpleMafic1
11 730820.452963 6.902599e+06 -3825.776297 258.709000 21.801 1 SimpleMafic1
... ... ... ... ... ... ... ...
29 722403.813000 6.880913e+06 470.707065 123.702047 80.000 1 EarlyGranite
30 721229.000500 6.880766e+06 477.680894 255.876557 80.000 1 EarlyGranite
31 720690.563000 6.882822e+06 489.909423 254.444427 80.000 1 EarlyGranite
32 718928.344000 6.883606e+06 509.462245 176.274084 80.000 1 EarlyGranite
33 715991.281500 6.882773e+06 505.165864 152.654159 80.000 1 EarlyGranite
34 712907.375500 6.880766e+06 512.582136 142.596411 80.000 1 EarlyGranite
35 710459.844000 6.880522e+06 511.839758 232.658556 80.000 1 EarlyGranite
36 709970.344000 6.882724e+06 532.967915 283.997896 80.000 1 EarlyGranite
37 709089.250500 6.883312e+06 519.457428 153.495937 80.000 1 EarlyGranite
38 705858.500500 6.880032e+06 494.307044 127.403250 80.000 1 EarlyGranite
39 701844.531500 6.875137e+06 476.658525 131.656118 80.000 1 EarlyGranite
40 698466.937500 6.871074e+06 463.972201 127.377257 80.000 1 EarlyGranite

41 rows × 7 columns

Defining Series


In [5]:
sandstone.set_series({"EarlyGranite_Series":sandstone.formations[-1], 
                      "BIF_Series":(sandstone.formations[0], sandstone.formations[1]),
                      "SimpleMafic_Series":sandstone.formations[2]})
sandstone.series


Out[5]:
BIF_Series EarlyGranite_Series SimpleMafic_Series
0 SimpleMafic2 EarlyGranite SimpleMafic1
1 SimpleBIF EarlyGranite SimpleMafic1

In [7]:
sys.version_info


Out[7]:
sys.version_info(major=3, minor=5, micro=2, releaselevel='final', serial=0)

Early granite


In [8]:
sandstone.compute_potential_field("EarlyGranite_Series", verbose = 1)
sandstone.plot_potential_field_2D(direction = "y", cell_pos = 13, figsize=(7,6), contour_lines = 20)


The serie formations are EarlyGranite

In [9]:
sandstone.potential_interfaces;

In [6]:
%matplotlib qt4
block = np.ones_like(sandstone.Z_x)
block[sandstone.Z_x>sandstone.potential_interfaces[0]] = 0
block[sandstone.Z_x<sandstone.potential_interfaces[-1]] = 1
block = block.reshape(40,40,150)
#block = np.swapaxes(block, 0, 1)
plt.imshow(block[:,8,:].T, origin = "bottom", aspect = "equal", extent = (sandstone.xmin, sandstone.xmax,
                                                                           sandstone.zmin, sandstone.zmax),
           interpolation = "none")


Warning: Cannot change to a different GUI toolkit: qt4. Using notebook instead.
Out[6]:
<matplotlib.image.AxesImage at 0x7f32066bac88>

BIF Series


In [7]:
sandstone.compute_potential_field("BIF_Series", verbose=1)
sandstone.plot_potential_field_2D(direction = "y", cell_pos = 12, figsize=(7,6), contour_lines = 100)


The serie formations are SimpleMafic2|SimpleBIF

In [178]:
sandstone.potential_interfaces, sandstone.layers[0].shape;

In [8]:
%matplotlib qt4
block = np.ones_like(sandstone.Z_x)
block[sandstone.Z_x>sandstone.potential_interfaces[0]] = 0
block[(sandstone.Z_x<sandstone.potential_interfaces[0]) * (sandstone.Z_x>sandstone.potential_interfaces[-1])] = 1
block[sandstone.Z_x<sandstone.potential_interfaces[-1]] = 2
block = block.reshape(40,40,150)
plt.imshow(block[:,13,:].T, origin = "bottom", aspect = "equal", extent = (sandstone.xmin, sandstone.xmax,
                                                                           sandstone.zmin, sandstone.zmax),
          interpolation = "none")


Warning: Cannot change to a different GUI toolkit: qt4. Using notebook instead.
Out[8]:
<matplotlib.image.AxesImage at 0x7f32064d30b8>

SImple mafic


In [9]:
sandstone.compute_potential_field("SimpleMafic_Series", verbose = 1)
sandstone.plot_potential_field_2D(direction = "y", cell_pos = 15, figsize=(7,6), contour_lines = 20)


The serie formations are SimpleMafic1

In [182]:
sandstone.potential_interfaces, sandstone.layers[0].shape;

In [10]:
%matplotlib qt4
block = np.ones_like(sandstone.Z_x)
block[sandstone.Z_x>sandstone.potential_interfaces[0]] = 0
block[sandstone.Z_x<sandstone.potential_interfaces[-1]] = 1
block = block.reshape(40,40,150)
#block = np.swapaxes(block, 0, 1)
plt.imshow(block[:,13,:].T, origin = "bottom", aspect = "equal", extent = (sandstone.xmin, sandstone.xmax,
                                                                           sandstone.zmin, sandstone.zmax))


Warning: Cannot change to a different GUI toolkit: qt4. Using notebook instead.
Out[10]:
<matplotlib.image.AxesImage at 0x7f3206321080>

Optimizing the export of lithologies

Here I am going to try to return from the theano interpolate function the internal type of the result (in this case DK I guess) so I can make another function in python I guess to decide which potential field I calculate at every grid_pos


In [18]:
# Reset the block
sandstone.block.set_value(np.zeros_like(sandstone.grid[:,0]))

# Compute the block
sandstone.compute_block_model([0,1,2], verbose = 1)


4
[1 1 1 ..., 1 1 1] 0
The serie formations are EarlyGranite
3
[1 1 1 ..., 1 1 1] 21576
The serie formations are SimpleMafic1
[1 2]
[1 1 1 ..., 1 1 1] 33781
The serie formations are SimpleMafic2|SimpleBIF

In [19]:
%matplotlib qt4

plot_block =  sandstone.block.get_value().reshape(40,40,150)
plt.imshow(plot_block[:,13,:].T, origin = "bottom", aspect = "equal",
           extent = (sandstone.xmin, sandstone.xmax, sandstone.zmin, sandstone.zmax), interpolation = "none")


Warning: Cannot change to a different GUI toolkit: qt4. Using notebook instead.
Out[19]:
<matplotlib.image.AxesImage at 0x7ff6b7bb6320>

Export vtk


In [14]:
"""Export model to VTK

Export the geology blocks to VTK for visualisation of the entire 3-D model in an
external VTK viewer, e.g. Paraview.

..Note:: Requires pyevtk, available for free on: https://github.com/firedrakeproject/firedrake/tree/master/python/evtk

**Optional keywords**:
    - *vtk_filename* = string : filename of VTK file (default: output_name)
    - *data* = np.array : data array to export to VKT (default: entire block model)
"""
vtk_filename = "noddyFunct2"

extent_x = 10
extent_y = 10
extent_z = 10

delx = 0.2
dely = 0.2
delz = 0.2
from pyevtk.hl import gridToVTK
# Coordinates
x = np.arange(0, extent_x + 0.1*delx, delx, dtype='float64')
y = np.arange(0, extent_y + 0.1*dely, dely, dtype='float64')
z = np.arange(0, extent_z + 0.1*delz, delz, dtype='float64')

# self.block = np.swapaxes(self.block, 0, 2)
gridToVTK(vtk_filename, x, y, z, cellData = {"geology" : sol})


---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-14-8308869b7d0c> in <module>()
     19 dely = 0.2
     20 delz = 0.2
---> 21 from pyevtk.hl import gridToVTK
     22 # Coordinates
     23 x = np.arange(0, extent_x + 0.1*delx, delx, dtype='float64')

ImportError: No module named 'pyevtk'

Performance Analysis

CPU


In [32]:
%%timeit
sol =  interpolator.geoMigueller(dips,dips_angles,azimuths,polarity, rest, ref)[0]


10 loops, best of 3: 46.8 ms per loop

In [172]:
sandstone.block_export.profile.summary()


Function profiling
==================
  Message: /home/bl3/PycharmProjects/GeMpy/GeMpy/GeoMig.py:778
  Time in 12 calls to Function.__call__: 1.747251e+01s
  Time in Function.fn.__call__: 1.746418e+01s (99.952%)
  Time in thunks: 1.695012e+01s (97.010%)
  Total compile time: 8.084836e+00s
    Number of Apply nodes: 358
    Theano Optimizer time: 7.368957e+00s
       Theano validate time: 3.972366e-01s
    Theano Linker time (includes C, CUDA code generation/compiling): 4.228358e-01s
       Import time 0.000000e+00s

Time in all call to theano.grad() 0.000000e+00s
Time since theano import 4116.375s
Class
---
<% time> <sum %> <apply time> <time per call> <type> <#call> <#apply> <Class name>
  51.6%    51.6%       8.746s       6.57e-03s     C     1332     111   theano.tensor.elemwise.Elemwise
  21.5%    73.1%       3.647s       2.76e-02s     C      132      11   theano.tensor.basic.Alloc
   9.1%    82.2%       1.545s       4.29e-02s     Py      36       3   theano.tensor.basic.Nonzero
   6.9%    89.1%       1.170s       8.12e-03s     C      144      12   theano.tensor.basic.Join
   6.8%    95.9%       1.153s       9.61e-03s     C      120      10   theano.tensor.blas.Dot22Scalar
   3.3%    99.2%       0.552s       5.75e-03s     C       96       8   theano.tensor.elemwise.Sum
   0.5%    99.7%       0.080s       3.35e-03s     C       24       2   theano.tensor.subtensor.AdvancedSubtensor1
   0.3%    99.9%       0.043s       3.58e-03s     C       12       1   theano.tensor.subtensor.AdvancedIncSubtensor1
   0.0%    99.9%       0.005s       4.09e-04s     Py      12       1   theano.tensor.nlinalg.MatrixInverse
   0.0%   100.0%       0.002s       1.75e-04s     Py      12       1   theano.scan_module.scan_op.Scan
   0.0%   100.0%       0.002s       1.66e-04s     C       12       1   theano.compile.ops.DeepCopyOp
   0.0%   100.0%       0.001s       3.25e-06s     C      300      25   theano.tensor.subtensor.IncSubtensor
   0.0%   100.0%       0.001s       2.46e-06s     C      384      32   theano.tensor.basic.Reshape
   0.0%   100.0%       0.001s       1.18e-06s     C      780      65   theano.tensor.elemwise.DimShuffle
   0.0%   100.0%       0.001s       2.84e-06s     C      324      27   theano.tensor.subtensor.Subtensor
   0.0%   100.0%       0.001s       4.49e-05s     Py      12       1   theano.tensor.extra_ops.FillDiagonal
   0.0%   100.0%       0.000s       1.88e-06s     C      204      17   theano.tensor.opt.MakeVector
   0.0%   100.0%       0.000s       9.55e-07s     C      216      18   theano.tensor.basic.ScalarFromTensor
   0.0%   100.0%       0.000s       1.45e-06s     C      108       9   theano.compile.ops.Shape_i
   0.0%   100.0%       0.000s       1.15e-05s     C       12       1   theano.tensor.blas_c.CGemv
   ... (remaining 2 Classes account for   0.00%(0.00s) of the runtime)

Ops
---
<% time> <sum %> <apply time> <time per call> <type> <#call> <#apply> <Op name>
  21.5%    21.5%       3.647s       2.76e-02s     C      132       11   Alloc
  17.9%    39.5%       3.040s       2.53e-01s     C       12        1   Elemwise{Composite{(i0 * i1 * LT(Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}(i2, i3, i4), i5) * (((i6 + ((i7 * Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}(i2, i3, i4)) / i8)) - ((i9 * Composite{(sqr(i0) * i0)}(Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}(i2, i3, i4))) / i10)) + ((i11 * Composite{(sqr(sqr(i0)) * i0)}(Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}(i2, i3, i4))) / i12)))}}[(0, 1)]
  16.1%    55.6%       2.736s       2.28e-01s     C       12        1   Elemwise{Composite{(i0 * ((LT(Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}(i1, i2, i3), i4) * ((i5 + (i6 * Composite{(sqr(i0) * i0)}((Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}(i1, i2, i3) / i4))) + (i7 * Composite{((sqr(sqr(i0)) * sqr(i0)) * i0)}((Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}(i1, i2, i3) / i4)))) - ((i8 * sqr((Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}(i1, i2, i3) / i4))) + (i9 * Composite{(sqr(sqr(i0)
  12.4%    68.0%       2.102s       1.17e-02s     C      180       15   Elemwise{sub,no_inplace}
   9.1%    77.1%       1.545s       4.29e-02s     Py      36        3   Nonzero
   6.9%    84.0%       1.170s       8.12e-03s     C      144       12   Join
   6.8%    90.8%       1.153s       9.61e-03s     C      120       10   Dot22Scalar
   3.6%    94.4%       0.602s       7.17e-03s     C       84        7   Elemwise{mul,no_inplace}
   3.2%    97.5%       0.536s       1.12e-02s     C       48        4   Sum{axis=[0], acc_dtype=float64}
   1.0%    98.5%       0.165s       6.86e-03s     C       24        2   Elemwise{Mul}[(0, 1)]
   0.5%    99.0%       0.080s       3.35e-03s     C       24        2   AdvancedSubtensor1
   0.4%    99.4%       0.067s       5.62e-03s     C       12        1   Elemwise{Composite{((i0 / i1) + ((i2 * i3) / i1) + ((i4 * i5 * i6) / i7))}}[(0, 0)]
   0.3%    99.6%       0.043s       3.58e-03s     C       12        1   AdvancedIncSubtensor1{no_inplace,set}
   0.1%    99.7%       0.017s       1.40e-03s     C       12        1   Elemwise{Composite{(i0 * LE(i1, i2) * GE(i1, i3))}}
   0.1%    99.8%       0.015s       3.22e-04s     C       48        4   Sum{axis=[1], acc_dtype=float64}
   0.1%    99.9%       0.010s       2.91e-04s     C       36        3   Elemwise{Sqr}[(0, 0)]
   0.0%    99.9%       0.005s       4.09e-04s     Py      12        1   MatrixInverse
   0.0%    99.9%       0.003s       2.32e-04s     C       12        1   Elemwise{Cast{int8}}
   0.0%    99.9%       0.002s       1.75e-04s     Py      12        1   for{cpu,scan_fn}
   0.0%    99.9%       0.002s       1.66e-04s     C       12        1   DeepCopyOp
   ... (remaining 79 Ops account for   0.06%(0.01s) of the runtime)

Apply
------
<% time> <sum %> <apply time> <time per call> <#call> <id> <Apply name>
  20.2%    20.2%       3.425s       2.85e-01s     12   331   Alloc(CGemv{inplace}.0, Elemwise{Composite{((i0 // i1) + i2)}}[(0, 0)].0, TensorConstant{1}, TensorConstant{1}, Elemwise{add,no_inplace}.0)
  17.9%    38.1%       3.040s       2.53e-01s     12   339   Elemwise{Composite{(i0 * i1 * LT(Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}(i2, i3, i4), i5) * (((i6 + ((i7 * Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}(i2, i3, i4)) / i8)) - ((i9 * Composite{(sqr(i0) * i0)}(Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}(i2, i3, i4))) / i10)) + ((i11 * Composite{(sqr(sqr(i0)) * i0)}(Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}(i2, i3, i4))) / i12)))}}[(0, 1)](Subtensor{:int64:}.0, Join.0, Reshape{2
  16.1%    54.3%       2.736s       2.28e-01s     12   340   Elemwise{Composite{(i0 * ((LT(Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}(i1, i2, i3), i4) * ((i5 + (i6 * Composite{(sqr(i0) * i0)}((Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}(i1, i2, i3) / i4))) + (i7 * Composite{((sqr(sqr(i0)) * sqr(i0)) * i0)}((Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}(i1, i2, i3) / i4)))) - ((i8 * sqr((Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}(i1, i2, i3) / i4))) + (i9 * Composite{(sqr(sqr(i0)) * i0)}((C
   8.1%    62.4%       1.374s       1.14e-01s     12   134   Nonzero(Reshape{1}.0)
   8.0%    70.4%       1.361s       1.13e-01s     12   290   Elemwise{sub,no_inplace}(InplaceDimShuffle{0,x}.0, InplaceDimShuffle{1,0}.0)
   6.6%    77.0%       1.123s       9.36e-02s     12   304   Join(TensorConstant{0}, Elemwise{sub,no_inplace}.0, Elemwise{sub,no_inplace}.0, Elemwise{sub,no_inplace}.0)
   3.7%    80.8%       0.632s       5.27e-02s     12   264   Dot22Scalar(Reshape{2}.0, InplaceDimShuffle{1,0}.0, TensorConstant{2.0})
   3.4%    84.1%       0.570s       4.75e-02s     12    42   Elemwise{mul,no_inplace}(universal matrix, InplaceDimShuffle{x,0}.0)
   2.3%    86.4%       0.382s       3.18e-02s     12   292   Elemwise{sub,no_inplace}(InplaceDimShuffle{0,x}.0, InplaceDimShuffle{1,0}.0)
   2.1%    88.5%       0.359s       2.99e-02s     12   291   Elemwise{sub,no_inplace}(InplaceDimShuffle{0,x}.0, InplaceDimShuffle{1,0}.0)
   2.0%    90.5%       0.346s       2.89e-02s     12   342   Sum{axis=[0], acc_dtype=float64}(Elemwise{Composite{(i0 * i1 * LT(Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}(i2, i3, i4), i5) * (((i6 + ((i7 * Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}(i2, i3, i4)) / i8)) - ((i9 * Composite{(sqr(i0) * i0)}(Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}(i2, i3, i4))) / i10)) + ((i11 * Composite{(sqr(sqr(i0)) * i0)}(Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}(i2, i3, i4))) / i12)))}}[(0, 1)].0)
   1.6%    92.2%       0.273s       2.27e-02s     12   265   Dot22Scalar(Rest of the points of the layers, InplaceDimShuffle{1,0}.0, TensorConstant{2.0})
   1.5%    93.6%       0.247s       2.06e-02s     12   266   Dot22Scalar(Reference points for every layer, InplaceDimShuffle{1,0}.0, TensorConstant{2.0})
   1.3%    94.9%       0.222s       1.85e-02s     12   240   Alloc(Subtensor{:int64:}.0, Elemwise{Composite{((i0 // i1) + i2)}}[(0, 0)].0, TensorConstant{1}, TensorConstant{1}, Elemwise{Composite{Switch(LT(i0, i1), Switch(LT((i2 + i0), i1), i1, (i2 + i0)), Switch(LT(i0, i2), i0, i2))}}.0)
   1.0%    95.9%       0.165s       1.37e-02s     12   338   Elemwise{Mul}[(0, 1)](Subtensor{int64::}.0, InplaceDimShuffle{1,0}.0, Subtensor{:int64:}.0)
   0.9%    96.8%       0.151s       1.26e-02s     12   343   Sum{axis=[0], acc_dtype=float64}(Elemwise{Composite{(i0 * ((LT(Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}(i1, i2, i3), i4) * ((i5 + (i6 * Composite{(sqr(i0) * i0)}((Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}(i1, i2, i3) / i4))) + (i7 * Composite{((sqr(sqr(i0)) * sqr(i0)) * i0)}((Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}(i1, i2, i3) / i4)))) - ((i8 * sqr((Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}(i1, i2, i3) / i4))) + (i9 * 
   0.8%    97.6%       0.136s       1.13e-02s     12   179   Nonzero(Reshape{1}.0)
   0.4%    98.0%       0.067s       5.62e-03s     12   344   Elemwise{Composite{((i0 / i1) + ((i2 * i3) / i1) + ((i4 * i5 * i6) / i7))}}[(0, 0)](Sum{axis=[0], acc_dtype=float64}.0, InplaceDimShuffle{x}.0, InplaceDimShuffle{x}.0, Sum{axis=[0], acc_dtype=float64}.0, TensorConstant{(1,) of -1.0}, InplaceDimShuffle{x}.0, Sum{axis=[0], acc_dtype=float64}.0, InplaceDimShuffle{x}.0)
   0.4%    98.3%       0.060s       4.96e-03s     12   180   AdvancedSubtensor1(Reshape{1}.0, Subtensor{int64}.0)
   0.3%    98.6%       0.043s       3.58e-03s     12   356   AdvancedIncSubtensor1{no_inplace,set}(<TensorType(float32, vector)>, Sum{axis=[0], acc_dtype=float64}.0, Subtensor{int64}.0)
   ... (remaining 338 Apply instances account for 1.42%(0.24s) of the runtime)

Here are tips to potentially make your code run faster
                 (if you think of new ones, suggest them on the mailing list).
                 Test them first, as they are not guaranteed to always provide a speedup.
  - Try the Theano flag floatX=float32
We don't know if amdlibm will accelerate this scalar op. deg2rad
We don't know if amdlibm will accelerate this scalar op. deg2rad
  - Try installing amdlibm and set the Theano flag lib.amdlibm=True. This speeds up only some Elemwise operation.

GPU


In [23]:
interpolator.theano_set_3D()


/home/miguel/anaconda3/lib/python3.5/site-packages/ipykernel/__main__.py:1: DeprecationWarning: stack(*tensors) interface is deprecated, use stack(tensors, axis=0) instead.
  if __name__ == '__main__':

In [26]:
%%timeit
sol =  interpolator.geoMigueller(dips,dips_angles,azimuths,polarity, rest, ref)[0].reshape(20,20,20, order = "C")


10 loops, best of 3: 15 ms per loop

In [27]:
interpolator.geoMigueller.profile.summary()


Function profiling
==================
  Message: /home/miguel/PycharmProjects/GeMpy/GeoMig.py:1313
  Time in 42 calls to Function.__call__: 7.134078e-01s
  Time in Function.fn.__call__: 7.101927e-01s (99.549%)
  Time in thunks: 5.815070e-01s (81.511%)
  Total compile time: 2.534589e+00s
    Number of Apply nodes: 290
    Theano Optimizer time: 2.050112e+00s
       Theano validate time: 1.564834e-01s
    Theano Linker time (includes C, CUDA code generation/compiling): 4.177537e-01s
       Import time 0.000000e+00s

Time in all call to theano.grad() 0.000000e+00s
Time since theano import 360.828s
Class
---
<% time> <sum %> <apply time> <time per call> <type> <#call> <#apply> <Class name>
  37.6%    37.6%       0.219s       1.93e-04s     C     1134      27   theano.tensor.elemwise.Elemwise
  16.2%    53.8%       0.094s       3.12e-05s     C     3024      72   theano.sandbox.cuda.basic_ops.GpuElemwise
  13.5%    67.3%       0.079s       1.87e-04s     C      420      10   theano.tensor.blas.Dot22Scalar
   9.5%    76.9%       0.056s       6.01e-05s     C      924      22   theano.sandbox.cuda.basic_ops.GpuFromHost
   6.3%    83.2%       0.037s       8.70e-04s     Py      42       1   theano.tensor.nlinalg.MatrixInverse
   3.9%    87.0%       0.022s       3.57e-05s     C      630      15   theano.sandbox.cuda.basic_ops.GpuIncSubtensor
   3.8%    90.8%       0.022s       7.45e-05s     C      294       7   theano.sandbox.cuda.basic_ops.GpuAlloc
   3.2%    94.0%       0.018s       7.32e-05s     C      252       6   theano.sandbox.cuda.basic_ops.GpuJoin
   2.5%    96.5%       0.015s       3.89e-05s     C      378       9   theano.sandbox.cuda.basic_ops.HostFromGpu
   1.6%    98.1%       0.009s       1.32e-05s     C      714      17   theano.sandbox.cuda.basic_ops.GpuReshape
   0.4%    98.5%       0.002s       1.90e-05s     C      126       3   theano.sandbox.cuda.basic_ops.GpuCAReduce
   0.2%    98.8%       0.001s       9.42e-07s     C     1470      35   theano.sandbox.cuda.basic_ops.GpuDimShuffle
   0.2%    99.0%       0.001s       2.85e-05s     Py      42       1   theano.tensor.extra_ops.FillDiagonal
   0.2%    99.1%       0.001s       6.17e-06s     C      168       4   theano.tensor.elemwise.Sum
   0.2%    99.3%       0.001s       1.60e-06s     C      630      15   theano.sandbox.cuda.basic_ops.GpuSubtensor
   0.1%    99.5%       0.001s       3.29e-06s     C      252       6   theano.tensor.subtensor.IncSubtensor
   0.1%    99.6%       0.001s       1.77e-05s     C       42       1   theano.sandbox.cuda.basic_ops.GpuAllocEmpty
   0.1%    99.7%       0.001s       9.17e-07s     C      546      13   theano.tensor.opt.MakeVector
   0.1%    99.8%       0.000s       5.26e-06s     C       84       2   theano.tensor.basic.Alloc
   0.1%    99.8%       0.000s       2.10e-06s     C      168       4   theano.tensor.elemwise.DimShuffle
   ... (remaining 5 Classes account for   0.19%(0.00s) of the runtime)

Ops
---
<% time> <sum %> <apply time> <time per call> <type> <#call> <#apply> <Op name>
  37.2%    37.2%       0.216s       5.15e-04s     C      420       10   Elemwise{Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}}
  13.5%    50.7%       0.079s       1.87e-04s     C      420       10   Dot22Scalar
   9.5%    60.2%       0.056s       6.01e-05s     C      924       22   GpuFromHost
   6.4%    66.6%       0.037s       6.32e-05s     C      588       14   GpuElemwise{sub,no_inplace}
   6.3%    72.9%       0.037s       8.70e-04s     Py      42        1   MatrixInverse
   3.5%    76.4%       0.020s       9.64e-05s     C      210        5   GpuAlloc
   3.2%    79.6%       0.018s       7.32e-05s     C      252        6   GpuJoin
   3.1%    82.7%       0.018s       4.29e-05s     C      420       10   GpuElemwise{Composite{Cast{float32}(LT(i0, i1))},no_inplace}
   3.0%    85.7%       0.018s       5.22e-05s     C      336        8   GpuElemwise{Composite{(i0 * (i1 ** i2))},no_inplace}
   2.5%    88.2%       0.015s       3.89e-05s     C      378        9   HostFromGpu
   2.2%    90.3%       0.013s       4.27e-05s     C      294        7   GpuIncSubtensor{InplaceSet;int64:int64:, int64:int64:}
   1.6%    92.0%       0.009s       1.32e-05s     C      714       17   GpuReshape{2}
   1.3%    93.3%       0.007s       8.91e-05s     C       84        2   GpuElemwise{Composite{(i0 * sqr(i1))},no_inplace}
   0.6%    93.8%       0.003s       3.85e-05s     C       84        2   GpuIncSubtensor{InplaceSet;int64::, int64:int64:}
   0.5%    94.4%       0.003s       3.76e-05s     C       84        2   GpuIncSubtensor{InplaceSet;int64:int64:, int64::}
   0.4%    94.8%       0.002s       1.90e-05s     C      126        3   GpuCAReduce{add}{1,0}
   0.4%    95.1%       0.002s       2.45e-05s     C       84        2   GpuIncSubtensor{InplaceSet;int64:int64:, int64}
   0.3%    95.4%       0.002s       1.96e-05s     C       84        2   GpuAlloc{memset_0=True}
   0.2%    95.6%       0.001s       2.86e-05s     C       42        1   GpuIncSubtensor{InplaceSet;:int64:, int64}
   0.2%    95.8%       0.001s       2.85e-05s     Py      42        1   FillDiagonal
   ... (remaining 67 Ops account for   4.19%(0.02s) of the runtime)

Apply
------
<% time> <sum %> <apply time> <time per call> <#call> <id> <Apply name>
  22.8%    22.8%       0.133s       3.16e-03s     42   205   Elemwise{Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}}(Reshape{2}.0, Reshape{2}.0, Dot22Scalar.0)
   7.9%    30.7%       0.046s       1.09e-03s     42   162   Dot22Scalar(Elemwise{Cast{float64}}.0, InplaceDimShuffle{1,0}.0, TensorConstant{2.0})
   6.9%    37.6%       0.040s       9.60e-04s     42   197   Elemwise{Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}}(Reshape{2}.0, Reshape{2}.0, Dot22Scalar.0)
   6.9%    44.5%       0.040s       9.55e-04s     42   198   Elemwise{Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}}(Reshape{2}.0, Reshape{2}.0, Dot22Scalar.0)
   6.3%    50.8%       0.037s       8.70e-04s     42   271   MatrixInverse(HostFromGpu.0)
   3.0%    53.8%       0.018s       4.20e-04s     42   115   Dot22Scalar(Elemwise{Cast{float64}}.0, InplaceDimShuffle{1,0}.0, TensorConstant{2.0})
   2.9%    56.7%       0.017s       3.97e-04s     42   215   GpuFromHost(Elemwise{Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}}.0)
   2.6%    59.3%       0.015s       3.56e-04s     42   207   GpuFromHost(Elemwise{Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}}.0)
   2.0%    61.3%       0.012s       2.83e-04s     42   114   Dot22Scalar(Elemwise{Cast{float64}}.0, InplaceDimShuffle{1,0}.0, TensorConstant{2.0})
   1.5%    62.8%       0.009s       2.04e-04s     42   275   GpuAlloc(GpuGemv{inplace}.0, Shape_i{0}.0, TensorConstant{1}, TensorConstant{1}, Elemwise{add,no_inplace}.0)
   1.2%    64.0%       0.007s       1.61e-04s     42   208   GpuFromHost(Elemwise{Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}}.0)
   1.1%    65.1%       0.006s       1.53e-04s     42   129   GpuAlloc(GpuElemwise{sub,no_inplace}.0, TensorConstant{1}, TensorConstant{3}, Elemwise{Composite{Switch(EQ(i0, i1), (i0 // (-i0)), i0)}}.0, Shape_i{0}.0)
   1.0%    66.1%       0.006s       1.40e-04s     42   230   GpuElemwise{Composite{Cast{float32}(LT(i0, i1))},no_inplace}(GpuFromHost.0, GpuDimShuffle{x,x}.0)
   0.9%    67.0%       0.005s       1.28e-04s     42   105   GpuElemwise{sub,no_inplace}(GpuDimShuffle{x,0}.0, GpuReshape{2}.0)
   0.9%    67.9%       0.005s       1.21e-04s     42   289   HostFromGpu(GpuElemwise{Composite{((((i0 * i1) / i2) + i3) + i4)}}[(0, 1)].0)
   0.9%    68.8%       0.005s       1.20e-04s     42   150   GpuJoin(TensorConstant{0}, GpuElemwise{sub,no_inplace}.0, GpuElemwise{sub,no_inplace}.0, GpuElemwise{sub,no_inplace}.0)
   0.8%    69.6%       0.005s       1.12e-04s     42   144   GpuJoin(TensorConstant{0}, GpuElemwise{sub,no_inplace}.0, GpuElemwise{sub,no_inplace}.0, GpuElemwise{sub,no_inplace}.0)
   0.8%    70.3%       0.004s       1.05e-04s     42   125   GpuElemwise{sub,no_inplace}(GpuDimShuffle{0,x}.0, GpuDimShuffle{1,0}.0)
   0.7%    71.1%       0.004s       1.02e-04s     42   202   GpuFromHost(Elemwise{Composite{Cast{float32}(sqrt(((i0 + i1) - i2)))}}.0)
   0.7%    71.8%       0.004s       1.00e-04s     42   138   GpuElemwise{sub,no_inplace}(GpuDimShuffle{0,x}.0, GpuDimShuffle{1,0}.0)
   ... (remaining 270 Apply instances account for 28.22%(0.16s) of the runtime)

Here are tips to potentially make your code run faster
                 (if you think of new ones, suggest them on the mailing list).
                 Test them first, as they are not guaranteed to always provide a speedup.
  - Try installing amdlibm and set the Theano flag lib.amdlibm=True. This speeds up only some Elemwise operation.