Browse Source

Removed calls to shared_from_this from DipoleSource, this allows for pybind11 wrapping and should improve performance

iss7
Trevor Irons 5 years ago
parent
commit
edd62be899

+ 4
- 3
Modules/FDEM1D/include/DipoleSource.h View File

@@ -41,9 +41,10 @@ namespace Lemma {
41 41
     /// \details  More complex sources are constructed from a superposition of
42 42
     ///           dipoles.
43 43
     // ==========================================================================
44
-    //class DipoleSource : public std::enable_shared_from_this<DipoleSource>,  LemmaObject {
45
-    class DipoleSource : public LemmaObject, std::enable_shared_from_this<DipoleSource> {
46
-    //class DipoleSource : public LemmaObject, private std::enable_shared_from_this<DipoleSource> {
44
+    // pybind11 struggles with deriving from enable_shared_from_this,
45
+    //          instead we revert to raw pointers inside Lemma which also boosts performance
46
+    //class DipoleSource : public LemmaObject, std::enable_shared_from_this<DipoleSource> {
47
+    class DipoleSource : public LemmaObject {
47 48
 
48 49
         // ====================    FRIENDS     ======================
49 50
 

+ 5
- 5
Modules/FDEM1D/python/pyFDEM1D.cpp View File

@@ -88,17 +88,17 @@ PYBIND11_MODULE(FDEM1D, m) {
88 88
 
89 89
     ;
90 90
 
91
-    //py::class_<Lemma::DipoleSource, std::shared_ptr<Lemma::DipoleSource> > DipoleSource(m, "DipoleSource");
91
+    py::class_<Lemma::DipoleSource, std::shared_ptr<Lemma::DipoleSource> > DipoleSource(m, "DipoleSource");
92 92
 
93 93
         // lifecycle
94
-        //DipoleSource.def(py::init(&Lemma::DipoleSource::NewSP))
94
+        DipoleSource.def(py::init(&Lemma::DipoleSource::NewSP))
95 95
         //.def_static("DeSerialize", py::overload_cast<const std::string&>(&Lemma::DipoleSource::DeSerialize), "Construct object from yaml representation")
96 96
 
97 97
         // print
98
-        //.def("Serialize", &Lemma::DipoleSource::Print, "YAML representation of the class")
99
-        //.def("__repr__", &Lemma::DipoleSource::Print)
98
+        .def("Serialize", &Lemma::DipoleSource::Print, "YAML representation of the class")
99
+        .def("__repr__", &Lemma::DipoleSource::Print)
100 100
 
101
-        //;
101
+        ;
102 102
 }
103 103
 
104 104
 

+ 3
- 1
Modules/FDEM1D/src/DipoleSource.cpp View File

@@ -276,9 +276,11 @@ namespace Lemma {
276 276
         layr = Earth->GetLayerAtThisDepth(Receivers->GetLocation(irec)[2]);
277 277
 
278 278
         KernelManager = KernelEM1DManager::NewSP();
279
+
279 280
             KernelManager->SetEarth(Earth);
280 281
             // alternative is to use weak_ptr here, this is deep and internal, and we are safe.
281
-            KernelManager->SetDipoleSource( shared_from_this().get() , ifreq, Receivers->GetLocation(irec)[2]);
282
+            //KernelManager->SetDipoleSource( shared_from_this().get() , ifreq, Receivers->GetLocation(irec)[2]);
283
+            KernelManager->SetDipoleSource( this, ifreq, Receivers->GetLocation(irec)[2]);
282 284
 
283 285
             //KernelManager->SetDipoleSource( this.get() , ifreq, Receivers->GetLocation(irec)[2] );
284 286
             kernelFreq = Freqs(ifreq); // this is never used

+ 41
- 0
python/build_wheels.sh View File

@@ -0,0 +1,41 @@
1
+#!/bin/bash
2
+set -e -x
3
+
4
+export PYHOME=/home
5
+cd ${PYHOME}
6
+
7
+/opt/python/cp37-cp37m/bin/pip install twine cmake
8
+ln -s /opt/python/cp37-cp37m/bin/cmake /usr/bin/cmake
9
+
10
+# Compile wheels
11
+for PYBIN in /opt/python/cp3*/bin; do
12
+    "${PYBIN}/pip" wheel /io/ -w wheelhouse/
13
+    "${PYBIN}/python" /io/setup.py sdist -d /io/wheelhouse/
14
+done
15
+
16
+# Bundle external shared libraries into the wheels
17
+for whl in wheelhouse/*.whl; do
18
+    auditwheel repair "$whl" -w /io/wheelhouse/
19
+done
20
+
21
+# Test
22
+for PYBIN in /opt/python/cp3*/bin/; do
23
+    "${PYBIN}/pip" install -r /io/requirements-test.txt
24
+    "${PYBIN}/pip" install --no-index -f /io/wheelhouse nb-cpp
25
+    (cd "$PYHOME"; "${PYBIN}/pytest" /io/test/)
26
+done
27
+
28
+#  Upload
29
+for WHEEL in /io/wheelhouse/nb_cpp*; do
30
+    # dev
31
+    # /opt/python/cp37-cp37m/bin/twine upload \
32
+    #     --skip-existing \
33
+    #     --repository-url https://test.pypi.org/legacy/ \
34
+    #     -u "${TWINE_USERNAME}" -p "${TWINE_PASSWORD}" \
35
+    #     "${WHEEL}"
36
+    # prod
37
+    /opt/python/cp37-cp37m/bin/twine upload \
38
+        --skip-existing \
39
+        -u "${TWINE_USERNAME}" -p "${TWINE_PASSWORD}" \
40
+        "${WHEEL}"
41
+done

+ 5
- 0
python/publish.sh View File

@@ -0,0 +1,5 @@
1
+rm -rf dist
2
+python setup.py build
3
+python setup.py bdist_wheel
4
+auditwheel repair --plat manylinux2010_x86_64  pyLemma-0.0.2-cp37-cp37m-linux_x86_64.whl
5
+twine upload dist/*

Loading…
Cancel
Save