gimli-org / gimli

Geophysical Inversion and Modeling Library :earth_africa:
https://www.pygimli.org
Other
375 stars 137 forks source link

Initial tests failed with pyGIMLi 1.0.12 #202

Closed poprafka closed 4 years ago

poprafka commented 4 years ago

Problem description

Hello, I just installed a latests release 1.12 of pyGIMLi, but I failed some initial tests. For every single failure a following error is listed:

"TypeError: No registered converter was able to produce a C++ rvalue of type long from this Python object of type numpy.int32"

Your environment

Operating system: Windows 10 Python version: 3.7.4 pyGIMLi version: 1.12 Way of installation: conda install -c gimli -c conda-forge pygimli=1.0.12

Steps to reproduce

Tell us how to reproduce this issue. Ideally, you could paste the code that produces the error:


import pygimli as pg
pg.test()

### Actual behavior

================================== FAILURES ===================================
___________________ TestFiniteElementBasics.test_Dirichlet ____________________

self = <pygimli.testing.test_FEM.TestFiniteElementBasics testMethod=test_Dirichlet>

    def test_Dirichlet(self):
        """
        """
        def _testP1_(mesh, show=False):
            """ Laplace u = 0 solves u = x for u(r=0)=0 and u(r=1)=1
                Test for u == exact x for P1 base functions
            """
            u = pg.solve(mesh, a=1, b=0, f=0,
                         bc={'Dirichlet': [[1, 0], [2, 1]]})

            if show:
                if mesh.dim()==1:
                    pg.plt.plot(pg.x(mesh), u)
                    pg.wait()
                elif mesh.dim()==2:
                    pg.show(mesh, u, label='u')
                    pg.wait()

            xMin = mesh.xmin()
            xSpan = (mesh.xmax() - xMin)
            np.testing.assert_allclose(u, (pg.x(mesh)-xMin)/ xSpan)
            return u

        def _testP2_(mesh, show=False):
            """ Laplace u = 2 solves u = x² for u(r=0)=0 and u(r=1)=1
                Test for u == exact x² for P2 base functions
            """
            meshp2 = mesh.createP2()
            u = pg.solve(meshp2, f=-2, bc={'Dirichlet': [[1, 0], [2, 1]]})

            # find test pos different from node pos
            meshTests = mesh.createH2()
            meshTests = meshTests.createH2()

            c = [c.center() for c in meshTests.cells()]
            startPos = meshTests.node(0).pos()

            if mesh.dim() == 2:
                c = [b.center() for b in meshTests.boundaries(meshTests.boundaryMarkers()==4)]

            c.sort(key=lambda c_: c_.distance(startPos))
            ui = pg.interpolate(meshp2, u, c)
            xi = pg.utils.cumDist(c) + startPos.distance(c[0])

            if show:
                pg.plt.plot(xi, ui)
                pg.plt.plot(xi, xi**2)
                pg.wait()

            np.testing.assert_allclose(ui, xi**2)

        _testP1_(pg.createGrid(x=np.linspace(0, 1, 11)), show=False) #1D
        _testP1_(pg.createGrid(x=np.linspace(-2, 1, 11), y=np.linspace(0, 1, 11))) #2D reg quad
        _testP1_(pg.createGrid(x=np.linspace(-0.04, 0.01, 11), y=np.linspace(-0.4, 0, 11))) #2D scaled
        _testP1_(pg.createGrid(x=np.linspace(-2, 1, 11), y=np.linspace( 0, 1, 11),
                             z=np.linspace( 0, 1, 11))) #3D

        mesh = pg.meshtools.createMesh(pg.meshtools.createWorld(start=[4, -4], end=[6, -6], worldMarker=0), area=0.1)
>       mesh.setBoundaryMarkers(np.array([0,1,3,2,4])[mesh.boundaryMarkers()])
E       TypeError: No registered converter was able to produce a C++ rvalue of type long from this Python object of type numpy.int32

C:\Users\David\Miniconda3\lib\site-packages\pygimli\testing\test_FEM.py:143: TypeError
_____________________ TestIterBug.test_MissingRefCounter ______________________

