Skip to content

Commit

Permalink
Revert "Main to JAX"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jammy2211 authored Oct 25, 2024
1 parent 6c1f19e commit 686ddad
Show file tree
Hide file tree
Showing 26 changed files with 424 additions and 373 deletions.
3 changes: 2 additions & 1 deletion autogalaxy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from autoarray.dataset.interferometer.dataset import Interferometer # noqa
from autoarray.dataset.dataset_model import DatasetModel
from autoarray.dataset.over_sampling import OverSamplingDataset
from autoarray.inversion.inversion.mapper_valued import MapperValued
from autoarray.inversion.pixelization import mesh # noqa
from autoarray.inversion import regularization as reg # noqa
from autoarray.inversion.pixelization import image_mesh
Expand Down Expand Up @@ -109,6 +108,8 @@
from .gui.clicker import Clicker
from .gui.scribbler import Scribbler

from .analysis.clump_model import ClumpModel

from autoconf import conf

conf.instance.register(__file__)
Expand Down
1 change: 1 addition & 0 deletions autogalaxy/aggregator/ellipse/fit_ellipse.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def _fit_ellipse_from(
for dataset, ellipse_list, multipole_lists in zip(
dataset_list, ellipse_list_list, multipole_list_list
):

for ellipse, multipole_list in zip(ellipse_list, multipole_lists):
fit_dataset_list.append(
FitEllipse(
Expand Down
8 changes: 4 additions & 4 deletions autogalaxy/aggregator/galaxies.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ def _galaxies_from(fit: af.Fit, instance: af.ModelInstance) -> List[Galaxy]:
if instance is not None:
galaxies = instance.galaxies

if hasattr(instance, "extra_galaxies"):
galaxies = galaxies + fit.instance.extra_galaxies
if hasattr(instance, "clumps"):
galaxies = galaxies + fit.instance.clumps

else:
galaxies = fit.instance.galaxies

if hasattr(fit.instance, "extra_galaxies"):
galaxies = galaxies + fit.instance.extra_galaxies
if hasattr(fit.instance, "clumps"):
galaxies = galaxies + fit.instance.clumps

if fit.children is not None:
if len(fit.children) > 0:
Expand Down
19 changes: 9 additions & 10 deletions autogalaxy/analysis/analysis/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def galaxies_via_instance_from(
"""
Create a list of galaxies from a model instance, which is used to fit the dataset.
The instance may only contain galaxies, in which case this function is redundant. However, if extra galaxies
are included, the instance will contain both galaxies and extra galaxies, and they should be added to create
The instance may only contain galaxies, in which case this function is redundant. However, if the clumns
API is being used, the instance will contain both galaxies and clumps, and they should be added to create
the single list of galaxies used to fit the dataset.
Parameters
Expand All @@ -56,12 +56,11 @@ def galaxies_via_instance_from(
-------
A list of galaxies that is used to then fit the dataset.
"""
if hasattr(instance, "extra_galaxies"):
if getattr(instance, "extra_galaxies", None) is not None:
return Galaxies(
galaxies=instance.galaxies + instance.extra_galaxies,
run_time_dict=run_time_dict
)
if hasattr(instance, "clumps"):
return Galaxies(
galaxies=instance.galaxies + instance.clumps,
run_time_dict=run_time_dict,
)

return Galaxies(galaxies=instance.galaxies, run_time_dict=run_time_dict)

Expand Down Expand Up @@ -148,7 +147,7 @@ def profile_log_likelihood_function(
An instance of the model that is being fitted to the data by this analysis (whose parameters have been set
via a non-linear search).
paths
The paths object which manages all paths, e.g. where the non-linear search outputs are stored,
The PyAutoFit paths object which manages all paths, e.g. where the non-linear search outputs are stored,
visualization and the pickled objects used by the aggregator output by this function.
Returns
Expand Down Expand Up @@ -239,7 +238,7 @@ def output_profiling_info(
Parameters
----------
paths
The paths object which manages all paths, e.g. where the non-linear search outputs are stored,
The PyAutoFit paths object which manages all paths, e.g. where the non-linear search outputs are stored,
visualization and the pickled objects used by the aggregator output by this function.
run_time_dict
A dictionary containing the profiling times of the functions called by the `log_likelihood_function`.
Expand Down
4 changes: 2 additions & 2 deletions autogalaxy/analysis/analysis/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def save_attributes(self, paths: af.DirectoryPaths):
Parameters
----------
paths
The paths object which manages all paths, e.g. where the non-linear search outputs are stored,
The PyAutoFit paths object which manages all paths, e.g. where the non-linear search outputs are stored,
visualization, and the pickled objects used by the aggregator output by this function.
"""
paths.save_fits(
Expand Down Expand Up @@ -145,7 +145,7 @@ def save_results(self, paths: af.DirectoryPaths, result: ResultDataset):
Parameters
----------
paths
The paths object which manages all paths, e.g. where the non-linear search outputs are stored,
The PyAutoFit paths object which manages all paths, e.g. where the non-linear search outputs are stored,
visualization and the pickled objects used by the aggregator output by this function.
result
The result of a model fit, including the non-linear search, samples and maximum likelihood tracer.
Expand Down
81 changes: 34 additions & 47 deletions autogalaxy/analysis/chaining_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,90 +166,77 @@ def source_from(
return source_custom_model_from(result=result, source_is_model=True)


def extra_galaxies_from(
def clumps_from(
result: Result,
light_as_model: bool = False,
mass_as_model: bool = False,
free_centre: bool = False,
) -> af.Collection:
"""
The extra galaxies API models the light and / or mass of additional galaxies surrouding the main galaxy or
strong lens system.
The clump API models the light and / or mass of additional galaxies surrouding the main galaxy or strong lens
system.
This function performs model composition of extra galaxies for fits using the search chaining API. It makes it
possible to pass the extra galaxy parameters from a previous search to a new search, such that the new extra
galaxies are either treated as an instance or model component.
This function performs model composition of clumps for fits using the search chaining API. It makes it possible to
pass the clump parameters from a previous search to a new search, such that the new clumps are either treated
as an instance or model component.
This function currently requires that mass profiles are `IsothermalSph` objects and that light profiles are
`Sersic` objects. This will be generalised in the future.
Parameters
----------
result
The result, which includes extra galaxies, of the previous search, which via prior passing are used to create
the new extra galaxy model.
The result, which includes clumps, of the previous search, which via prior passing are used to create the new
clump model.
light_as_model
If `True`, the extra_galaxy light is passed as a model component, else it is a fixed instance.
If `True`, the clump light is passed as a model component, else it is a fixed instance.
mass_as_model
If `True`, the extra_galaxy mass is passed as a model component, else it is a fixed instance.
If `True`, the clump mass is passed as a model component, else it is a fixed instance.
free_centre
If `True`, the requested mass and/or light model centres are passed as a model, else they are fixed.
Returns
-------
af.Collection
A collection of extra galaxy `Galaxy` objects, where each is either an instance or model component.
A collection of clump `Galaxy` objects, where each clump is either an instance or model component.
"""
# ideal API:

# extra_galaxies = result.instance.extra_galaxies.as_model((LightProfile, mp.MassProfile,), fixed="centre", prior_pass=True)

if result.instance.extra_galaxies is None:
return None
# clumps = result.instance.clumps.as_model((LightProfile, mp.MassProfile,), fixed="centre", prior_pass=True)

if mass_as_model:
extra_galaxies = result.instance.extra_galaxies.as_model((MassProfile,))

for extra_galaxy_index in range(len(result.instance.extra_galaxies)):
if hasattr(result.instance.extra_galaxies[extra_galaxy_index], "mass"):
extra_galaxies[
extra_galaxy_index
].mass.centre = result.instance.extra_galaxies[
extra_galaxy_index
clumps = result.instance.clumps.as_model((MassProfile,))

for clump_index in range(len(result.instance.clumps)):
if hasattr(result.instance.clumps[clump_index], "mass"):
clumps[clump_index].mass.centre = result.instance.clumps[
clump_index
].mass.centre
extra_galaxies[
extra_galaxy_index
].mass.einstein_radius = result.model.extra_galaxies[
extra_galaxy_index
clumps[clump_index].mass.einstein_radius = result.model.clumps[
clump_index
].mass.einstein_radius
if free_centre:
extra_galaxies[
extra_galaxy_index
].mass.centre = result.model.extra_galaxies[
extra_galaxy_index
clumps[clump_index].mass.centre = result.model.clumps[
clump_index
].mass.centre

elif light_as_model:
extra_galaxies = result.instance.extra_galaxies.as_model((LightProfile,))

for extra_galaxy_index in range(len(result.instance.extra_galaxies)):
if extra_galaxies[extra_galaxy_index].bulge is not None:
extra_galaxies[
extra_galaxy_index
].bulge.centre = result.instance.extra_galaxies[
extra_galaxy_index
].bulge.centre
clumps = result.instance.clumps.as_model((LightProfile,))

for clump_index in range(len(result.instance.clumps)):
if clumps[clump_index].light is not None:
clumps[clump_index].light.centre = result.instance.clumps[
clump_index
].light.centre
if free_centre:
extra_galaxies[
extra_galaxy_index
].bulge.centre = result.model.extra_galaxies[
extra_galaxy_index
].bulge.centre
clumps[clump_index].light.centre = result.model.clumps[
clump_index
].light.centre

else:
extra_galaxies = result.instance.extra_galaxies.as_model(())
clumps = result.instance.clumps.as_model(())

return extra_galaxies
return clumps


def lp_chain_tracer_from(light_result, settings_search):
Expand Down
Loading

0 comments on commit 686ddad

Please sign in to comment.