Jammy2211 / PyAutoGalaxy

PyAutoGalaxy: Open-Source Multiwavelength Galaxy Structure & Morphology
https://pyautogalaxy.readthedocs.io/
MIT License
28 stars 14 forks source link

Package fails 3/454 unit tests with pytest #35

Closed alexandergagliano closed 2 years ago

alexandergagliano commented 2 years ago

When running pytest, the code catches 3 test failures across 2 files -- test_autogalaxy/imaging/test_fit_imaging.py and test_autogalaxy/profiles/light_profiles/test_light_profiles.py. The error messages are:

----------------------------------------------------------------------------------- Captured stdout setup ------------------------------------------------------------------------------------
2022-07-17 12:10:33,661 - autoarray.dataset.imaging - INFO - IMAGING - Data masked, contains a total of 9 image-pixels
------------------------------------------------------------------------------------- Captured log setup -------------------------------------------------------------------------------------
INFO     autoarray.dataset.imaging:imaging.py:366 IMAGING - Data masked, contains a total of 9 image-pixels
____________________________________________________________________ TestMoffat.test__intensity_as_radius__correct_value _____________________________________________________________________

self = <test_light_profiles.TestMoffat object at 0x7ff87748a850>

    def test__intensity_as_radius__correct_value(self):
>       moffat = ag.lp.EllMoffat(
            centre=(0.0, 0.0),
            elliptical_comps=(0.0, 0.0),
            intensity=1.0,
            alpha=1.0,
            beta=1.0,
        )
E       AttributeError: module 'autogalaxy.profiles.light_profiles' has no attribute 'EllMoffat'

test_autogalaxy/profiles/light_profiles/test_light_profiles.py:344: AttributeError

and

____________________________________________________________________ test__plane_linear_light_profiles_to_light_profiles _____________________________________________________________________

masked_imaging_7x7 = <autoarray.dataset.imaging.Imaging object at 0x7ff84c1fd880>

    def test__plane_linear_light_profiles_to_light_profiles(masked_imaging_7x7):

        g0 = ag.Galaxy(redshift=0.5, light_profile=ag.lp.EllSersic(intensity=1.0))

        g0_linear = ag.Galaxy(
            redshift=0.5, light_profile=ag.lp_linear.EllSersic(sersic_index=1.0)
        )

        g1_linear = ag.Galaxy(
            redshift=1.0, light_profile=ag.lp_linear.EllSersic(sersic_index=4.0)
        )

        plane = ag.Plane(galaxies=[g0, g0_linear, g1_linear])

        fit = ag.FitImaging(dataset=masked_imaging_7x7, plane=plane)

        assert fit.galaxies[0].light_profile.intensity == pytest.approx(1.0, 1.0e-4)

>       plane = fit.plane_linear_light_profiles_to_light_profiles
E       AttributeError: 'FitImaging' object has no attribute 'plane_linear_light_profiles_to_light_profiles'

test_autogalaxy/imaging/test_fit_imaging.py:587: AttributeError

and

_________________________________________________________________________________ test__fit_figure_of_merit __________________________________________________________________________________

