Jammy2211 / PyAutoLens

PyAutoLens: Open Source Strong Gravitational Lensing
https://pyautolens.readthedocs.io/
MIT License
165 stars 32 forks source link

API consistency issues? #198

Open PeterEDz opened 2 years ago

PeterEDz commented 2 years ago

I am trying to run autolens for pretty much the first time. IT looks to be a great package. Congratulations! At present I am working my way through the tutorials.

I seem to have run into some issues, which may be API related and may be due to deprecated features in autolens and would like clarification and/or toreport a bug/bugs.

For reference I am running Ubuntu 20.04 and pip-installed autolens. I am running absolutely standard Jupyter notebooks on my own machine (basically cut-and-paste versions of yours plus "notes to self"), intended for later adaptation and not using Binder.

I have however run your examples in Binder and they run. The copied code has thrown errors when run locally.

To be specific:

In the example labelled "galaxies" the tracer example given:

tracer = al.Tracer.from_galaxies( galaxies=[lens_galaxy, source_galaxy], cosmology: ag.cosmo.LensingCosmology = ag.cosmo.Planck15() )

doesn't want to run: erroring on the cosmology. However removing the cosmology a workaround seems to be to default the cosmology so:

tracer = al.Tracer.from_galaxies( galaxies=[lens_galaxy, source_galaxy] )

runs "just fine"

In the examples under Lensing (Extending Objects)

bulge=al.lmp.EllSersic(
    centre=(0.0, 0.0),
    axis_ratio=0.9,
    angle=45.0,
    intensity=0.5,
    effective_radius=0.3,
    sersic_index=2.5,
    mass_to_light_ratio=0.3,
   )

errors with the message:

---------------------------------------------------------------------------

TypeError Traceback (most recent call last) /tmp/ipykernel_5436/3811423805.py in 1 lens_galaxy_0 = al.Galaxy( 2 redshift=0.5, ----> 3 bulge=al.lmp.EllSersic( 4 centre=(0.0, 0.0), 5 axis_ratio=0.9,

TypeError: EllSersic.init() got an unexpected keyword argument 'axis_ratio'

I can't find anything in the manual referring to al.lmp... (which I assume refers to a light and mass profile library). So I can't actually see what the parameters should be.

As a result I want to raise two issues:

  1. The lack of an API makes it difficult to debug code.
  2. There is a question as to whether there is an issue with using local Jupyter Notebooks, rather than Binder.

Any comments that you can give greatly appreciated.

Jammy2211 commented 2 years ago

The issues are due to a few typos in the readthedocs code snippets -- ooops!

I have updated the two examples you listed above to as follows:

    tracer = al.Tracer.from_galaxies(
        galaxies=[lens_galaxy, source_galaxy], cosmology=al.cosmo.Planck15()
    )
        bulge=al.lmp.EllSersic(
            centre=(0.0, 0.0),
            elliptical_comps=(0.0, 0.05),
            intensity=0.5,
            effective_radius=0.3,
            sersic_index=2.5,
            mass_to_light_ratio=0.3,
        ),

The readthedocs examples are taken from the following overview notebooks, which are tested against on release and therefore should work correctly, so this may be a better reference for now.

https://github.com/Jammy2211/autolens_workspace/tree/release/notebooks/overview

I will have a think about running readtheedocs code to prevent this from happening.

The lack of an API makes it difficult to debug code.

Do you simply meaning that certain objects (e.g. lmp. objects) are missing from here:

https://pyautolens.readthedocs.io/en/latest/api/api.html