self = <pygimli.testing.test_IterBug.TestIterBug testMethod=test_MissingRefCounter>

    def test_MissingRefCounter(self):
        """
        """
        a = pg.RVector(10, 1)

        # das geht schief wegen fehlendem referenzcounter. der Iter nutzt das
        # temporaere Object a(0,9) das nicht weiter gezaehlt wird
        # ich glaub unsere pygimli objecte brauchen einen refcounter
        # wenn sie von py aus generiert werden
        # print((a(0, 9).beginPyIter()[0], "!=", a[0]))
>       self.assertNotEqual(a(0, 9).beginPyIter()[0], a[0])
E       AssertionError: 1.0 == 1.0

C:\Users\David\Miniconda3\lib\site-packages\pygimli\testing\test_IterBug.py:21: AssertionError
___________________ TestRVectorMethods.test_NumpyToIVector ____________________

self = <pygimli.testing.test_RValueConverter.TestRVectorMethods testMethod=test_NumpyToIVector>

    def test_NumpyToIVector(self):
        """Implemented in custom_rvalue.cpp."""
        x = np.array(range(-10, 10))
>       a = pg.IVector(x)
E       TypeError: No registered converter was able to produce a C++ rvalue of type long from this Python object of type numpy.int32

C:\Users\David\Miniconda3\lib\site-packages\pygimli\testing\test_RValueConverter.py:90: TypeError
___________________ TestRVectorMethods.test_NumpyToRVector ____________________

self = <pygimli.testing.test_RValueConverter.TestRVectorMethods testMethod=test_NumpyToRVector>

    def test_NumpyToRVector(self):
        """Implemented in custom_rvalue.cpp."""
        x = np.arange(0, 1., 0.2)
        a = pg.RVector(x)
        self.assertEqual(a.size(), len(x))
        self.assertEqual(pg.sum(a), sum(x))

        x = np.arange(0, 1., 0.2, dtype=np.float64)
        a = pg.RVector(x)
        self.assertEqual(a.size(), len(x))
        self.assertEqual(pg.sum(a), sum(x))

        x = np.arange(10, dtype=np.int)
        a = pg.RVector(x)
        self.assertEqual(a.size(), len(x))
        self.assertEqual(pg.sum(a), sum(x))

        x = np.arange(10, dtype=np.long)
        a = pg.RVector(x)

        self.assertEqual(a.size(), len(x))
        self.assertEqual(pg.sum(a), sum(x))

>       self.assertEqual(pg.sum(x), sum(x))
E       TypeError: No registered converter was able to produce a C++ rvalue of type long from this Python object of type numpy.int32

C:\Users\David\Miniconda3\lib\site-packages\pygimli\testing\test_RValueConverter.py:145: TypeError
_________________________ TestMisc.test_Int64Problem __________________________

self = <pygimli.testing.test_misc.TestMisc testMethod=test_Int64Problem>

    def test_Int64Problem(self):
        data = pg.DataContainerERT()
        pos = np.arange(4, dtype=np.int)
>       data.createFourPointData(0, pos[0], pos[1], pos[2], pos[3])
E       Boost.Python.ArgumentError: Python argument types in
E           None.createFourPointData(DataContainerERT, int, numpy.int32, numpy.int32, numpy.int32, numpy.int32)
E       did not match C++ signature:
E           createFourPointData(GIMLI::DataContainerERT {lvalue}, unsigned long long i, long eaID, long ebID, long emID, long enID)

C:\Users\David\Miniconda3\lib\site-packages\pygimli\testing\test_misc.py:85: ArgumentError
halbmy commented 4 years ago

Thank you for reporting. These failed tests are one reason why the conda versions for Windows are still for testing (see also the last comment on #85), but we are working on solving them. All errors are related to definitions of integer variables and avoidable by additional casts (e.g. int(nr) for the last one).

So please go ahead exploring and using pyGIMLi.

poprafka commented 4 years ago

Thanks Thomas for instant reaction! As also some plotting issues occurred, I'll reinstall the pyGIMLi in a conventional way, using binary wheel files, immediately after they will be available for v1.12. However, looking forward for the times when the installation via conda will be an option also for Windows machines.

halbmy commented 4 years ago

I've created a new conda package with the version 1.0.12.1 where all test are passed. Check it out.

The wheel or msi versions are identical and had the same problems.

poprafka commented 4 years ago

Works like a charm now! I just had to downgrade the matplotlib to v 3.0.3 to resolve some minor plotting issues. Thanks for support and immediate reaction!

halbmy commented 4 years ago

Great to hear all works well! Can you report about the problems related to matplotlib (coming up with version 3.1)?