masked_imaging_7x7 = <autoarray.dataset.imaging.Imaging object at 0x7ff84bbe2730>

    def test__fit_figure_of_merit(masked_imaging_7x7):

        g0 = ag.Galaxy(redshift=0.5, light_profile=ag.lp.EllSersic(intensity=1.0))
        g1 = ag.Galaxy(redshift=0.5, light_profile=ag.lp.EllSersic(intensity=1.0))

        plane = ag.Plane(redshift=0.5, galaxies=[g0, g1])

        fit = ag.FitImaging(dataset=masked_imaging_7x7, plane=plane)

        assert fit.log_likelihood == pytest.approx(-75938.05, 1e-4)
        assert fit.figure_of_merit == pytest.approx(-75938.05, 1.0e-4)

        pix = ag.pix.Rectangular(shape=(3, 3))
        reg = ag.reg.Constant(coefficient=1.0)

        galaxy_pix = ag.Galaxy(redshift=0.5, pixelization=pix, regularization=reg)

        plane = ag.Plane(galaxies=[ag.Galaxy(redshift=0.5), galaxy_pix])

        fit = ag.FitImaging(dataset=masked_imaging_7x7, plane=plane)

        assert fit.log_evidence == pytest.approx(-22.9005, 1e-4)
        assert fit.figure_of_merit == pytest.approx(-22.9005, 1.0e-4)

        galaxy_light = ag.Galaxy(redshift=0.5, light_profile=ag.lp.EllSersic(intensity=1.0))

        plane = ag.Plane(redshift=0.5, galaxies=[galaxy_light, galaxy_pix])

        fit = ag.FitImaging(dataset=masked_imaging_7x7, plane=plane)

        assert fit.log_evidence == pytest.approx(-6840.5851, 1e-4)
        assert fit.figure_of_merit == pytest.approx(-6840.5851, 1.0e-4)

        g0_linear_light = ag.Galaxy(
            redshift=0.5, light_profile=ag.lp_linear.EllSersic(sersic_index=1.0)
        )

        g1_linear_light = ag.Galaxy(
            redshift=0.5, light_profile=ag.lp_linear.EllSersic(sersic_index=4.0)
        )

        plane = ag.Plane(redshift=0.5, galaxies=[g0_linear_light, g1_linear_light])

        fit = ag.FitImaging(dataset=masked_imaging_7x7, plane=plane)

        assert fit.log_likelihood == pytest.approx(-14.52327, 1e-4)
        assert fit.figure_of_merit == pytest.approx(-14.52327, 1.0e-4)

        g0_operated_light = ag.Galaxy(
            redshift=0.5, light_profile=ag.lp_operated.EllSersic(intensity=1.0)
        )
        g1_operated_light = ag.Galaxy(
            redshift=0.5, light_profile=ag.lp_operated.EllSersic(intensity=1.0)
        )

        plane = ag.Plane(redshift=0.5, galaxies=[g0_operated_light, g1_operated_light])

        fit = ag.FitImaging(dataset=masked_imaging_7x7, plane=plane)

        assert fit.log_likelihood == pytest.approx(-342374.9618, 1e-4)
        assert fit.figure_of_merit == pytest.approx(-342374.9618, 1.0e-4)

        g0_linear_operated_light = ag.Galaxy(
>           redshift=0.5, light_profile=ag.lp_linear_operated.EllSersic(sersic_index=1.0)
        )
E       AttributeError: module 'autogalaxy.profiles.light_profiles.light_profiles_linear_operated' has no attribute 'EllSersic'

test_autogalaxy/imaging/test_fit_imaging.py:208: AttributeError

Related to #4475.

Jammy2211 commented 2 years ago

A git pull should fix this.

alexandergagliano commented 2 years ago

@Jammy2211 I've done a fresh install and a fresh pull of this repo and now am getting five errors (they look related to the original 3). I should mention that this is after pip installing the package and then running the code tests from this repo. If the pypi release and the repo are at different versions, that might be the cause?

E       AttributeError: module 'autogalaxy.profiles.light_profiles.light_profiles_linear_operated' has no attribute 'EllSersic'

imaging/test_fit_imaging.py:208: AttributeError
E       AttributeError: 'FitImaging' object has no attribute 'plane_linear_light_profiles_to_light_profiles'

imaging/test_fit_imaging.py:587: AttributeError
E       AssertionError: assert not True
E        +  where True = isinstance(EllSersic\ncentre: (0.0, 0.0)\nelliptical_comps: (0.0, 0.0)\nintensity: 1.0\neffective_radius: 0.6\nsersic_index: 4.0, <class 'autogalaxy.profiles.light_profiles.light_profiles_linear.LightProfileLinear'>)
E        +    where EllSersic\ncentre: (0.0, 0.0)\nelliptical_comps: (0.0, 0.0)\nintensity: 1.0\neffective_radius: 0.6\nsersic_index: 4.0 = Redshift: 0.5\nLight Profiles:\nEllSersic\ncentre: (0.0, 0.0)\nelliptical_comps: (0.0, 0.0)\nintensity: 1.0\neffective_radius: 0.6\nsersic_index: 4.0.bulge
E        +    and   <class 'autogalaxy.profiles.light_profiles.light_profiles_linear.LightProfileLinear'> = <module 'autogalaxy.profiles.light_profiles.light_profiles_linear' from '/Users/alexgagliano/miniconda3/lib/python3.9/site-packages/autogalaxy/profiles/light_profiles/light_profiles_linear.py'>.LightProfileLinear
E        +      where <module 'autogalaxy.profiles.light_profiles.light_profiles_linear' from '/Users/alexgagliano/miniconda3/lib/python3.9/site-packages/autogalaxy/profiles/light_profiles/light_profiles_linear.py'> = ag.lp_linear

imaging/model/test_result_imaging.py:58: AssertionError
E       AttributeError: module 'autogalaxy.profiles.light_profiles' has no attribute 'EllMoffat'

profiles/light_profiles/test_light_profiles.py:229: AttributeError
E       assert 9.0 < Array2D(2.89827085)
E        +  where Array2D(2.89827085) = <autoarray.dataset.imaging.Imaging object at 0x7fe5beee66a0>.signal_to_noise_max

profiles/light_profiles/test_snr_light_profiles.py:40: AssertionError
Jammy2211 commented 2 years ago

Ok yes, the issue is that the pip install and master branch are out of sync (as one would expect).

If you are to run the tests you should also run the PyAutoGalaxy source code cloned from the repo (and will possibly need the parent projects cloned as well):

https://pyautogalaxy.readthedocs.io/en/latest/installation/source.html

alexandergagliano commented 2 years ago

A few errors in PyAutoArray after following the instructions in "Build All Projects" here. It looks like these are all coming from similar functions:

===================================================================================== short test summary info ====================================================================================== FAILED test_autoarray/inversion/inversion/test_factory.py::testinversion_imaging__via_regularizations - AttributeError: module 'autoarray.util.nn.nn_py' has no attribute 'natural_interpolatio... FAILED test_autoarray/inversion/linear_eqn/test_leq_util.py::TestCurvatureMatrixImaging::testcurvature_matrix_via_preload_imaging - assert False FAILED test_autoarray/inversion/mappers/test_voronoi.py::testpix_indexes_for_sub_slim_index__matches_util - AttributeError: module 'autoarray.util.nn.nn_py' has no attribute 'natural_interpol... FAILED test_autoarray/structures/grids/test_grid_2d_pixelizations.py::TestGrid2DVoronoi::testinterpolated_array_from - AttributeError: module 'autoarray.util.nn.nn_py' has no attribute 'natur... FAILED test_autoarray/util/test_nn.py::test__returning_weights_correct - AttributeError: module 'autoarray.util.nn.nn_py' has no attribute 'natural_interpolation_weights' FAILED test_autoarray/util/test_nn.py::test__nn_interpolation_correct - AttributeError: module 'autoarray.util.nn.nn_py' has no attribute 'natural_interpolation' ====================================================================== 6 failed, 835 passed, 15 warnings in 154.93s (0:02:34) ======================================================================

alexandergagliano commented 2 years ago

PyAutoArray testing re-done from scratch in a new conda environment and fails the same tests.

Jammy2211 commented 2 years ago

Yeah these tests require an optional C library, I hadnt really considered we put some tests that depend on it.

Will look into fixing them by removing the dependency.

Jammy2211 commented 2 years ago

Pushed what I think is a fix, feel free to reopn this issue if theres still failing tests.

alexandergagliano commented 2 years ago

Confirming that, yes, the fix works and all tests pass.